Coverage Report

Created: 2019-06-19 13:33

/src/systemd/src/basic/io-util.h
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: LGPL-2.1+ */
2
#pragma once
3
4
#include <stdbool.h>
5
#include <stddef.h>
6
#include <stdint.h>
7
#include <sys/types.h>
8
#include <sys/uio.h>
9
10
#include "macro.h"
11
#include "time-util.h"
12
13
int flush_fd(int fd);
14
15
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);
16
int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll);
17
int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll);
18
19
int pipe_eof(int fd);
20
21
int fd_wait_for_event(int fd, int event, usec_t timeout);
22
23
ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length);
24
25
0
static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) {
26
0
        size_t j, r = 0;
27
0
28
0
        for (j = 0; j < n; j++)
29
0
                r += i[j].iov_len;
30
0
31
0
        return r;
32
0
}
Unexecuted instantiation: sd-dhcp-client.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-dhcp-server.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-radv.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: icmp6-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-kmsg.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-server.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-stream.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-syslog.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-audit.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-console.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-context.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journald-native.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: load-fragment.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: manager.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: show-status.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: socket.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: unit.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: automount.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: dynamic-user.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: execute.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: dbus-execute.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: fuzz-varlink.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: fuzz-dhcp-server.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: libudev-queue.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: ask-password-api.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: efivars.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journal-importer.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: logs-show.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: nscd-flush.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: pager.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: spawn-polkit-agent.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: btrfs-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: copy.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: fd-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: io-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: log.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: random-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: terminal-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: time-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: bus-message.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: bus-socket.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: device-monitor.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: netlink-socket.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-resolve.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: id128-util.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-id128.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-daemon.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-login.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: compress.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: journal-send.c:IOVEC_TOTAL_SIZE
Unexecuted instantiation: sd-journal.c:IOVEC_TOTAL_SIZE
33
34
547k
static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
35
547k
        size_t j;
36
547k
37
1.09M
        for (j = 0; j < n; j++) {
38
547k
                size_t sub;
39
547k
40
547k
                if (_unlikely_(k <= 0))
41
547k
                        break;
42
547k
43
547k
                sub = MIN(i[j].iov_len, k);
44
547k
                i[j].iov_len -= sub;
45
547k
                i[j].iov_base = (uint8_t*) i[j].iov_base + sub;
46
547k
                k -= sub;
47
547k
        }
48
547k
49
547k
        return k;
50
547k
}
Unexecuted instantiation: sd-dhcp-client.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-dhcp-server.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-radv.c:IOVEC_INCREMENT
Unexecuted instantiation: icmp6-util.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-kmsg.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-server.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-stream.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-syslog.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-audit.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-console.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-context.c:IOVEC_INCREMENT
Unexecuted instantiation: journald-native.c:IOVEC_INCREMENT
Unexecuted instantiation: load-fragment.c:IOVEC_INCREMENT
Unexecuted instantiation: manager.c:IOVEC_INCREMENT
Unexecuted instantiation: show-status.c:IOVEC_INCREMENT
Unexecuted instantiation: socket.c:IOVEC_INCREMENT
Unexecuted instantiation: unit.c:IOVEC_INCREMENT
Unexecuted instantiation: automount.c:IOVEC_INCREMENT
Unexecuted instantiation: dynamic-user.c:IOVEC_INCREMENT
Unexecuted instantiation: execute.c:IOVEC_INCREMENT
Unexecuted instantiation: dbus-execute.c:IOVEC_INCREMENT
fuzz-varlink.c:IOVEC_INCREMENT
Line
Count
Source
34
547k
static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
35
547k
        size_t j;
36
547k
37
1.09M
        for (j = 0; j < n; j++) {
38
547k
                size_t sub;
39
547k
40
547k
                if (_unlikely_(k <= 0))
41
547k
                        break;
42
547k
43
547k
                sub = MIN(i[j].iov_len, k);
44
547k
                i[j].iov_len -= sub;
45
547k
                i[j].iov_base = (uint8_t*) i[j].iov_base + sub;
46
547k
                k -= sub;
47
547k
        }
48
547k
49
547k
        return k;
