mirror of https://github.com/martanne/abduco
Added -C option
for collection of exit status and creation of new session in one go
This commit is contained in:
parent
0a94807d60
commit
1946d8387a
13
abduco.1
13
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 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
|
||||
Create a new session but do not attach to it.
|
||||
.TP
|
||||
|
|
|
|||
28
abduco.c
28
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);
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +391,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 terminate) {
|
||||
if (server.socket > 0)
|
||||
close(server.socket);
|
||||
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");
|
||||
} else {
|
||||
info("session terminated with exit status %d", status);
|
||||
exit(status);
|
||||
if (terminate)
|
||||
exit(status);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -500,6 +501,7 @@ int main(int argc, char *argv[]) {
|
|||
case 'a':
|
||||
case 'A':
|
||||
case 'c':
|
||||
case 'C':
|
||||
case 'n':
|
||||
action = argv[arg][1];
|
||||
break;
|
||||
|
|
@ -528,7 +530,8 @@ int main(int argc, char *argv[]) {
|
|||
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();
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &orig_term) != -1) {
|
||||
|
|
@ -543,8 +546,21 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
server.read_pty = (action == 'n');
|
||||
|
||||
switch (action) {
|
||||
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 'c':
|
||||
if (!create_session(server.session_name, cmd))
|
||||
|
|
@ -553,7 +569,7 @@ 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue