aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-05-14 17:32:34 -0400
committerJesse Luehrs <doy@tozt.net>2016-05-14 17:33:20 -0400
commitbfe96a6aa5fa3ca9a05b658efbcaee9dc01b5235 (patch)
treef32a44cd6676acbdbcc685a0782e6d51889efaf0
parent1c3406e8b486ec22f16d4e5bf6a28d35ca744af3 (diff)
downloadrunes-bfe96a6aa5fa3ca9a05b658efbcaee9dc01b5235.tar.gz
runes-bfe96a6aa5fa3ca9a05b658efbcaee9dc01b5235.zip
support spawning terminals with different environments
-rw-r--r--src/daemon.c2
-rw-r--r--src/pty-unix.c12
-rw-r--r--src/pty-unix.h2
-rw-r--r--src/runes.c3
-rw-r--r--src/term.c5
-rw-r--r--src/term.h3
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);