aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2011-04-06 22:29:26 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2011-04-06 22:29:26 +0000
commite5f4bf3f3ec206bedf0f4a04b8158cff8c734f11 (patch)
treebc143973bb375f5176d41a00384d7cab9bbb944d
parent13c54a04a0ef236dd2df36ca3fa5fd1b89272be6 (diff)
downloadrtmux-e5f4bf3f3ec206bedf0f4a04b8158cff8c734f11.tar.gz
rtmux-e5f4bf3f3ec206bedf0f4a04b8158cff8c734f11.tar.bz2
rtmux-e5f4bf3f3ec206bedf0f4a04b8158cff8c734f11.zip
|PatchSet 884
|Date: 2011/04/06 22:51:31 |Author: nicm |Branch: HEAD |Tag: (none) |Log: |Change so that an empty session name always means the current sessions |even if given with, for example, -t '', and explicitly forbid empty |session names and those containing a : when they are created.
-rw-r--r--cmd-new-session.c14
-rw-r--r--cmd-rename-session.c6
-rw-r--r--cmd.c12
-rw-r--r--session.c9
-rw-r--r--tmux.h3
5 files changed, 34 insertions, 10 deletions
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 175a3d41..18fffa1b 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-new-session.c,v 1.85 2011-04-06 22:24:00 nicm Exp $ */
+/* $Id: cmd-new-session.c,v 1.86 2011-04-06 22:29:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -68,9 +68,15 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int sx, sy, i;
newname = args_get(args, 's');
- if (newname != NULL && session_find(newname) != NULL) {
- ctx->error(ctx, "duplicate session: %s", newname);
- return (-1);
+ if (newname != NULL) {
+ if (!session_check_name(newname)) {
+ ctx->error(ctx, "bad session name: %s", newname);
+ return (-1);
+ }
+ if (session_find(newname) != NULL) {
+ ctx->error(ctx, "duplicate session: %s", newname);
+ return (-1);
+ }
}
target = args_get(args, 't');
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index af6d8e9c..fd070c77 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-rename-session.c,v 1.23 2011-04-06 22:24:01 nicm Exp $ */
+/* $Id: cmd-rename-session.c,v 1.24 2011-04-06 22:29:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -46,6 +46,10 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *newname;
newname = args->argv[0];
+ if (!session_check_name(newname)) {
+ ctx->error(ctx, "bad session name: %s", newname);
+ return (-1);
+ }
if (session_find(newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", newname);
return (-1);
diff --git a/cmd.c b/cmd.c
index 70c8e3ad..23458af7 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.151 2011-04-06 22:24:01 nicm Exp $ */
+/* $Id: cmd.c,v 1.152 2011-04-06 22:29:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -724,6 +724,12 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
if (arglen != 0 && tmparg[arglen - 1] == ':')
tmparg[arglen - 1] = '\0';
+ /* An empty session name is the current session. */
+ if (*tmparg == '\0') {
+ xfree (tmparg);
+ return (cmd_current_session(ctx, prefer_unattached));
+ }
+
/* Find the session, if any. */
s = cmd_lookup_session(tmparg, &ambiguous);
@@ -839,7 +845,7 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
- if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
+ if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
@@ -980,7 +986,7 @@ no_colon:
lookup_session:
if (ambiguous)
goto not_found;
- if ((s = cmd_lookup_session(arg, &ambiguous)) == NULL)
+ if (*arg != '\0' && (s = cmd_lookup_session(arg, &ambiguous)) == NULL)
goto no_session;
if (sp != NULL)
diff --git a/session.c b/session.c
index 3e92d3d6..3eac8c23 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $Id: session.c,v 1.88 2011-02-15 15:09:52 tcunha Exp $ */
+/* $Id: session.c,v 1.89 2011-04-06 22:29:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -163,6 +163,13 @@ session_destroy(struct session *s)
RB_INSERT(sessions, &dead_sessions, s);
}
+/* Check a session name is valid: not empty and no colons. */
+int
+session_check_name(const char *name)
+{
+ return (*name != '\0' && strchr(name, ':') == NULL);
+}
+
/* Update session active time. */
void
session_update_activity(struct session *s)
diff --git a/tmux.h b/tmux.h
index f8152714..9d76f608 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.617 2011-04-06 22:24:01 nicm Exp $ */
+/* $Id: tmux.h,v 1.618 2011-04-06 22:29:26 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1974,6 +1974,7 @@ struct session *session_create(const char *, const char *, const char *,
struct environ *, struct termios *, int, u_int, u_int,
char **);
void session_destroy(struct session *);
+int session_check_name(const char *);
void session_update_activity(struct session *);
struct session *session_next_session(struct session *);
struct session *session_previous_session(struct session *);