diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2014-04-22 20:34:09 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2014-04-22 20:35:44 -0300 |
commit | 1afbc190872b72eaf8f2b3cb1efbbef5a0add268 (patch) | |
tree | 3a856a87b545c1e137ca98c0e782f8d26a91b237 /TraceScreen.c | |
parent | 28d4cad5fe728a0b116e5c91e426dca4eff14f78 (diff) |
safer code, test for return of fcntl
Diffstat (limited to 'TraceScreen.c')
-rw-r--r-- | TraceScreen.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/TraceScreen.c b/TraceScreen.c index 89581a9b..5823022f 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -87,9 +87,11 @@ void TraceScreen_run(TraceScreen* this) { if (child == -1) return; if (child == 0) { dup2(fdpair[1], STDERR_FILENO); - fcntl(fdpair[1], F_SETFL, O_NONBLOCK); - sprintf(buffer, "%d", this->process->pid); - execlp("strace", "strace", "-p", buffer, NULL); + int ok = fcntl(fdpair[1], F_SETFL, O_NONBLOCK); + if (ok != -1) { + sprintf(buffer, "%d", this->process->pid); + execlp("strace", "strace", "-p", buffer, NULL); + } const char* message = "Could not execute 'strace'. Please make sure it is available in your $PATH."; write(fdpair[1], message, strlen(message)); exit(1); |