added testing mode and changed detach return value

This commit is contained in:
Michael Krayer 2023-10-11 15:00:44 +02:00
parent 9531cfcdac
commit 6c6b505327
1 changed files with 13 additions and 3 deletions

16
splex.c
View File

@ -62,6 +62,8 @@
#define countof(arr) (sizeof(arr) / sizeof((arr)[0]))
#define RV_DETACH -1000
enum PacketType {
MSG_CONTENT = 0,
MSG_ATTACH = 1,
@ -532,7 +534,7 @@ static bool attach_session(const char *name, const bool terminate) {
client_setup_terminal();
int status = client_mainloop();
client_restore_terminal();
if (status == -1) {
if (status == RV_DETACH) {
info("detached");
} else if (status == -EIO) {
info("exited due to I/O errors");
@ -601,13 +603,13 @@ int main(int argc, char *argv[]) {
server.name = basename(argv[0]);
gethostname(server.host+1, sizeof(server.host) - 1);
while ((opt = getopt(argc, argv, "aAchlne:qrvz")) != -1) {
while ((opt = getopt(argc, argv, "aAchlne:qrtvz")) != -1) {
switch (opt) {
case 'a':
case 'A':
case 'c':
case 'n':
case 't':
action = opt;
break;
case 'e':
@ -706,6 +708,14 @@ int main(int argc, char *argv[]) {
goto redo;
}
break;
case 't':
if (!session_alive(server.session_name)) {
if (!create_session(server.session_name, cmd))
die("create-session");
}
if (!attach_session(server.session_name, true))
die("attach-session");
break;
}
return 0;