summaryrefslogtreecommitdiffstats
path: root/session.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-02-15 15:09:52 +0000
committerTiago Cunha <tcunha@gmx.com>2011-02-15 15:09:52 +0000
commit4e4568cade9c54f02b0f41d9372f4124f1fb54be (patch)
treed139a54b7d0b9606f098773ec01d52ebadd361f7 /session.c
parentd0d1c0e486dc13b6e5db93819ca1b634d384f283 (diff)
Sync OpenBSD patchset 852:
Check if the index is in use and fail before creating the child process, rather than leaving a stray child on failure.
Diffstat (limited to 'session.c')
-rw-r--r--session.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/session.c b/session.c
index 39b30cad..3e92d3d6 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $Id: session.c,v 1.87 2011-01-21 23:53:01 tcunha Exp $ */
+/* $Id: session.c,v 1.88 2011-02-15 15:09:52 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -211,10 +211,16 @@ session_new(struct session *s,
const char *name, const char *cmd, const char *cwd, int idx, char **cause)
{
struct window *w;
+ struct winlink *wl;
struct environ env;
const char *shell;
u_int hlimit;
+ if ((wl = winlink_add(&s->windows, idx)) == NULL) {
+ xasprintf(cause, "index in use: %d", idx);
+ return (NULL);
+ }
+
environ_init(&env);
environ_copy(&global_environ, &env);
environ_copy(&s->environ, &env);
@@ -228,15 +234,18 @@ session_new(struct session *s,
w = window_create(
name, cmd, shell, cwd, &env, s->tio, s->sx, s->sy, hlimit, cause);
if (w == NULL) {
+ winlink_remove(&s->windows, wl);
environ_free(&env);
return (NULL);
}
+ winlink_set_window(wl, w);
environ_free(&env);
if (options_get_number(&s->options, "set-remain-on-exit"))
options_set_number(&w->options, "remain-on-exit", 1);
- return (session_attach(s, w, idx, cause));
+ session_group_synchronize_from(s);
+ return (wl);
}
/* Attach a window to a session. */
@@ -245,8 +254,12 @@ session_attach(struct session *s, struct window *w, int idx, char **cause)
{
struct winlink *wl;
- if ((wl = winlink_add(&s->windows, w, idx)) == NULL)
+ if ((wl = winlink_add(&s->windows, idx)) == NULL) {
xasprintf(cause, "index in use: %d", idx);
+ return (NULL);
+ }
+ winlink_set_window(wl, w);
+
session_group_synchronize_from(s);
return (wl);
}
@@ -525,7 +538,8 @@ session_group_synchronize1(struct session *target, struct session *s)
/* Link all the windows from the target. */
RB_FOREACH(wl, winlinks, ww) {
- wl2 = winlink_add(&s->windows, wl->window, wl->idx);
+ wl2 = winlink_add(&s->windows, wl->idx);
+ winlink_set_window(wl2, wl->window);
wl2->flags |= wl->flags & WINLINK_ALERTFLAGS;
}