summaryrefslogtreecommitdiff
path: root/attach.c
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 /attach.c
parent203193838dbc2e6acea953c484a030e5632ca5cf (diff)
Fix fd leakage.
Prevent atexit from being called twice on dtach -A.
Diffstat (limited to 'attach.c')
-rw-r--r--attach.c25
1 files changed, 14 insertions, 11 deletions
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);