diff options
| author | Ned T. Crigler <crigler@users.sourceforge.net> | 2001-11-28 22:56:40 +0000 |
|---|---|---|
| committer | Ned T. Crigler <crigler@users.sourceforge.net> | 2001-11-28 22:56:40 +0000 |
| commit | 3653366fd8247744d2ee5389f5107f6eb5545ddd (patch) | |
| tree | ef1c67fb070fc68ecc3abedbdd32defb2227b28d /attach.c | |
| parent | 203193838dbc2e6acea953c484a030e5632ca5cf (diff) | |
Fix fd leakage.
Prevent atexit from being called twice on dtach -A.
Diffstat (limited to 'attach.c')
| -rw-r--r-- | attach.c | 25 |
1 files changed, 14 insertions, 11 deletions
@@ -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); |
