Remove -C mode, in favour of a -f flag

that works with -c, -n or -A, which forces the creation of a
new session when there is an existing but already terminated
session of the same name.
This commit is contained in:
yy 2015-02-26 13:58:05 +01:00 committed by Marc André Tanner
parent 7962cb99f3
commit 0102cf840e
2 changed files with 15 additions and 19 deletions

View File

@ -12,14 +12,6 @@ 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 ]
@ -93,14 +85,13 @@ Readonly session, i.e. user input is ignored.
.BI \-e \ detachkey .BI \-e \ detachkey
Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey. Set the key to detach which by default is set to CTRL+\\ i.e. ^\\ to detachkey.
.TP .TP
.BI \-f
Force creation of session when there is an already terminated session of the same name,
after showing its exit status.
.TP
.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

@ -483,7 +483,7 @@ static bool attach_session(const char *name, const bool terminate) {
exit(status); exit(status);
} }
return true; return terminate;
} }
static int session_filter(const struct dirent *d) { static int session_filter(const struct dirent *d) {
@ -529,6 +529,7 @@ static int list_session(void) {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool force = false;
char **cmd = NULL, action = '\0'; char **cmd = NULL, action = '\0';
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);
@ -562,6 +563,9 @@ int main(int argc, char *argv[]) {
*esc = CTRL(esc[1]); *esc = CTRL(esc[1]);
KEY_DETACH = *esc; KEY_DETACH = *esc;
break; break;
case 'f':
force = true;
break;
case 'r': case 'r':
client.readonly = true; client.readonly = true;
break; break;
@ -597,8 +601,9 @@ int main(int argc, char *argv[]) {
redo: redo:
switch (action) { switch (action) {
case 'C': case 'n':
if (set_socket_name(&sockaddr, server.session_name)) { case 'c':
if (force && set_socket_name(&sockaddr, server.session_name)) {
struct stat sb; struct stat sb;
if (stat(sockaddr.sun_path, &sb) == 0 && S_ISSOCK(sb.st_mode)) { if (stat(sockaddr.sun_path, &sb) == 0 && S_ISSOCK(sb.st_mode)) {
if (sb.st_mode & S_IXGRP) { if (sb.st_mode & S_IXGRP) {
@ -609,17 +614,17 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
} }
force = false;
} }
case 'n':
case 'c':
if (!create_session(server.session_name, cmd)) if (!create_session(server.session_name, cmd))
die("create-session"); die("create-session");
if (action == 'n') if (action == 'n')
break; break;
case 'a': case 'a':
case 'A': case 'A':
if (!attach_session(server.session_name, true)) { if (!attach_session(server.session_name, !force || action == 'a')) {
if (action == 'A') { if (action == 'A') {
force = false;
action = 'c'; action = 'c';
goto redo; goto redo;
} }