Ticket #3689: 3689-bash-subshell-V3.patch
File 3689-bash-subshell-V3.patch, 2.8 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
-
lib/shell.c
old new 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 if it has an internal variable with respective name. 198 We unset environmental variable of the same name in the child fork to make sure it's internal. 199 --------------------------------------------------------------------------------------------- */ 200 static gboolean 201 mc_shell_internal_variable_set (mc_shell_t * mc_shell, const char * name) 202 { 203 pid_t cpid, w; 204 int status; 205 char *command; 206 207 command = g_strdup_printf ("([ -z \"${%s+x}\" ] && exit 1) || exit 0", name); 208 209 cpid = fork(); 210 if (cpid == -1) { 211 /* failed to fork */ 212 g_free (command); 213 return FALSE; 214 } 215 216 if (cpid == 0) { /* Code executed by child */ 217 unsetenv(name); 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 196 237 static void 197 238 mc_shell_recognize_path (mc_shell_t * mc_shell) 198 239 { 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) 240 /* If shell is not symlinked to busybox, it is safe to assume it is a real shell 241 Let's assume shell is bash if BASH internal variable is set */ 242 if (mc_shell_internal_variable_set (mc_shell, "BASH")) 201 243 { 202 244 mc_shell->type = SHELL_BASH; 203 mc_shell->name = "bash";245 mc_shell->name = mc_shell->path; 204 246 } 205 247 else if (strstr (mc_shell->path, "/sh") != NULL || getenv ("SH") != NULL) 206 248 {