Skip to content

Commit c614711

Browse files
committed
tree-wide: use SYNTHETIC_ERRNO() where appropriate
1 parent c1db999 commit c614711

File tree

3 files changed

+36
-67
lines changed

3 files changed

+36
-67
lines changed

src/cgtop/cgtop.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -922,10 +922,9 @@ static int run(int argc, char *argv[]) {
922922

923923
arg_count = (mask & CGROUP_MASK_PIDS) ? COUNT_PIDS : COUNT_USERSPACE_PROCESSES;
924924

925-
if (arg_recursive_unset && arg_count == COUNT_PIDS) {
926-
log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
927-
return -EINVAL;
928-
}
925+
if (arg_recursive_unset && arg_count == COUNT_PIDS)
926+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
927+
"Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
929928

930929
r = show_cgroup_get_path_and_warn(arg_machine, arg_root, &root);
931930
if (r < 0)

src/nspawn/nspawn.c

Lines changed: 31 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,8 @@ static int parse_argv(int argc, char *argv[]) {
949949

950950
case ARG_LINK_JOURNAL:
951951
r = parse_link_journal(optarg, &arg_link_journal, &arg_link_journal_try);
952-
if (r < 0) {
953-
log_error_errno(r, "Failed to parse link journal mode %s", optarg);
954-
return -EINVAL;
955-
}
952+
if (r < 0)
953+
return log_error_errno(r, "Failed to parse link journal mode %s", optarg);
956954

957955
arg_settings_mask |= SETTING_LINK_JOURNAL;
958956
break;
@@ -1243,9 +1241,8 @@ static int parse_argv(int argc, char *argv[]) {
12431241
if (r < 0)
12441242
return log_error_errno(r, "Failed to parse root hash: %s", optarg);
12451243
if (l < sizeof(sd_id128_t)) {
1246-
log_error("Root hash must be at least 128bit long: %s", optarg);
12471244
free(k);
1248-
return -EINVAL;
1245+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Root hash must be at least 128bit long: %s", optarg);
12491246
}
12501247

12511248
free(arg_root_hash);
@@ -1389,10 +1386,8 @@ static int parse_argv(int argc, char *argv[]) {
13891386
"read-only\n"
13901387
"passive\n"
13911388
"pipe");
1392-
else {
1393-
log_error("Unknown console mode: %s", optarg);
1394-
return -EINVAL;
1395-
}
1389+
else
1390+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown console mode: %s", optarg);
13961391

13971392
arg_settings_mask |= SETTING_CONSOLE_MODE;
13981393
break;
@@ -2618,10 +2613,8 @@ static int determine_names(void) {
26182613
return log_error_errno(r, "Failed to determine current directory: %m");
26192614
}
26202615

2621-
if (!arg_directory && !arg_image) {
2622-
log_error("Failed to determine path, please use -D or -i.");
2623-
return -EINVAL;
2624-
}
2616+
if (!arg_directory && !arg_image)
2617+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to determine path, please use -D or -i.");
26252618
}
26262619

26272620
if (!arg_machine) {
@@ -2644,10 +2637,8 @@ static int determine_names(void) {
26442637
return log_oom();
26452638

26462639
hostname_cleanup(arg_machine);
2647-
if (!machine_name_is_valid(arg_machine)) {
2648-
log_error("Failed to determine machine name automatically, please use -M.");
2649-
return -EINVAL;
2650-
}
2640+
if (!machine_name_is_valid(arg_machine))
2641+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to determine machine name automatically, please use -M.");
26512642

26522643
if (arg_ephemeral) {
26532644
char *b;
@@ -2774,10 +2765,8 @@ static int patch_sysctl(void) {
27742765
break;
27752766
}
27762767

2777-
if (!good) {
2778-
log_error("Refusing to write to sysctl '%s', as it is not safe in the selected namespaces.", *k);
2779-
return -EPERM;
2780-
}
2768+
if (!good)
2769+
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Refusing to write to sysctl '%s', as it is not safe in the selected namespaces.", *k);
27812770

27822771
r = sysctl_write(*k, *v);
27832772
if (r < 0)
@@ -4162,10 +4151,9 @@ static int run_container(int master,
41624151
log_debug_errno(r, "Cannot determine if passed network namespace path '%s' really refers to a network namespace, assuming it does.", arg_network_namespace_path);
41634152
else if (r < 0)
41644153
return log_error_errno(r, "Failed to check %s fs type: %m", arg_network_namespace_path);
4165-
else if (r == 0) {
4166-
log_error("Path %s doesn't refer to a network namespace, refusing.", arg_network_namespace_path);
4167-
return -EINVAL;
4168-
}
4154+
else if (r == 0)
4155+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
4156+
"Path %s doesn't refer to a network namespace, refusing.", arg_network_namespace_path);
41694157
}
41704158

41714159
*pid = raw_clone(SIGCHLD|CLONE_NEWNS);
@@ -4228,10 +4216,8 @@ static int run_container(int master,
42284216
l = recv(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, 0);
42294217
if (l < 0)
42304218
return log_error_errno(errno, "Failed to read UID shift: %m");
4231-
if (l != sizeof arg_uid_shift) {
4232-
log_error("Short read while reading UID shift.");
4233-
return -EIO;
4234-
}
4219+
if (l != sizeof arg_uid_shift)
4220+
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading UID shift.");
42354221

42364222
if (arg_userns_mode == USER_NAMESPACE_PICK) {
42374223
/* If we are supposed to pick the UID shift, let's try to use the shift read from the
@@ -4245,10 +4231,8 @@ static int run_container(int master,
42454231
l = send(uid_shift_socket_pair[0], &arg_uid_shift, sizeof arg_uid_shift, MSG_NOSIGNAL);
42464232
if (l < 0)
42474233
return log_error_errno(errno, "Failed to send UID shift: %m");
4248-
if (l != sizeof arg_uid_shift) {
4249-
log_error("Short write while writing UID shift.");
4250-
return -EIO;
4251-
}
4234+
if (l != sizeof arg_uid_shift)
4235+
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write while writing UID shift.");
42524236
}
42534237
}
42544238

@@ -4257,11 +4241,9 @@ static int run_container(int master,
42574241
l = recv(unified_cgroup_hierarchy_socket_pair[0], &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), 0);
42584242
if (l < 0)
42594243
return log_error_errno(errno, "Failed to read cgroup mode: %m");
4260-
if (l != sizeof(arg_unified_cgroup_hierarchy)) {
4261-
log_error("Short read while reading cgroup mode (%zu bytes).%s",
4262-
l, l == 0 ? " The child is most likely dead." : "");
4263-
return -EIO;
4264-
}
4244+
if (l != sizeof(arg_unified_cgroup_hierarchy))
4245+
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading cgroup mode (%zu bytes).%s",
4246+
l, l == 0 ? " The child is most likely dead." : "");
42654247
}
42664248

42674249
/* Wait for the outer child. */
@@ -4275,19 +4257,15 @@ static int run_container(int master,
42754257
l = recv(pid_socket_pair[0], pid, sizeof *pid, 0);
42764258
if (l < 0)
42774259
return log_error_errno(errno, "Failed to read inner child PID: %m");
4278-
if (l != sizeof *pid) {
4279-
log_error("Short read while reading inner child PID.");
4280-
return -EIO;
4281-
}
4260+
if (l != sizeof *pid)
4261+
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading inner child PID.");
42824262

42834263
/* We also retrieve container UUID in case it was generated by outer child */
42844264
l = recv(uuid_socket_pair[0], &arg_uuid, sizeof arg_uuid, 0);
42854265
if (l < 0)
42864266
return log_error_errno(errno, "Failed to read container machine ID: %m");
4287-
if (l != sizeof(arg_uuid)) {
4288-
log_error("Short read while reading container machined ID.");
4289-
return -EIO;
4290-
}
4267+
if (l != sizeof(arg_uuid))
4268+
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short read while reading container machined ID.");
42914269

42924270
/* We also retrieve the socket used for notifications generated by outer child */
42934271
notify_socket = receive_one_fd(notify_socket_pair[0], 0);
@@ -4298,10 +4276,8 @@ static int run_container(int master,
42984276
log_debug("Init process invoked as PID "PID_FMT, *pid);
42994277

43004278
if (arg_userns_mode != USER_NAMESPACE_NO) {
4301-
if (!barrier_place_and_sync(&barrier)) { /* #1 */
4302-
log_error("Child died too early.");
4303-
return -ESRCH;
4304-
}
4279+
if (!barrier_place_and_sync(&barrier)) /* #1 */
4280+
return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early.");
43054281

43064282
r = setup_uid_map(*pid);
43074283
if (r < 0)
@@ -4313,10 +4289,8 @@ static int run_container(int master,
43134289
if (arg_private_network) {
43144290
if (!arg_network_namespace_path) {
43154291
/* Wait until the child has unshared its network namespace. */
4316-
if (!barrier_place_and_sync(&barrier)) { /* #3 */
4317-
log_error("Child died too early");
4318-
return -ESRCH;
4319-
}
4292+
if (!barrier_place_and_sync(&barrier)) /* #3 */
4293+
return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early");
43204294
}
43214295

43224296
r = move_network_interfaces(*pid, arg_network_interfaces);
@@ -4472,10 +4446,8 @@ static int run_container(int master,
44724446
return r;
44734447

44744448
/* Let the child know that we are ready and wait that the child is completely ready now. */
4475-
if (!barrier_place_and_sync(&barrier)) { /* #5 */
4476-
log_error("Child died too early.");
4477-
return -ESRCH;
4478-
}
4449+
if (!barrier_place_and_sync(&barrier)) /* #5 */
4450+
return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Child died too early.");
44794451

44804452
/* At this point we have made use of the UID we picked, and thus nss-mymachines
44814453
* will make them appear in getpwuid(), thus we can release the /etc/passwd lock. */

src/resolve/resolvectl.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ int ifname_mangle(const char *s) {
119119
}
120120
}
121121

122-
if (arg_ifindex > 0 && arg_ifindex != ifi) {
123-
log_error("Specified multiple different interfaces. Refusing.");
124-
return -EINVAL;
125-
}
122+
if (arg_ifindex > 0 && arg_ifindex != ifi)
123+
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Specified multiple different interfaces. Refusing.");
126124

127125
arg_ifindex = ifi;
128126
free_and_replace(arg_ifname, iface);

0 commit comments

Comments
 (0)