about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.c10
-rw-r--r--src/wrapped/wrappedlibc.c13
2 files changed, 23 insertions, 0 deletions
diff --git a/src/core.c b/src/core.c
index 6025f621..5224e086 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1002,6 +1002,7 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf
         box64_zoom = 1;
     }
     // special case for bash
+    int setup_bash_rcfile = 0;
     if (!strcmp(box64_guest_name, "bash") || !strcmp(box64_guest_name, "box64-bash")) {
         printf_log(LOG_INFO, "Bash detected, disabling banner\n");
         if (!BOX64ENV(nobanner)) {
@@ -1010,8 +1011,10 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf
         }
         if (!bashpath) {
             bashpath = (char*)prog;
+            SET_BOX64ENV(bash, (char*)prog);
             setenv("BOX64_BASH", prog, 1);
         }
+        setup_bash_rcfile = 1;
     }
     if(!bashpath)
         bashpath = ResolveFile("box64-bash", &my_context->box64_path);
@@ -1032,6 +1035,13 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf
         my_context->argv[i] = box_strdup(argv[i+nextarg]);
         printf_log(LOG_INFO, "argv[%i]=\"%s\"\n", i, my_context->argv[i]);
     }
+
+    // Setup custom bash rcfile iff no args are present
+    if (setup_bash_rcfile && my_context->argc == 1) {
+        add_argv("--rcfile");
+        add_argv("box64-custom-bashrc-file"); // handled by my_open
+    }
+
     if(BOX64ENV(nosandbox))
     {
         add_argv("--no-sandbox");
diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c
index 742ae677..4fa9ed62 100644
--- a/src/wrapped/wrappedlibc.c
+++ b/src/wrapped/wrappedlibc.c
@@ -1956,6 +1956,19 @@ EXPORT int32_t my_open(x64emu_t* emu, void* pathname, int32_t flags, uint32_t mo
         return -1;
     }
     #endif
+
+    if (!strcmp((const char*)pathname, "box64-custom-bashrc-file")) {
+        int tmp = shm_open("box64-custom-bashrc-file", O_RDWR | O_CREAT, S_IRWXU);
+        if (tmp < 0) return open(pathname, flags, mode); // error fallback
+        shm_unlink("box64-custom-bashrc-file");
+        const char* content = "if [ -f ~/.bashrc ]\nthen\n. ~/.bashrc\nfi\nexport PS1=\"(box64) \"$PS1\nexport BOX64_NOBANNER=1\nexport BOX64_LOG=0\n";
+        size_t dummy;
+        dummy = write(tmp, content, strlen(content));
+        (void)dummy;
+        lseek(tmp, 0, SEEK_SET);
+        return tmp;
+    }
+
     int ret = open(pathname, flags, mode);
     return ret;
 }