From 1afbc190872b72eaf8f2b3cb1efbbef5a0add268 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 22 Apr 2014 20:34:09 -0300 Subject: safer code, test for return of fcntl --- TraceScreen.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'TraceScreen.c') 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); -- cgit v1.2.3