From 6bfce64c3215c7e50fc682b5999767d450c2a5c5 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 22 Dec 2014 13:53:11 +1300 Subject: [PATCH 1/5] Added -C option for collection of exit status and creation of new session in one go --- abduco.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/abduco.c b/abduco.c index bae1111..9ac8a51 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,43 @@ 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"); + return 1; + } + } + free(filename); + + /* Create new session */ + action = 'c'; + goto redo; } return 0; From 940dee8aa0f3cb7e9e2ca9079cbb8cd62eceeb38 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 22 Dec 2014 13:56:09 +1300 Subject: [PATCH 2/5] Updated man page with new -C option --- abduco.1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 From 6037b2d87253d096c040f268ed150eefdd04a1c8 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 22 Dec 2014 13:57:48 +1300 Subject: [PATCH 3/5] Fixed memory leak --- abduco.c | 1 + 1 file changed, 1 insertion(+) diff --git a/abduco.c b/abduco.c index 9ac8a51..4bfdedd 100644 --- a/abduco.c +++ b/abduco.c @@ -582,6 +582,7 @@ int main(int argc, char *argv[]) { attach_session(server.session_name, false); } else { info("session not yet exited"); + free(filename); return 1; } } From 04fa77ef73b3a1856d02625b96ce1baf5db364e6 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 22 Dec 2014 14:00:18 +1300 Subject: [PATCH 4/5] Renamed readme so it renders properly on github etc --- README => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README => README.md (100%) diff --git a/README b/README.md similarity index 100% rename from README rename to README.md From 6e70784f38d650c98f26124c8118b99138081bb9 Mon Sep 17 00:00:00 2001 From: David Date: Mon, 22 Dec 2014 14:01:50 +1300 Subject: [PATCH 5/5] Slight formatting change --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 587e566..50830aa 100644 --- a/README.md +++ 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.