40a46b
From 7ebf4a0faffecb3a0c8abe8bea47502044038d66 Mon Sep 17 00:00:00 2001
40a46b
From: lc85446 <lc85446@alibaba-inc.com>
40a46b
Date: Thu, 26 Nov 2015 11:46:40 +0800
40a46b
Subject: [PATCH] core:execute: fix fork() fail handling in exec_spawn()
40a46b
40a46b
If pid < 0 after fork(), 0 is always returned because r =
40a46b
exec_context_load_environment() has exited successfully.
40a46b
40a46b
This will make the caller of exec_spawn() not able to handle
40a46b
the fork() error case and make systemd abort assert() possibly.
40a46b
40a46b
Cherry-picked from: 74129a127676e4f0edac0db4296c103e76ec6694
40a46b
Resolves: #1437114
40a46b
---
40a46b
 src/core/execute.c | 2 +-
40a46b
 1 file changed, 1 insertion(+), 1 deletion(-)
40a46b
40a46b
diff --git a/src/core/execute.c b/src/core/execute.c
40a46b
index 4265b9c34..e68276973 100644
40a46b
--- a/src/core/execute.c
40a46b
+++ b/src/core/execute.c
40a46b
@@ -1977,7 +1977,7 @@ int exec_spawn(ExecCommand *command,
40a46b
                         NULL);
40a46b
         pid = fork();
40a46b
         if (pid < 0)
40a46b
-                return log_unit_error_errno(params->unit_id, r, "Failed to fork: %m");
40a46b
+                return log_unit_error_errno(params->unit_id, errno, "Failed to fork: %m");
40a46b
 
40a46b
         if (pid == 0) {
40a46b
                 int exit_status;