mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-30 05:28:50 +00:00
Wait for all children processes to stop
This fixes installation failing when we check for the wrong child and don't let the installer finish. However, this code now ignores the status from the child. I might see if there's a better way around fixing that..
This commit is contained in:
1 parent
f36397e89c
commit
b2cb1bd531
1 file changed
+25
-13
Vendored
+25
-13
@@ -32,21 +32,33 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, arguments, NULL) == errAuthorizationSuccess)
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, arguments, NULL) == errAuthorizationSuccess) {
|
||||
#pragma clang diagnostic pop
|
||||
{
|
||||
int status = 0;
|
||||
pid_t pid = 0;
|
||||
|
||||
do {
|
||||
pid = wait(&status);
|
||||
} while (pid == -1 && errno == EINTR);
|
||||
|
||||
if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
returnValue = NO;
|
||||
}
|
||||
else
|
||||
// Wait for every child to finish termination because we won't know which particular child is ours.
|
||||
// Perhaps in the future writing a custom wrapper tool that communicates its pid in stdout may be a better route
|
||||
// However that has the security issue of anyone being able to swap in our tool with their own
|
||||
// Another possible idea is using sh -c and echo'ing the pid which we read from here, then executing our command,
|
||||
// but we would have to be careful about sanitizing paths, \ escaping quotation marks, ...
|
||||
while (true) {
|
||||
pid_t waitPid = 0;
|
||||
int waitStatus = 0;
|
||||
|
||||
waitPid = wait(&waitStatus);
|
||||
if (waitPid != -1 || errno == EINTR) {
|
||||
// Continue and wait for all children to terminate
|
||||
} else {
|
||||
if (errno != ECHILD) {
|
||||
// Ran into an abnormal error
|
||||
returnValue = NO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// We can't check the status from wait() here because the child whose status we check may not be the child we are responsible for
|
||||
// So we will assume that the process terminated successfully; I know, not ideal.
|
||||
} else {
|
||||
returnValue = NO;
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user