/* -*-c-*-
*
- * $Id: xcatch.c,v 1.4 1999/03/24 22:23:57 mdw Exp $
+ * $Id: xcatch.c,v 1.7 1999/05/21 22:09:19 mdw Exp $
*
* Catch input and trap it in an X window
*
/*----- Revision history --------------------------------------------------*
*
* $Log: xcatch.c,v $
+ * Revision 1.7 1999/05/21 22:09:19 mdw
+ * Take advantage of new dynamic string macros.
+ *
+ * Revision 1.6 1999/05/19 20:41:15 mdw
+ * Track gratuitous change in mdwopt interface.
+ *
+ * Revision 1.5 1999/05/05 18:55:18 mdw
+ * Block SIGCHLD around the `fork' call to prevent a race.
+ *
* Revision 1.4 1999/03/24 22:23:57 mdw
* Improve display for large files. Keep newly added material in view if
* scrolled to bottom of window.
{ "help", 0, 0, 'h' },
{ "usage", 0, 0, 'u' },
{ "version", 0, 0, 'v' },
- { "file", gFlag_argReq, 0, 'f' },
- { "font", gFlag_argReq, 0, 'F' },
+ { "file", OPTF_ARGREQ, 0, 'f' },
+ { "font", OPTF_ARGREQ, 0, 'F' },
{ 0, 0, 0, 0 }
};
int i = mdwopt(argc, argv, "huvf:F:", opt, 0, 0, 0);
else {
int pfd[2];
struct sigaction sa;
+ sigset_t newmask, oldmask;
/* --- Set up a signal handler --- */
if (pipe(pfd))
die(1, "couldn't open pipe: %s", strerror(errno));
+
+ sigemptyset(&newmask);
+ sigaddset(&newmask, SIGCHLD);
+ sigprocmask(SIG_BLOCK, &newmask, &oldmask);
+
kid = fork();
if (kid < 0)
die(1, "couldn't fork: %s", strerror(errno));
if (kid == 0) {
- dstr d;
+ dstr d = DSTR_INIT;
close(pfd[0]);
if (pfd[1] != STDOUT_FILENO)
close(pfd[1]);
execvp(argv[optind], argv + optind);
- dstr_create(&d);
dstr_putf(&d, "%s: couldn't run `%s': %s\n",
QUIS, argv[optind], strerror(errno));
write(STDERR_FILENO, d.buf, d.len);
+ dstr_destroy(&d);
_exit(127);
}
+
+ sigprocmask(SIG_SETMASK, &oldmask, 0);
fd = pfd[0];
close(pfd[1]);
}