Try to detect and remove stale sockets when dtach -A is used. Be
paranoid about this, and only remove the specified file if connect says the connection was refused and stat says the file is a socket. Also dtach -A now only tries to create the socket if the connection was refused or the socket did not exist, instead of on any random error as before.
This commit is contained in:
parent
e06f8dfcdf
commit
5dbd8fe920
12
attach.c
12
attach.c
|
|
@ -60,6 +60,18 @@ connect_socket(char *name)
|
|||
if (connect(s, (struct sockaddr*)&sockun, sizeof(sockun)) < 0)
|
||||
{
|
||||
close(s);
|
||||
|
||||
/* ECONNREFUSED is also returned for regular files, so make
|
||||
** sure we are trying to connect to a socket. */
|
||||
if (errno == ECONNREFUSED)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if (stat(name, &st) < 0)
|
||||
return -1;
|
||||
else if (!S_ISSOCK(st.st_mode) || S_ISREG(st.st_mode))
|
||||
errno = ENOTSOCK;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
return s;
|
||||
|
|
|
|||
8
dtach.h
8
dtach.h
|
|
@ -73,6 +73,14 @@
|
|||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#ifndef S_ISREG
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
#ifndef S_ISSOCK
|
||||
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
#endif
|
||||
|
||||
extern char *progname, *sockname;
|
||||
extern int detach_char, no_suspend, redraw_method;
|
||||
extern struct termios orig_term;
|
||||
|
|
|
|||
Loading…
Reference in New Issue