mirror of https://github.com/martanne/abduco
Mark the socket executable if clients are connected
This commit is contained in:
parent
95db782096
commit
a3700092cb
2
abduco.c
2
abduco.c
|
|
@ -357,7 +357,7 @@ static int list_session() {
|
|||
struct stat sb; char buf[255];
|
||||
if (stat(namelist[n]->d_name, &sb) == 0) {
|
||||
strftime(buf, sizeof(buf), "%a%t %d.%m.%Y %T", localtime(&sb.st_atime));
|
||||
printf(" %s\t%s\n", buf, namelist[n]->d_name);
|
||||
printf("%c %s\t%s\n", sb.st_mode & S_IXUSR ? '*' : ' ', buf, namelist[n]->d_name);
|
||||
}
|
||||
free(namelist[n]);
|
||||
}
|
||||
|
|
|
|||
17
server.c
17
server.c
|
|
@ -18,6 +18,18 @@ static void client_free(Client *c) {
|
|||
free(c);
|
||||
}
|
||||
|
||||
static int server_mark_socket_exec(bool exec) {
|
||||
struct stat sb;
|
||||
if (stat(sockaddr.sun_path, &sb) == -1)
|
||||
return -1;
|
||||
mode_t mode = sb.st_mode;
|
||||
if (exec)
|
||||
mode |= S_IXUSR;
|
||||
else
|
||||
mode &= ~S_IXUSR;
|
||||
return chmod(sockaddr.sun_path, mode);
|
||||
}
|
||||
|
||||
static int server_create_socket(const char *name) {
|
||||
int socket = create_socket(name);
|
||||
if (socket == -1)
|
||||
|
|
@ -52,6 +64,8 @@ static Client *server_accept_client(time_t now) {
|
|||
Client *c = client_malloc(newfd);
|
||||
if (!c)
|
||||
return NULL;
|
||||
if (!server.clients)
|
||||
server_mark_socket_exec(true);
|
||||
server_set_socket_non_blocking(newfd);
|
||||
c->socket = newfd;
|
||||
c->state = STATE_CONNECTED;
|
||||
|
|
@ -262,7 +276,8 @@ static void server_mainloop() {
|
|||
Client *t = c->next;
|
||||
client_free(c);
|
||||
*prev_next = c = t;
|
||||
server.client_count--;
|
||||
if (--server.client_count == 0)
|
||||
server_mark_socket_exec(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue