version 1.17, 2009/07/28 06:48:44 |
version 1.18, 2009/08/08 21:52:43 |
|
|
|
|
struct window * |
struct window * |
window_create(const char *name, const char *cmd, const char *cwd, |
window_create(const char *name, const char *cmd, const char *cwd, |
const char **envp, u_int sx, u_int sy, u_int hlimit, char **cause) |
struct environ *env, u_int sx, u_int sy, u_int hlimit, char **cause) |
{ |
{ |
struct window *w; |
struct window *w; |
struct window_pane *wp; |
struct window_pane *wp; |
|
|
w = window_create1(sx, sy); |
w = window_create1(sx, sy); |
wp = window_add_pane(w, hlimit); |
wp = window_add_pane(w, hlimit); |
layout_init(w); |
layout_init(w); |
if (window_pane_spawn(wp, cmd, cwd, envp, cause) != 0) { |
if (window_pane_spawn(wp, cmd, cwd, env, cause) != 0) { |
window_destroy(w); |
window_destroy(w); |
return (NULL); |
return (NULL); |
} |
} |
|
|
|
|
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, char **cause) |
const char *cmd, const char *cwd, struct environ *env, char **cause) |
{ |
{ |
struct winsize ws; |
struct winsize ws; |
int mode; |
int mode; |
const char **envq, *ptr; |
char *argv0, **varp, *var; |
char *argv0; |
ARRAY_DECL(, char *) varlist; |
struct timeval tv; |
struct environ_entry *envent; |
|
const char *ptr; |
|
struct timeval tv; |
|
u_int i; |
|
|
if (wp->fd != -1) |
if (wp->fd != -1) |
close(wp->fd); |
close(wp->fd); |
|
|
case 0: |
case 0: |
if (chdir(wp->cwd) != 0) |
if (chdir(wp->cwd) != 0) |
chdir("/"); |
chdir("/"); |
for (envq = envp; *envq != NULL; envq++) { |
|
if (putenv(xstrdup(*envq)) != 0) |
ARRAY_INIT(&varlist); |
fatal("putenv failed"); |
for (varp = environ; *varp != NULL; varp++) { |
|
var = xstrdup(*varp); |
|
var[strcspn(var, "=")] = '\0'; |
|
ARRAY_ADD(&varlist, var); |
} |
} |
|
for (i = 0; i < ARRAY_LENGTH(&varlist); i++) { |
|
var = ARRAY_ITEM(&varlist, i); |
|
unsetenv(var); |
|
} |
|
RB_FOREACH(envent, environ, env) { |
|
if (envent->value != NULL) |
|
setenv(envent->name, envent->value, 1); |
|
} |
|
|
sigreset(); |
sigreset(); |
log_close(); |
log_close(); |
|
|