]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: error handling modernizations
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Mar 2023 08:37:41 +0000 (09:37 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 1 Mar 2023 22:52:55 +0000 (22:52 +0000)
src/core/execute.c
src/nspawn/nspawn.c

index e23faf25bd94e98933b43980f9ba89ecacd92848..dda8736804c5a01078f191f8f912c2db3fb25851 100644 (file)
@@ -4655,11 +4655,13 @@ static int exec_child(
 
         if (mpol_is_valid(numa_policy_get_type(&context->numa_policy))) {
                 r = apply_numa_policy(&context->numa_policy);
-                if (r == -EOPNOTSUPP)
-                        log_unit_debug_errno(unit, r, "NUMA support not available, ignoring.");
-                else if (r < 0) {
-                        *exit_status = EXIT_NUMA_POLICY;
-                        return log_unit_error_errno(unit, r, "Failed to set NUMA memory policy: %m");
+                if (r < 0) {
+                        if (ERRNO_IS_NOT_SUPPORTED(r))
+                                log_unit_debug_errno(unit, r, "NUMA support not available, ignoring.");
+                        else {
+                                *exit_status = EXIT_NUMA_POLICY;
+                                return log_unit_error_errno(unit, r, "Failed to set NUMA memory policy: %m");
+                        }
                 }
         }
 
@@ -4917,12 +4919,14 @@ static int exec_child(
 
                 if (ns_type_supported(NAMESPACE_NET)) {
                         r = setup_shareable_ns(runtime->netns_storage_socket, CLONE_NEWNET);
-                        if (r == -EPERM)
-                                log_unit_warning_errno(unit, r,
-                                                       "PrivateNetwork=yes is configured, but network namespace setup failed, ignoring: %m");
-                        else if (r < 0) {
-                                *exit_status = EXIT_NETWORK;
-                                return log_unit_error_errno(unit, r, "Failed to set up network namespacing: %m");
+                        if (r < 0) {
+                                if (ERRNO_IS_PRIVILEGE(r))
+                                        log_unit_warning_errno(unit, r,
+                                                               "PrivateNetwork=yes is configured, but network namespace setup failed, ignoring: %m");
+                                else {
+                                        *exit_status = EXIT_NETWORK;
+                                        return log_unit_error_errno(unit, r, "Failed to set up network namespacing: %m");
+                                }
                         }
                 } else if (context->network_namespace_path) {
                         *exit_status = EXIT_NETWORK;
index e498dc59c6e5aadafb9a8f0e79bb5acf9c2c7b42..5065c77fbbcc20d7dd513c217a5eba17e77abbde 100644 (file)
@@ -5518,8 +5518,8 @@ static int run(int argc, char *argv[]) {
                  * two systems write to the same /var). Let's allow it for the special cases where /var is
                  * either copied (i.e. --ephemeral) or replaced (i.e. --volatile=yes|state). */
                 if (path_equal(arg_directory, "/") && !(arg_ephemeral || IN_SET(arg_volatile_mode, VOLATILE_YES, VOLATILE_STATE))) {
-                        log_error("Spawning container on root directory is not supported. Consider using --ephemeral, --volatile=yes or --volatile=state.");
-                        r = -EINVAL;
+                        r = log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                            "Spawning container on root directory is not supported. Consider using --ephemeral, --volatile=yes or --volatile=state.");
                         goto finish;
                 }