Skip to content

Commit

Permalink
Add xpipe() to lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
landley committed Feb 8, 2016
1 parent 9b14cb6 commit 85f54d8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void xaccess(char *path, int flags);
void xunlink(char *path);
int xcreate(char *path, int flags, int mode);
int xopen(char *path, int flags);
void xpipe(int pp);
void xclose(int fd);
int xdup(int fd);
FILE *xfdopen(int fd, char *mode);
Expand Down
6 changes: 6 additions & 0 deletions lib/xwrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void xexit(void)
if (toys.rebound) longjmp(*toys.rebound, 1);
if (fflush(NULL) || ferror(stdout))
if (!toys.exitval) perror_msg("write");

exit(toys.exitval);
}

Expand Down Expand Up @@ -309,6 +310,11 @@ int xopen(char *path, int flags)
return xcreate(path, flags, 0);
}

void xpipe(int pp)
{
if (pipe(pp)) perror_exit("xpipe");
}

void xclose(int fd)
{
if (close(fd)) perror_exit("xclose");
Expand Down
2 changes: 1 addition & 1 deletion toys/pending/syslogd.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ void syslogd_main(void)
}

// Setup signals
if (pipe(TT.sigfd) < 0) error_exit("pipe failed\n");
xpipe(TT.sigfd);

fcntl(TT.sigfd[1] , F_SETFD, FD_CLOEXEC);
fcntl(TT.sigfd[0] , F_SETFD, FD_CLOEXEC);
Expand Down
2 changes: 1 addition & 1 deletion toys/pending/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ static void compress_stream(struct archive_handler *tar_hdl)
int pipefd[2];
pid_t cpid;

if (pipe(pipefd) == -1) error_exit("pipe");
xpipe(pipefd);

signal(SIGPIPE, SIG_IGN);
cpid = fork();
Expand Down

0 comments on commit 85f54d8

Please sign in to comment.