aboutsummaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-08-21 12:35:47 +0000
committerTiago Cunha <tcunha@gmx.com>2011-08-21 12:35:47 +0000
commitb9bbe1d81c41411f62e73c180c02ec05cc224efd (patch)
treed430f518bf5de3ff4c99f235c9d1a6734ad30328 /session.c
parentcd62411d783f189025854e05154ddfbeea2872b8 (diff)
downloadrtmux-b9bbe1d81c41411f62e73c180c02ec05cc224efd.tar.gz
rtmux-b9bbe1d81c41411f62e73c180c02ec05cc224efd.tar.bz2
rtmux-b9bbe1d81c41411f62e73c180c02ec05cc224efd.zip
Sync OpenBSD patchset 943:
Correctly skip existing numbers when generating the name for a new session.
Diffstat (limited to 'session.c')
-rw-r--r--session.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/session.c b/session.c
index 4f5a7fee..2fa61d2b 100644
--- a/session.c
+++ b/session.c
@@ -118,11 +118,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) {