NEWS: fix typo
[s-mailx.git] / popen.c
blob0434fac2aa88edd67639ffd26616fbed4626f932
1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Handling of pipes, child processes, temporary files, file enwrapping.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 - 2014 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
6 */
7 /*
8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
40 #ifndef HAVE_AMALGAMATION
41 # include "nail.h"
42 #endif
44 #include <sys/wait.h>
46 #include <fcntl.h>
48 #define READ 0
49 #define WRITE 1
51 #ifndef O_CLOEXEC
52 # define _OUR_CLOEXEC
53 # define O_CLOEXEC 0
54 # define _SET_CLOEXEC(FD) fcntl((FD), F_SETFD, FD_CLOEXEC)
55 #else
56 # define _SET_CLOEXEC(FD)
57 #endif
59 struct fp {
60 FILE *fp;
61 struct fp *link;
62 char *realfile;
63 long offset;
64 int omode;
65 int pipe;
66 int pid;
67 enum {
68 FP_RAW = 0,
69 FP_GZIP = 1<<0,
70 FP_XZ = 1<<1,
71 FP_BZIP2 = 1<<2,
72 FP_IMAP = 1<<3,
73 FP_MAILDIR = 1<<4,
74 FP_MASK = (1<<5) - 1,
75 FP_READONLY = 1<<5
76 } compressed;
79 struct child {
80 int pid;
81 char done;
82 char free;
83 int status;
84 struct child *link;
87 static struct fp *fp_head;
88 static struct child *_popen_child;
90 static int scan_mode(char const *mode, int *omode);
91 static void register_file(FILE *fp, int omode, int ispipe, int pid,
92 int compressed, char const *realfile, long offset);
93 static enum okay _compress(struct fp *fpp);
94 static int _decompress(int compression, int infd, int outfd);
95 static enum okay unregister_file(FILE *fp);
96 static int file_pid(FILE *fp);
97 static int wait_command(int pid);
98 static struct child *findchild(int pid);
99 static void delchild(struct child *cp);
101 static int
102 scan_mode(char const *mode, int *omode)
104 static struct {
105 char const mode[4];
106 int omode;
107 } const maps[] = {
108 {"r", O_RDONLY},
109 {"w", O_WRONLY | O_CREAT | O_TRUNC},
110 {"wx", O_WRONLY | O_CREAT | O_EXCL},
111 {"a", O_WRONLY | O_APPEND | O_CREAT},
112 {"a+", O_RDWR | O_APPEND},
113 {"r+", O_RDWR},
114 {"w+", O_RDWR | O_CREAT | O_EXCL}
117 int i;
118 NYD_ENTER;
120 for (i = 0; UICMP(z, i, <, NELEM(maps)); ++i)
121 if (!strcmp(maps[i].mode, mode)) {
122 *omode = maps[i].omode;
123 i = 0;
124 goto jleave;
127 fprintf(stderr, tr(152, "Internal error: bad stdio open mode %s\n"), mode);
128 errno = EINVAL;
129 *omode = 0; /* (silence CC) */
130 i = -1;
131 jleave:
132 NYD_LEAVE;
133 return i;
136 static void
137 register_file(FILE *fp, int omode, int ispipe, int pid, int compressed,
138 char const *realfile, long offset)
140 struct fp *fpp;
141 NYD_ENTER;
143 fpp = smalloc(sizeof *fpp);
144 fpp->fp = fp;
145 fpp->omode = omode;
146 fpp->pipe = ispipe;
147 fpp->pid = pid;
148 fpp->link = fp_head;
149 fpp->compressed = compressed;
150 fpp->realfile = realfile ? sstrdup(realfile) : NULL;
151 fpp->offset = offset;
152 fp_head = fpp;
153 NYD_LEAVE;
156 static enum okay
157 _compress(struct fp *fpp)
159 char const *cmd[2];
160 int outfd;
161 enum okay rv;
162 NYD_ENTER;
164 if (fpp->omode == O_RDONLY) {
165 rv = OKAY;
166 goto jleave;
168 rv = STOP;
170 fflush(fpp->fp);
171 clearerr(fpp->fp);
172 if (fseek(fpp->fp, fpp->offset, SEEK_SET) < 0)
173 goto jleave;
175 #ifdef HAVE_IMAP
176 if ((fpp->compressed & FP_MASK) == FP_IMAP) {
177 rv = imap_append(fpp->realfile, fpp->fp);
178 goto jleave;
180 #endif
181 if ((fpp->compressed & FP_MASK) == FP_MAILDIR) {
182 rv = maildir_append(fpp->realfile, fpp->fp);
183 goto jleave;
186 outfd = open(fpp->realfile, (fpp->omode | O_CREAT) & ~O_EXCL, 0666);
187 if (outfd < 0) {
188 fprintf(stderr, "Fatal: cannot create ");
189 perror(fpp->realfile);
190 goto jleave;
192 if ((fpp->omode & O_APPEND) == 0)
193 ftruncate(outfd, 0);
194 switch (fpp->compressed & FP_MASK) {
195 case FP_GZIP:
196 cmd[0] = "gzip"; cmd[1] = "-c"; break;
197 case FP_BZIP2:
198 cmd[0] = "bzip2"; cmd[1] = "-c"; break;
199 case FP_XZ:
200 cmd[0] = "xz"; cmd[1] = "-c"; break;
201 default:
202 cmd[0] = "cat"; cmd[1] = NULL; break;
204 if (run_command(cmd[0], 0, fileno(fpp->fp), outfd, cmd[1], NULL, NULL) >= 0)
205 rv = OKAY;
206 close(outfd);
207 jleave:
208 NYD_LEAVE;
209 return rv;
212 static int
213 _decompress(int compression, int infd, int outfd)
215 char const *cmd[2];
216 int rv;
217 NYD_ENTER;
219 switch (compression & FP_MASK) {
220 case FP_GZIP: cmd[0] = "gzip"; cmd[1] = "-cd"; break;
221 case FP_BZIP2: cmd[0] = "bzip2"; cmd[1] = "-cd"; break;
222 case FP_XZ: cmd[0] = "xz"; cmd[1] = "-cd"; break;
223 default: cmd[0] = "cat"; cmd[1] = NULL; break;
224 case FP_IMAP:
225 case FP_MAILDIR:
226 rv = 0;
227 goto jleave;
229 rv = run_command(cmd[0], 0, infd, outfd, cmd[1], NULL, NULL);
230 jleave:
231 NYD_LEAVE;
232 return rv;
235 static enum okay
236 unregister_file(FILE *fp)
238 struct fp **pp, *p;
239 enum okay rv = OKAY;
240 NYD_ENTER;
242 for (pp = &fp_head; (p = *pp) != NULL; pp = &p->link)
243 if (p->fp == fp) {
244 if ((p->compressed & FP_MASK) != FP_RAW) /* TODO ;} */
245 rv = _compress(p);
246 *pp = p->link;
247 free(p);
248 goto jleave;
250 rv = STOP;
251 panic(tr(153, "Invalid file pointer"));
252 jleave:
253 NYD_LEAVE;
254 return rv;
257 static int
258 file_pid(FILE *fp)
260 int rv;
261 struct fp *p;
262 NYD_ENTER;
264 rv = -1;
265 for (p = fp_head; p; p = p->link)
266 if (p->fp == fp) {
267 rv = p->pid;
268 break;
270 NYD_LEAVE;
271 return rv;
274 static int
275 wait_command(int pid)
277 int rv = 0;
278 NYD_ENTER;
280 if (!wait_child(pid, NULL)) {
281 if (ok_blook(bsdcompat) || ok_blook(bsdmsgs))
282 fprintf(stderr, tr(154, "Fatal error in process.\n"));
283 rv = -1;
285 NYD_LEAVE;
286 return rv;
289 static struct child *
290 findchild(int pid)
292 struct child **cpp;
293 NYD_ENTER;
295 for (cpp = &_popen_child; *cpp != NULL && (*cpp)->pid != pid;
296 cpp = &(*cpp)->link)
298 if (*cpp == NULL) {
299 *cpp = smalloc(sizeof **cpp);
300 (*cpp)->pid = pid;
301 (*cpp)->done = (*cpp)->free = 0;
302 (*cpp)->link = NULL;
304 NYD_LEAVE;
305 return *cpp;
308 static void
309 delchild(struct child *cp)
311 struct child **cpp;
312 NYD_ENTER;
314 for (cpp = &_popen_child; *cpp != cp; cpp = &(*cpp)->link)
316 *cpp = cp->link;
317 free(cp);
318 NYD_LEAVE;
321 FL FILE *
322 safe_fopen(char const *file, char const *oflags, int *xflags)
324 int osflags, fd;
325 FILE *fp = NULL;
326 NYD_ENTER;
328 if (scan_mode(oflags, &osflags) < 0)
329 goto jleave;
330 osflags |= O_CLOEXEC;
331 if (xflags != NULL)
332 *xflags = osflags;
334 if ((fd = open(file, osflags, 0666)) < 0)
335 goto jleave;
336 _SET_CLOEXEC(fd);
338 fp = fdopen(fd, oflags);
339 jleave:
340 NYD_LEAVE;
341 return fp;
344 FL FILE *
345 Fopen(char const *file, char const *oflags)
347 FILE *fp;
348 int osflags;
349 NYD_ENTER;
351 if ((fp = safe_fopen(file, oflags, &osflags)) != NULL)
352 register_file(fp, osflags, 0, 0, FP_RAW, NULL, 0L);
353 NYD_LEAVE;
354 return fp;
357 FL FILE *
358 Fdopen(int fd, char const *oflags)
360 FILE *fp;
361 int osflags;
362 NYD_ENTER;
364 scan_mode(oflags, &osflags);
365 osflags |= O_CLOEXEC;
367 if ((fp = fdopen(fd, oflags)) != NULL)
368 register_file(fp, osflags, 0, 0, FP_RAW, NULL, 0L);
369 NYD_LEAVE;
370 return fp;
373 FL int
374 Fclose(FILE *fp)
376 int i = 0;
377 NYD_ENTER;
379 if (unregister_file(fp) == OKAY)
380 i |= 1;
381 if (fclose(fp) == 0)
382 i |= 2;
383 NYD_LEAVE;
384 return i == 3 ? 0 : EOF;
387 FL FILE *
388 Zopen(char const *file, char const *oflags, int *compression) /* FIXME MESS! */
390 FILE *rv = NULL;
391 int _compression, osflags, mode, infd;
392 enum oflags rof;
393 long offset;
394 enum protocol p;
395 NYD_ENTER;
397 if (compression == NULL)
398 compression = &_compression;
400 if (scan_mode(oflags, &osflags) < 0)
401 goto jleave;
402 rof = OF_RDWR | OF_UNLINK;
403 if (osflags & O_APPEND)
404 rof |= OF_APPEND;
405 if (osflags == O_RDONLY) {
406 mode = R_OK;
407 *compression = FP_READONLY;
408 } else {
409 mode = R_OK | W_OK;
410 *compression = 0;
413 /* TODO ???? */
414 if ((osflags & O_APPEND) && ((p = which_protocol(file)) == PROTO_IMAP ||
415 p == PROTO_MAILDIR)) {
416 *compression |= (p == PROTO_IMAP) ? FP_IMAP : FP_MAILDIR;
417 osflags = O_RDWR | O_APPEND | O_CREAT;
418 infd = -1;
419 } else {
420 char const *ext;
422 if ((ext = strrchr(file, '.')) != NULL) {
423 if (!strcmp(ext, ".gz"))
424 *compression |= FP_GZIP;
425 else if (!strcmp(ext, ".xz"))
426 *compression |= FP_XZ;
427 else if (!strcmp(ext, ".bz2"))
428 *compression |= FP_BZIP2;
429 else
430 goto jraw;
431 } else {
432 jraw:
433 *compression |= FP_RAW;
434 rv = Fopen(file, oflags);
435 goto jleave;
437 if ((infd = open(file, (mode & W_OK) ? O_RDWR : O_RDONLY)) == -1 &&
438 (!(osflags & O_CREAT) || errno != ENOENT))
439 goto jleave;
442 if ((rv = Ftmp(NULL, "zopen", rof, 0600)) == NULL) {
443 perror(tr(167, "tmpfile"));
444 goto jerr;
446 if (infd >= 0 || (*compression & FP_MASK) == FP_IMAP ||
447 (*compression & FP_MASK) == FP_MAILDIR) {
448 if (_decompress(*compression, infd, fileno(rv)) < 0) {
449 jerr:
450 if (rv != NULL)
451 Fclose(rv);
452 rv = NULL;
453 if (infd >= 0)
454 close(infd);
455 goto jleave;
457 } else {
458 if ((infd = creat(file, 0666)) == -1) {
459 Fclose(rv);
460 rv = NULL;
461 goto jleave;
464 if (infd >= 0)
465 close(infd);
466 fflush(rv);
468 if (!(osflags & O_APPEND))
469 rewind(rv);
470 if ((offset = ftell(rv)) == -1) {
471 Fclose(rv);
472 rv = NULL;
473 goto jleave;
475 register_file(rv, osflags, 0, 0, *compression, file, offset);
476 jleave:
477 NYD_LEAVE;
478 return rv;
481 FL FILE *
482 Ftmp(char **fn, char const *prefix, enum oflags oflags, int mode)
484 FILE *fp = NULL;
485 char *cp_base, *cp;
486 int fd;
487 NYD_ENTER;
489 cp_base =
490 cp = smalloc(strlen(tempdir) + 1 + sizeof("mail") + strlen(prefix) + 7 +1);
491 cp = sstpcpy(cp, tempdir);
492 *cp++ = '/';
493 cp = sstpcpy(cp, "mail");
494 if (*prefix) {
495 *cp++ = '-';
496 cp = sstpcpy(cp, prefix);
498 /* TODO Ftmp(): unroll our own creation loop with atoi(random()) */
499 sstpcpy(cp, ".XXXXXX");
501 hold_all_sigs();
502 #ifdef HAVE_MKSTEMP
503 if ((fd = mkstemp(cp_base)) == -1)
504 goto jfree;
505 if (mode != (S_IRUSR | S_IWUSR) && fchmod(fd, mode) == -1)
506 goto jclose;
507 if (oflags & OF_APPEND) {
508 int f;
510 if ((f = fcntl(fd, F_GETFL)) == -1 ||
511 fcntl(fd, F_SETFL, f | O_APPEND) == -1) {
512 jclose:
513 close(fd);
514 goto junlink;
517 if (!(oflags & OF_REGISTER))
518 fcntl(fd, F_SETFD, FD_CLOEXEC);
519 #else
520 if (mktemp(cp_base) == NULL)
521 goto jfree;
522 if ((fd = open(cp_base, O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC |
523 (oflags & OF_APPEND ? O_APPEND : 0), mode)) < 0)
524 goto junlink;
525 #endif
527 fp = (*((oflags & OF_REGISTER) ? &Fdopen : &fdopen))(fd,
528 (oflags & OF_RDWR ? "w+" : "w"));
529 if (fp == NULL || (oflags & OF_UNLINK)) {
530 junlink:
531 unlink(cp_base);
532 goto jfree;
535 if (fn != NULL)
536 *fn = cp_base;
537 jleave:
538 if (fp == NULL || !(oflags & OF_HOLDSIGS))
539 rele_all_sigs();
540 NYD_LEAVE;
541 return fp;
542 jfree:
543 if ((cp = cp_base) != NULL)
544 free(cp);
545 goto jleave;
548 FL void
549 Ftmp_release(char **fn)
551 char *cp;
552 NYD_ENTER;
554 cp = *fn;
555 *fn = NULL;
556 if (cp != NULL) {
557 unlink(cp);
558 rele_all_sigs();
559 free(cp);
561 NYD_LEAVE;
564 FL void
565 Ftmp_free(char **fn)
567 char *cp;
568 NYD_ENTER;
570 cp = *fn;
571 *fn = NULL;
572 if (cp != NULL)
573 free(cp);
574 NYD_LEAVE;
577 FL bool_t
578 pipe_cloexec(int fd[2])
580 bool_t rv = FAL0;
581 NYD_ENTER;
583 if (pipe(fd) < 0)
584 goto jleave;
585 fcntl(fd[0], F_SETFD, FD_CLOEXEC);
586 fcntl(fd[1], F_SETFD, FD_CLOEXEC);
587 rv = TRU1;
588 jleave:
589 NYD_LEAVE;
590 return rv;
593 FL FILE *
594 Popen(char const *cmd, char const *mode, char const *sh, int newfd1)
596 int p[2], myside, hisside, fd0, fd1, pid;
597 char mod[2] = { '0', '\0' };
598 sigset_t nset;
599 FILE *rv = NULL;
600 NYD_ENTER;
602 if (!pipe_cloexec(p))
603 goto jleave;
605 if (*mode == 'r') {
606 myside = p[READ];
607 fd0 = -1;
608 hisside = fd1 = p[WRITE];
609 mod[0] = *mode;
610 } else if (*mode == 'W') {
611 myside = p[WRITE];
612 hisside = fd0 = p[READ];
613 fd1 = newfd1;
614 mod[0] = 'w';
615 } else {
616 myside = p[WRITE];
617 hisside = fd0 = p[READ];
618 fd1 = -1;
619 mod[0] = 'w';
621 sigemptyset(&nset);
622 if (sh == NULL) {
623 pid = start_command(cmd, &nset, fd0, fd1, NULL, NULL, NULL);
624 } else {
625 pid = start_command(sh, &nset, fd0, fd1, "-c", cmd, NULL);
627 if (pid < 0) {
628 close(p[READ]);
629 close(p[WRITE]);
630 goto jleave;
632 close(hisside);
633 if ((rv = fdopen(myside, mod)) != NULL)
634 register_file(rv, 0, 1, pid, FP_RAW, NULL, 0L);
635 jleave:
636 NYD_LEAVE;
637 return rv;
640 FL bool_t
641 Pclose(FILE *ptr, bool_t dowait)
643 sigset_t nset, oset;
644 int pid;
645 bool_t rv = FAL0;
646 NYD_ENTER;
648 pid = file_pid(ptr);
649 if (pid < 0)
650 goto jleave;
651 unregister_file(ptr);
652 fclose(ptr);
653 if (dowait) {
654 sigemptyset(&nset);
655 sigaddset(&nset, SIGINT);
656 sigaddset(&nset, SIGHUP);
657 sigprocmask(SIG_BLOCK, &nset, &oset);
658 rv = wait_child(pid, NULL);
659 sigprocmask(SIG_SETMASK, &oset, NULL);
660 } else {
661 free_child(pid);
662 rv = TRU1;
664 jleave:
665 NYD_LEAVE;
666 return rv;
669 FL void
670 close_all_files(void)
672 NYD_ENTER;
673 while (fp_head != NULL)
674 if (fp_head->pipe)
675 Pclose(fp_head->fp, TRU1);
676 else
677 Fclose(fp_head->fp);
678 NYD_LEAVE;
681 FL int
682 run_command(char const *cmd, sigset_t *mask, int infd, int outfd,
683 char const *a0, char const *a1, char const *a2)
685 int rv;
686 NYD_ENTER;
688 if ((rv = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0)
689 rv = -1;
690 else
691 rv = wait_command(rv);
692 NYD_LEAVE;
693 return rv;
696 FL int
697 start_command(char const *cmd, sigset_t *mask, int infd, int outfd,
698 char const *a0, char const *a1, char const *a2)
700 int rv;
701 NYD_ENTER;
703 if ((rv = fork()) < 0) {
704 perror("fork");
705 rv = -1;
706 } else if (rv == 0) {
707 char *argv[100];
708 int i = getrawlist(cmd, strlen(cmd), argv, NELEM(argv), 0);
710 if ((argv[i++] = UNCONST(a0)) != NULL &&
711 (argv[i++] = UNCONST(a1)) != NULL &&
712 (argv[i++] = UNCONST(a2)) != NULL)
713 argv[i] = NULL;
714 prepare_child(mask, infd, outfd);
715 execvp(argv[0], argv);
716 perror(argv[0]);
717 _exit(1);
719 NYD_LEAVE;
720 return rv;
723 FL void
724 prepare_child(sigset_t *nset, int infd, int outfd)
726 int i;
727 sigset_t fset;
728 NYD_ENTER;
730 /* All file descriptors other than 0, 1, and 2 are supposed to be cloexec */
731 if (infd >= 0)
732 dup2(infd, 0);
733 if (outfd >= 0)
734 dup2(outfd, 1);
736 if (nset) {
737 for (i = 1; i < NSIG; ++i)
738 if (sigismember(nset, i))
739 safe_signal(i, SIG_IGN);
740 if (!sigismember(nset, SIGINT))
741 safe_signal(SIGINT, SIG_DFL);
744 sigemptyset(&fset);
745 sigprocmask(SIG_SETMASK, &fset, NULL);
746 NYD_LEAVE;
749 FL void
750 sigchild(int signo)
752 int pid, status;
753 struct child *cp;
754 NYD_X; /* Signal handler */
755 UNUSED(signo);
757 jagain:
758 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
759 cp = findchild(pid);
760 if (cp->free)
761 delchild(cp);
762 else {
763 cp->done = 1;
764 cp->status = status;
767 if (pid == -1 && errno == EINTR)
768 goto jagain;
771 FL void
772 free_child(int pid)
774 sigset_t nset, oset;
775 struct child *cp;
776 NYD_ENTER;
778 sigemptyset(&nset);
779 sigaddset(&nset, SIGCHLD);
780 sigprocmask(SIG_BLOCK, &nset, &oset);
782 cp = findchild(pid);
783 if (cp->done)
784 delchild(cp);
785 else
786 cp->free = 1;
788 sigprocmask(SIG_SETMASK, &oset, NULL);
789 NYD_LEAVE;
792 FL bool_t
793 wait_child(int pid, int *wait_status)
795 sigset_t nset, oset;
796 struct child *cp;
797 int ws;
798 bool_t rv;
799 NYD_ENTER;
801 sigemptyset(&nset);
802 sigaddset(&nset, SIGCHLD);
803 sigprocmask(SIG_BLOCK, &nset, &oset);
805 cp = findchild(pid);
806 while (!cp->done)
807 sigsuspend(&oset);
808 ws = cp->status;
809 delchild(cp);
811 sigprocmask(SIG_SETMASK, &oset, NULL);
813 if (wait_status != NULL)
814 *wait_status = ws;
815 rv = (WIFEXITED(ws) && WEXITSTATUS(ws) == 0);
816 NYD_LEAVE;
817 return rv;
820 #ifdef _OUR_CLOEXEC
821 # undef O_CLOEXEC
822 # undef _OUR_CLOEXEC
823 #endif
824 #undef _SET_CLOEXEC
826 /* vim:set fenc=utf-8:s-it-mode */