Added -C option

for collection of exit status and creation of new session in one go
This commit is contained in:
David 2014-12-22 12:54:57 +01:00 committed by Marc André Tanner
parent 0a94807d60
commit 1946d8387a
2 changed files with 35 additions and 6 deletions

View File

@ -12,6 +12,14 @@ abduco - terminal session manager
.RI [ args \ ... "" ] .RI [ args \ ... "" ]
.br .br
.B abduco .B abduco
.RB [ \-e
.IR detachkey ]
.RB \-C
.RB name
.RB command
.RI [ args \ ... "" ]
.br
.B abduco
.RB [ \-r ] .RB [ \-r ]
.RB [ \-e .RB [ \-e
.IR detachkey ] .IR detachkey ]
@ -88,6 +96,11 @@ Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey.
.BI \-c .BI \-c
Create a new session and attach immediately to it. Create a new session and attach immediately to it.
.TP .TP
.BI \-C
Show the exit status of an already terminated session, and create a new session under the same name.
If the session does not exist, it acts like
.BI \-c
.TP
.BI \-n .BI \-n
Create a new session but do not attach to it. Create a new session but do not attach to it.
.TP .TP

View File

@ -210,7 +210,7 @@ static void die(const char *s) {
} }
static void usage(void) { static void usage(void) {
fprintf(stderr, "usage: abduco [-a|-A|-c|-n] [-r] [-e detachkey] name command\n"); fprintf(stderr, "usage: abduco [-a|-A|-c|-C|-n] [-r] [-e detachkey] name command\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -391,7 +391,7 @@ static bool create_session(const char *name, char * const argv[]) {
return true; return true;
} }
static bool attach_session(const char *name) { static bool attach_session(const char *name, const bool terminate) {
if (server.socket > 0) if (server.socket > 0)
close(server.socket); close(server.socket);
if (!set_socket_name(&sockaddr, name) || (server.socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) if (!set_socket_name(&sockaddr, name) || (server.socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
@ -430,7 +430,8 @@ static bool attach_session(const char *name) {
info("exited due to I/O errors"); info("exited due to I/O errors");
} else { } else {
info("session terminated with exit status %d", status); info("session terminated with exit status %d", status);
exit(status); if (terminate)
exit(status);
} }
return true; return true;
@ -500,6 +501,7 @@ int main(int argc, char *argv[]) {
case 'a': case 'a':
case 'A': case 'A':
case 'c': case 'c':
case 'C':
case 'n': case 'n':
action = argv[arg][1]; action = argv[arg][1];
break; break;
@ -528,7 +530,8 @@ int main(int argc, char *argv[]) {
cmd[0] = "dvtm"; cmd[0] = "dvtm";
} }
if (!action || !server.session_name || ((action == 'c' || action == 'A') && client.readonly)) if (!action || !server.session_name ||
((action == 'c' || action == 'C' || action == 'A') && client.readonly))
usage(); usage();
if (tcgetattr(STDIN_FILENO, &orig_term) != -1) { if (tcgetattr(STDIN_FILENO, &orig_term) != -1) {
@ -543,8 +546,21 @@ int main(int argc, char *argv[]) {
server.read_pty = (action == 'n'); server.read_pty = (action == 'n');
switch (action) {
redo: redo:
switch (action) {
case 'C':
if (set_socket_name(&sockaddr, server.session_name)) {
struct stat sb;
if (stat(sockaddr.sun_path, &sb) == 0 && S_ISSOCK(sb.st_mode)) {
if (sb.st_mode & S_IXGRP) {
/* Attach session in order to print old exit status */
attach_session(server.session_name, false);
} else {
info("session not yet terminated");
return 1;
}
}
}
case 'n': case 'n':
case 'c': case 'c':
if (!create_session(server.session_name, cmd)) if (!create_session(server.session_name, cmd))
@ -553,7 +569,7 @@ int main(int argc, char *argv[]) {
break; break;
case 'a': case 'a':
case 'A': case 'A':
if (!attach_session(server.session_name)) { if (!attach_session(server.session_name, true)) {
if (action == 'A') { if (action == 'A') {
action = 'c'; action = 'c';
goto redo; goto redo;