mirror of
https://github.com/LukeSmithxyz/st.git
synced 2024-11-22 07:15:59 +01:00
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>
This commit is contained in:
parent
92e092efe6
commit
abfad4c4fc
1 changed files with 12 additions and 14 deletions
26
st.c
26
st.c
|
@ -513,7 +513,7 @@ static STREscape strescseq;
|
||||||
static int cmdfd;
|
static int cmdfd;
|
||||||
static pid_t pid;
|
static pid_t pid;
|
||||||
static Selection sel;
|
static Selection sel;
|
||||||
static int iofd = STDOUT_FILENO;
|
static int iofd = 1;
|
||||||
static char **opt_cmd = NULL;
|
static char **opt_cmd = NULL;
|
||||||
static char *opt_io = NULL;
|
static char *opt_io = NULL;
|
||||||
static char *opt_title = NULL;
|
static char *opt_title = NULL;
|
||||||
|
@ -1207,7 +1207,7 @@ die(const char *errstr, ...) {
|
||||||
va_start(ap, errstr);
|
va_start(ap, errstr);
|
||||||
vfprintf(stderr, errstr, ap);
|
vfprintf(stderr, errstr, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
exit(EXIT_FAILURE);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1256,12 +1256,12 @@ execsh(void) {
|
||||||
signal(SIGALRM, SIG_DFL);
|
signal(SIGALRM, SIG_DFL);
|
||||||
|
|
||||||
execvp(prog, args);
|
execvp(prog, args);
|
||||||
_exit(EXIT_FAILURE);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sigchld(int a) {
|
sigchld(int a) {
|
||||||
int stat, ret;
|
int stat;
|
||||||
pid_t p;
|
pid_t p;
|
||||||
|
|
||||||
if((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
if((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
||||||
|
@ -1270,10 +1270,9 @@ sigchld(int a) {
|
||||||
if(pid != p)
|
if(pid != p)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ret = WIFEXITED(stat) ? WEXITSTATUS(stat) : EXIT_FAILURE;
|
if (!WIFEXITED(stat) || WEXITSTATUS(stat))
|
||||||
if (ret != EXIT_SUCCESS)
|
|
||||||
die("child finished with error '%d'\n", stat);
|
die("child finished with error '%d'\n", stat);
|
||||||
exit(EXIT_SUCCESS);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1309,8 +1308,7 @@ ttynew(void) {
|
||||||
if(opt_io) {
|
if(opt_io) {
|
||||||
term.mode |= MODE_PRINT;
|
term.mode |= MODE_PRINT;
|
||||||
iofd = (!strcmp(opt_io, "-")) ?
|
iofd = (!strcmp(opt_io, "-")) ?
|
||||||
STDOUT_FILENO :
|
1 : open(opt_io, O_WRONLY | O_CREAT, 0666);
|
||||||
open(opt_io, O_WRONLY | O_CREAT, 0666);
|
|
||||||
if(iofd < 0) {
|
if(iofd < 0) {
|
||||||
fprintf(stderr, "Error opening %s:%s\n",
|
fprintf(stderr, "Error opening %s:%s\n",
|
||||||
opt_io, strerror(errno));
|
opt_io, strerror(errno));
|
||||||
|
@ -1320,7 +1318,7 @@ ttynew(void) {
|
||||||
if (opt_line) {
|
if (opt_line) {
|
||||||
if((cmdfd = open(opt_line, O_RDWR)) < 0)
|
if((cmdfd = open(opt_line, O_RDWR)) < 0)
|
||||||
die("open line failed: %s\n", strerror(errno));
|
die("open line failed: %s\n", strerror(errno));
|
||||||
close(STDIN_FILENO);
|
close(0);
|
||||||
dup(cmdfd);
|
dup(cmdfd);
|
||||||
stty();
|
stty();
|
||||||
return;
|
return;
|
||||||
|
@ -1337,9 +1335,9 @@ ttynew(void) {
|
||||||
case 0:
|
case 0:
|
||||||
close(iofd);
|
close(iofd);
|
||||||
setsid(); /* create a new process group */
|
setsid(); /* create a new process group */
|
||||||
dup2(s, STDIN_FILENO);
|
dup2(s, 0);
|
||||||
dup2(s, STDOUT_FILENO);
|
dup2(s, 1);
|
||||||
dup2(s, STDERR_FILENO);
|
dup2(s, 2);
|
||||||
if(ioctl(s, TIOCSCTTY, NULL) < 0)
|
if(ioctl(s, TIOCSCTTY, NULL) < 0)
|
||||||
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
|
die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
|
||||||
close(s);
|
close(s);
|
||||||
|
@ -3871,7 +3869,7 @@ cmessage(XEvent *e) {
|
||||||
} else if(e->xclient.data.l[0] == xw.wmdeletewin) {
|
} else if(e->xclient.data.l[0] == xw.wmdeletewin) {
|
||||||
/* Send SIGHUP to shell */
|
/* Send SIGHUP to shell */
|
||||||
kill(pid, SIGHUP);
|
kill(pid, SIGHUP);
|
||||||
exit(EXIT_SUCCESS);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue