aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFRIGN <dev@frign.de>2015-07-08 23:49:25 +0200
committerChristoph Lohmann <20h@r-36.net>2015-07-09 18:34:41 +0200
commitabfad4c4fc69ebb22febfe32677aadd112ce375a (patch)
tree57f76f8a1fa41e9a5edeb39df1fce22b926560ba
parent92e092efe6c6b2a6b6ec9da33170317d4426cab0 (diff)
downloadst-abfad4c4fc69ebb22febfe32677aadd112ce375a.tar.gz
st-abfad4c4fc69ebb22febfe32677aadd112ce375a.zip
Remove insane *_FILENO and EXIT_* usage
Any system having different assignments than the usual 0, 1, 2 for the standard file numbers and 0, 1 for the exit-statuses is broken beyond repair. Let's keep it simple and just use the numbers, no reason to fall out of the window here and bend down for POSIX. In one occasion, the ret-variable was not necessary. The check was rewritten. Signed-off-by: Christoph Lohmann <20h@r-36.net>
-rw-r--r--st.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/st.c b/st.c
index b89d094..46c0b6e 100644
--- a/st.c
+++ b/st.c
@@ -513,7 +513,7 @@ static STREscape strescseq;
513static int cmdfd; 513static int cmdfd;
514static pid_t pid; 514static pid_t pid;
515static Selection sel; 515static Selection sel;
516static int iofd = STDOUT_FILENO; 516static int iofd = 1;
517static char **opt_cmd = NULL; 517static char **opt_cmd = NULL;
518static char *opt_io = NULL; 518static char *opt_io = NULL;
519static char *opt_title = NULL; 519static char *opt_title = NULL;
@@ -1207,7 +1207,7 @@ die(const char *errstr, ...) {
1207 va_start(ap, errstr); 1207 va_start(ap, errstr);
1208 vfprintf(stderr, errstr, ap); 1208 vfprintf(stderr, errstr, ap);
1209 va_end(ap); 1209 va_end(ap);
1210 exit(EXIT_FAILURE); 1210 exit(1);
1211} 1211}
1212 1212
1213void 1213void
@@ -1256,12 +1256,12 @@ execsh(void) {
1256 signal(SIGALRM, SIG_DFL); 1256 signal(SIGALRM, SIG_DFL);
1257 1257
1258 execvp(prog, args); 1258 execvp(prog, args);
1259 _exit(EXIT_FAILURE); 1259 _exit(1);
1260} 1260}
1261 1261
1262void 1262void
1263sigchld(int a) { 1263sigchld(int a) {
1264 int stat, ret; 1264 int stat;
1265 pid_t p; 1265 pid_t p;
1266 1266
1267 if((p = waitpid(pid, &stat, WNOHANG)) < 0) 1267 if((p = waitpid(pid, &stat, WNOHANG)) < 0)
@@ -1270,10 +1270,9 @@ sigchld(int a) {
1270 if(pid != p) 1270 if(pid != p)
1271 return; 1271 return;
1272 1272
1273 ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE; 1273 if (!WIFEXITED(stat) || WEXITSTATUS(stat))
1274 if (ret != EXIT_SUCCESS)
1275 die("child finished with error '%d'\n", stat); 1274 die("child finished with error '%d'\n", stat);
1276 exit(EXIT_SUCCESS); 1275 exit(0);
1277} 1276}
1278 1277
1279 1278
@@ -1309,8 +1308,7 @@ ttynew(void) {
1309 if(opt_io) { 1308 if(opt_io) {
1310 term.mode |= MODE_PRINT; 1309 term.mode |= MODE_PRINT;
1311 iofd = (!strcmp(opt_io, "-")) ? 1310 iofd = (!strcmp(opt_io, "-")) ?
1312 STDOUT_FILENO : 1311 1 : open(opt_io, O_WRONLY | O_CREAT, 0666);
1313 open(opt_io, O_WRONLY | O_CREAT, 0666);
1314 if(iofd < 0) { 1312 if(iofd < 0) {
1315 fprintf(stderr, "Error opening %s:%s\n", 1313 fprintf(stderr, "Error opening %s:%s\n",
1316 opt_io, strerror(errno)); 1314 opt_io, strerror(errno));
@@ -1320,7 +1318,7 @@ ttynew(void) {
1320 if (opt_line) { 1318 if (opt_line) {
1321 if((cmdfd = open(opt_line, O_RDWR)) < 0) 1319 if((cmdfd = open(opt_line, O_RDWR)) < 0)
1322 die("open line failed: %s\n", strerror(errno)); 1320 die("open line failed: %s\n", strerror(errno));
1323 close(STDIN_FILENO); 1321 close(0);
1324 dup(cmdfd); 1322 dup(cmdfd);
1325 stty(); 1323 stty();
1326 return; 1324 return;
@@ -1337,9 +1335,9 @@ ttynew(void) {
1337 case 0: 1335 case 0:
1338 close(iofd); 1336 close(iofd);
1339 setsid(); /* create a new process group */ 1337 setsid(); /* create a new process group */
1340 dup2(s, STDIN_FILENO); 1338 dup2(s, 0);
1341 dup2(s, STDOUT_FILENO); 1339 dup2(s, 1);
1342 dup2(s, STDERR_FILENO); 1340 dup2(s, 2);
1343 if(ioctl(s, TIOCSCTTY, NULL) < 0) 1341 if(ioctl(s, TIOCSCTTY, NULL) < 0)
1344 die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); 1342 die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
1345 close(s); 1343 close(s);
@@ -3871,7 +3869,7 @@ cmessage(XEvent *e) {
3871 } else if(e->xclient.data.l[0] == xw.wmdeletewin) { 3869 } else if(e->xclient.data.l[0] == xw.wmdeletewin) {
3872 /* Send SIGHUP to shell */ 3870 /* Send SIGHUP to shell */
3873 kill(pid, SIGHUP); 3871 kill(pid, SIGHUP);
3874 exit(EXIT_SUCCESS); 3872 exit(0);
3875 } 3873 }
3876} 3874}
3877 3875