Make socket executable when there are attached clients.
Based on dtach-0.8-socket-exec-bit.diff by Kodest.
This commit is contained in:
parent
3fb977f175
commit
8527d8e876
33
master.c
33
master.c
|
|
@ -214,6 +214,25 @@ create_socket(char *name)
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update the modes on the socket. */
|
||||||
|
static void
|
||||||
|
update_socket_modes(int exec)
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
mode_t newmode;
|
||||||
|
|
||||||
|
if (stat(sockname, &st) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (exec)
|
||||||
|
newmode = st.st_mode | S_IXUSR;
|
||||||
|
else
|
||||||
|
newmode = st.st_mode & ~S_IXUSR;
|
||||||
|
|
||||||
|
if (st.st_mode != newmode)
|
||||||
|
chmod(sockname, newmode);
|
||||||
|
}
|
||||||
|
|
||||||
/* Process activity on the pty - Input and terminal changes are sent out to
|
/* Process activity on the pty - Input and terminal changes are sent out to
|
||||||
** the attached clients. If the pty goes away, we die. */
|
** the attached clients. If the pty goes away, we die. */
|
||||||
static void
|
static void
|
||||||
|
|
@ -415,6 +434,8 @@ master_process(int s, char **argv, int waitattach, int statusfd)
|
||||||
int highest_fd;
|
int highest_fd;
|
||||||
int nullfd;
|
int nullfd;
|
||||||
|
|
||||||
|
int has_attached_client = 0;
|
||||||
|
|
||||||
/* Okay, disassociate ourselves from the original terminal, as we
|
/* Okay, disassociate ourselves from the original terminal, as we
|
||||||
** don't care what happens to it. */
|
** don't care what happens to it. */
|
||||||
setsid();
|
setsid();
|
||||||
|
|
@ -457,6 +478,8 @@ master_process(int s, char **argv, int waitattach, int statusfd)
|
||||||
/* Loop forever. */
|
/* Loop forever. */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
int new_has_attached_client = 0;
|
||||||
|
|
||||||
/* Re-initialize the file descriptor set for select. */
|
/* Re-initialize the file descriptor set for select. */
|
||||||
FD_ZERO(&readfds);
|
FD_ZERO(&readfds);
|
||||||
FD_SET(s, &readfds);
|
FD_SET(s, &readfds);
|
||||||
|
|
@ -483,6 +506,16 @@ master_process(int s, char **argv, int waitattach, int statusfd)
|
||||||
FD_SET(p->fd, &readfds);
|
FD_SET(p->fd, &readfds);
|
||||||
if (p->fd > highest_fd)
|
if (p->fd > highest_fd)
|
||||||
highest_fd = p->fd;
|
highest_fd = p->fd;
|
||||||
|
|
||||||
|
if (p->attached)
|
||||||
|
new_has_attached_client = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* chmod the socket if necessary. */
|
||||||
|
if (has_attached_client != new_has_attached_client)
|
||||||
|
{
|
||||||
|
update_socket_modes(new_has_attached_client);
|
||||||
|
has_attached_client = new_has_attached_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for something to happen. */
|
/* Wait for something to happen. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue