@@ -2015,16 +2015,20 @@ static int apply_working_directory(
20152015 const ExecContext * context ,
20162016 const ExecParameters * params ,
20172017 const char * home ,
2018- const bool needs_mount_ns ) {
2018+ const bool needs_mount_ns ,
2019+ int * exit_status ) {
20192020
20202021 const char * d , * wd ;
20212022
20222023 assert (context );
2024+ assert (exit_status );
20232025
20242026 if (context -> working_directory_home ) {
20252027
2026- if (!home )
2028+ if (!home ) {
2029+ * exit_status = EXIT_CHDIR ;
20272030 return - ENXIO ;
2031+ }
20282032
20292033 wd = home ;
20302034
@@ -2035,15 +2039,19 @@ static int apply_working_directory(
20352039
20362040 if (params -> flags & EXEC_APPLY_CHROOT ) {
20372041 if (!needs_mount_ns && context -> root_directory )
2038- if (chroot (context -> root_directory ) < 0 )
2042+ if (chroot (context -> root_directory ) < 0 ) {
2043+ * exit_status = EXIT_CHROOT ;
20392044 return - errno ;
2045+ }
20402046
20412047 d = wd ;
20422048 } else
20432049 d = prefix_roota (context -> root_directory , wd );
20442050
2045- if (chdir (d ) < 0 && !context -> working_directory_missing_ok )
2051+ if (chdir (d ) < 0 && !context -> working_directory_missing_ok ) {
2052+ * exit_status = EXIT_CHDIR ;
20462053 return - errno ;
2054+ }
20472055
20482056 return 0 ;
20492057}
@@ -2606,11 +2614,9 @@ static int exec_child(
26062614 }
26072615
26082616 /* Apply just after mount namespace setup */
2609- r = apply_working_directory (context , params , home , needs_mount_namespace );
2610- if (r < 0 ) {
2611- * exit_status = EXIT_CHROOT ;
2617+ r = apply_working_directory (context , params , home , needs_mount_namespace , exit_status );
2618+ if (r < 0 )
26122619 return r ;
2613- }
26142620
26152621 /* Drop groups as early as possbile */
26162622 if ((params -> flags & EXEC_APPLY_PERMISSIONS ) && !command -> privileged ) {
0 commit comments