about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-09-03 03:18:30 +0800
committerGitHub <noreply@github.com>2025-09-02 21:18:30 +0200
commit94c40d99f61fccdaa95ad4a8081e61a733f6a192 (patch)
tree7f2f225ee191911705310a39c851d508d9cc1b41 /src
parent28d07f9bf03c76013db8d15477e8d1f46d1b930d (diff)
downloadbox64-94c40d99f61fccdaa95ad4a8081e61a733f6a192.tar.gz
box64-94c40d99f61fccdaa95ad4a8081e61a733f6a192.zip
[BASH] Use custom PS1 prefix to make box64-bash more distinguishable (#2998)
* [BASH] Use custom PS1 prefix to make box64-bash more distinguishable

* quick fix

* tweaks

* review
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;
 }