Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child process doesn't terminate if execvp fails #84

Closed
Voxel07 opened this issue Jul 27, 2021 · 4 comments · Fixed by #118
Closed

Child process doesn't terminate if execvp fails #84

Voxel07 opened this issue Jul 27, 2021 · 4 comments · Fixed by #118
Assignees

Comments

@Voxel07
Copy link

Voxel07 commented Jul 27, 2021

In process_utils.cpp at L80, the child process should not return the execvp value but exit with it.

return ret; should be _exit(ret);

Otherwise, if the exec command fails, the child process will not be terminated and continue to run the main process code.

Question return or exit
Question _exit or exit

Log Snipped:

2021-07-27T09:23:54.3444Z [I] Installing image file: 'appUpdate' type: 'application' [Install]
2021-07-27T09:23:54.3444Z [I] Starting ChildProcess [ADUC_LaunchChildProcess]
2021-07-27T09:23:54.3445Z [I] Arg 0 = -af [ADUC_LaunchChildProcess]
2021-07-27T09:23:54.3445Z [I] Arg 1 = /tmp/aduc-dl-210727092348/appUpdate [ADUC_LaunchChildProcess]
2021-07-27T09:23:54.3445Z [I] Arg 2 = --debug [ADUC_LaunchChildProcess]
execvp failed, ret -1, error 2
2021-07-27T09:23:54.7003Z [E] Install failed, extendedResultCode = -1 [Install]
2021-07-27T09:23:54.7025Z [I] Action 'Install' complete. Result: 0, -1 [ADUC_Workflow_WorkCompletionCallback]
2021-07-27T09:23:54.7026Z [E] Install failed. error 0, -1 - Expecting service to send Cancel action [ADUC_Workflow_WorkCompletionCallback]
2021-07-27T09:23:54.7026Z [I] Setting UpdateState to Failed [ADUC_SetUpdateStateHelper]
2021-07-27T09:23:54.7026Z [I] Reporting state: 255, Failed (255); HTTP 500; result 0, -1 [AzureDeviceUpdateCoreInterface_ReportStateAndResultAsync]
2021-07-27T09:23:54.7072Z [I] Child process terminated normally, signal 0 [ADUC_LaunchChildProcess]
2021-07-27T09:23:54.7073Z [I] Install succeeded [Install]
2021-07-27T09:23:54.7073Z [I] Action 'Install' complete. Result: 1, 0 [ADUC_Workflow_WorkCompletionCallback]
2021-07-27T09:23:54.7074Z [I] WorkCompletionCallback: Install succeeded. Going to state InstallSucceeded [ADUC_Workflow_WorkCompletionCallback]
2021-07-27T09:23:54.7074Z [I] Setting UpdateState to InstallSucceeded [ADUC_SetUpdateStateHelper]
2021-07-27T09:23:54.7074Z [I] Reporting state: InstallSucceeded (4) [AzureDeviceUpdateCoreInterface_ReportStateAndResultAsync]
2021-07-27T09:23:54.7075Z [I] Calling ADUC_RebootSystem [ADUC_MethodCall_RebootSystem]
2021-07-27T09:23:54.7075Z [I] ADUC_RebootSystem called. Rebooting system. [ADUC_RebootSystem]
2021-07-27T09:23:54.7132Z [E] Reboot failed. [ADUC_RebootSystem]
@ValOlson
Copy link
Contributor

Hi @Voxel07,

Thank you for raising this issue. We will investigate and add a fix in our code.

@wasabii
Copy link

wasabii commented Dec 15, 2021

#113

This was linked to pull requests Feb 4, 2022
@jw-msft
Copy link
Contributor

jw-msft commented Feb 4, 2022

Thank you for your contributions @wasabii and @Voxel07. The fix was included with the 0.8.0 release. It is mentioned in the CHANGELOG.md and release notes under Notable fixes.

@jw-msft
Copy link
Contributor

jw-msft commented Feb 4, 2022

--- a/src/utils/process_utils/src/process_utils.cpp
+++ b/src/utils/process_utils/src/process_utils.cpp
@@ -80,11 +80,11 @@ int ADUC_LaunchChildProcess(const std::string& command, std::vector<std::string>

         // The exec() functions only return if an error has occurred.
         // The return value is -1, and errno is set to indicate the error.
-        int ret = execvp(command.c_str(), &argv[0]);
+        int status = execvp(command.c_str(), &argv[0]);

-        fprintf(stderr, "execvp failed, ret %d, error %d\n", ret, errno);
+        fprintf(stderr, "execvp failed, returned %d, error %d\n", status, errno);

-        return ret;
+        _exit(EXIT_FAILURE);
     }

     close(filedes[WRITE_END]);

@jw-msft jw-msft closed this as completed Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants