From 165f7d72641bf3880eb73bbd37d3e4d61ce98019 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sat, 17 Sep 2016 00:51:55 -0400 Subject: Check child status in pbd --- .bin/pbd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.bin/pbd.c b/.bin/pbd.c index 3f924f2c..47fdedc4 100755 --- a/.bin/pbd.c +++ b/.bin/pbd.c @@ -1,5 +1,5 @@ #if 0 -exec clang -Weverything -Wno-missing-prototypes $@ -o $(dirname $0)/pbd $0 +exec clang -Weverything $@ -o $(dirname $0)/pbd $0 #endif #include @@ -11,14 +11,16 @@ exec clang -Weverything -Wno-missing-prototypes $@ -o $(dirname $0)/pbd $0 #include #include -void spawn(const char *cmd, int child_fd, int parent_fd) { +static void spawn(const char *cmd, int child_fd, int parent_fd) { pid_t pid = fork(); if (pid < 0) err(EX_OSERR, "fork"); if (pid) { - if (waitpid(pid, NULL, 0) < 0) + int status; + if (waitpid(pid, &status, 0) < 0) err(EX_OSERR, "waitpid"); - // TODO: Check child status. + if (status) + warnx("child %s status %d", cmd, status); } else { if (dup2(parent_fd, child_fd) < 0) err(EX_OSERR, "dup2"); @@ -49,12 +51,13 @@ int main() { spawn("pbpaste", STDOUT_FILENO, client); - uint8_t x; - ssize_t peek = recv(client, &x, 1, MSG_PEEK); + uint8_t p; + ssize_t peek = recv(client, &p, 1, MSG_PEEK); if (peek < 0) err(EX_IOERR, "recv"); if (peek) spawn("pbcopy", STDIN_FILENO, client); - if (close(client) < 0) warn("close"); + if (close(client) < 0) + err(EX_IOERR, "close"); } } -- cgit 1.4.1