summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/cmd-new-session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2012-07-11 07:10:16 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2012-07-11 07:10:16 +0000
commit156a018a1068e24b3e4fe3c282d9f7c23218f83d (patch)
treed810dc12ac531587df2b51a4c4a39e577eb803d0 /usr.bin/tmux/cmd-new-session.c
parent5fbceaea80d4bc47fc3ffb9f184c6b478e3b16d1 (diff)
Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix problems with using some commands in a command sequence. Most of the work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.
Diffstat (limited to 'usr.bin/tmux/cmd-new-session.c')
-rw-r--r--usr.bin/tmux/cmd-new-session.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index 244d8a033cd..8c43d1f42c9 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.44 2012/07/10 11:53:01 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.45 2012/07/11 07:10:15 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,8 +30,8 @@
* Create a new session and attach to the current terminal unless -d is given.
*/
-int cmd_new_session_check(struct args *);
-int cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
+enum cmd_retval cmd_new_session_check(struct args *);
+enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
@@ -44,15 +44,15 @@ const struct cmd_entry cmd_new_session_entry = {
cmd_new_session_exec
};
-int
+enum cmd_retval
cmd_new_session_check(struct args *args)
{
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n')))
- return (-1);
- return (0);
+ return (CMD_RETURN_ERROR);
+ return (CMD_RETURN_NORMAL);
}
-int
+enum cmd_retval
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
@@ -71,11 +71,11 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (newname != NULL) {
if (!session_check_name(newname)) {
ctx->error(ctx, "bad session name: %s", newname);
- return (-1);
+ return (CMD_RETURN_ERROR);
}
if (session_find(newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", newname);
- return (-1);
+ return (CMD_RETURN_ERROR);
}
}
@@ -83,7 +83,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (target != NULL) {
groupwith = cmd_find_session(ctx, target, 0);
if (groupwith == NULL)
- return (-1);
+ return (CMD_RETURN_ERROR);
} else
groupwith = NULL;
@@ -131,7 +131,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
ctx->error(ctx, "open terminal failed: %s", cause);
free(cause);
- return (-1);
+ return (CMD_RETURN_ERROR);
}
}
@@ -163,7 +163,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "width %s", errstr);
- return (-1);
+ return (CMD_RETURN_ERROR);
}
}
if (args_has(args, 'y')) {
@@ -171,7 +171,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "height %s", errstr);
- return (-1);
+ return (CMD_RETURN_ERROR);
}
}
}
@@ -202,7 +202,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
if (s == NULL) {
ctx->error(ctx, "create session failed: %s", cause);
free(cause);
- return (-1);
+ return (CMD_RETURN_ERROR);
}
environ_free(&env);
@@ -269,5 +269,5 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
ARRAY_FREE(&cfg_causes);
}
- return (!detached); /* 1 means don't tell command client to exit */
+ return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
}