diff --git a/splex.c b/splex.c index b96bc4a..f14b29b 100644 --- a/splex.c +++ b/splex.c @@ -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;