Skip to content

Commit

Permalink
Pass $TERM to emulated process
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Apr 6, 2018
1 parent fb2c5a2 commit 20dac20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
#include "xX_main_Xx.h"

int main(int argc, char *const argv[]) {
int err = xX_main_Xx(argc, argv);
char *const *envp = NULL;
if (getenv("TERM"))
envp = (char *[]) {getenv("TERM") - strlen("TERM") - 1, NULL};
int err = xX_main_Xx(argc, argv, envp);
if (err < 0) {
fprintf(stderr, "%s\n", strerror(-err));
return err;
Expand Down
2 changes: 1 addition & 1 deletion tools/ptraceomatic.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static void prepare_tracee(int pid) {
}

int main(int argc, char *const argv[]) {
int err = xX_main_Xx(argc, argv);
int err = xX_main_Xx(argc, argv, NULL);
if (err < 0) {
fprintf(stderr, "%s\n", strerror(-err));
return err;
Expand Down
6 changes: 4 additions & 2 deletions xX_main_Xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static void exit_handler(int code) {
// this function parses command line arguments and initializes global
// data structures. thanks programming discussions discord server for the name.
// https://discord.gg/9zT7NHP
static inline int xX_main_Xx(int argc, char *const argv[]) {
static inline int xX_main_Xx(int argc, char *const argv[], char *const *envp) {
// parse cli options
int opt;
const char *root = "";
Expand Down Expand Up @@ -50,7 +50,9 @@ static inline int xX_main_Xx(int argc, char *const argv[]) {
fs_chdir(current->fs, pwd);
}

err = sys_execve(argv[optind], argv + optind, (char *[]) {NULL});
if (envp == NULL)
envp = (char *[]) {NULL};
err = sys_execve(argv[optind], argv + optind, envp);
if (err < 0)
return err;
err = create_stdio(real_tty_driver);
Expand Down

0 comments on commit 20dac20

Please sign in to comment.