diff options
author | Lennart Poettering <lennart@poettering.net> | 2017-02-09 13:17:00 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2017-02-09 13:18:35 +0100 |
commit | 376fecf6709fa7a080c9f5b4f9ee34b9eecfc0ac (patch) | |
tree | fba57ac1542db8e53e42db2db6cc67986775549d /src | |
parent | execute: use prefix_roota() where appropriate (diff) | |
download | systemd-376fecf6709fa7a080c9f5b4f9ee34b9eecfc0ac.tar.xz systemd-376fecf6709fa7a080c9f5b4f9ee34b9eecfc0ac.zip |
execute: set the right exit status for CHDIR vs. CHROOT
Fixes: #5125
Diffstat (limited to 'src')
-rw-r--r-- | src/core/execute.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index be03695776..6041da46d6 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -2015,16 +2015,20 @@ static int apply_working_directory( const ExecContext *context, const ExecParameters *params, const char *home, - const bool needs_mount_ns) { + const bool needs_mount_ns, + int *exit_status) { const char *d, *wd; assert(context); + assert(exit_status); if (context->working_directory_home) { - if (!home) + if (!home) { + *exit_status = EXIT_CHDIR; return -ENXIO; + } wd = home; @@ -2035,15 +2039,19 @@ static int apply_working_directory( if (params->flags & EXEC_APPLY_CHROOT) { if (!needs_mount_ns && context->root_directory) - if (chroot(context->root_directory) < 0) + if (chroot(context->root_directory) < 0) { + *exit_status = EXIT_CHROOT; return -errno; + } d = wd; } else d = prefix_roota(context->root_directory, wd); - if (chdir(d) < 0 && !context->working_directory_missing_ok) + if (chdir(d) < 0 && !context->working_directory_missing_ok) { + *exit_status = EXIT_CHDIR; return -errno; + } return 0; } @@ -2606,11 +2614,9 @@ static int exec_child( } /* Apply just after mount namespace setup */ - r = apply_working_directory(context, params, home, needs_mount_namespace); - if (r < 0) { - *exit_status = EXIT_CHROOT; + r = apply_working_directory(context, params, home, needs_mount_namespace, exit_status); + if (r < 0) return r; - } /* Drop groups as early as possbile */ if ((params->flags & EXEC_APPLY_PERMISSIONS) && !command->privileged) { |