Fix fd leakage.

Prevent atexit from being called twice on dtach -A.
This commit is contained in:
Ned T. Crigler 2001-11-28 22:56:40 +00:00
parent 203193838d
commit 3653366fd8
3 changed files with 28 additions and 11 deletions

4
README
View File

@ -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

View File

@ -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);

View File

@ -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;
}