abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit a3700092cbd7d214cc952e405aa825719f06c2ad
parent 95db7820961275b017be4a46a05717af62351c0a
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Thu,  6 Mar 2014 22:24:38 +0100

Mark the socket executable if clients are connected

Diffstat:
abduco.c | 2+-
server.c | 17++++++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/abduco.c b/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]); } diff --git a/server.c b/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; }