mirror of
https://github.com/tmux/tmux.git
synced 2024-11-13 23:58:51 +00:00
Better error messages for fork.
This commit is contained in:
parent
3f171917f6
commit
4d9af27b0b
3
CHANGES
3
CHANGES
@ -1,5 +1,6 @@
|
|||||||
23 January 2009
|
23 January 2009
|
||||||
|
|
||||||
|
* Better error messages when creating a session or window fails.
|
||||||
* Oops. Return non-zero on error. Reported by Will Maier.
|
* Oops. Return non-zero on error. Reported by Will Maier.
|
||||||
|
|
||||||
21 January 2009
|
21 January 2009
|
||||||
@ -1001,7 +1002,7 @@
|
|||||||
(including mutt, emacs). No status bar yet and no key remapping or other
|
(including mutt, emacs). No status bar yet and no key remapping or other
|
||||||
customisation.
|
customisation.
|
||||||
|
|
||||||
$Id: CHANGES,v 1.231 2009-01-23 16:19:56 nicm Exp $
|
$Id: CHANGES,v 1.232 2009-01-23 16:59:14 nicm Exp $
|
||||||
|
|
||||||
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
|
||||||
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
|
||||||
|
1
TODO
1
TODO
@ -86,5 +86,4 @@
|
|||||||
- document split-window -p and -l
|
- document split-window -p and -l
|
||||||
- UTF-8 combining characters don't work (probably should be width 1 but are
|
- UTF-8 combining characters don't work (probably should be width 1 but are
|
||||||
listed as 2)
|
listed as 2)
|
||||||
- better error reporting from session_new etc
|
|
||||||
- attach should have a flag to create session if it doesn't exist
|
- attach should have a flag to create session if it doesn't exist
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-attach-session.c,v 1.23 2009-01-19 18:23:40 nicm Exp $ */
|
/* $Id: cmd-attach-session.c,v 1.24 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -62,7 +62,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tty_open(&ctx->cmdclient->tty, &cause) != 0) {
|
if (tty_open(&ctx->cmdclient->tty, &cause) != 0) {
|
||||||
ctx->error(ctx, "%s", cause);
|
ctx->error(ctx, "terminal open failed: %s", cause);
|
||||||
xfree(cause);
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-link-window.c,v 1.27 2009-01-19 18:23:40 nicm Exp $ */
|
/* $Id: cmd-link-window.c,v 1.28 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -47,6 +47,7 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct cmd_srcdst_data *data = self->data;
|
struct cmd_srcdst_data *data = self->data;
|
||||||
struct session *dst;
|
struct session *dst;
|
||||||
struct winlink *wl_src, *wl_dst;
|
struct winlink *wl_src, *wl_dst;
|
||||||
|
char *cause;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
|
if ((wl_src = cmd_find_window(ctx, data->src, NULL)) == NULL)
|
||||||
@ -89,9 +90,10 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_dst = session_attach(dst, wl_src->window, idx);
|
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||||
if (wl_dst == NULL) {
|
if (wl_dst == NULL) {
|
||||||
ctx->error(ctx, "index in use: %d", idx);
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-move-window.c,v 1.4 2009-01-19 18:23:40 nicm Exp $ */
|
/* $Id: cmd-move-window.c,v 1.5 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -50,6 +50,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct client *c;
|
struct client *c;
|
||||||
u_int i;
|
u_int i;
|
||||||
int destroyed, idx;
|
int destroyed, idx;
|
||||||
|
char *cause;
|
||||||
|
|
||||||
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
|
if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
@ -91,9 +92,10 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_dst = session_attach(dst, wl_src->window, idx);
|
wl_dst = session_attach(dst, wl_src->window, idx, &cause);
|
||||||
if (wl_dst == NULL) {
|
if (wl_dst == NULL) {
|
||||||
ctx->error(ctx, "index in use: %d", idx);
|
ctx->error(ctx, "attach window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-new-session.c,v 1.37 2009-01-20 19:35:03 nicm Exp $ */
|
/* $Id: cmd-new-session.c,v 1.38 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -158,14 +158,18 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) {
|
if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) {
|
||||||
ctx->error(ctx, "%s", cause);
|
ctx->error(ctx, "open terminal failed: %s", cause);
|
||||||
xfree(cause);
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((s = session_create(data->newname, cmd, cwd, sx, sy)) == NULL)
|
s = session_create(data->newname, cmd, cwd, sx, sy, &cause);
|
||||||
fatalx("session_create failed");
|
if (s == NULL) {
|
||||||
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
if (data->winname != NULL) {
|
if (data->winname != NULL) {
|
||||||
xfree(s->curw->window->name);
|
xfree(s->curw->window->name);
|
||||||
s->curw->window->name = xstrdup(data->winname);
|
s->curw->window->name = xstrdup(data->winname);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-new-window.c,v 1.30 2009-01-21 22:21:49 nicm Exp $ */
|
/* $Id: cmd-new-window.c,v 1.31 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -120,7 +120,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct cmd_new_window_data *data = self->data;
|
struct cmd_new_window_data *data = self->data;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct winlink *wl;
|
struct winlink *wl;
|
||||||
char *cmd, *cwd;
|
char *cmd, *cwd, *cause;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
@ -168,9 +168,10 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
else
|
else
|
||||||
cwd = ctx->cmdclient->cwd;
|
cwd = ctx->cmdclient->cwd;
|
||||||
|
|
||||||
wl = session_new(s, data->name, cmd, cwd, idx);
|
wl = session_new(s, data->name, cmd, cwd, idx, &cause);
|
||||||
if (wl == NULL) {
|
if (wl == NULL) {
|
||||||
ctx->error(ctx, "command failed: %s", cmd);
|
ctx->error(ctx, "create window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (!data->flag_detached) {
|
if (!data->flag_detached) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-respawn-window.c,v 1.12 2009-01-19 18:23:40 nicm Exp $ */
|
/* $Id: cmd-respawn-window.c,v 1.13 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -50,7 +50,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
const char *env[] = CHILD_ENVIRON;
|
const char *env[] = CHILD_ENVIRON;
|
||||||
char buf[256];
|
char buf[256], *cause;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
@ -77,8 +77,9 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
window_destroy_panes(w);
|
window_destroy_panes(w);
|
||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
window_pane_resize(wp, w->sx, w->sy);
|
window_pane_resize(wp, w->sx, w->sy);
|
||||||
if (window_pane_spawn(wp, data->arg, NULL, env) != 0) {
|
if (window_pane_spawn(wp, data->arg, NULL, env, &cause) != 0) {
|
||||||
ctx->error(ctx, "respawn failed: %s:%d", s->name, wl->idx);
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
screen_reinit(&wp->base);
|
screen_reinit(&wp->base);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd-split-window.c,v 1.7 2009-01-21 19:38:51 nicm Exp $ */
|
/* $Id: cmd-split-window.c,v 1.8 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -140,8 +140,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct window *w;
|
struct window *w;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
const char *env[] = CHILD_ENVIRON;
|
const char *env[] = CHILD_ENVIRON;
|
||||||
char buf[256];
|
char buf[256], *cmd, *cwd, *cause;
|
||||||
char *cmd, *cwd;
|
|
||||||
u_int i, hlimit, lines;
|
u_int i, hlimit, lines;
|
||||||
|
|
||||||
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
|
||||||
@ -168,8 +167,10 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
lines = (w->active->sy * data->percentage) / 100;
|
lines = (w->active->sy * data->percentage) / 100;
|
||||||
|
|
||||||
hlimit = options_get_number(&s->options, "history-limit");
|
hlimit = options_get_number(&s->options, "history-limit");
|
||||||
if ((wp = window_add_pane(w, lines, cmd, cwd, env, hlimit)) == NULL) {
|
wp = window_add_pane(w, lines, cmd, cwd, env, hlimit, &cause);
|
||||||
ctx->error(ctx, "command failed: %s", cmd);
|
if (wp == NULL) {
|
||||||
|
ctx->error(ctx, "create pane failed: %s", cause);
|
||||||
|
xfree(cause);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
server_redraw_window(w);
|
server_redraw_window(w);
|
||||||
|
22
session.c
22
session.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: session.c,v 1.51 2009-01-18 18:31:45 nicm Exp $ */
|
/* $Id: session.c,v 1.52 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -112,8 +112,8 @@ session_find(const char *name)
|
|||||||
|
|
||||||
/* Create a new session. */
|
/* Create a new session. */
|
||||||
struct session *
|
struct session *
|
||||||
session_create(
|
session_create(const char *name,
|
||||||
const char *name, const char *cmd, const char *cwd, u_int sx, u_int sy)
|
const char *cmd, const char *cwd, u_int sx, u_int sy, char **cause)
|
||||||
{
|
{
|
||||||
struct session *s;
|
struct session *s;
|
||||||
u_int i;
|
u_int i;
|
||||||
@ -145,7 +145,7 @@ session_create(
|
|||||||
s->name = xstrdup(name);
|
s->name = xstrdup(name);
|
||||||
else
|
else
|
||||||
xasprintf(&s->name, "%u", i);
|
xasprintf(&s->name, "%u", i);
|
||||||
if (session_new(s, NULL, cmd, cwd, -1) == NULL) {
|
if (session_new(s, NULL, cmd, cwd, -1, cause) == NULL) {
|
||||||
session_destroy(s);
|
session_destroy(s);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ session_index(struct session *s, u_int *i)
|
|||||||
/* Create a new window on a session. */
|
/* Create a new window on a session. */
|
||||||
struct winlink *
|
struct winlink *
|
||||||
session_new(struct session *s,
|
session_new(struct session *s,
|
||||||
const char *name, const char *cmd, const char *cwd, int idx)
|
const char *name, const char *cmd, const char *cwd, int idx, char **cause)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
const char *env[] = CHILD_ENVIRON;
|
const char *env[] = CHILD_ENVIRON;
|
||||||
@ -210,18 +210,22 @@ session_new(struct session *s,
|
|||||||
env[0] = buf;
|
env[0] = buf;
|
||||||
|
|
||||||
hlimit = options_get_number(&s->options, "history-limit");
|
hlimit = options_get_number(&s->options, "history-limit");
|
||||||
w = window_create(name, cmd, cwd, env, s->sx, s->sy, hlimit);
|
w = window_create(name, cmd, cwd, env, s->sx, s->sy, hlimit, cause);
|
||||||
if (w == NULL)
|
if (w == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
return (session_attach(s, w, idx));
|
return (session_attach(s, w, idx, cause));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Attach a window to a session. */
|
/* Attach a window to a session. */
|
||||||
struct winlink *
|
struct winlink *
|
||||||
session_attach(struct session *s, struct window *w, int idx)
|
session_attach(struct session *s, struct window *w, int idx, char **cause)
|
||||||
{
|
{
|
||||||
return (winlink_add(&s->windows, w, idx));
|
struct winlink *wl;
|
||||||
|
|
||||||
|
if ((wl = winlink_add(&s->windows, w, idx)) == NULL)
|
||||||
|
xasprintf(cause, "index in use: %d", idx);
|
||||||
|
return (wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detach a window from a session. */
|
/* Detach a window from a session. */
|
||||||
|
17
tmux.h
17
tmux.h
@ -1,4 +1,4 @@
|
|||||||
/* $Id: tmux.h,v 1.247 2009-01-21 22:47:31 nicm Exp $ */
|
/* $Id: tmux.h,v 1.248 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -1419,12 +1419,12 @@ void winlink_stack_push(struct winlink_stack *, struct winlink *);
|
|||||||
void winlink_stack_remove(struct winlink_stack *, struct winlink *);
|
void winlink_stack_remove(struct winlink_stack *, struct winlink *);
|
||||||
int window_index(struct window *, u_int *);
|
int window_index(struct window *, u_int *);
|
||||||
struct window *window_create(const char *, const char *,
|
struct window *window_create(const char *, const char *,
|
||||||
const char *, const char **, u_int, u_int, u_int);
|
const char *, const char **, u_int, u_int, u_int, char **);
|
||||||
void window_destroy(struct window *);
|
void window_destroy(struct window *);
|
||||||
int window_resize(struct window *, u_int, u_int);
|
int window_resize(struct window *, u_int, u_int);
|
||||||
void window_set_active_pane(struct window *, struct window_pane *);
|
void window_set_active_pane(struct window *, struct window_pane *);
|
||||||
struct window_pane *window_add_pane(struct window *, int,
|
struct window_pane *window_add_pane(struct window *, int,
|
||||||
const char *, const char *, const char **, u_int);
|
const char *, const char *, const char **, u_int, char **);
|
||||||
void window_remove_pane(struct window *, struct window_pane *);
|
void window_remove_pane(struct window *, struct window_pane *);
|
||||||
u_int window_index_of_pane(struct window *, struct window_pane *);
|
u_int window_index_of_pane(struct window *, struct window_pane *);
|
||||||
struct window_pane *window_pane_at_index(struct window *, u_int);
|
struct window_pane *window_pane_at_index(struct window *, u_int);
|
||||||
@ -1435,7 +1435,7 @@ void window_destroy_panes(struct window *);
|
|||||||
struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
|
struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int);
|
||||||
void window_pane_destroy(struct window_pane *);
|
void window_pane_destroy(struct window_pane *);
|
||||||
int window_pane_spawn(struct window_pane *,
|
int window_pane_spawn(struct window_pane *,
|
||||||
const char *, const char *, const char **);
|
const char *, const char *, const char **, char **);
|
||||||
int window_pane_resize(struct window_pane *, u_int, u_int);
|
int window_pane_resize(struct window_pane *, u_int, u_int);
|
||||||
void window_calculate_sizes(struct window *);
|
void window_calculate_sizes(struct window *);
|
||||||
int window_pane_set_mode(
|
int window_pane_set_mode(
|
||||||
@ -1478,13 +1478,14 @@ void session_alert_cancel(struct session *, struct winlink *);
|
|||||||
int session_alert_has(struct session *, struct winlink *, int);
|
int session_alert_has(struct session *, struct winlink *, int);
|
||||||
int session_alert_has_window(struct session *, struct window *, int);
|
int session_alert_has_window(struct session *, struct window *, int);
|
||||||
struct session *session_find(const char *);
|
struct session *session_find(const char *);
|
||||||
struct session *session_create(
|
struct session *session_create(const char *, const char *,
|
||||||
const char *, const char *, const char *, u_int, u_int);
|
const char *, u_int, u_int, char **);
|
||||||
void session_destroy(struct session *);
|
void session_destroy(struct session *);
|
||||||
int session_index(struct session *, u_int *);
|
int session_index(struct session *, u_int *);
|
||||||
struct winlink *session_new(struct session *,
|
struct winlink *session_new(struct session *,
|
||||||
const char *, const char *, const char *, int);
|
const char *, const char *, const char *, int, char **);
|
||||||
struct winlink *session_attach(struct session *, struct window *, int);
|
struct winlink *session_attach(
|
||||||
|
struct session *, struct window *, int, char **);
|
||||||
int session_detach(struct session *, struct winlink *);
|
int session_detach(struct session *, struct winlink *);
|
||||||
int session_has(struct session *, struct window *);
|
int session_has(struct session *, struct window *);
|
||||||
int session_next(struct session *, int);
|
int session_next(struct session *, int);
|
||||||
|
25
window.c
25
window.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: window.c,v 1.61 2009-01-21 19:38:51 nicm Exp $ */
|
/* $Id: window.c,v 1.62 2009-01-23 16:59:14 nicm Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -19,6 +19,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@ -200,13 +201,14 @@ window_index(struct window *s, u_int *i)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct window *
|
struct window *
|
||||||
window_create(const char *name, const char *cmd,
|
window_create(const char *name, const char *cmd, const char *cwd,
|
||||||
const char *cwd, const char **envp, u_int sx, u_int sy, u_int hlimit)
|
const char **envp, u_int sx, u_int sy, u_int hlimit, char **cause)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
w = xmalloc(sizeof *w);
|
w = xmalloc(sizeof *w);
|
||||||
|
w->name = NULL;
|
||||||
w->flags = 0;
|
w->flags = 0;
|
||||||
|
|
||||||
TAILQ_INIT(&w->panes);
|
TAILQ_INIT(&w->panes);
|
||||||
@ -228,7 +230,7 @@ window_create(const char *name, const char *cmd,
|
|||||||
ARRAY_ADD(&windows, w);
|
ARRAY_ADD(&windows, w);
|
||||||
w->references = 0;
|
w->references = 0;
|
||||||
|
|
||||||
if (window_add_pane(w, -1, cmd, cwd, envp, hlimit) == NULL) {
|
if (window_add_pane(w, -1, cmd, cwd, envp, hlimit, cause) == NULL) {
|
||||||
window_destroy(w);
|
window_destroy(w);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -257,7 +259,8 @@ window_destroy(struct window *w)
|
|||||||
|
|
||||||
window_destroy_panes(w);
|
window_destroy_panes(w);
|
||||||
|
|
||||||
xfree(w->name);
|
if (w->name != NULL)
|
||||||
|
xfree(w->name);
|
||||||
xfree(w);
|
xfree(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,8 +381,8 @@ window_set_active_pane(struct window *w, struct window_pane *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct window_pane *
|
struct window_pane *
|
||||||
window_add_pane(struct window *w, int wanty,
|
window_add_pane(struct window *w, int wanty, const char *cmd,
|
||||||
const char *cmd, const char *cwd, const char **envp, u_int hlimit)
|
const char *cwd, const char **envp, u_int hlimit, char **cause)
|
||||||
{
|
{
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int sizey;
|
u_int sizey;
|
||||||
@ -408,7 +411,7 @@ window_add_pane(struct window *w, int wanty,
|
|||||||
else
|
else
|
||||||
TAILQ_INSERT_AFTER(&w->panes, w->active, wp, entry);
|
TAILQ_INSERT_AFTER(&w->panes, w->active, wp, entry);
|
||||||
window_update_panes(w);
|
window_update_panes(w);
|
||||||
if (window_pane_spawn(wp, cmd, cwd, envp) != 0) {
|
if (window_pane_spawn(wp, cmd, cwd, envp, cause) != 0) {
|
||||||
window_remove_pane(w, wp);
|
window_remove_pane(w, wp);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@ -535,7 +538,7 @@ window_pane_destroy(struct window_pane *wp)
|
|||||||
|
|
||||||
int
|
int
|
||||||
window_pane_spawn(struct window_pane *wp,
|
window_pane_spawn(struct window_pane *wp,
|
||||||
const char *cmd, const char *cwd, const char **envp)
|
const char *cmd, const char *cwd, const char **envp, char **cause)
|
||||||
{
|
{
|
||||||
struct winsize ws;
|
struct winsize ws;
|
||||||
int mode;
|
int mode;
|
||||||
@ -568,7 +571,9 @@ window_pane_spawn(struct window_pane *wp,
|
|||||||
|
|
||||||
switch (forkpty(&wp->fd, NULL, NULL, &ws)) {
|
switch (forkpty(&wp->fd, NULL, NULL, &ws)) {
|
||||||
case -1:
|
case -1:
|
||||||
return (1);
|
wp->fd = -1;
|
||||||
|
xasprintf(cause, "%s: %s", cmd, strerror(errno));
|
||||||
|
return (-1);
|
||||||
case 0:
|
case 0:
|
||||||
if (chdir(wp->cwd) != 0)
|
if (chdir(wp->cwd) != 0)
|
||||||
chdir("/");
|
chdir("/");
|
||||||
|
Loading…
Reference in New Issue
Block a user