Mark zombie sessions with '+' symbol

These are sessions which have no clients connected but their underlying
command already terminated.
This commit is contained in:
Marc André Tanner 2014-06-18 14:24:20 +02:00
parent fdf943d520
commit 54c1dbddb2
2 changed files with 13 additions and 6 deletions

View File

@ -401,7 +401,12 @@ static int list_session() {
struct stat sb; char buf[255];
if (stat(namelist[n]->d_name, &sb) == 0) {
strftime(buf, sizeof(buf), "%a%t %F %T", localtime(&sb.st_atime));
printf("%c %s\t%s\n", sb.st_mode & S_IXUSR ? '*' : ' ', buf, namelist[n]->d_name);
char status = ' ';
if (sb.st_mode & S_IXUSR)
status = '*';
else if (sb.st_mode & S_IXGRP)
status = '+';
printf("%c %s\t%s\n", status, buf, namelist[n]->d_name);
}
free(namelist[n]);
}

View File

@ -18,15 +18,16 @@ static void client_free(Client *c) {
free(c);
}
static int server_mark_socket_exec(bool exec) {
static int server_mark_socket_exec(bool exec, bool usr) {
struct stat sb;
if (stat(sockaddr.sun_path, &sb) == -1)
return -1;
mode_t mode = sb.st_mode;
mode_t flag = usr ? S_IXUSR : S_IXGRP;
if (exec)
mode |= S_IXUSR;
mode |= flag;
else
mode &= ~S_IXUSR;
mode &= ~flag;
return chmod(sockaddr.sun_path, mode);
}
@ -64,7 +65,7 @@ static Client *server_accept_client() {
if (!c)
return NULL;
if (!server.clients)
server_mark_socket_exec(true);
server_mark_socket_exec(true, true);
server_set_socket_non_blocking(newfd);
c->socket = newfd;
c->state = STATE_CONNECTED;
@ -122,6 +123,7 @@ static void server_pty_died_handler(int sig) {
if (pid == -1)
break;
server.exit_status = WEXITSTATUS(server.exit_status);
server_mark_socket_exec(true, false);
}
debug("server pty died: %d\n", server.exit_status);
@ -196,7 +198,7 @@ static void server_mainloop() {
};
server_send_packet(server.clients, &pkt);
} else if (!server.clients) {
server_mark_socket_exec(false);
server_mark_socket_exec(false, true);
}
continue;
}