50
547k
}
Unexecuted instantiation: fuzz-dhcp-server.c:IOVEC_INCREMENT
Unexecuted instantiation: libudev-queue.c:IOVEC_INCREMENT
Unexecuted instantiation: ask-password-api.c:IOVEC_INCREMENT
Unexecuted instantiation: efivars.c:IOVEC_INCREMENT
Unexecuted instantiation: journal-importer.c:IOVEC_INCREMENT
Unexecuted instantiation: logs-show.c:IOVEC_INCREMENT
Unexecuted instantiation: nscd-flush.c:IOVEC_INCREMENT
Unexecuted instantiation: pager.c:IOVEC_INCREMENT
Unexecuted instantiation: spawn-polkit-agent.c:IOVEC_INCREMENT
Unexecuted instantiation: btrfs-util.c:IOVEC_INCREMENT
Unexecuted instantiation: copy.c:IOVEC_INCREMENT
Unexecuted instantiation: fd-util.c:IOVEC_INCREMENT
Unexecuted instantiation: io-util.c:IOVEC_INCREMENT
Unexecuted instantiation: log.c:IOVEC_INCREMENT
Unexecuted instantiation: random-util.c:IOVEC_INCREMENT
Unexecuted instantiation: terminal-util.c:IOVEC_INCREMENT
Unexecuted instantiation: time-util.c:IOVEC_INCREMENT
Unexecuted instantiation: bus-message.c:IOVEC_INCREMENT
Unexecuted instantiation: bus-socket.c:IOVEC_INCREMENT
Unexecuted instantiation: device-monitor.c:IOVEC_INCREMENT
Unexecuted instantiation: netlink-socket.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-resolve.c:IOVEC_INCREMENT
Unexecuted instantiation: id128-util.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-id128.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-daemon.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-login.c:IOVEC_INCREMENT
Unexecuted instantiation: compress.c:IOVEC_INCREMENT
Unexecuted instantiation: journal-send.c:IOVEC_INCREMENT
Unexecuted instantiation: sd-journal.c:IOVEC_INCREMENT
51
52
0
static inline bool FILE_SIZE_VALID(uint64_t l) {
53
0
        /* ftruncate() and friends take an unsigned file size, but actually cannot deal with file sizes larger than
54
0
         * 2^63 since the kernel internally handles it as signed value. This call allows checking for this early. */
55
0
56
0
        return (l >> 63) == 0;
57
0
}
Unexecuted instantiation: sd-dhcp-client.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-dhcp-server.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-radv.c:FILE_SIZE_VALID
Unexecuted instantiation: icmp6-util.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-kmsg.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-server.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-stream.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-syslog.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-audit.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-console.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-context.c:FILE_SIZE_VALID
Unexecuted instantiation: journald-native.c:FILE_SIZE_VALID
Unexecuted instantiation: load-fragment.c:FILE_SIZE_VALID
Unexecuted instantiation: manager.c:FILE_SIZE_VALID
Unexecuted instantiation: show-status.c:FILE_SIZE_VALID
Unexecuted instantiation: socket.c:FILE_SIZE_VALID
Unexecuted instantiation: unit.c:FILE_SIZE_VALID
Unexecuted instantiation: automount.c:FILE_SIZE_VALID
Unexecuted instantiation: dynamic-user.c:FILE_SIZE_VALID
Unexecuted instantiation: execute.c:FILE_SIZE_VALID
Unexecuted instantiation: dbus-execute.c:FILE_SIZE_VALID
Unexecuted instantiation: fuzz-varlink.c:FILE_SIZE_VALID
Unexecuted instantiation: fuzz-dhcp-server.c:FILE_SIZE_VALID
Unexecuted instantiation: libudev-queue.c:FILE_SIZE_VALID
Unexecuted instantiation: ask-password-api.c:FILE_SIZE_VALID
Unexecuted instantiation: efivars.c:FILE_SIZE_VALID
Unexecuted instantiation: journal-importer.c:FILE_SIZE_VALID
Unexecuted instantiation: logs-show.c:FILE_SIZE_VALID
Unexecuted instantiation: nscd-flush.c:FILE_SIZE_VALID
Unexecuted instantiation: pager.c:FILE_SIZE_VALID
Unexecuted instantiation: spawn-polkit-agent.c:FILE_SIZE_VALID
Unexecuted instantiation: btrfs-util.c:FILE_SIZE_VALID
Unexecuted instantiation: copy.c:FILE_SIZE_VALID
Unexecuted instantiation: fd-util.c:FILE_SIZE_VALID
Unexecuted instantiation: io-util.c:FILE_SIZE_VALID
Unexecuted instantiation: log.c:FILE_SIZE_VALID
Unexecuted instantiation: random-util.c:FILE_SIZE_VALID
Unexecuted instantiation: terminal-util.c:FILE_SIZE_VALID
Unexecuted instantiation: time-util.c:FILE_SIZE_VALID
Unexecuted instantiation: bus-message.c:FILE_SIZE_VALID
Unexecuted instantiation: bus-socket.c:FILE_SIZE_VALID
Unexecuted instantiation: device-monitor.c:FILE_SIZE_VALID
Unexecuted instantiation: netlink-socket.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-resolve.c:FILE_SIZE_VALID
Unexecuted instantiation: id128-util.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-id128.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-daemon.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-login.c:FILE_SIZE_VALID
Unexecuted instantiation: compress.c:FILE_SIZE_VALID
Unexecuted instantiation: journal-send.c:FILE_SIZE_VALID
Unexecuted instantiation: sd-journal.c:FILE_SIZE_VALID
58
59
0
static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) {
60
0
61
0
        /* Same as above, but allows one extra value: -1 as indication for infinity. */
62
0
63
0
        if (l == (uint64_t) -1)
64
0
                return true;
65
0
66
0
        return FILE_SIZE_VALID(l);
67
0
68
0
}
Unexecuted instantiation: sd-dhcp-client.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-dhcp-server.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-radv.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: icmp6-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-kmsg.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-server.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-stream.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-syslog.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-audit.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-console.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-context.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journald-native.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: load-fragment.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: manager.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: show-status.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: socket.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: unit.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: automount.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: dynamic-user.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: execute.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: dbus-execute.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: fuzz-varlink.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: fuzz-dhcp-server.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: libudev-queue.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: ask-password-api.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: efivars.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journal-importer.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: logs-show.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: nscd-flush.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: pager.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: spawn-polkit-agent.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: btrfs-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: copy.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: fd-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: io-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: log.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: random-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: terminal-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: time-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: bus-message.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: bus-socket.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: device-monitor.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: netlink-socket.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-resolve.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: id128-util.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-id128.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-daemon.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-login.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: compress.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: journal-send.c:FILE_SIZE_VALID_OR_INFINITY
Unexecuted instantiation: sd-journal.c:FILE_SIZE_VALID_OR_INFINITY
69
70
21.4M
#define IOVEC_INIT(base, len) { .iov_base = (base), .iov_len = (len) }
71
5.46M
#define IOVEC_MAKE(base, len) (struct iovec) IOVEC_INIT(base, len)
72
15.9M
#define IOVEC_INIT_STRING(string) IOVEC_INIT((char*) string, strlen(string))
73
15.9M
#define IOVEC_MAKE_STRING(string) (struct iovec) IOVEC_INIT_STRING(string)
74
75
char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value);