diff options
| author | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-06-19 00:10:00 +0200 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@users.sourceforge.net> | 2008-06-19 00:10:00 +0200 |
| commit | a54366fd435e11ef3d594bcf3419df400725dabe (patch) | |
| tree | 2a4378e78f5b0a6d318282e11b8e1e58e9a39c15 /UCoreUtils.pas | |
| parent | 5a7f575133656f20cf64ee591818a5178a002788 (diff) | |
| download | tuxcmd-a54366fd435e11ef3d594bcf3419df400725dabe.tar.xz | |
Fix crash while executing invalid command
Diffstat (limited to 'UCoreUtils.pas')
| -rw-r--r-- | UCoreUtils.pas | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 8fa6fef..ed697d5 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -1129,6 +1129,7 @@ begin end; // Duplicate this process + DebugMsg(['SpawnProcess: before fork']); child_pid := fork; if child_pid <> 0 then begin Result := child_pid; @@ -1140,14 +1141,17 @@ begin if args_list <> nil then libc_free(args_list); Application.ProcessMessages; Running := ChildExitStatus < 0; + DebugMsg(['SpawnProcess: ChildExitStatus = ', ChildExitStatus]); if not Running then Result := 0; if not WIFEXITED(ChildExitStatus) then Result := WTERMSIG(ChildExitStatus); + DebugMsg(['SpawnProcess: Result = ', Result]); end else begin // Now execute AppPath, searching for it in the path execvp(PChar(AppPath), args_list); // The execvp function returns only if an error occurs sigqueue(getppid, SIGUSR1, sv); - Halt(ConstERRSpawn); + DebugMsg(['SpawnProcess: forked: error, sending SIGUSR1']); + _exit(ConstERRSpawn); end; ChildExitStatus := -1; end; @@ -1241,7 +1245,11 @@ begin if Length(Args) = 0 then Exit; for x := 0 to Length(Args) - 1 do Args[x] := RemoveQuotation(Args[x]); DebugMsg(['**** Running spawn']); - x := SpawnProcess(Args[0], Running, Args); + try + x := SpawnProcess(Args[0], Running, Args); + except + on E: Exception do DebugMsg(['ExecuteProgram(AppCMDLine = ''', AppCMDLine, '''): Exception: ', E.Message]); + end; DebugMsg(['**** Running spawn -- done']); Result := Running; if not Running then ErrorSignal := x; @@ -1378,7 +1386,7 @@ begin execvp(PChar(Parameters[0]), args_list); DebugMsg(['***** HandleSystemCommand: failed execvp: something went wrong...']); WriteLn(erroutput, 'Error executing command'); - Halt(ConstERRSpawn); + _exit(ConstERRSpawn); end; Result := Length(s) = 0; @@ -1929,7 +1937,7 @@ begin memset(@sigchld_action, 0, SizeOf(__sigaction)); sigchld_action.__sigaction_handler := @signal_proc; sigaction(SIGUSR1, @sigchld_action, nil); - sigaction(SIGCHLD, @sigchld_action, nil); + sigaction(SIGCHLD, @sigchld_action, nil); end; procedure SetupColors; |
