Ticket #3689: 3689-bash-subshell-V2.patch

File 3689-bash-subshell-V2.patch, 2.7 KB (added by alllexx88, 5 years ago)
  • src/subshell/common.c

    a b  
    355355    switch (mc_global.shell->type) 
    356356    { 
    357357    case SHELL_BASH: 
    358         execl (mc_global.shell->path, "bash", "-rcfile", init_file, (char *) NULL); 
     358        execl (mc_global.shell->path, mc_global.shell->name, "-rcfile", init_file, (char *) NULL); 
    359359        break; 
    360360 
    361361    case SHELL_ZSH: 
  • lib/shell.c

    a b  
    3333#include <stdarg.h> 
    3434#include <stdio.h> 
    3535#include <stdlib.h> 
     36#include <sys/wait.h> 
     37#include <unistd.h> 
    3638 
    3739#include "global.h" 
    3840#include "util.h" 
     
    191193        mc_shell->type = SHELL_NONE; 
    192194} 
    193195 
     196/* --------------------------------------------------------------------------------------------- 
     197   This function returns TRUE for a shell in two cases: 
     198   1) the shell has an internal variable with respective name 
     199   2) environmental variable with respective name is set 
     200   --------------------------------------------------------------------------------------------- */ 
     201static gboolean 
     202mc_shell_internal_variable_set (mc_shell_t * mc_shell, const char * name) 
     203{ 
     204    pid_t cpid, w; 
     205    int status; 
     206    char *command; 
     207 
     208    command = g_strdup_printf ("([ -z \"${%s+x}\" ] && exit 1) || exit 0", name); 
     209 
     210    cpid = fork(); 
     211    if (cpid == -1) { 
     212        /* failed to fork */ 
     213        g_free (command); 
     214        return FALSE; 
     215    } 
     216 
     217   if (cpid == 0) {            /* Code executed by child */ 
     218        execl(mc_shell->path, mc_shell->path, "-c", command, (char *) NULL); 
     219        /* execl failed */ 
     220        exit(1); 
     221   } else {                    /* Code executed by parent */ 
     222        g_free (command); 
     223        do { 
     224            w = waitpid(cpid, &status, WUNTRACED | WCONTINUED); 
     225            if (w == -1) { 
     226                /* witpid error */ 
     227                return FALSE; 
     228            } 
     229        } while (!WIFEXITED(status) && !WIFSIGNALED(status)); 
     230 
     231        return (WIFEXITED(status)) && (WEXITSTATUS(status) == 0); 
     232    } 
     233} 
     234 
    194235/* --------------------------------------------------------------------------------------------- */ 
    195236 
     237 
    196238static void 
    197239mc_shell_recognize_path (mc_shell_t * mc_shell) 
    198240{ 
    199     /* If shell is not symlinked to busybox, it is safe to assume it is a real shell */ 
    200     if (strstr (mc_shell->path, "/bash") != NULL || getenv ("BASH") != NULL) 
     241    /* If shell is not symlinked to busybox, it is safe to assume it is a real shell 
     242       Let's assume shell is bash if BASH variable is set */ 
     243    if (mc_shell_internal_variable_set (mc_shell, "BASH")) 
    201244    { 
    202245        mc_shell->type = SHELL_BASH; 
    203         mc_shell->name = "bash"; 
     246        mc_shell->name = mc_shell->path; 
    204247    } 
    205248    else if (strstr (mc_shell->path, "/sh") != NULL || getenv ("SH") != NULL) 
    206249    {