mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-12-25 01:29:53 +03:00
Merge pull request #258 from ajeecai/Run_deadlock
Fix a deadlock when Run() to create a process.
This commit is contained in:
commit
b1f74268b1
47
src/Mayaqua/Unix.c
Normal file → Executable file
47
src/Mayaqua/Unix.c
Normal file → Executable file
@ -1219,7 +1219,9 @@ bool UnixRunW(wchar_t *filename, wchar_t *arg, bool hide, bool wait)
|
||||
bool UnixRun(char *filename, char *arg, bool hide, bool wait)
|
||||
{
|
||||
TOKEN_LIST *t;
|
||||
char **args;
|
||||
UINT ret;
|
||||
|
||||
// Validate arguments
|
||||
if (filename == NULL)
|
||||
{
|
||||
@ -1230,6 +1232,25 @@ bool UnixRun(char *filename, char *arg, bool hide, bool wait)
|
||||
arg = "";
|
||||
}
|
||||
|
||||
Print("", filename, arg);
|
||||
t = ParseToken(arg, " ");
|
||||
if (t == NULL)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
UINT num_args;
|
||||
UINT i;
|
||||
num_args = t->NumTokens + 2;
|
||||
args = ZeroMalloc(sizeof(char *) * num_args);
|
||||
args[0] = filename;
|
||||
for (i = 1;i < num_args - 1;i++)
|
||||
{
|
||||
args[i] = t->Token[i - 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Create a child process
|
||||
ret = fork();
|
||||
if (ret == -1)
|
||||
@ -1240,39 +1261,21 @@ bool UnixRun(char *filename, char *arg, bool hide, bool wait)
|
||||
|
||||
if (ret == 0)
|
||||
{
|
||||
Print("", filename, arg);
|
||||
// Child process
|
||||
if (hide)
|
||||
{
|
||||
// Close the standard I/O
|
||||
UnixCloseIO();
|
||||
}
|
||||
|
||||
t = ParseToken(arg, " ");
|
||||
if (t == NULL)
|
||||
{
|
||||
AbortExit();
|
||||
}
|
||||
else
|
||||
{
|
||||
char **args;
|
||||
UINT num_args;
|
||||
UINT i;
|
||||
num_args = t->NumTokens + 2;
|
||||
args = ZeroMalloc(sizeof(char *) * num_args);
|
||||
args[0] = filename;
|
||||
for (i = 1;i < num_args - 1;i++)
|
||||
{
|
||||
args[i] = t->Token[i - 1];
|
||||
}
|
||||
execvp(filename, args);
|
||||
AbortExit();
|
||||
}
|
||||
execvp(filename, args);
|
||||
AbortExit();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Parent process
|
||||
pid_t pid = (pid_t)ret;
|
||||
Free(args);
|
||||
FreeToken(t);
|
||||
|
||||
if (wait)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user