This commit is contained in:
David Phillips 2014-12-22 01:23:12 +00:00
commit 5ad325150d
3 changed files with 64 additions and 12 deletions

View File

@ -8,25 +8,25 @@ but more lightweight, replacement of the before mentioned tools.
Quickstart 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': new session named 'demo':
$ abduco -c demo $ abduco -c demo
An arbitrary application can be started as follows: 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: displayed by running:
$ abduco $ abduco
Active sessions (on host hostname) Active sessions (on host hostname)
Fri 2014-11-14 18:52:36 demo Fri 2014-11-14 18:52:36 demo
The session can be restored with The session can be restored with
$ abduco -a demo $ abduco -a demo
Read the manual page for further information. Read the manual page for further information.

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 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 .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);
} }
@ -383,7 +383,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 fully_exit) {
if (server.socket > 0) if (server.socket > 0)
close(server.socket); close(server.socket);
if ((server.socket = create_socket(name)) == -1) 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"); 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 (fully_exit)
exit(status);
return false;
} }
return true; return true;
@ -472,6 +475,10 @@ static int list_session(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char **cmd = NULL, action = '\0'; char **cmd = NULL, action = '\0';
struct stat sb;
char* filename;
size_t size;
server.name = basename(argv[0]); server.name = basename(argv[0]);
gethostname(server.host+1, sizeof(server.host) - 1); gethostname(server.host+1, sizeof(server.host) - 1);
if (argc == 1) if (argc == 1)
@ -492,6 +499,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;
@ -545,13 +553,44 @@ 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;
} }
die("attach-session"); 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; return 0;