diff --git a/README b/README.md similarity index 62% rename from README rename to README.md index 587e566..50830aa 100644 --- a/README +++ b/README.md @@ -8,25 +8,25 @@ but more lightweight, replacement of the before mentioned tools. Quickstart ---------- -Assuming dvtm is located somewhere in $PATH, the following creates a +Assuming dvtm is located somewhere in `$PATH`, the following creates a new session named 'demo': - $ abduco -c demo + $ abduco -c demo An arbitrary application can be started as follows: - $ abduco -c demo your-application + $ abduco -c demo your-application -CTRL+\ detaches from the active session. All available sessions can be +`CTRL+\` detaches from the active session. All available sessions can be displayed by running: - $ abduco - Active sessions (on host hostname) - Fri 2014-11-14 18:52:36 demo + $ abduco + Active sessions (on host hostname) + Fri 2014-11-14 18:52:36 demo The session can be restored with - $ abduco -a demo + $ abduco -a demo Read the manual page for further information. diff --git a/abduco.1 b/abduco.1 index 9594e74..dd96c04 100644 --- a/abduco.1 +++ b/abduco.1 @@ -12,6 +12,14 @@ abduco - terminal session manager .RI [ args \ ... "" ] .br .B abduco +.RB [ \-e +.IR detachkey ] +.RB \-C +.RB name +.RB command +.RI [ args \ ... "" ] +.br +.B abduco .RB [ \-r ] .RB [ \-e .IR detachkey ] @@ -88,6 +96,11 @@ Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey. .BI \-c Create a new session and attach immediately to it. .TP +.BI \-C +Show the exit status of an already exited session, and create a new session under the same name. +If the session doesn't exist, it acts like +.BI \-c +.TP .BI \-n Create a new session but do not attach to it. .TP diff --git a/abduco.c b/abduco.c index bae1111..4bfdedd 100644 --- a/abduco.c +++ b/abduco.c @@ -210,7 +210,7 @@ static void die(const char *s) { } 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); } @@ -383,7 +383,7 @@ static bool create_session(const char *name, char * const argv[]) { return true; } -static bool attach_session(const char *name) { +static bool attach_session(const char *name, const bool fully_exit) { if (server.socket > 0) close(server.socket); if ((server.socket = create_socket(name)) == -1) @@ -422,7 +422,10 @@ static bool attach_session(const char *name) { info("exited due to I/O errors"); } else { info("session terminated with exit status %d", status); - exit(status); + if (fully_exit) + exit(status); + + return false; } return true; @@ -472,6 +475,10 @@ static int list_session(void) { int main(int argc, char *argv[]) { char **cmd = NULL, action = '\0'; + struct stat sb; + char* filename; + size_t size; + server.name = basename(argv[0]); gethostname(server.host+1, sizeof(server.host) - 1); if (argc == 1) @@ -492,6 +499,7 @@ int main(int argc, char *argv[]) { case 'a': case 'A': case 'c': + case 'C': case 'n': action = argv[arg][1]; break; @@ -545,13 +553,44 @@ int main(int argc, char *argv[]) { break; case 'a': case 'A': - if (!attach_session(server.session_name)) { + if (!attach_session(server.session_name, true)) { if (action == 'A') { action = 'c'; goto redo; } die("attach-session"); } + break; + case 'C': + if (create_socket_dir() == -1) + die("create-socket-dir"); + + size = strlen(sockaddr.sun_path) + + strlen(server.session_name) + + strlen(server.host) + 1; + + if ((filename = malloc(size)) == NULL) + die("malloc"); + + snprintf(filename, size, "%s%s%s", sockaddr.sun_path, + server.session_name, + server.host); + + if (stat(filename, &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 exited"); + free(filename); + return 1; + } + } + free(filename); + + /* Create new session */ + action = 'c'; + goto redo; } return 0;