tree-wide: flatten nested error checks
This commit is contained in:
committed by
Yu Watanabe
parent
13a74f350e
commit
94446e4f5a
+6
-10
@@ -1263,12 +1263,10 @@ int flush_accept(int fd) {
|
||||
int cfd;
|
||||
|
||||
r = fd_wait_for_event(fd, POLLIN, 0);
|
||||
if (r < 0) {
|
||||
if (r == -EINTR)
|
||||
continue;
|
||||
|
||||
if (r == -EINTR)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
if (r == 0)
|
||||
return 0;
|
||||
|
||||
@@ -1305,12 +1303,10 @@ ssize_t flush_mqueue(int fd) {
|
||||
ssize_t l;
|
||||
|
||||
r = fd_wait_for_event(fd, POLLIN, /* timeout= */ 0);
|
||||
if (r < 0) {
|
||||
if (r == -EINTR)
|
||||
continue;
|
||||
|
||||
if (r == -EINTR)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
if (r == 0)
|
||||
return count;
|
||||
|
||||
|
||||
+3
-5
@@ -199,12 +199,10 @@ static Virtualization detect_vm_dmi_vendor(void) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
|
||||
r = read_one_line_file(*vendor, &s);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
continue;
|
||||
|
||||
if (r == -ENOENT)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
FOREACH_ELEMENT(dmi_vendor, dmi_vendor_table)
|
||||
if (startswith(s, dmi_vendor->vendor)) {
|
||||
|
||||
@@ -810,12 +810,10 @@ static int report_credentials_per_func(const char *title, int (*get_directory_fu
|
||||
assert(get_directory_func);
|
||||
|
||||
r = get_directory_func(&d);
|
||||
if (r < 0) {
|
||||
if (r == -ENXIO) /* Env var not set */
|
||||
return 0;
|
||||
|
||||
if (r == -ENXIO) /* Env var not set */
|
||||
return 0;
|
||||
if (r < 0)
|
||||
return log_warning_errno(r, "Failed to determine %s directory: %m", title);
|
||||
}
|
||||
|
||||
r = readdir_all_at(AT_FDCWD, d, RECURSE_DIR_SORT|RECURSE_DIR_IGNORE_DOT, &de);
|
||||
if (r < 0)
|
||||
|
||||
@@ -5573,16 +5573,13 @@ int config_parse_emergency_action(
|
||||
runtime_scope = ltype; /* otherwise, assume the scope is passed in via ltype */
|
||||
|
||||
r = parse_emergency_action(rvalue, runtime_scope, x);
|
||||
if (r < 0) {
|
||||
if (r == -EOPNOTSUPP)
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"%s= specified as %s mode action, ignoring: %s",
|
||||
lvalue, runtime_scope_to_string(runtime_scope), rvalue);
|
||||
else
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse %s=, ignoring: %s", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
if (r == -EOPNOTSUPP)
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"%s= specified as %s mode action, ignoring: %s",
|
||||
lvalue, runtime_scope_to_string(runtime_scope), rvalue);
|
||||
else if (r < 0)
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse %s=, ignoring: %s", lvalue, rvalue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -198,18 +198,16 @@ static int manager_deserialize_one_unit(Manager *m, const char *name, FILE *f, F
|
||||
int r;
|
||||
|
||||
r = manager_load_unit(m, name, NULL, NULL, &u);
|
||||
if (r < 0) {
|
||||
if (r == -ENOMEM)
|
||||
return r;
|
||||
if (r == -ENOMEM)
|
||||
return r;
|
||||
if (r < 0)
|
||||
return log_notice_errno(r, "Failed to load unit \"%s\", skipping deserialization: %m", name);
|
||||
}
|
||||
|
||||
r = unit_deserialize_state(u, f, fds);
|
||||
if (r < 0) {
|
||||
if (r == -ENOMEM)
|
||||
return r;
|
||||
if (r == -ENOMEM)
|
||||
return r;
|
||||
if (r < 0)
|
||||
return log_notice_errno(r, "Failed to deserialize unit \"%s\", skipping: %m", name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+12
-14
@@ -174,23 +174,21 @@ static int run(int argc, char *argv[]) {
|
||||
case ACTION_ESCAPE:
|
||||
if (arg_path) {
|
||||
r = unit_name_path_escape(*i, &e);
|
||||
if (r < 0) {
|
||||
if (r == -EINVAL) {
|
||||
/* If escaping failed because the string was invalid, let's print a
|
||||
* friendly message about it. Catch these specific error cases
|
||||
* explicitly. */
|
||||
|
||||
if (!path_is_valid(*i))
|
||||
return log_error_errno(r, "Input '%s' is not a valid file system path, failed to escape.", *i);
|
||||
if (!path_is_absolute(*i))
|
||||
return log_error_errno(r, "Input '%s' is not an absolute file system path, failed to escape.", *i);
|
||||
if (!path_is_normalized(*i))
|
||||
return log_error_errno(r, "Input '%s' is not a normalized file system path, failed to escape.", *i);
|
||||
}
|
||||
if (r == -EINVAL) {
|
||||
/* If escaping failed because the string was invalid, let's print a
|
||||
* friendly message about it. Catch these specific error cases
|
||||
* explicitly. */
|
||||
|
||||
if (!path_is_valid(*i))
|
||||
return log_error_errno(r, "Input '%s' is not a valid file system path, failed to escape.", *i);
|
||||
if (!path_is_absolute(*i))
|
||||
return log_error_errno(r, "Input '%s' is not an absolute file system path, failed to escape.", *i);
|
||||
if (!path_is_normalized(*i))
|
||||
return log_error_errno(r, "Input '%s' is not a normalized file system path, failed to escape.", *i);
|
||||
}
|
||||
if (r < 0)
|
||||
/* All other error cases. */
|
||||
return log_error_errno(r, "Failed to escape string: %m");
|
||||
}
|
||||
|
||||
/* If the escaping worked, then still warn if the path is not like we'd like
|
||||
* it. Because that means escaping is not necessarily reversible. */
|
||||
|
||||
@@ -71,12 +71,10 @@ static int fscrypt_unlink_key(UserRecord *h) {
|
||||
char *d;
|
||||
|
||||
r = keyring_describe(*key, &description);
|
||||
if (r < 0) {
|
||||
if (r == -ENOKEY) /* Something else deleted it already, that's ok. */
|
||||
continue;
|
||||
|
||||
if (r == -ENOKEY) /* Something else deleted it already, that's ok. */
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to describe key id %d: %m", *key);
|
||||
}
|
||||
|
||||
/* The description is the final element as per manpage. */
|
||||
d = strrchr(description, ';');
|
||||
|
||||
@@ -2353,16 +2353,12 @@ int home_create_luks(
|
||||
0,
|
||||
LOCK_EX,
|
||||
&setup->loop);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT) { /* this means /dev/loop-control doesn't exist, i.e. we are in a container
|
||||
* or similar and loopback bock devices are not available, return a
|
||||
* recognizable error in this case. */
|
||||
log_error_errno(r, "Loopback block device support is not available on this system.");
|
||||
return -ENOLINK; /* Make recognizable */
|
||||
}
|
||||
|
||||
if (r == -ENOENT) /* this means /dev/loop-control doesn't exist, i.e. we are in a container
|
||||
* or similar and loopback bock devices are not available, return a
|
||||
* recognizable error in this case. */
|
||||
return log_error_errno(SYNTHETIC_ERRNO(ENOLINK), "Loopback block device support is not available on this system.");
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to set up loopback device for %s: %m", setup->temporary_image_path);
|
||||
}
|
||||
|
||||
log_info("Setting up loopback device %s completed.", setup->loop->node ?: ip);
|
||||
|
||||
|
||||
@@ -1802,12 +1802,10 @@ int device_read_db_internal_filename(sd_device *device, const char *filename) {
|
||||
assert(filename);
|
||||
|
||||
r = read_full_file(filename, &db, &db_len);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
|
||||
if (r == -ENOENT)
|
||||
return 0;
|
||||
if (r < 0)
|
||||
return log_device_debug_errno(device, r, "sd-device: Failed to read db '%s': %m", filename);
|
||||
}
|
||||
|
||||
/* devices with a database entry are initialized */
|
||||
device->is_initialized = true;
|
||||
|
||||
@@ -772,14 +772,13 @@ int manager_read_efi_boot_loader_entries(Manager *m) {
|
||||
return 0;
|
||||
|
||||
r = efi_loader_get_entries(&m->efi_boot_loader_entries);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) {
|
||||
log_debug_errno(r, "Boot loader reported no entries.");
|
||||
m->efi_boot_loader_entries_set = true;
|
||||
return 0;
|
||||
}
|
||||
return log_error_errno(r, "Failed to determine entries reported by boot loader: %m");
|
||||
if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r)) {
|
||||
log_debug_errno(r, "Boot loader reported no entries.");
|
||||
m->efi_boot_loader_entries_set = true;
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine entries reported by boot loader: %m");
|
||||
|
||||
m->efi_boot_loader_entries_set = true;
|
||||
return 1;
|
||||
|
||||
@@ -2820,15 +2820,13 @@ static int method_schedule_shutdown(sd_bus_message *message, void *userdata, sd_
|
||||
if (elapse == USEC_INFINITY) {
|
||||
if (m->maintenance_time) {
|
||||
r = calendar_spec_next_usec(m->maintenance_time, now(CLOCK_REALTIME), &elapse);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT)
|
||||
return sd_bus_error_set(error,
|
||||
BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED,
|
||||
"No upcoming maintenance window scheduled");
|
||||
|
||||
if (r == -ENOENT)
|
||||
return sd_bus_error_set(error,
|
||||
BUS_ERROR_DESIGNATED_MAINTENANCE_TIME_NOT_SCHEDULED,
|
||||
"No upcoming maintenance window scheduled");
|
||||
if (r < 0)
|
||||
return sd_bus_error_set_errnof(error, r,
|
||||
"Failed to determine next maintenance window: %m");
|
||||
}
|
||||
|
||||
log_info("Scheduled %s at maintenance window %s", type, FORMAT_TIMESTAMP(elapse));
|
||||
} else
|
||||
|
||||
+11
-14
@@ -8297,13 +8297,12 @@ static int context_fstab(Context *context) {
|
||||
switch (arg_append_fstab) {
|
||||
case APPEND_AUTO: {
|
||||
r = read_full_file(path, &c, NULL);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT) {
|
||||
log_debug("File fstab not found in %s", path);
|
||||
break;
|
||||
}
|
||||
return log_error_errno(r, "Failed to open %s: %m", path);
|
||||
if (r == -ENOENT) {
|
||||
log_debug("File fstab not found in %s", path);
|
||||
break;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to open %s: %m", path);
|
||||
|
||||
const char *acs, *ace;
|
||||
acs = find_line(c, AUTOMATIC_FSTAB_HEADER_START);
|
||||
@@ -9713,11 +9712,10 @@ static int parse_efi_variable_factory_reset(void) {
|
||||
return 0;
|
||||
|
||||
r = efi_get_variable_string(EFI_SYSTEMD_VARIABLE_STR("FactoryReset"), &value);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r))
|
||||
return 0;
|
||||
if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r))
|
||||
return 0;
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to read EFI variable FactoryReset: %m");
|
||||
}
|
||||
|
||||
log_warning("Warning, EFI variable FactoryReset is in use, please migrate to use FactoryResetRequest instead, support will be removed in v260!");
|
||||
|
||||
@@ -9738,11 +9736,10 @@ static int remove_efi_variable_factory_reset(void) {
|
||||
// FIXME: Remove this in v260, see above
|
||||
|
||||
r = efi_set_variable(EFI_SYSTEMD_VARIABLE_STR("FactoryReset"), NULL, 0);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r))
|
||||
return 0;
|
||||
if (r == -ENOENT || ERRNO_IS_NEG_NOT_SUPPORTED(r))
|
||||
return 0;
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to remove EFI variable FactoryReset: %m");
|
||||
}
|
||||
|
||||
log_info("Successfully unset EFI variable FactoryReset.");
|
||||
return 0;
|
||||
|
||||
@@ -51,14 +51,12 @@ static int builtin_net_setup_link(UdevEvent *event, int argc, char **argv) {
|
||||
return log_device_warning_errno(dev, r, "Failed to get link information: %m");
|
||||
|
||||
r = link_get_config(ctx, link);
|
||||
if (r < 0) {
|
||||
if (r == -ENOENT) {
|
||||
log_device_debug_errno(dev, r, "No matching link configuration found, ignoring device.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return log_device_error_errno(dev, r, "Failed to get link config: %m");
|
||||
if (r == -ENOENT) {
|
||||
log_device_debug_errno(dev, r, "No matching link configuration found, ignoring device.");
|
||||
return 0;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_device_error_errno(dev, r, "Failed to get link config: %m");
|
||||
|
||||
r = link_apply_config(ctx, link);
|
||||
if (r == -ENODEV)
|
||||
|
||||
Reference in New Issue
Block a user