summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed T. Crigler <crigler@users.sourceforge.net>2001-11-28 22:56:40 +0000
committerNed T. Crigler <crigler@users.sourceforge.net>2001-11-28 22:56:40 +0000
commit3653366fd8247744d2ee5389f5107f6eb5545ddd (patch)
treeef1c67fb070fc68ecc3abedbdd32defb2227b28d
parent203193838dbc2e6acea953c484a030e5632ca5cf (diff)
Fix fd leakage.
Prevent atexit from being called twice on dtach -A.
-rw-r--r--README4
-rw-r--r--attach.c25
-rw-r--r--master.c10
3 files changed, 28 insertions, 11 deletions
diff --git a/README b/README
index d1d9c77..c3744e8 100644
--- a/README
+++ b/README
@@ -96,6 +96,10 @@ to dtach when attaching.
5. CHANGES
+The changes since version 0.4 are:
+- Fix fd leakage.
+- Prevent atexit from being called twice on dtach -A.
+
The changes in version 0.4 are:
- Slightly improved README and dtach.1
- Portability updates thanks to sourceforge's compile farm. dtach should now
diff --git a/attach.c b/attach.c
index ba2e3a0..f3d575e 100644
--- a/attach.c
+++ b/attach.c
@@ -63,7 +63,10 @@ connect_socket(char *name)
sockun.sun_family = AF_UNIX;
strcpy(sockun.sun_path, name);
if (connect(s, (struct sockaddr*)&sockun, sizeof(sockun)) < 0)
+ {
+ close(s);
return -1;
+ }
return s;
}
@@ -135,6 +138,17 @@ attach_main(int noerror)
struct packet pkt;
unsigned char buf[BUFSIZE];
+ /* Attempt to open the socket. Don't display an error if noerror is
+ ** set. */
+ s = connect_socket(sockname);
+ if (s < 0)
+ {
+ if (!noerror)
+ printf("%s: %s: %s\n", progname, sockname,
+ strerror(errno));
+ return 1;
+ }
+
/* The current terminal settings are equal to the original terminal
** settings at this point. */
cur_term = orig_term;
@@ -151,17 +165,6 @@ attach_main(int noerror)
signal(SIGQUIT, die);
signal(SIGWINCH, win_change);
- /* Attempt to open the socket. Don't display an error if noerror is
- ** set. */
- s = connect_socket(sockname);
- if (s < 0)
- {
- if (!noerror)
- printf("%s: %s: %s\n", progname, sockname,
- strerror(errno));
- return 1;
- }
-
/* Set raw mode, almost. We allow flow control to work, for instance. */
cur_term.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL);
cur_term.c_oflag &= ~(OPOST);
diff --git a/master.c b/master.c
index 07f8431..0aad0cc 100644
--- a/master.c
+++ b/master.c
@@ -125,12 +125,21 @@ create_socket(char *name)
sockun.sun_family = AF_UNIX;
strcpy(sockun.sun_path, name);
if (bind(s, (struct sockaddr*)&sockun, sizeof(sockun)) < 0)
+ {
+ close(s);
return -1;
+ }
if (listen(s, 128) < 0)
+ {
+ close(s);
return -1;
+ }
/* chmod it to prevent any suprises */
if (chmod(name, 0600) < 0)
+ {
+ close(s);
return -1;
+ }
return s;
}
@@ -353,6 +362,7 @@ master_main(char **argv)
return 0;
}
/* Parent - just return. */
+ close(s);
return 0;
}