Ticket #3689: 3689-bash-subshell-V2.patch
File 3689-bash-subshell-V2.patch, 2.7 KB (added by alllexx88, 8 years ago) |
---|
-
src/subshell/common.c
a b 355 355 switch (mc_global.shell->type) 356 356 { 357 357 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); 359 359 break; 360 360 361 361 case SHELL_ZSH: -
lib/shell.c
a b 33 33 #include <stdarg.h> 34 34 #include <stdio.h> 35 35 #include <stdlib.h> 36 #include <sys/wait.h> 37 #include <unistd.h> 36 38 37 39 #include "global.h" 38 40 #include "util.h" … … 191 193 mc_shell->type = SHELL_NONE; 192 194 } 193 195 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 --------------------------------------------------------------------------------------------- */ 201 static gboolean 202 mc_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 194 235 /* --------------------------------------------------------------------------------------------- */ 195 236 237 196 238 static void 197 239 mc_shell_recognize_path (mc_shell_t * mc_shell) 198 240 { 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")) 201 244 { 202 245 mc_shell->type = SHELL_BASH; 203 mc_shell->name = "bash";246 mc_shell->name = mc_shell->path; 204 247 } 205 248 else if (strstr (mc_shell->path, "/sh") != NULL || getenv ("SH") != NULL) 206 249 {