From bfe96a6aa5fa3ca9a05b658efbcaee9dc01b5235 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 14 May 2016 17:32:34 -0400 Subject: support spawning terminals with different environments --- src/daemon.c | 2 +- src/pty-unix.c | 12 +++++++++++- src/pty-unix.h | 2 +- src/runes.c | 3 ++- src/term.c | 5 +++-- src/term.h | 3 ++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 2202b7f..8c1269e 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -179,7 +179,7 @@ static int runes_daemon_handle_request(void *t) } runes_term_register_with_loop( - runes_term_new(argc, argv, daemon->wb), daemon->loop); + runes_term_new(argc, argv, NULL, NULL, daemon->wb), daemon->loop); } free(argv); diff --git a/src/pty-unix.c b/src/pty-unix.c index ba4ea34..376a92d 100644 --- a/src/pty-unix.c +++ b/src/pty-unix.c @@ -18,6 +18,8 @@ #include "term.h" #include "window-xlib.h" +extern char **environ; + static int runes_pty_input_cb(void *t); RunesPty *runes_pty_new() @@ -32,7 +34,7 @@ RunesPty *runes_pty_new() return pty; } -void runes_pty_spawn_subprocess(RunesTerm *t) +void runes_pty_spawn_subprocess(RunesTerm *t, char *envp[], char *cwd) { RunesPty *pty = t->pty; @@ -90,6 +92,14 @@ void runes_pty_spawn_subprocess(RunesTerm *t) unsetenv("LINES"); unsetenv("COLUMNS"); + if (cwd) { + chdir(cwd); + } + + if (envp) { + environ = envp; + } + if (strpbrk(cmd, " $")) { execlp("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL); } diff --git a/src/pty-unix.h b/src/pty-unix.h index d4c5ea6..8894072 100644 --- a/src/pty-unix.h +++ b/src/pty-unix.h @@ -14,7 +14,7 @@ struct runes_pty { }; RunesPty *runes_pty_new(void); -void runes_pty_spawn_subprocess(RunesTerm *t); +void runes_pty_spawn_subprocess(RunesTerm *t, char *envp[], char *cwd); void runes_pty_init_loop(RunesTerm *t, RunesLoop *loop); void runes_pty_set_window_size( RunesTerm *t, int row, int col, int xpixel, int ypixel); diff --git a/src/runes.c b/src/runes.c index b7ec368..933ec88 100644 --- a/src/runes.c +++ b/src/runes.c @@ -11,7 +11,8 @@ int main (int argc, char *argv[]) loop = runes_loop_new(); wb = runes_window_backend_new(); - runes_term_register_with_loop(runes_term_new(argc, argv, wb), loop); + runes_term_register_with_loop( + runes_term_new(argc, argv, NULL, NULL, wb), loop); runes_loop_run(loop); diff --git a/src/term.c b/src/term.c index 5118687..023dc8e 100644 --- a/src/term.c +++ b/src/term.c @@ -9,7 +9,8 @@ #include "pty-unix.h" #include "window-xlib.h" -RunesTerm *runes_term_new(int argc, char *argv[], RunesWindowBackend *wb) +RunesTerm *runes_term_new( + int argc, char *argv[], char *envp[], char *cwd, RunesWindowBackend *wb) { RunesTerm *t; int width, height; @@ -24,7 +25,7 @@ RunesTerm *runes_term_new(int argc, char *argv[], RunesWindowBackend *wb) vt100_screen_set_scrollback_length(t->scr, t->config->scrollback_length); runes_window_create_window(t, argc, argv); - runes_pty_spawn_subprocess(t); + runes_pty_spawn_subprocess(t, envp, cwd); runes_display_set_context(t, t->w->backend_cr); runes_window_get_size(t, &width, &height); diff --git a/src/term.h b/src/term.h index 32b06dd..3a915f7 100644 --- a/src/term.h +++ b/src/term.h @@ -14,7 +14,8 @@ struct runes_term { int refcnt; }; -RunesTerm *runes_term_new(int argc, char *argv[], RunesWindowBackend *wb); +RunesTerm *runes_term_new( + int argc, char *argv[], char *envp[], char *cwd, RunesWindowBackend *wb); void runes_term_register_with_loop(RunesTerm *t, RunesLoop *loop); void runes_term_set_window_size(RunesTerm *t, int xpixel, int ypixel); void runes_term_refcnt_inc(RunesTerm *t); -- cgit v1.2.3-54-g00ecf