diff options
| author | Ned T. Crigler <crigler@users.sourceforge.net> | 2014-08-03 22:23:35 -0700 |
|---|---|---|
| committer | Ned T. Crigler <crigler@users.sourceforge.net> | 2014-08-04 12:46:26 -0700 |
| commit | 8527d8e8765d2e19f118f915cec3301b1c6cf5ea (patch) | |
| tree | b93f9c95acbbc572bbfac7948762b47b9599f351 /master.c | |
| parent | 3fb977f175c747b4c5988559eadbf3d3b534a8c0 (diff) | |
Make socket executable when there are attached clients.
Based on dtach-0.8-socket-exec-bit.diff by Kodest.
Diffstat (limited to 'master.c')
| -rw-r--r-- | master.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -214,6 +214,25 @@ create_socket(char *name) 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 ** the attached clients. If the pty goes away, we die. */ static void @@ -415,6 +434,8 @@ master_process(int s, char **argv, int waitattach, int statusfd) int highest_fd; int nullfd; + int has_attached_client = 0; + /* Okay, disassociate ourselves from the original terminal, as we ** don't care what happens to it. */ setsid(); @@ -457,6 +478,8 @@ master_process(int s, char **argv, int waitattach, int statusfd) /* Loop forever. */ while (1) { + int new_has_attached_client = 0; + /* Re-initialize the file descriptor set for select. */ FD_ZERO(&readfds); FD_SET(s, &readfds); @@ -483,6 +506,16 @@ master_process(int s, char **argv, int waitattach, int statusfd) FD_SET(p->fd, &readfds); if (p->fd > highest_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. */ |
