* - fixed a rare deadlock after child termination
*/
-/*
- * script
- */
#include <stdio.h>
#include <stdlib.h>
#include <paths.h>
# include <utempter.h>
#endif
-#define DEFAULT_OUTPUT "typescript"
+#define DEFAULT_TYPESCRIPT_FILENAME "typescript"
enum { POLLFDS = 3 };
#endif
unsigned int
aflg:1, /* append output */
- eflg:1, /* return child exit value */
+ rc_wanted:1, /* return child exit value */
fflg:1, /* flush after each write */
qflg:1, /* suppress most output */
tflg:1, /* include timing file */
forceflg:1, /* write output to links */
isterm:1, /* is child process running as terminal */
die:1; /* terminate program */
+
sigset_t sigset; /* catch SIGCHLD and SIGWINCH with signalfd() */
int sigfd; /* file descriptor for signalfd() */
};
#endif
kill(ctl->child, SIGTERM); /* make sure we don't create orphans */
- if (ctl->eflg) {
+ if (ctl->timingfp)
+ fclose(ctl->timingfp);
+ fclose(ctl->typescriptfp);
+
+ if (ctl->rc_wanted) {
if (WIFSIGNALED(ctl->childstatus))
exit(WTERMSIG(ctl->childstatus) + 0x80);
else
exit(WEXITSTATUS(ctl->childstatus));
}
- if (ctl->timingfp)
- fclose(ctl->timingfp);
- fclose(ctl->typescriptfp);
exit(EXIT_SUCCESS);
}
ctl.cflg = optarg;
break;
case 'e':
- ctl.eflg = 1;
+ ctl.rc_wanted = 1;
break;
case 'f':
ctl.fflg = 1;
if (argc > 0)
ctl.fname = argv[0];
else {
- ctl.fname = DEFAULT_OUTPUT;
+ ctl.fname = DEFAULT_TYPESCRIPT_FILENAME;
die_if_link(&ctl);
}