summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@gmail.com>2025-06-17 11:46:25 -0700
committerNed T. Crigler <crigler@gmail.com>2025-06-17 11:46:25 -0700
commit5e3865328e4609f74bd10cb4575e429b8d1b3aa4 (patch)
tree7c70c9ed351ad771247ba84e64bed355fc3fb963
parent1e462729c1bc7325bb1126a674d1fb7b91cf836a (diff)
Make dtach -N return the exit status of the program
Also change the execvp error exit from 127 to 1 to be consistent between dtach -n and dtach -N.
-rw-r--r--dtach.h1
-rw-r--r--master.c11
2 files changed, 11 insertions, 1 deletions
diff --git a/dtach.h b/dtach.h
index 40d0879..56867c8 100644
--- a/dtach.h
+++ b/dtach.h
@@ -83,6 +83,7 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
+#include <sys/wait.h>
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
diff --git a/master.c b/master.c
index d5da2c3..3755f65 100644
--- a/master.c
+++ b/master.c
@@ -134,7 +134,7 @@ init_pty(char **argv, int statusfd)
printf("%s: could not execute %s: %s\r\n", progname,
*argv, strerror(errno));
fflush(stdout);
- _exit(127);
+ _exit(1);
}
/* Parent.. Finish up and return */
#ifdef BROKEN_MASTER
@@ -261,7 +261,16 @@ pty_activity(int s)
/* Error -> die */
if (len <= 0)
+ {
+ int status;
+
+ if (wait(&status) >= 0)
+ {
+ if (WIFEXITED(status))
+ exit(WEXITSTATUS(status));
+ }
exit(1);
+ }
#ifdef BROKEN_MASTER
/* Get the current terminal settings. */