diff --git a/psrelay/psrelay.c b/psrelay/psrelay.c index f1ef05b..5e613a1 100644 --- a/psrelay/psrelay.c +++ b/psrelay/psrelay.c @@ -1,7 +1,5 @@ -#include /* errno */ #include /* open(2), O_RDONLY */ -#include /* fprintf(3) */ -#include /* strerror(3) */ +#include /* fprintf(3), perror(3) */ #if !defined EX_OK || !defined EX_OSERR || !defined EX_USAGE # include #endif @@ -10,23 +8,6 @@ #include /* wait(2), WIFEXITED, WEXITSTATUS */ #include "libpsargs.h" -int oserr(char *argv0, char *s){ - - fprintf(stderr, "%s: %s\n", argv0, s); - - return EX_OSERR; -} - -int usage(char *s){ - - fprintf(stderr, - "Usage: %s \"[\" [command (arguments...)] \"]\"" - " \"[\" [command (arguments...)] \"]\"\n", - s); - - return EX_USAGE; -} - int main(int argc, char *argv[]){ int child; char **corr; @@ -35,13 +16,21 @@ int main(int argc, char *argv[]){ int i; int r; - if(argc < 2 || check_arg(curr = &argv[1]) != 2) - return usage(argc == 0 ? "" : argv[0]); + if(argc < 2 || check_arg(curr = &argv[1]) != 2){ + fprintf(stderr, + "Usage: %s \"[\" [command (arguments...)] \"]\"" + " \"[\" [command (arguments...)] \"]\"\n", + argc == 0 ? "" : argv[0]); + return EX_USAGE; + } /* substitute standard input for /dev/null */ if((fd = dup(STDIN_FILENO)) < 0 - || dup2(open("/dev/null", O_RDONLY), STDIN_FILENO) < 0) - return oserr(argv[0], strerror(errno)); + || dup2(open("/dev/null", O_RDONLY), STDIN_FILENO) + < 0){ + perror(argv[0]); + return EX_OSERR; + } for(i = 0; ; ++i){ *(corr = corresponding_arg(curr++)) = NULL; @@ -51,8 +40,10 @@ int main(int argc, char *argv[]){ if( r == -1 /* fork(2) failed */ || i == 1 || r == 0 /* exec(3) failed */ - || dup2(fd, STDIN_FILENO) != STDIN_FILENO) - return oserr(argv[0], strerror(errno)); + || dup2(fd, STDIN_FILENO) != STDIN_FILENO){ + perror(argv[0]); + return EX_OSERR; + } wait(&child); if(!WIFEXITED(child) || WEXITSTATUS(child) != 0)