summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2011-08-16 09:36:24 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2011-08-16 09:36:24 +0000
commit95691d9f53fb0cc630982c470e31999f7ccff698 (patch)
tree1bd94e4926921e7a9a3298ee3f9ab155cfc88de1 /usr.bin/tmux
parent7a2a522d54acc5ed3152fea02a666e07546dc23b (diff)
Correctly skip existing numbers when generating the name for a new
session.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/session.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index e05ba7b4d13..69956ad50bd 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.31 2011/04/06 21:51:31 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.32 2011/08/16 09:36:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -119,11 +119,18 @@ session_create(const char *name, const char *cmd, const char *cwd,
s->sx = sx;
s->sy = sy;
- s->idx = next_session++;
- if (name != NULL)
+ if (name != NULL) {
s->name = xstrdup(name);
- else
- xasprintf(&s->name, "%u", s->idx);
+ s->idx = next_session++;
+ } else {
+ s->name = NULL;
+ do {
+ s->idx = next_session++;
+ if (s->name != NULL)
+ xfree (s->name);
+ xasprintf(&s->name, "%u", s->idx);
+ } while (RB_FIND(sessions, &sessions, s) != NULL);
+ }
RB_INSERT(sessions, &sessions, s);
if (cmd != NULL) {