1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-28 05:57:33 +03:00

Merge pull request #17273 from mrc0mmand/coccinelle-check-for-bad-errno

coccinelle: resolve our own macros to avoid skipping functions
This commit is contained in:
Lennart Poettering 2020-10-12 11:39:25 +02:00 committed by GitHub
commit 656f7f8aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
70 changed files with 635 additions and 432 deletions

View File

@ -0,0 +1,10 @@
@@
constant c;
@@
(
- errno == -c
+ errno == c
|
- errno != -c
+ errno != c
)

231
coccinelle/macros.h Normal file
View File

@ -0,0 +1,231 @@
/* Collected macros from our systemd codebase to make the cocci semantic
* parser happy. Inspired by the original cocci macros file
* /usr/lib64/coccinelle/standard.h (including the YACFE_* symbols)
*/
// General
#define PTR_TO_PID(x)
// src/basic/macro.h
#define _printf_(a, b) __attribute__((__format__(printf, a, b)))
#define _alloc_(...) __attribute__((__alloc_size__(__VA_ARGS__)))
#define _sentinel_ __attribute__((__sentinel__))
#define _section_(x) __attribute__((__section__(x)))
#define _used_ __attribute__((__used__))
#define _unused_ __attribute__((__unused__))
#define _destructor_ __attribute__((__destructor__))
#define _pure_ __attribute__((__pure__))
#define _const_ __attribute__((__const__))
#define _deprecated_ __attribute__((__deprecated__))
#define _packed_ __attribute__((__packed__))
#define _malloc_ __attribute__((__malloc__))
#define _weak_ __attribute__((__weak__))
#define _likely_(x) (__builtin_expect(!!(x), 1))
#define _unlikely_(x) (__builtin_expect(!!(x), 0))
#define _public_ __attribute__((__visibility__("default")))
#define _hidden_ __attribute__((__visibility__("hidden")))
#define _weakref_(x) __attribute__((__weakref__(#x)))
#define _align_(x) __attribute__((__aligned__(x)))
#define _alignas_(x) __attribute__((__aligned__(__alignof(x))))
#define _alignptr_ __attribute__((__aligned__(sizeof(void*))))
#define _cleanup_(x) __attribute__((__cleanup__(x)))
#define _fallthrough_
#define _noreturn_ __attribute__((__noreturn__))
#define thread_local __thread
#define ELEMENTSOF(x) \
(__builtin_choose_expr( \
!__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
sizeof(x)/sizeof((x)[0]), \
VOID_0))
// src/basic/umask-util.h
#define _cleanup_umask_
#define RUN_WITH_UMASK(mask) \
for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
FLAGS_SET(_saved_umask_, S_IFMT); \
_saved_umask_ &= 0777)
// src/basic/hashmap.h
#define _IDX_ITERATOR_FIRST (UINT_MAX - 1)
#define HASHMAP_FOREACH(e, h) YACFE_ITERATOR
#define ORDERED_HASHMAP_FOREACH(e, h) YACFE_ITERATOR
#define HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
#define ORDERED_HASHMAP_FOREACH_KEY(e, k, h) YACFE_ITERATOR
// src/basic/list.h
#define LIST_HEAD(t,name) \
t *name
#define LIST_FIELDS(t,name) \
t *name##_next, *name##_prev
#define LIST_HEAD_INIT(head) \
do { \
(head) = NULL; \
} while (false)
#define LIST_INIT(name,item) \
do { \
typeof(*(item)) *_item = (item); \
assert(_item); \
_item->name##_prev = _item->name##_next = NULL; \
} while (false)
#define LIST_PREPEND(name,head,item) \
do { \
typeof(*(head)) **_head = &(head), *_item = (item); \
assert(_item); \
if ((_item->name##_next = *_head)) \
_item->name##_next->name##_prev = _item; \
_item->name##_prev = NULL; \
*_head = _item; \
} while (false)
#define LIST_APPEND(name,head,item) \
do { \
typeof(*(head)) **_hhead = &(head), *_tail; \
LIST_FIND_TAIL(name, *_hhead, _tail); \
LIST_INSERT_AFTER(name, *_hhead, _tail, item); \
} while (false)
#define LIST_REMOVE(name,head,item) \
do { \
typeof(*(head)) **_head = &(head), *_item = (item); \
assert(_item); \
if (_item->name##_next) \
_item->name##_next->name##_prev = _item->name##_prev; \
if (_item->name##_prev) \
_item->name##_prev->name##_next = _item->name##_next; \
else { \
assert(*_head == _item); \
*_head = _item->name##_next; \
} \
_item->name##_next = _item->name##_prev = NULL; \
} while (false)
#define LIST_FIND_HEAD(name,item,head) \
do { \
typeof(*(item)) *_item = (item); \
if (!_item) \
(head) = NULL; \
else { \
while (_item->name##_prev) \
_item = _item->name##_prev; \
(head) = _item; \
} \
} while (false)
#define LIST_FIND_TAIL(name,item,tail) \
do { \
typeof(*(item)) *_item = (item); \
if (!_item) \
(tail) = NULL; \
else { \
while (_item->name##_next) \
_item = _item->name##_next; \
(tail) = _item; \
} \
} while (false)
#define LIST_INSERT_AFTER(name,head,a,b) \
do { \
typeof(*(head)) **_head = &(head), *_a = (a), *_b = (b); \
assert(_b); \
if (!_a) { \
if ((_b->name##_next = *_head)) \
_b->name##_next->name##_prev = _b; \
_b->name##_prev = NULL; \
*_head = _b; \
} else { \
if ((_b->name##_next = _a->name##_next)) \
_b->name##_next->name##_prev = _b; \
_b->name##_prev = _a; \
_a->name##_next = _b; \
} \
} while (false)
#define LIST_INSERT_BEFORE(name,head,a,b) \
do { \
typeof(*(head)) **_head = &(head), *_a = (a), *_b = (b); \
assert(_b); \
if (!_a) { \
if (!*_head) { \
_b->name##_next = NULL; \
_b->name##_prev = NULL; \
*_head = _b; \
} else { \
typeof(*(head)) *_tail = (head); \
while (_tail->name##_next) \
_tail = _tail->name##_next; \
_b->name##_next = NULL; \
_b->name##_prev = _tail; \
_tail->name##_next = _b; \
} \
} else { \
if ((_b->name##_prev = _a->name##_prev)) \
_b->name##_prev->name##_next = _b; \
else \
*_head = _b; \
_b->name##_next = _a; \
_a->name##_prev = _b; \
} \
} while (false)
#define LIST_JUST_US(name,item) \
(!(item)->name##_prev && !(item)->name##_next) \
#define LIST_FOREACH(name,i,head) \
for ((i) = (head); (i); (i) = (i)->name##_next)
#define LIST_FOREACH_SAFE(name,i,n,head) \
for ((i) = (head); (i) && (((n) = (i)->name##_next), 1); (i) = (n))
#define LIST_FOREACH_BEFORE(name,i,p) \
for ((i) = (p)->name##_prev; (i); (i) = (i)->name##_prev)
#define LIST_FOREACH_AFTER(name,i,p) \
for ((i) = (p)->name##_next; (i); (i) = (i)->name##_next)
#define LIST_FOREACH_OTHERS(name,i,p) \
for (({ \
(i) = (p); \
while ((i) && (i)->name##_prev) \
(i) = (i)->name##_prev; \
if ((i) == (p)) \
(i) = (p)->name##_next; \
}); \
(i); \
(i) = (i)->name##_next == (p) ? (p)->name##_next : (i)->name##_next)
#define LIST_LOOP_BUT_ONE(name,i,head,p) \
for ((i) = (p)->name##_next ? (p)->name##_next : (head); \
(i) != (p); \
(i) = (i)->name##_next ? (i)->name##_next : (head))
#define LIST_IS_EMPTY(head) \
(!(head))
#define LIST_JOIN(name,a,b) \
do { \
assert(b); \
if (!(a)) \
(a) = (b); \
else { \
typeof(*(a)) *_head = (b), *_tail; \
LIST_FIND_TAIL(name, (a), _tail); \
_tail->name##_next = _head; \
_head->name##_prev = _tail; \
} \
(b) = NULL; \
} while (false)
// src/basic/strv.h
#define STRV_FOREACH(s, l) YACFE_ITERATOR
#define STRV_FOREACH_BACKWARDS(s, l) YACFE_ITERATOR
#define STRV_FOREACH_PAIR(x, y, l) YACFE_ITERATOR
// src/basic/socket-util.h
#define CMSG_BUFFER_TYPE(size) \
union { \
struct cmsghdr cmsghdr; \
uint8_t buf[size]; \
uint8_t align_check[(size) >= CMSG_SPACE(0) && \
(size) == CMSG_ALIGN(size) ? 1 : -1]; \
}
// src/libsystemd/sd-device/device-util.h
#define FOREACH_DEVICE_PROPERTY(device, key, value) YACFE_ITERATOR
#define FOREACH_DEVICE_TAG(device, tag) YACFE_ITERATOR
#define FOREACH_DEVICE_CURRENT_TAG(device, tag) YACFE_ITERATOR
#define FOREACH_DEVICE_SYSATTR(device, attr) YACFE_ITERATOR
#define FOREACH_DEVICE_DEVLINK(device, devlink) YACFE_ITERATOR
#define FOREACH_DEVICE(enumerator, device) YACFE_ITERATOR
#define FOREACH_SUBSYSTEM(enumerator, device) YACFE_ITERATOR
// src/basic/dirent-util.h
#define FOREACH_DIRENT(de, d, on_error) YACFE_ITERATOR
#define FOREACH_DIRENT_ALL(de, d, on_error) YACFE_ITERATOR

View File

@ -31,12 +31,12 @@ if ! parallel -h >/dev/null; then
exit 1 exit 1
fi fi
for SCRIPT in ${@-$top/coccinelle/*.cocci} ; do for SCRIPT in ${@-$top/coccinelle/*.cocci}; do
echo "--x-- Processing $SCRIPT --x--" echo "--x-- Processing $SCRIPT --x--"
TMPFILE=`mktemp` TMPFILE=`mktemp`
echo "+ spatch --sp-file $SCRIPT $args ..." echo "+ spatch --sp-file $SCRIPT $args ..."
parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \ parallel --halt now,fail=1 --keep-order --noswap --max-args=20 \
spatch --sp-file $SCRIPT $args ::: "${files[@]}" \ spatch --macro-file="$top/coccinelle/macros.h" --sp-file $SCRIPT $args ::: "${files[@]}" \
2>"$TMPFILE" || cat "$TMPFILE" 2>"$TMPFILE" || cat "$TMPFILE"
echo -e "--x-- Processed $SCRIPT --x--\n" echo -e "--x-- Processed $SCRIPT --x--\n"
done done

View File

@ -0,0 +1,27 @@
@@
position p : script:python() { p[0].file != "src/journal/lookup3.c" };
identifier id;
expression e;
@@
if (...)
- {
(
id@p(...);
|
e@p;
)
- }
@@
position p : script:python() { p[0].file != "src/journal/lookup3.c" };
identifier id;
expression e;
@@
if (...)
- {
(
return id@p(...);
|
return e@p;
)
- }

View File

@ -2185,10 +2185,10 @@ int analyze_security(sd_bus *bus, char **units, AnalyzeSecurityFlags flags) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to mangle unit name '%s': %m", *i); return log_error_errno(r, "Failed to mangle unit name '%s': %m", *i);
if (!endswith(mangled, ".service")) { if (!endswith(mangled, ".service"))
log_error("Unit %s is not a service unit, refusing.", *i); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unit %s is not a service unit, refusing.",
} *i);
if (unit_name_is_valid(mangled, UNIT_NAME_TEMPLATE)) { if (unit_name_is_valid(mangled, UNIT_NAME_TEMPLATE)) {
r = unit_name_replace_instance(mangled, "test-instance", &instance); r = unit_name_replace_instance(mangled, "test-instance", &instance);

View File

@ -1248,8 +1248,7 @@ static int expand_patterns(sd_bus *bus, char **patterns, char ***ret) {
} }
} }
*ret = expanded_patterns; *ret = TAKE_PTR(expanded_patterns); /* do not free */
expanded_patterns = NULL; /* do not free */
return 0; return 0;
} }

View File

@ -1393,14 +1393,13 @@ static int copy_quota_hierarchy(int fd, uint64_t old_subvol_id, uint64_t new_sub
} }
for (j = 0; j < n_old_parent_qgroups; j++) for (j = 0; j < n_old_parent_qgroups; j++)
if (old_parent_qgroups[j] == old_qgroups[i]) { if (old_parent_qgroups[j] == old_qgroups[i])
/* The old subvolume shared a common /* The old subvolume shared a common
* parent qgroup with its parent * parent qgroup with its parent
* subvolume. Let's set up something * subvolume. Let's set up something
* similar in the destination. */ * similar in the destination. */
copy_from_parent = true; copy_from_parent = true;
} }
}
if (!insert_intermediary_qgroup && !copy_from_parent) if (!insert_intermediary_qgroup && !copy_from_parent)
return 0; return 0;

View File

@ -160,8 +160,7 @@ int khash_new_with_key(khash **ret, const char *algorithm, const void *key, size
/* Temporary fix for rc kernel bug: https://bugzilla.redhat.com/show_bug.cgi?id=1395896 */ /* Temporary fix for rc kernel bug: https://bugzilla.redhat.com/show_bug.cgi?id=1395896 */
(void) send(h->fd, NULL, 0, 0); (void) send(h->fd, NULL, 0, 0);
*ret = h; *ret = TAKE_PTR(h);
h = NULL;
return 0; return 0;
} }

View File

@ -129,8 +129,5 @@ int socket_address_listen(
if (p) if (p)
(void) touch(p); (void) touch(p);
r = fd; return TAKE_FD(fd);
fd = -1;
return r;
} }

View File

@ -1130,14 +1130,13 @@ static int introspect(int argc, char **argv, void *userdata) {
(void) pager_open(arg_pager_flags); (void) pager_open(arg_pager_flags);
if (arg_legend) { if (arg_legend)
printf("%-*s %-*s %-*s %-*s %s\n", printf("%-*s %-*s %-*s %-*s %s\n",
(int) name_width, "NAME", (int) name_width, "NAME",
(int) type_width, "TYPE", (int) type_width, "TYPE",
(int) signature_width, "SIGNATURE", (int) signature_width, "SIGNATURE",
(int) result_width, "RESULT/VALUE", (int) result_width, "RESULT/VALUE",
"FLAGS"); "FLAGS");
}
for (j = 0; j < k; j++) { for (j = 0; j < k; j++) {
_cleanup_free_ char *ellipsized = NULL; _cleanup_free_ char *ellipsized = NULL;

View File

@ -540,10 +540,8 @@ static void automount_trigger_notify(Unit *u, Unit *other) {
MOUNT_MOUNTED, MOUNT_REMOUNTING, MOUNT_MOUNTED, MOUNT_REMOUNTING,
MOUNT_REMOUNTING_SIGTERM, MOUNT_REMOUNTING_SIGKILL, MOUNT_REMOUNTING_SIGTERM, MOUNT_REMOUNTING_SIGKILL,
MOUNT_UNMOUNTING_SIGTERM, MOUNT_UNMOUNTING_SIGKILL, MOUNT_UNMOUNTING_SIGTERM, MOUNT_UNMOUNTING_SIGKILL,
MOUNT_FAILED)) { MOUNT_FAILED))
(void) automount_send_ready(a, a->expire_tokens, -ENODEV); (void) automount_send_ready(a, a->expire_tokens, -ENODEV);
}
if (MOUNT(other)->state == MOUNT_DEAD) if (MOUNT(other)->state == MOUNT_DEAD)
(void) automount_send_ready(a, a->expire_tokens, 0); (void) automount_send_ready(a, a->expire_tokens, 0);

View File

@ -1500,9 +1500,9 @@ int bus_cgroup_set_property(
LIST_PREPEND(device_allow, c->device_allow, a); LIST_PREPEND(device_allow, c->device_allow, a);
} }
a->r = !!strchr(rwm, 'r'); a->r = strchr(rwm, 'r');
a->w = !!strchr(rwm, 'w'); a->w = strchr(rwm, 'w');
a->m = !!strchr(rwm, 'm'); a->m = strchr(rwm, 'm');
} }
n++; n++;

View File

@ -5772,11 +5772,10 @@ void exec_status_start(ExecStatus *s, pid_t pid) {
void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int code, int status) { void exec_status_exit(ExecStatus *s, const ExecContext *context, pid_t pid, int code, int status) {
assert(s); assert(s);
if (s->pid != pid) { if (s->pid != pid)
*s = (ExecStatus) { *s = (ExecStatus) {
.pid = pid, .pid = pid,
}; };
}
dual_timestamp_get(&s->exit_timestamp); dual_timestamp_get(&s->exit_timestamp);

View File

@ -1064,13 +1064,11 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option code."); assert_not_reached("Unhandled option code.");
} }
if (optind < argc && getpid_cached() != 1) { if (optind < argc && getpid_cached() != 1)
/* Hmm, when we aren't run as init system /* Hmm, when we aren't run as init system
* let's complain about excess arguments */ * let's complain about excess arguments */
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Excess arguments."); "Excess arguments.");
}
return 0; return 0;
} }
@ -1564,7 +1562,7 @@ static void initialize_clock(void) {
else else
log_info("RTC configured in localtime, applying delta of %i minutes to system time.", min); log_info("RTC configured in localtime, applying delta of %i minutes to system time.", min);
} else if (!in_initrd()) { } else if (!in_initrd())
/* /*
* Do a dummy very first call to seal the kernel's time warp magic. * Do a dummy very first call to seal the kernel's time warp magic.
* *
@ -1577,7 +1575,6 @@ static void initialize_clock(void) {
* be treated as UTC that way. * be treated as UTC that way.
*/ */
(void) clock_reset_timewarp(); (void) clock_reset_timewarp();
}
r = clock_apply_epoch(); r = clock_apply_epoch();
if (r < 0) if (r < 0)

View File

@ -1618,13 +1618,12 @@ int setup_namespace(
if (r < 0) if (r < 0)
goto finish; goto finish;
if (ns_info->private_dev) { if (ns_info->private_dev)
*(m++) = (MountEntry) { *(m++) = (MountEntry) {
.path_const = "/dev", .path_const = "/dev",
.mode = PRIVATE_DEV, .mode = PRIVATE_DEV,
.flags = DEV_MOUNT_OPTIONS, .flags = DEV_MOUNT_OPTIONS,
}; };
}
if (ns_info->protect_kernel_tunables) { if (ns_info->protect_kernel_tunables) {
r = append_static_mounts(&m, r = append_static_mounts(&m,
@ -1653,12 +1652,11 @@ int setup_namespace(
goto finish; goto finish;
} }
if (ns_info->protect_control_groups) { if (ns_info->protect_control_groups)
*(m++) = (MountEntry) { *(m++) = (MountEntry) {
.path_const = "/sys/fs/cgroup", .path_const = "/sys/fs/cgroup",
.mode = READONLY, .mode = READONLY,
}; };
}
r = append_protect_home(&m, ns_info->protect_home, ns_info->ignore_protect_paths); r = append_protect_home(&m, ns_info->protect_home, ns_info->ignore_protect_paths);
if (r < 0) if (r < 0)

View File

@ -96,10 +96,9 @@ int mac_selinux_setup(bool *loaded_policy) {
log_open(); log_open();
if (enforce > 0) { if (enforce > 0) {
if (!initialized) { if (!initialized)
log_emergency("Failed to load SELinux policy."); return log_emergency_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Failed to load SELinux policy.");
}
log_warning("Failed to load new SELinux policy. Continuing with old policy."); log_warning("Failed to load new SELinux policy. Continuing with old policy.");
} else } else

View File

@ -4201,7 +4201,7 @@ static void service_bus_name_owner_change(Unit *u, const char *new_owner) {
else else
log_unit_debug(u, "D-Bus name %s now not owned by anyone.", s->bus_name); log_unit_debug(u, "D-Bus name %s now not owned by anyone.", s->bus_name);
s->bus_name_good = !!new_owner; s->bus_name_good = new_owner;
/* Track the current owner, so we can reconstruct changes after a daemon reload */ /* Track the current owner, so we can reconstruct changes after a daemon reload */
r = free_and_strdup(&s->bus_name_owner, new_owner); r = free_and_strdup(&s->bus_name_owner, new_owner);

View File

@ -353,7 +353,7 @@ static int save_external_coredump(
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse resource limit '%s': %m", return log_error_errno(r, "Failed to parse resource limit '%s': %m",
context->meta[META_ARGV_RLIMIT]); context->meta[META_ARGV_RLIMIT]);
if (rlimit < page_size()) { if (rlimit < page_size())
/* Is coredumping disabled? Then don't bother saving/processing the /* Is coredumping disabled? Then don't bother saving/processing the
* coredump. Anything below PAGE_SIZE cannot give a readable coredump * coredump. Anything below PAGE_SIZE cannot give a readable coredump
* (the kernel uses ELF_EXEC_PAGESIZE which is not easily accessible, but * (the kernel uses ELF_EXEC_PAGESIZE which is not easily accessible, but
@ -361,7 +361,6 @@ static int save_external_coredump(
return log_info_errno(SYNTHETIC_ERRNO(EBADSLT), return log_info_errno(SYNTHETIC_ERRNO(EBADSLT),
"Resource limits disable core dumping for process %s (%s).", "Resource limits disable core dumping for process %s (%s).",
context->meta[META_ARGV_PID], context->meta[META_COMM]); context->meta[META_ARGV_PID], context->meta[META_COMM]);
}
process_limit = MAX(arg_process_size_max, storage_size_max()); process_limit = MAX(arg_process_size_max, storage_size_max());
if (process_limit == 0) if (process_limit == 0)

View File

@ -888,10 +888,9 @@ static int dump_core(int argc, char **argv, void *userdata) {
_cleanup_fclose_ FILE *f = NULL; _cleanup_fclose_ FILE *f = NULL;
int r; int r;
if (arg_field) { if (arg_field)
log_error("Option --field/-F only makes sense with list"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --field/-F only makes sense with list");
}
r = acquire_journal(&j, argv + 1); r = acquire_journal(&j, argv + 1);
if (r < 0) if (r < 0)
@ -943,10 +942,9 @@ static int run_debug(int argc, char **argv, void *userdata) {
if (!debugger) if (!debugger)
return -ENOMEM; return -ENOMEM;
if (arg_field) { if (arg_field)
log_error("Option --field/-F only makes sense with list"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --field/-F only makes sense with list");
}
r = acquire_journal(&j, argv + 1); r = acquire_journal(&j, argv + 1);
if (r < 0) if (r < 0)
@ -971,15 +969,13 @@ static int run_debug(int argc, char **argv, void *userdata) {
if (!exe) if (!exe)
return log_oom(); return log_oom();
if (endswith(exe, " (deleted)")) { if (endswith(exe, " (deleted)"))
log_error("Binary already deleted."); return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
return -ENOENT; "Binary already deleted.");
}
if (!path_is_absolute(exe)) { if (!path_is_absolute(exe))
log_error("Binary is not an absolute path."); return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
return -ENOENT; "Binary is not an absolute path.");
}
r = save_core(j, NULL, &path, &unlink_path); r = save_core(j, NULL, &path, &unlink_path);
if (r < 0) if (r < 0)

View File

@ -378,7 +378,7 @@ static int create_disk(
else else
fprintf(f, "Requires=%s\n", unit); fprintf(f, "Requires=%s\n", unit);
if (umount_unit) { if (umount_unit)
fprintf(f, fprintf(f,
"Wants=%s\n" "Wants=%s\n"
"Before=%s\n", "Before=%s\n",
@ -386,7 +386,6 @@ static int create_disk(
umount_unit umount_unit
); );
} }
}
if (!nofail) if (!nofail)
fprintf(f, fprintf(f,

View File

@ -832,10 +832,9 @@ static int run(int argc, char *argv[]) {
if (argc <= 1) if (argc <= 1)
return help(); return help();
if (argc < 3) { if (argc < 3)
log_error("This program requires at least two arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program requires at least two arguments.");
}
log_setup_service(); log_setup_service();

View File

@ -258,10 +258,9 @@ static int run(int argc, char *argv[]) {
log_setup_service(); log_setup_service();
if (argc > 2) { if (argc > 2)
log_error("This program expects one or no arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program expects one or no arguments.");
}
umask(0022); umask(0022);
@ -284,10 +283,10 @@ static int run(int argc, char *argv[]) {
if (stat(device, &st) < 0) if (stat(device, &st) < 0)
return log_error_errno(errno, "Failed to stat %s: %m", device); return log_error_errno(errno, "Failed to stat %s: %m", device);
if (!S_ISBLK(st.st_mode)) { if (!S_ISBLK(st.st_mode))
log_error("%s is not a block device.", device); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s is not a block device.",
} device);
r = sd_device_new_from_devnum(&dev, 'b', st.st_rdev); r = sd_device_new_from_devnum(&dev, 'b', st.st_rdev);
if (r < 0) if (r < 0)

View File

@ -401,7 +401,8 @@ int identity_add_fido2_parameters(
return 0; return 0;
#else #else
return log_error_errno(EOPNOTSUPP, "FIDO2 tokens not supported on this build."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"FIDO2 tokens not supported on this build.");
#endif #endif
} }
@ -467,7 +468,8 @@ finish:
fido_dev_info_free(&di, allocated); fido_dev_info_free(&di, allocated);
return r; return r;
#else #else
return log_error_errno(EOPNOTSUPP, "FIDO2 tokens not supported on this build."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"FIDO2 tokens not supported on this build.");
#endif #endif
} }

View File

@ -77,7 +77,9 @@ static int acquire_pkcs11_certificate(
r = pkcs11_find_token(uri, pkcs11_callback, &data); r = pkcs11_find_token(uri, pkcs11_callback, &data);
if (r == -EAGAIN) /* pkcs11_find_token() doesn't log about this error, but all others */ if (r == -EAGAIN) /* pkcs11_find_token() doesn't log about this error, but all others */
return log_error_errno(ENXIO, "Specified PKCS#11 token with URI '%s' not found.", uri); return log_error_errno(SYNTHETIC_ERRNO(ENXIO),
"Specified PKCS#11 token with URI '%s' not found.",
uri);
if (r < 0) if (r < 0)
return r; return r;
@ -86,7 +88,8 @@ static int acquire_pkcs11_certificate(
return 0; return 0;
#else #else
return log_error_errno(EOPNOTSUPP, "PKCS#11 tokens not supported on this build."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"PKCS#11 tokens not supported on this build.");
#endif #endif
} }
@ -415,7 +418,8 @@ int list_pkcs11_tokens(void) {
return 0; return 0;
#else #else
return log_error_errno(EOPNOTSUPP, "PKCS#11 tokens not supported on this build."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"PKCS#11 tokens not supported on this build.");
#endif #endif
} }

View File

@ -910,7 +910,8 @@ static int user_record_compile_effective_passwords(
* the old literal password only (and do not care for the old PKCS#11 token) */ * the old literal password only (and do not care for the old PKCS#11 token) */
if (strv_isempty(h->hashed_password)) if (strv_isempty(h->hashed_password))
return log_error_errno(EINVAL, "User record has no hashed passwords, refusing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"User record has no hashed passwords, refusing.");
/* Generates the list of plaintext passwords to propagate to LUKS/fscrypt devices, and checks whether /* Generates the list of plaintext passwords to propagate to LUKS/fscrypt devices, and checks whether
* we have a plaintext password for each hashed one. If we are missing one we'll fail, since we * we have a plaintext password for each hashed one. If we are missing one we'll fail, since we

View File

@ -194,10 +194,9 @@ static int show_status(int argc, char **argv, void *userdata) {
if (arg_pretty || arg_static || arg_transient) { if (arg_pretty || arg_static || arg_transient) {
const char *attr; const char *attr;
if (!!arg_static + !!arg_pretty + !!arg_transient > 1) { if (!!arg_static + !!arg_pretty + !!arg_transient > 1)
log_error("Cannot query more than one name type at a time"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot query more than one name type at a time");
}
attr = arg_pretty ? "PrettyHostname" : attr = arg_pretty ? "PrettyHostname" :
arg_static ? "StaticHostname" : "Hostname"; arg_static ? "StaticHostname" : "Hostname";

View File

@ -126,10 +126,10 @@ static int import_fs(int argc, char *argv[], void *userdata) {
local = empty_or_dash_to_null(local); local = empty_or_dash_to_null(local);
if (local) { if (local) {
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local image name '%s' is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local image name '%s' is not valid.",
} local);
if (!arg_force) { if (!arg_force) {
r = image_find(IMAGE_MACHINE, local, NULL); r = image_find(IMAGE_MACHINE, local, NULL);
@ -137,8 +137,9 @@ static int import_fs(int argc, char *argv[], void *userdata) {
if (r != -ENOENT) if (r != -ENOENT)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
} else { } else {
log_error("Image '%s' already exists.", local); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Image '%s' already exists.",
local);
} }
} }
} else } else

View File

@ -64,10 +64,10 @@ static int import_tar(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local image name '%s' is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local image name '%s' is not valid.",
} local);
if (!arg_force) { if (!arg_force) {
r = image_find(IMAGE_MACHINE, local, NULL); r = image_find(IMAGE_MACHINE, local, NULL);
@ -75,8 +75,9 @@ static int import_tar(int argc, char *argv[], void *userdata) {
if (r != -ENOENT) if (r != -ENOENT)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
} else { } else {
log_error("Image '%s' already exists.", local); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Image '%s' already exists.",
local);
} }
} }
} else } else
@ -158,10 +159,10 @@ static int import_raw(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local image name '%s' is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local image name '%s' is not valid.",
} local);
if (!arg_force) { if (!arg_force) {
r = image_find(IMAGE_MACHINE, local, NULL); r = image_find(IMAGE_MACHINE, local, NULL);
@ -169,8 +170,9 @@ static int import_raw(int argc, char *argv[], void *userdata) {
if (r != -ENOENT) if (r != -ENOENT)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
} else { } else {
log_error("Image '%s' already exists.", local); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Image '%s' already exists.",
local);
} }
} }
} else } else

View File

@ -389,10 +389,9 @@ int pull_verify(PullJob *main_job,
assert(checksum_job->state == PULL_JOB_DONE); assert(checksum_job->state == PULL_JOB_DONE);
if (!checksum_job->payload || checksum_job->payload_size <= 0) { if (!checksum_job->payload || checksum_job->payload_size <= 0)
log_error("Checksum is empty, cannot verify."); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Checksum is empty, cannot verify.");
}
r = verify_one(checksum_job, main_job); r = verify_one(checksum_job, main_job);
if (r < 0) if (r < 0)
@ -414,10 +413,9 @@ int pull_verify(PullJob *main_job,
assert(signature_job->state == PULL_JOB_DONE); assert(signature_job->state == PULL_JOB_DONE);
if (!signature_job->payload || signature_job->payload_size <= 0) { if (!signature_job->payload || signature_job->payload_size <= 0)
log_error("Signature is empty, cannot verify."); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Signature is empty, cannot verify.");
}
r = pipe2(gpg_pipe, O_CLOEXEC); r = pipe2(gpg_pipe, O_CLOEXEC);
if (r < 0) if (r < 0)

View File

@ -49,10 +49,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
int r; int r;
url = argv[1]; url = argv[1];
if (!http_url_is_valid(url)) { if (!http_url_is_valid(url))
log_error("URL '%s' is not valid.", url); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "URL '%s' is not valid.", url);
}
if (argc >= 3) if (argc >= 3)
local = argv[2]; local = argv[2];
@ -73,10 +72,10 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local image name '%s' is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local image name '%s' is not valid.",
} local);
if (!arg_force) { if (!arg_force) {
r = image_find(IMAGE_MACHINE, local, NULL); r = image_find(IMAGE_MACHINE, local, NULL);
@ -84,8 +83,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
if (r != -ENOENT) if (r != -ENOENT)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
} else { } else {
log_error("Image '%s' already exists.", local); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Image '%s' already exists.",
local);
} }
} }
@ -135,10 +135,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
int r; int r;
url = argv[1]; url = argv[1];
if (!http_url_is_valid(url)) { if (!http_url_is_valid(url))
log_error("URL '%s' is not valid.", url); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "URL '%s' is not valid.", url);
}
if (argc >= 3) if (argc >= 3)
local = argv[2]; local = argv[2];
@ -159,10 +158,10 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local image name '%s' is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local image name '%s' is not valid.",
} local);
if (!arg_force) { if (!arg_force) {
r = image_find(IMAGE_MACHINE, local, NULL); r = image_find(IMAGE_MACHINE, local, NULL);
@ -170,8 +169,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
if (r != -ENOENT) if (r != -ENOENT)
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local); return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
} else { } else {
log_error("Image '%s' already exists.", local); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Image '%s' already exists.",
local);
} }
} }

View File

@ -544,10 +544,10 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
assert(fdt >= 0); assert(fdt >= 0);
ret = lzma_easy_encoder(&s, LZMA_PRESET_DEFAULT, LZMA_CHECK_CRC64); ret = lzma_easy_encoder(&s, LZMA_PRESET_DEFAULT, LZMA_CHECK_CRC64);
if (ret != LZMA_OK) { if (ret != LZMA_OK)
log_error("Failed to initialize XZ encoder: code %u", ret); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to initialize XZ encoder: code %u",
} ret);
for (;;) { for (;;) {
if (s.avail_in == 0 && action == LZMA_RUN) { if (s.avail_in == 0 && action == LZMA_RUN) {
@ -579,10 +579,10 @@ int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
} }
ret = lzma_code(&s, action); ret = lzma_code(&s, action);
if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) { if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END))
log_error("Compression failed: code %u", ret); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Compression failed: code %u",
} ret);
if (s.avail_out == 0 || ret == LZMA_STREAM_END) { if (s.avail_out == 0 || ret == LZMA_STREAM_END) {
ssize_t n, k; ssize_t n, k;
@ -664,10 +664,10 @@ int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes) {
offset += n; offset += n;
total_out += n; total_out += n;
if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes) { if (max_bytes != (uint64_t) -1 && total_out > (size_t) max_bytes)
log_debug("Compressed stream longer than %"PRIu64" bytes", max_bytes); return log_debug_errno(SYNTHETIC_ERRNO(EFBIG),
return -EFBIG; "Compressed stream longer than %" PRIu64 " bytes",
} max_bytes);
if (size - offset < frame_size + 4) { if (size - offset < frame_size + 4) {
k = loop_write(fdt, buf, offset, false); k = loop_write(fdt, buf, offset, false);
@ -715,10 +715,10 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
assert(fdt >= 0); assert(fdt >= 0);
ret = lzma_stream_decoder(&s, UINT64_MAX, 0); ret = lzma_stream_decoder(&s, UINT64_MAX, 0);
if (ret != LZMA_OK) { if (ret != LZMA_OK)
log_debug("Failed to initialize XZ decoder: code %u", ret); return log_debug_errno(SYNTHETIC_ERRNO(ENOMEM),
return -ENOMEM; "Failed to initialize XZ decoder: code %u",
} ret);
for (;;) { for (;;) {
if (s.avail_in == 0 && action == LZMA_RUN) { if (s.avail_in == 0 && action == LZMA_RUN) {
@ -741,10 +741,10 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
} }
ret = lzma_code(&s, action); ret = lzma_code(&s, action);
if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END)) { if (!IN_SET(ret, LZMA_OK, LZMA_STREAM_END))
log_debug("Decompression failed: code %u", ret); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Decompression failed: code %u",
} ret);
if (s.avail_out == 0 || ret == LZMA_STREAM_END) { if (s.avail_out == 0 || ret == LZMA_STREAM_END) {
ssize_t n, k; ssize_t n, k;
@ -772,8 +772,8 @@ int decompress_stream_xz(int fdf, int fdt, uint64_t max_bytes) {
} }
} }
#else #else
log_debug("Cannot decompress file. Compiled without XZ support."); return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
return -EPROTONOSUPPORT; "Cannot decompress file. Compiled without XZ support.");
#endif #endif
} }
@ -833,8 +833,8 @@ int decompress_stream_lz4(int in, int out, uint64_t max_bytes) {
munmap(src, st.st_size); munmap(src, st.st_size);
return r; return r;
#else #else
log_debug("Cannot decompress file. Compiled without LZ4 support."); return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
return -EPROTONOSUPPORT; "Cannot decompress file. Compiled without LZ4 support.");
#endif #endif
} }
@ -1043,8 +1043,8 @@ int decompress_stream_zstd(int fdf, int fdt, uint64_t max_bytes) {
(double) (max_bytes - left) / in_bytes * 100); (double) (max_bytes - left) / in_bytes * 100);
return 0; return 0;
#else #else
log_debug("Cannot decompress file. Compiled without ZSTD support."); return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
return -EPROTONOSUPPORT; "Cannot decompress file. Compiled without ZSTD support.");
#endif #endif
} }

View File

@ -139,7 +139,7 @@ _printf_(1, 0) static int fill_iovec_sprintf(const char *format, va_list ap, int
if (i >= n) { if (i >= n) {
n = MAX(i*2, 4); n = MAX(i*2, 4);
c = realloc(iov, n * sizeof(struct iovec)); c = reallocarray(iov, n, sizeof(struct iovec));
if (!c) { if (!c) {
r = -ENOMEM; r = -ENOMEM;
goto fail; goto fail;

View File

@ -199,10 +199,9 @@ static int add_matches_for_device(sd_journal *j, const char *devpath) {
assert(j); assert(j);
assert(devpath); assert(devpath);
if (!path_startswith(devpath, "/dev/")) { if (!path_startswith(devpath, "/dev/"))
log_error("Devpath does not start with /dev/"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Devpath does not start with /dev/");
}
if (stat(devpath, &st) < 0) if (stat(devpath, &st) < 0)
return log_error_errno(errno, "Couldn't stat file: %m"); return log_error_errno(errno, "Couldn't stat file: %m");
@ -1055,35 +1054,30 @@ static int parse_argv(int argc, char *argv[]) {
if (arg_follow && !arg_no_tail && !arg_since && arg_lines == ARG_LINES_DEFAULT) if (arg_follow && !arg_no_tail && !arg_since && arg_lines == ARG_LINES_DEFAULT)
arg_lines = 10; arg_lines = 10;
if (!!arg_directory + !!arg_file + !!arg_machine + !!arg_root + !!arg_image > 1) { if (!!arg_directory + !!arg_file + !!arg_machine + !!arg_root + !!arg_image > 1)
log_error("Please specify at most one of -D/--directory=, --file=, -M/--machine=, --root=, --image=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Please specify at most one of -D/--directory=, --file=, -M/--machine=, --root=, --image=.");
}
if (arg_since_set && arg_until_set && arg_since > arg_until) { if (arg_since_set && arg_until_set && arg_since > arg_until)
log_error("--since= must be before --until=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--since= must be before --until=.");
}
if (!!arg_cursor + !!arg_after_cursor + !!arg_since_set > 1) { if (!!arg_cursor + !!arg_after_cursor + !!arg_since_set > 1)
log_error("Please specify only one of --since=, --cursor=, and --after-cursor."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Please specify only one of --since=, --cursor=, and --after-cursor.");
}
if (arg_follow && arg_reverse) { if (arg_follow && arg_reverse)
log_error("Please specify either --reverse= or --follow=, not both."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Please specify either --reverse= or --follow=, not both.");
}
if (!IN_SET(arg_action, ACTION_SHOW, ACTION_DUMP_CATALOG, ACTION_LIST_CATALOG) && optind < argc) { if (!IN_SET(arg_action, ACTION_SHOW, ACTION_DUMP_CATALOG, ACTION_LIST_CATALOG) && optind < argc)
log_error("Extraneous arguments starting with '%s'", argv[optind]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Extraneous arguments starting with '%s'",
} argv[optind]);
if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && arg_merge) { if ((arg_boot || arg_action == ACTION_LIST_BOOTS) && arg_merge)
log_error("Using --boot or --list-boots with --merge is not supported."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Using --boot or --list-boots with --merge is not supported.");
}
if (!strv_isempty(arg_system_units) && arg_journal_type == SD_JOURNAL_CURRENT_USER) { if (!strv_isempty(arg_system_units) && arg_journal_type == SD_JOURNAL_CURRENT_USER) {
/* Specifying --user and --unit= at the same time makes no sense (as the former excludes the user /* Specifying --user and --unit= at the same time makes no sense (as the former excludes the user
@ -1921,7 +1915,8 @@ static int setup_keys(void) {
"Please write down the following %ssecret verification key%s. It should be stored\n" "Please write down the following %ssecret verification key%s. It should be stored\n"
"in a safe location and should not be saved locally on disk.\n" "in a safe location and should not be saved locally on disk.\n"
"\n\t%s", "\n\t%s",
hn ?: "", hn ? "/" : "", SD_ID128_FORMAT_VAL(machine), strempty(hn), hn ? "/" : "",
SD_ID128_FORMAT_VAL(machine),
ansi_highlight(), ansi_normal(), ansi_highlight(), ansi_normal(),
p, p,
format_timespan(tsb, sizeof(tsb), arg_interval, 0), format_timespan(tsb, sizeof(tsb), arg_interval, 0),
@ -2476,7 +2471,7 @@ int main(int argc, char *argv[]) {
after_cursor = true; after_cursor = true;
} }
} else } else
after_cursor = !!arg_after_cursor; after_cursor = arg_after_cursor;
if (cursor) { if (cursor) {
r = sd_journal_seek_cursor(j, cursor); r = sd_journal_seek_cursor(j, cursor);

View File

@ -7,6 +7,7 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "chattr-util.h" #include "chattr-util.h"
#include "io-util.h"
#include "journal-file.h" #include "journal-file.h"
#include "journal-internal.h" #include "journal-internal.h"
#include "log.h" #include "log.h"
@ -92,13 +93,11 @@ static void run_test(void) {
previous_ts = ts; previous_ts = ts;
assert_se(asprintf(&p, "NUMBER=%u", i) >= 0); assert_se(asprintf(&p, "NUMBER=%u", i) >= 0);
iovec[0].iov_base = p; iovec[0] = IOVEC_MAKE(p, strlen(p));
iovec[0].iov_len = strlen(p);
assert_se(asprintf(&q, "MAGIC=%s", i % 5 == 0 ? "quux" : "waldo") >= 0); assert_se(asprintf(&q, "MAGIC=%s", i % 5 == 0 ? "quux" : "waldo") >= 0);
iovec[1].iov_base = q; iovec[1] = IOVEC_MAKE(q, strlen(q));
iovec[1].iov_len = strlen(q);
if (i % 10 == 0) if (i % 10 == 0)
assert_se(journal_file_append_entry(three, &ts, NULL, iovec, 2, NULL, NULL, NULL) == 0); assert_se(journal_file_append_entry(three, &ts, NULL, iovec, 2, NULL, NULL, NULL) == 0);

View File

@ -26,11 +26,10 @@ int dhcp_validate_duid_len(uint16_t duid_type, size_t duid_len, bool strict) {
if (duid_len > MAX_DUID_LEN) if (duid_len > MAX_DUID_LEN)
return -EINVAL; return -EINVAL;
if (!strict) { if (!strict)
/* Strict validation is not requested. We only ensure that the /* Strict validation is not requested. We only ensure that the
* DUID is not too long. */ * DUID is not too long. */
return 0; return 0;
}
switch (duid_type) { switch (duid_type) {
case DUID_TYPE_LLT: case DUID_TYPE_LLT:

View File

@ -1880,12 +1880,11 @@ static int client_receive_message_udp(
assert(client); assert(client);
buflen = next_datagram_size_fd(fd); buflen = next_datagram_size_fd(fd);
if (buflen == -ENETDOWN) { if (buflen == -ENETDOWN)
/* the link is down. Don't return an error or the I/O event /* the link is down. Don't return an error or the I/O event
source will be disconnected and we won't be able to receive source will be disconnected and we won't be able to receive
packets again when the link comes back. */ packets again when the link comes back. */
return 0; return 0;
}
if (buflen < 0) if (buflen < 0)
return buflen; return buflen;

View File

@ -1233,10 +1233,8 @@ int dhcp_lease_load(sd_dhcp_lease **ret, const char *lease_file) {
if (!a) if (!a)
return -ENOMEM; return -ENOMEM;
if (!strv_isempty(a)) { if (!strv_isempty(a))
lease->search_domains = a; lease->search_domains = TAKE_PTR(a);
a = NULL;
}
} }
if (routes) { if (routes) {

View File

@ -1420,12 +1420,11 @@ static int client_receive_message(
assert(client->event); assert(client->event);
buflen = next_datagram_size_fd(fd); buflen = next_datagram_size_fd(fd);
if (buflen == -ENETDOWN) { if (buflen == -ENETDOWN)
/* the link is down. Don't return an error or the I/O event /* the link is down. Don't return an error or the I/O event
source will be disconnected and we won't be able to receive source will be disconnected and we won't be able to receive
packets again when the link comes back. */ packets again when the link comes back. */
return 0; return 0;
}
if (buflen < 0) if (buflen < 0)
return buflen; return buflen;

View File

@ -23,10 +23,10 @@ static void test_pool(struct in_addr *address, unsigned size, int ret) {
static int test_basic(sd_event *event) { static int test_basic(sd_event *event) {
_cleanup_(sd_dhcp_server_unrefp) sd_dhcp_server *server = NULL; _cleanup_(sd_dhcp_server_unrefp) sd_dhcp_server *server = NULL;
struct in_addr address_lo = { struct in_addr address_lo = {
.s_addr = htonl(INADDR_LOOPBACK), .s_addr = htobe32(INADDR_LOOPBACK),
}; };
struct in_addr address_any = { struct in_addr address_any = {
.s_addr = htonl(INADDR_ANY), .s_addr = htobe32(INADDR_ANY),
}; };
int r; int r;
@ -105,7 +105,7 @@ static void test_message_handler(void) {
.end = SD_DHCP_OPTION_END, .end = SD_DHCP_OPTION_END,
}; };
struct in_addr address_lo = { struct in_addr address_lo = {
.s_addr = htonl(INADDR_LOOPBACK), .s_addr = htobe32(INADDR_LOOPBACK),
}; };
assert_se(sd_dhcp_server_new(&server, 1) >= 0); assert_se(sd_dhcp_server_new(&server, 1) >= 0);

View File

@ -285,8 +285,7 @@ static void* client1(void *p) {
assert_se(streq(hello, "hello")); assert_se(streq(hello, "hello"));
if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) { if (pipe2(pp, O_CLOEXEC|O_NONBLOCK) < 0) {
log_error_errno(errno, "Failed to allocate pipe: %m"); r = log_error_errno(errno, "Failed to allocate pipe: %m");
r = -errno;
goto finish; goto finish;
} }

View File

@ -548,10 +548,9 @@ static void test_pidfd(void) {
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0);
pid = fork(); pid = fork();
if (pid == 0) { if (pid == 0)
/* child */ /* child */
_exit(66); _exit(66);
}
assert_se(pid > 1); assert_se(pid > 1);

View File

@ -343,10 +343,10 @@ _public_ int sd_hwdb_new(sd_hwdb **ret) {
return log_debug_errno(errno, "Failed to map %s: %m", hwdb_bin_path); return log_debug_errno(errno, "Failed to map %s: %m", hwdb_bin_path);
if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 || if (memcmp(hwdb->map, sig, sizeof(hwdb->head->signature)) != 0 ||
(size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size)) { (size_t) hwdb->st.st_size != le64toh(hwdb->head->file_size))
log_debug("Failed to recognize the format of %s", hwdb_bin_path); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to recognize the format of %s",
} hwdb_bin_path);
log_debug("=== trie on-disk ==="); log_debug("=== trie on-disk ===");
log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version)); log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version));

View File

@ -139,7 +139,7 @@ static void test_route(sd_netlink *rtnl) {
return; return;
} }
addr.s_addr = htonl(INADDR_LOOPBACK); addr.s_addr = htobe32(INADDR_LOOPBACK);
r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &addr); r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &addr);
if (r < 0) { if (r < 0) {

View File

@ -63,7 +63,7 @@ int main(int argc, char *argv[]) {
struct sockaddr_in sa = { struct sockaddr_in sa = {
.sin_family = AF_INET, .sin_family = AF_INET,
.sin_port = htons(80) .sin_port = htobe16(80)
}; };
assert_se(sd_resolve_default(&resolve) >= 0); assert_se(sd_resolve_default(&resolve) >= 0);

View File

@ -545,8 +545,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
printf("\t Unit: %s\n", i.scope); printf("\t Unit: %s\n", i.scope);
show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i.scope, i.leader); show_unit_cgroup(bus, "org.freedesktop.systemd1.Scope", i.scope, i.leader);
if (arg_transport == BUS_TRANSPORT_LOCAL) { if (arg_transport == BUS_TRANSPORT_LOCAL)
show_journal_by_unit( show_journal_by_unit(
stdout, stdout,
i.scope, i.scope,
@ -561,7 +560,6 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
true, true,
NULL); NULL);
} }
}
return 0; return 0;
} }

View File

@ -21,6 +21,7 @@
#include "parse-util.h" #include "parse-util.h"
#include "path-util.h" #include "path-util.h"
#include "process-util.h" #include "process-util.h"
#include "stdio-util.h"
#include "strv.h" #include "strv.h"
#include "terminal-util.h" #include "terminal-util.h"
#include "udev-util.h" #include "udev-util.h"
@ -533,7 +534,7 @@ int manager_spawn_autovt(Manager *m, unsigned vtnr) {
return -EBUSY; return -EBUSY;
} }
snprintf(name, sizeof(name), "autovt@tty%u.service", vtnr); xsprintf(name, "autovt@tty%u.service", vtnr);
r = sd_bus_call_method( r = sd_bus_call_method(
m->bus, m->bus,
"org.freedesktop.systemd1", "org.freedesktop.systemd1",

View File

@ -1312,15 +1312,13 @@ static int login_machine(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
if (!strv_isempty(arg_setenv) || arg_uid) { if (!strv_isempty(arg_setenv) || arg_uid)
log_error("--setenv= and --uid= are not supported for 'login'. Use 'shell' instead."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--setenv= and --uid= are not supported for 'login'. Use 'shell' instead.");
}
if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE)) { if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE))
log_error("Login only supported on local machines."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Login only supported on local machines.");
}
polkit_agent_open_if_enabled(arg_transport, arg_ask_password); polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
@ -1369,10 +1367,9 @@ static int shell_machine(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE)) { if (!IN_SET(arg_transport, BUS_TRANSPORT_LOCAL, BUS_TRANSPORT_MACHINE))
log_error("Shell only supported on local machines."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Shell only supported on local machines.");
}
/* Pass $TERM to shell session, if not explicitly specified. */ /* Pass $TERM to shell session, if not explicitly specified. */
if (!strv_find_prefix(arg_setenv, "TERM=")) { if (!strv_find_prefix(arg_setenv, "TERM=")) {
@ -1525,10 +1522,10 @@ static int read_only_image(int argc, char *argv[], void *userdata) {
if (argc > 2) { if (argc > 2) {
b = parse_boolean(argv[2]); b = parse_boolean(argv[2]);
if (b < 0) { if (b < 0)
log_error("Failed to parse boolean argument: %s", argv[2]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse boolean argument: %s",
} argv[2]);
} }
polkit_agent_open_if_enabled(arg_transport, arg_ask_password); polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
@ -1602,10 +1599,10 @@ static int start_machine(int argc, char *argv[], void *userdata) {
r = image_exists(bus, argv[i]); r = image_exists(bus, argv[i]);
if (r < 0) if (r < 0)
return r; return r;
if (r == 0) { if (r == 0)
log_error("Machine image '%s' does not exist.", argv[i]); return log_error_errno(SYNTHETIC_ERRNO(ENXIO),
return -ENXIO; "Machine image '%s' does not exist.",
} argv[i]);
r = sd_bus_call_method( r = sd_bus_call_method(
bus, bus,
@ -1674,10 +1671,10 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
r = image_exists(bus, argv[i]); r = image_exists(bus, argv[i]);
if (r < 0) if (r < 0)
return r; return r;
if (r == 0) { if (r == 0)
log_error("Machine image '%s' does not exist.", argv[i]); return log_error_errno(SYNTHETIC_ERRNO(ENXIO),
return -ENXIO; "Machine image '%s' does not exist.",
} argv[i]);
r = sd_bus_message_append(m, "s", unit); r = sd_bus_message_append(m, "s", unit);
if (r < 0) if (r < 0)
@ -1874,10 +1871,9 @@ static int import_tar(int argc, char *argv[], void *userdata) {
local = fn; local = fn;
} }
if (!local) { if (!local)
log_error("Need either path or local name."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Need either path or local name.");
}
r = tar_strip_suffixes(local, &ll); r = tar_strip_suffixes(local, &ll);
if (r < 0) if (r < 0)
@ -1885,10 +1881,10 @@ static int import_tar(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local name %s is not a suitable machine name.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local name %s is not a suitable machine name.",
} local);
if (path) { if (path) {
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY); fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
@ -1935,10 +1931,9 @@ static int import_raw(int argc, char *argv[], void *userdata) {
local = fn; local = fn;
} }
if (!local) { if (!local)
log_error("Need either path or local name."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Need either path or local name.");
}
r = raw_strip_suffixes(local, &ll); r = raw_strip_suffixes(local, &ll);
if (r < 0) if (r < 0)
@ -1946,10 +1941,10 @@ static int import_raw(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local name %s is not a suitable machine name.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local name %s is not a suitable machine name.",
} local);
if (path) { if (path) {
fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY); fd = open(path, O_RDONLY|O_CLOEXEC|O_NOCTTY);
@ -1996,15 +1991,14 @@ static int import_fs(int argc, char *argv[], void *userdata) {
local = fn; local = fn;
} }
if (!local) { if (!local)
log_error("Need either path or local name."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Need either path or local name.");
}
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local name %s is not a suitable machine name.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local name %s is not a suitable machine name.",
} local);
if (path) { if (path) {
fd = open(path, O_DIRECTORY|O_RDONLY|O_CLOEXEC); fd = open(path, O_DIRECTORY|O_RDONLY|O_CLOEXEC);
@ -2054,10 +2048,9 @@ static int export_tar(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
local = argv[1]; local = argv[1];
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Machine name %s is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Machine name %s is not valid.", local);
}
if (argc >= 3) if (argc >= 3)
path = argv[2]; path = argv[2];
@ -2097,10 +2090,9 @@ static int export_raw(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
local = argv[1]; local = argv[1];
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Machine name %s is not valid.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Machine name %s is not valid.", local);
}
if (argc >= 3) if (argc >= 3)
path = argv[2]; path = argv[2];
@ -2140,10 +2132,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
remote = argv[1]; remote = argv[1];
if (!http_url_is_valid(remote)) { if (!http_url_is_valid(remote))
log_error("URL '%s' is not valid.", remote); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "URL '%s' is not valid.", remote);
}
if (argc >= 3) if (argc >= 3)
local = argv[2]; local = argv[2];
@ -2164,10 +2155,10 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local name %s is not a suitable machine name.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local name %s is not a suitable machine name.",
} local);
} }
r = bus_message_new_method_call(bus, &m, bus_import_mgr, "PullTar"); r = bus_message_new_method_call(bus, &m, bus_import_mgr, "PullTar");
@ -2197,10 +2188,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
assert(bus); assert(bus);
remote = argv[1]; remote = argv[1];
if (!http_url_is_valid(remote)) { if (!http_url_is_valid(remote))
log_error("URL '%s' is not valid.", remote); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "URL '%s' is not valid.", remote);
}
if (argc >= 3) if (argc >= 3)
local = argv[2]; local = argv[2];
@ -2221,10 +2211,10 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
local = ll; local = ll;
if (!machine_name_is_valid(local)) { if (!machine_name_is_valid(local))
log_error("Local name %s is not a suitable machine name.", local); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Local name %s is not a suitable machine name.",
} local);
} }
r = bus_message_new_method_call(bus, &m, bus_import_mgr, "PullRaw"); r = bus_message_new_method_call(bus, &m, bus_import_mgr, "PullRaw");

View File

@ -923,10 +923,9 @@ static int umount_by_device(sd_bus *bus, const char *what) {
if (stat(what, &st) < 0) if (stat(what, &st) < 0)
return log_error_errno(errno, "Can't stat %s: %m", what); return log_error_errno(errno, "Can't stat %s: %m", what);
if (!S_ISBLK(st.st_mode)) { if (!S_ISBLK(st.st_mode))
log_error("Not a block device: %s", what); return log_error_errno(SYNTHETIC_ERRNO(ENOTBLK),
return -ENOTBLK; "Not a block device: %s", what);
}
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev); r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
if (r < 0) if (r < 0)
@ -1249,10 +1248,10 @@ static int discover_loop_backing_file(void) {
escaped = xescape(basename(arg_mount_what), "\\"); escaped = xescape(basename(arg_mount_what), "\\");
if (!escaped) if (!escaped)
return log_oom(); return log_oom();
if (!filename_is_valid(escaped)) { if (!filename_is_valid(escaped))
log_error("Escaped name %s is not a valid filename.", escaped); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Escaped name %s is not a valid filename.",
} escaped);
arg_mount_where = path_join("/run/media/system", escaped); arg_mount_where = path_join("/run/media/system", escaped);
if (!arg_mount_where) if (!arg_mount_where)
@ -1265,10 +1264,9 @@ static int discover_loop_backing_file(void) {
if (stat(loop_dev, &st) < 0) if (stat(loop_dev, &st) < 0)
return log_error_errno(errno, "Can't stat %s: %m", loop_dev); return log_error_errno(errno, "Can't stat %s: %m", loop_dev);
if (!S_ISBLK(st.st_mode)) { if (!S_ISBLK(st.st_mode))
log_error("Invalid file type: %s", loop_dev); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid file type: %s", loop_dev);
}
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev); r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
if (r < 0) if (r < 0)
@ -1309,19 +1307,19 @@ static int discover_device(void) {
if (S_ISREG(st.st_mode)) if (S_ISREG(st.st_mode))
return discover_loop_backing_file(); return discover_loop_backing_file();
if (!S_ISBLK(st.st_mode)) { if (!S_ISBLK(st.st_mode))
log_error("Invalid file type: %s", arg_mount_what); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid file type: %s",
} arg_mount_what);
r = sd_device_new_from_devnum(&d, 'b', st.st_rdev); r = sd_device_new_from_devnum(&d, 'b', st.st_rdev);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to get device from device number: %m"); return log_error_errno(r, "Failed to get device from device number: %m");
if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem")) { if (sd_device_get_property_value(d, "ID_FS_USAGE", &v) < 0 || !streq(v, "filesystem"))
log_error("%s does not contain a known file system.", arg_mount_what); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s does not contain a known file system.",
} arg_mount_what);
r = acquire_mount_type(d); r = acquire_mount_type(d);
if (r < 0) if (r < 0)
@ -1462,10 +1460,10 @@ static int run(int argc, char* argv[]) {
return action_umount(bus, argc, argv); return action_umount(bus, argc, argv);
if ((!arg_mount_type || fstype_is_blockdev_backed(arg_mount_type)) if ((!arg_mount_type || fstype_is_blockdev_backed(arg_mount_type))
&& !path_is_normalized(arg_mount_what)) { && !path_is_normalized(arg_mount_what))
log_error("Path contains non-normalized components: %s", arg_mount_what); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path contains non-normalized components: %s",
} arg_mount_what);
if (arg_discover) { if (arg_discover) {
r = discover_device(); r = discover_device();
@ -1473,20 +1471,19 @@ static int run(int argc, char* argv[]) {
return r; return r;
} }
if (!arg_mount_where) { if (!arg_mount_where)
log_error("Can't figure out where to mount %s.", arg_mount_what); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Can't figure out where to mount %s.",
} arg_mount_what);
if (path_equal(arg_mount_where, "/")) { if (path_equal(arg_mount_where, "/"))
log_error("Refusing to operate on root directory."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Refusing to operate on root directory.");
}
if (!path_is_normalized(arg_mount_where)) { if (!path_is_normalized(arg_mount_where))
log_error("Path contains non-normalized components: %s", arg_mount_where); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path contains non-normalized components: %s",
} arg_mount_where);
if (streq_ptr(arg_mount_type, "auto")) if (streq_ptr(arg_mount_type, "auto"))
arg_mount_type = mfree(arg_mount_type); arg_mount_type = mfree(arg_mount_type);
@ -1516,11 +1513,10 @@ static int run(int argc, char* argv[]) {
if (arg_mount_type && if (arg_mount_type &&
!streq(arg_mount_type, "auto") && !streq(arg_mount_type, "auto") &&
arg_uid != UID_INVALID && arg_uid != UID_INVALID &&
!fstype_can_uid_gid(arg_mount_type)) { !fstype_can_uid_gid(arg_mount_type))
log_error("File system type %s is not known to support uid=/gid=, refusing.", return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"File system type %s is not known to support uid=/gid=, refusing.",
arg_mount_type); arg_mount_type);
return -EOPNOTSUPP;
}
switch (arg_action) { switch (arg_action) {

View File

@ -1653,12 +1653,11 @@ static int link_status_one(
if (r < 0) if (r < 0)
return table_log_add_error(r); return table_log_add_error(r);
if (info->port_state <= BR_STATE_BLOCKING) { if (info->port_state <= BR_STATE_BLOCKING)
r = table_add_many(table, r = table_add_many(table,
TABLE_EMPTY, TABLE_EMPTY,
TABLE_STRING, "Port State:", TABLE_STRING, "Port State:",
TABLE_STRING, bridge_state_to_string(info->port_state)); TABLE_STRING, bridge_state_to_string(info->port_state));
}
} else if (streq_ptr(info->netdev_kind, "bond")) { } else if (streq_ptr(info->netdev_kind, "bond")) {
r = table_add_many(table, r = table_add_many(table,
TABLE_EMPTY, TABLE_EMPTY,

View File

@ -762,10 +762,9 @@ int config_parse_dhcp_send_option(
} }
case DHCP_OPTION_DATA_STRING: case DHCP_OPTION_DATA_STRING:
sz = cunescape(p, UNESCAPE_ACCEPT_NUL, &q); sz = cunescape(p, UNESCAPE_ACCEPT_NUL, &q);
if (sz < 0) { if (sz < 0)
log_syntax(unit, LOG_WARNING, filename, line, sz, log_syntax(unit, LOG_WARNING, filename, line, sz,
"Failed to decode DHCP option data, ignoring assignment: %s", p); "Failed to decode DHCP option data, ignoring assignment: %s", p);
}
udata = q; udata = q;
break; break;

View File

@ -123,11 +123,10 @@ int config_parse_generic_random_early_detection_u32(
return 0; return 0;
} }
if (v > MAX_DPs) { if (v > MAX_DPs)
log_syntax(unit, LOG_WARNING, filename, line, 0, log_syntax(unit, LOG_WARNING, filename, line, 0,
"Invalid '%s=', ignoring assignment: %s", "Invalid '%s=', ignoring assignment: %s",
lvalue, rvalue); lvalue, rvalue);
}
*p = v; *p = v;
qdisc = NULL; qdisc = NULL;

View File

@ -79,11 +79,10 @@ int config_parse_trivial_link_equalizer_id(
lvalue, rvalue); lvalue, rvalue);
return 0; return 0;
} }
if (id > INT_MAX) { if (id > INT_MAX)
log_syntax(unit, LOG_WARNING, filename, line, 0, log_syntax(unit, LOG_WARNING, filename, line, 0,
"'%s=' is too large, ignoring assignment: %s", "'%s=' is too large, ignoring assignment: %s",
lvalue, rvalue); lvalue, rvalue);
}
teql->id = id; teql->id = id;

View File

@ -660,10 +660,9 @@ static int oci_namespaces(const char *name, JsonVariant *v, JsonDispatchFlags fl
s->network_namespace_path = data.path; s->network_namespace_path = data.path;
} }
if (FLAGS_SET(n, data.type)) { if (FLAGS_SET(n, data.type))
return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL), return json_log(e, flags, SYNTHETIC_ERRNO(EINVAL),
"Duplicate namespace specification, refusing."); "Duplicate namespace specification, refusing.");
}
n |= data.type; n |= data.type;
} }
@ -2216,14 +2215,14 @@ int oci_load(FILE *f, const char *bundle, Settings **ret) {
} }
v = json_variant_by_key(oci, "ociVersion"); v = json_variant_by_key(oci, "ociVersion");
if (!v) { if (!v)
log_error("JSON file '%s' is not an OCI bundle configuration file. Refusing.", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "JSON file '%s' is not an OCI bundle configuration file. Refusing.",
} path);
if (!streq_ptr(json_variant_string(v), "1.0.0")) { if (!streq_ptr(json_variant_string(v), "1.0.0"))
log_error("OCI bundle version not supported: %s", strna(json_variant_string(v))); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "OCI bundle version not supported: %s",
} strna(json_variant_string(v)));
// { // {
// _cleanup_free_ char *formatted = NULL; // _cleanup_free_ char *formatted = NULL;

View File

@ -4342,7 +4342,7 @@ static int load_settings(void) {
/* If all settings are masked, there's no point in looking for /* If all settings are masked, there's no point in looking for
* the settings file */ * the settings file */
if ((arg_settings_mask & _SETTINGS_MASK_ALL) == _SETTINGS_MASK_ALL) if (FLAGS_SET(arg_settings_mask, _SETTINGS_MASK_ALL))
return 0; return 0;
fn = strjoina(arg_machine, ".nspawn"); fn = strjoina(arg_machine, ".nspawn");

View File

@ -595,7 +595,7 @@ enum nss_status _nss_systemd_initgroups_dyn(
new_size = limit; new_size = limit;
/* Enlarge buffer */ /* Enlarge buffer */
new_groups = realloc(*groupsp, new_size * sizeof(**groupsp)); new_groups = reallocarray(*groupsp, new_size, sizeof(**groupsp));
if (!new_groups) { if (!new_groups) {
UNPROTECT_ERRNO; UNPROTECT_ERRNO;
*errnop = ENOMEM; *errnop = ENOMEM;

View File

@ -434,10 +434,9 @@ static int portable_extract_by_path(
if (isempty(name) && fd < 0) if (isempty(name) && fd < 0)
break; break;
if (isempty(name) || fd < 0) { if (isempty(name) || fd < 0)
log_debug("Invalid item sent from child."); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid item sent from child.");
}
add = portable_metadata_new(name, fd); add = portable_metadata_new(name, fd);
if (!add) if (!add)

View File

@ -261,10 +261,9 @@ static int resolve_host(sd_bus *bus, const char *name) {
(int) strlen(name), c == 0 ? name : "", c == 0 ? ":" : " ", (int) strlen(name), c == 0 ? name : "", c == 0 ? ":" : " ",
canonical); canonical);
if (c == 0) { if (c == 0)
log_error("%s: no addresses found", name); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "%s: no addresses found", name);
}
print_source(flags, ts); print_source(flags, ts);
@ -356,10 +355,9 @@ static int resolve_address(sd_bus *bus, int family, const union in_addr_union *a
if (r < 0) if (r < 0)
return bus_log_parse_error(r); return bus_log_parse_error(r);
if (c == 0) { if (c == 0)
log_error("%s: no names found", pretty); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "%s: no names found", pretty);
}
print_source(flags, ts); print_source(flags, ts);
@ -2050,10 +2048,10 @@ static int call_domain(sd_bus *bus, char **domain, const BusLocator *locator, sd
r = dns_name_is_valid(n); r = dns_name_is_valid(n);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to validate specified domain %s: %m", n); return log_error_errno(r, "Failed to validate specified domain %s: %m", n);
if (r == 0) { if (r == 0)
log_error("Domain not valid: %s", n); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Domain not valid: %s",
} n);
r = sd_bus_message_append(req, "(sb)", n, **p == '~'); r = sd_bus_message_append(req, "(sb)", n, **p == '~');
if (r < 0) if (r < 0)
@ -2348,10 +2346,10 @@ static int verb_nta(int argc, char **argv, void *userdata) {
r = dns_name_is_valid(*p); r = dns_name_is_valid(*p);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to validate specified domain %s: %m", *p); return log_error_errno(r, "Failed to validate specified domain %s: %m", *p);
if (r == 0) { if (r == 0)
log_error("Domain not valid: %s", *p); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Domain not valid: %s",
} *p);
} }
r = call_nta(bus, clear ? NULL : argv + 2, bus_resolve_mgr, &error); r = call_nta(bus, clear ? NULL : argv + 2, bus_resolve_mgr, &error);

View File

@ -1435,7 +1435,7 @@ int dns_packet_read_name(
n += r; n += r;
continue; continue;
} else if (allow_compression && (c & 0xc0) == 0xc0) { } else if (allow_compression && FLAGS_SET(c, 0xc0)) {
uint16_t ptr; uint16_t ptr;
/* Pointer */ /* Pointer */
@ -2250,12 +2250,11 @@ static int dns_packet_extract_answer(DnsPacket *p, DnsAnswer **ret_answer) {
if (DNS_PACKET_QR(p)) { if (DNS_PACKET_QR(p)) {
/* Additional checks for responses */ /* Additional checks for responses */
if (!DNS_RESOURCE_RECORD_OPT_VERSION_SUPPORTED(rr)) { if (!DNS_RESOURCE_RECORD_OPT_VERSION_SUPPORTED(rr))
/* If this is a reply and we don't know the EDNS version /* If this is a reply and we don't know the EDNS version
* then something is weird... */ * then something is weird... */
log_debug("EDNS version newer that our request, bad server."); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "EDNS version newer that our request, bad server.");
}
if (has_rfc6975) { if (has_rfc6975) {
/* If the OPT RR contains RFC6975 algorithm data, then this /* If the OPT RR contains RFC6975 algorithm data, then this

View File

@ -908,13 +908,11 @@ static int dns_query_cname_redirect(DnsQuery *q, const DnsResourceRecord *cname)
if (r == 0 && k == 0) /* No actual cname happened? */ if (r == 0 && k == 0) /* No actual cname happened? */
return -ELOOP; return -ELOOP;
if (q->answer_protocol == DNS_PROTOCOL_DNS) { if (q->answer_protocol == DNS_PROTOCOL_DNS)
/* Don't permit CNAME redirects from unicast DNS to LLMNR or MulticastDNS, so that global resources /* Don't permit CNAME redirects from unicast DNS to LLMNR or MulticastDNS, so that global resources
* cannot invade the local namespace. The opposite way we permit: local names may redirect to global * cannot invade the local namespace. The opposite way we permit: local names may redirect to global
* ones. */ * ones. */
q->flags &= ~(SD_RESOLVED_LLMNR|SD_RESOLVED_MDNS); /* mask away the local protocols */ q->flags &= ~(SD_RESOLVED_LLMNR|SD_RESOLVED_MDNS); /* mask away the local protocols */
}
/* Turn off searching for the new name */ /* Turn off searching for the new name */
q->flags |= SD_RESOLVED_NO_SEARCH; q->flags |= SD_RESOLVED_NO_SEARCH;

View File

@ -97,15 +97,15 @@ static int dnssd_service_load(Manager *manager, const char *filename) {
if (r < 0) if (r < 0)
return r; return r;
if (!service->name_template) { if (!service->name_template)
log_error("%s doesn't define service instance name", service->name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s doesn't define service instance name",
} service->name);
if (!service->type) { if (!service->type)
log_error("%s doesn't define service type", service->name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s doesn't define service type",
} service->name);
if (LIST_IS_EMPTY(service->txt_data_items)) { if (LIST_IS_EMPTY(service->txt_data_items)) {
txt_data = new0(DnssdTxtData, 1); txt_data = new0(DnssdTxtData, 1);

View File

@ -786,10 +786,8 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
l = recvmsg_safe(fd, &mh, 0); l = recvmsg_safe(fd, &mh, 0);
if (IN_SET(l, -EAGAIN, -EINTR)) if (IN_SET(l, -EAGAIN, -EINTR))
return 0; return 0;
if (l < 0) if (l <= 0)
return l; return l;
if (l == 0)
return 0;
assert(!(mh.msg_flags & MSG_TRUNC)); assert(!(mh.msg_flags & MSG_TRUNC));

View File

@ -538,14 +538,13 @@ static int parse_argv(int argc, char *argv[]) {
arg_aggressive_gc = true; arg_aggressive_gc = true;
} }
if (arg_stdio == ARG_STDIO_AUTO) { if (arg_stdio == ARG_STDIO_AUTO)
/* If we both --pty and --pipe are specified we'll automatically pick --pty if we are connected fully /* If we both --pty and --pipe are specified we'll automatically pick --pty if we are connected fully
* to a TTY and pick direct fd passing otherwise. This way, we automatically adapt to usage in a shell * to a TTY and pick direct fd passing otherwise. This way, we automatically adapt to usage in a shell
* pipeline, but we are neatly interactive with tty-level isolation otherwise. */ * pipeline, but we are neatly interactive with tty-level isolation otherwise. */
arg_stdio = isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) ? arg_stdio = isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) ?
ARG_STDIO_PTY : ARG_STDIO_PTY :
ARG_STDIO_DIRECT; ARG_STDIO_DIRECT;
}
if (argc > optind) { if (argc > optind) {
char **l; char **l;
@ -1336,7 +1335,7 @@ static int start_transient_service(
if (c.cpu_usage_nsec != NSEC_INFINITY) { if (c.cpu_usage_nsec != NSEC_INFINITY) {
char ts[FORMAT_TIMESPAN_MAX]; char ts[FORMAT_TIMESPAN_MAX];
log_info("CPU time consumed: %s", log_info("CPU time consumed: %s",
format_timespan(ts, sizeof ts, (c.cpu_usage_nsec + NSEC_PER_USEC - 1) / NSEC_PER_USEC, USEC_PER_MSEC)); format_timespan(ts, sizeof ts, DIV_ROUND_UP(c.cpu_usage_nsec, NSEC_PER_USEC), USEC_PER_MSEC));
} }
if (c.ip_ingress_bytes != UINT64_MAX) { if (c.ip_ingress_bytes != UINT64_MAX) {

View File

@ -266,12 +266,10 @@ int bus_connect_transport(BusTransport transport, const char *host, bool user, s
if (user) if (user)
r = sd_bus_default_user(&bus); r = sd_bus_default_user(&bus);
else { else {
if (sd_booted() <= 0) { if (sd_booted() <= 0)
/* Print a friendly message when the local system is actually not running systemd as PID 1. */ /* Print a friendly message when the local system is actually not running systemd as PID 1. */
log_error("System has not been booted with systemd as init system (PID 1). Can't operate."); return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
"System has not been booted with systemd as init system (PID 1). Can't operate.");
return -EHOSTDOWN;
}
r = sd_bus_default_system(&bus); r = sd_bus_default_system(&bus);
} }
break; break;

View File

@ -224,7 +224,7 @@ static int wait_for_partitions_to_appear(
if (r < 0) if (r < 0)
return r; return r;
if (r == 0) if (r == 0)
return log_debug_errno(EPROTONOSUPPORT, return log_debug_errno(SYNTHETIC_ERRNO(EPROTONOSUPPORT),
"Device is a loop device and partition scanning is off!"); "Device is a loop device and partition scanning is off!");
return -EINVAL; /* original error */ return -EINVAL; /* original error */

View File

@ -791,8 +791,8 @@ static int slot_process(
rv = m->C_GetTokenInfo(slotid, &token_info); rv = m->C_GetTokenInfo(slotid, &token_info);
if (rv == CKR_TOKEN_NOT_PRESENT) { if (rv == CKR_TOKEN_NOT_PRESENT) {
log_debug("Token not present in slot, ignoring."); return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
return -EAGAIN; "Token not present in slot, ignoring.");
} else if (rv != CKR_OK) { } else if (rv != CKR_OK) {
log_warning("Failed to acquire token info for slot %lu, ignoring slot: %s", slotid, p11_kit_strerror(rv)); log_warning("Failed to acquire token info for slot %lu, ignoring slot: %s", slotid, p11_kit_strerror(rv));
return -EAGAIN; return -EAGAIN;
@ -808,10 +808,10 @@ static int slot_process(
return -EAGAIN; return -EAGAIN;
} }
if (search_uri && !p11_kit_uri_match_token_info(search_uri, &token_info)) { if (search_uri && !p11_kit_uri_match_token_info(search_uri, &token_info))
log_debug("Found non-matching token with URI %s.", token_uri_string); return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
return -EAGAIN; "Found non-matching token with URI %s.",
} token_uri_string);
log_debug("Found matching token with URI %s.", token_uri_string); log_debug("Found matching token with URI %s.", token_uri_string);
@ -876,10 +876,9 @@ static int module_process(
log_warning("Failed to get slot list, ignoring module: %s", p11_kit_strerror(rv)); log_warning("Failed to get slot list, ignoring module: %s", p11_kit_strerror(rv));
return -EAGAIN; return -EAGAIN;
} }
if (n_slotids == 0) { if (n_slotids == 0)
log_debug("This module has no slots? Ignoring module."); return log_debug_errno(SYNTHETIC_ERRNO(EAGAIN),
return -EAGAIN; "This module has no slots? Ignoring module.");
}
for (k = 0; k < n_slotids; k++) { for (k = 0; k < n_slotids; k++) {
r = slot_process( r = slot_process(

View File

@ -473,15 +473,13 @@ int pty_forward_new(
f->master = master; f->master = master;
if (ioctl(f->output_fd, TIOCGWINSZ, &ws) < 0) { if (ioctl(f->output_fd, TIOCGWINSZ, &ws) < 0)
/* If we can't get the resolution from the output fd, then use our internal, regular width/height, /* If we can't get the resolution from the output fd, then use our internal, regular width/height,
* i.e. something derived from $COLUMNS and $LINES if set. */ * i.e. something derived from $COLUMNS and $LINES if set. */
ws = (struct winsize) { ws = (struct winsize) {
.ws_row = lines(), .ws_row = lines(),
.ws_col = columns(), .ws_col = columns(),
}; };
}
(void) ioctl(master, TIOCSWINSZ, &ws); (void) ioctl(master, TIOCSWINSZ, &ws);

View File

@ -1190,7 +1190,7 @@ int seccomp_restrict_namespaces(unsigned long retain) {
} }
/* NOOP? */ /* NOOP? */
if ((retain & NAMESPACE_FLAGS_ALL) == NAMESPACE_FLAGS_ALL) if (FLAGS_SET(retain, NAMESPACE_FLAGS_ALL))
return 0; return 0;
SECCOMP_FOREACH_LOCAL_ARCH(arch) { SECCOMP_FOREACH_LOCAL_ARCH(arch) {
@ -1228,7 +1228,7 @@ int seccomp_restrict_namespaces(unsigned long retain) {
unsigned long f; unsigned long f;
f = namespace_flag_map[i].flag; f = namespace_flag_map[i].flag;
if ((retain & f) == f) { if (FLAGS_SET(retain, f)) {
log_debug("Permitting %s.", namespace_flag_map[i].name); log_debug("Permitting %s.", namespace_flag_map[i].name);
continue; continue;
} }

View File

@ -187,11 +187,10 @@ int logind_check_inhibitors(enum action a) {
if (c <= 0) if (c <= 0)
return 0; return 0;
log_error("Please retry operation after closing inhibitors and logging out other users.\n" return log_error_errno(SYNTHETIC_ERRNO(EPERM),
"Please retry operation after closing inhibitors and logging out other users.\n"
"Alternatively, ignore inhibitors and users with 'systemctl %s -i'.", "Alternatively, ignore inhibitors and users with 'systemctl %s -i'.",
action_table[a].verb); action_table[a].verb);
return -EPERM;
#else #else
return 0; return 0;
#endif #endif

View File

@ -106,7 +106,7 @@ static void test_device_parents(struct udev *udev, const char *syspath) {
log_info("/* %s, device %s */", __func__, syspath); log_info("/* %s, device %s */", __func__, syspath);
device = udev_device_new_from_syspath(udev, syspath); device = udev_device_new_from_syspath(udev, syspath);
if (device == NULL) if (!device)
return; return;
log_info("looking at parents"); log_info("looking at parents");
@ -142,7 +142,7 @@ static void test_device_subsys_name(struct udev *udev, const char *subsys, const
log_info("looking up device: '%s:%s'", subsys, dev); log_info("looking up device: '%s:%s'", subsys, dev);
device = udev_device_new_from_subsystem_sysname(udev, subsys, dev); device = udev_device_new_from_subsystem_sysname(udev, subsys, dev);
if (device == NULL) if (!device)
log_warning_errno(errno, "udev_device_new_from_subsystem_sysname: %m"); log_warning_errno(errno, "udev_device_new_from_subsystem_sysname: %m");
else else
print_device(device); print_device(device);
@ -213,7 +213,7 @@ static void test_monitor(struct udev *udev) {
for (i = 0; i < fdcount; i++) { for (i = 0; i < fdcount; i++) {
if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) { if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
device = udev_monitor_receive_device(udev_monitor); device = udev_monitor_receive_device(udev_monitor);
if (device == NULL) { if (!device) {
printf("no device from socket\n"); printf("no device from socket\n");
continue; continue;
} }

View File

@ -1417,10 +1417,10 @@ static int create_file(Item *i, const char *path) {
if (fstat(fd, &stbuf) < 0) if (fstat(fd, &stbuf) < 0)
return log_error_errno(errno, "stat(%s) failed: %m", path); return log_error_errno(errno, "stat(%s) failed: %m", path);
if (!S_ISREG(stbuf.st_mode)) { if (!S_ISREG(stbuf.st_mode))
log_error("%s exists and is not a regular file.", path); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "%s exists and is not a regular file.",
} path);
st = &stbuf; st = &stbuf;
} else { } else {
@ -1481,10 +1481,10 @@ static int truncate_file(Item *i, const char *path) {
fd = openat(dir_fd, bn, O_NOFOLLOW|O_CLOEXEC|O_PATH, i->mode); fd = openat(dir_fd, bn, O_NOFOLLOW|O_CLOEXEC|O_PATH, i->mode);
if (fd < 0) { if (fd < 0) {
if (errno == ENOENT) { if (errno == ENOENT)
log_error("Cannot create file %s on a read-only file system.", path); return log_error_errno(SYNTHETIC_ERRNO(EROFS),
return -EROFS; "Cannot create file %s on a read-only file system.",
} path);
return log_error_errno(errno, "Failed to re-open file %s: %m", path); return log_error_errno(errno, "Failed to re-open file %s: %m", path);
} }
@ -1495,10 +1495,10 @@ static int truncate_file(Item *i, const char *path) {
if (fstat(fd, &stbuf) < 0) if (fstat(fd, &stbuf) < 0)
return log_error_errno(errno, "stat(%s) failed: %m", path); return log_error_errno(errno, "stat(%s) failed: %m", path);
if (!S_ISREG(stbuf.st_mode)) { if (!S_ISREG(stbuf.st_mode))
log_error("%s exists and is not a regular file.", path); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "%s exists and is not a regular file.",
} path);
if (stbuf.st_size > 0) { if (stbuf.st_size > 0) {
if (ftruncate(fd, 0) < 0) { if (ftruncate(fd, 0) < 0) {