From ae6e647845833789237b78772583dd1babd66680 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Wed, 2 Jan 2013 17:00:30 +0400 Subject: [PATCH] (mc_global_t::shell): new member to store user's shell ...instead of global variable "shell". Signed-off-by: Andrew Borodin --- lib/global.c | 2 ++ lib/global.h | 3 +++ src/clipboard.c | 5 ++--- src/execute.c | 12 ++++++------ src/main.c | 15 ++++++++------- src/setup.c | 3 --- src/setup.h | 2 -- src/subshell.c | 18 +++++++++--------- src/vfs/extfs/extfs.c | 3 +-- 9 files changed, 31 insertions(+), 32 deletions(-) diff --git a/lib/global.c b/lib/global.c index 8b18c7c3b..8a217fbde 100644 --- a/lib/global.c +++ b/lib/global.c @@ -94,6 +94,8 @@ mc_global_t mc_global = { .subshell_pty = 0, #endif /* !ENABLE_SUBSHELL */ + .shell = NULL, + .xterm_flag = FALSE, .disable_x11 = FALSE, .slow_terminal = FALSE, diff --git a/lib/global.h b/lib/global.h index f13dfc04f..66828e515 100644 --- a/lib/global.h +++ b/lib/global.h @@ -244,6 +244,9 @@ typedef struct int subshell_pty; #endif /* !ENABLE_SUBSHELL */ + /* The user's shell */ + char *shell; + /* This flag is set by xterm detection routine in function main() */ /* It is used by function view_other_cmd() */ gboolean xterm_flag; diff --git a/src/clipboard.c b/src/clipboard.c index 9ceb1fb2e..375a81b79 100644 --- a/src/clipboard.c +++ b/src/clipboard.c @@ -36,7 +36,6 @@ #include "lib/vfs/vfs.h" -#include "setup.h" #include "src/execute.h" #include "clipboard.h" @@ -81,7 +80,7 @@ clipboard_file_to_ext_clip (const gchar * event_group_name, const gchar * event_ cmd = g_strconcat (clipboard_store_path, " ", tmp, " 2>/dev/null", (char *) NULL); if (cmd != NULL) - res = my_system (EXECUTE_AS_SHELL, shell, cmd); + res = my_system (EXECUTE_AS_SHELL, mc_global.tty.shell, cmd); g_free (cmd); g_free (tmp); @@ -111,7 +110,7 @@ clipboard_file_from_ext_clip (const gchar * event_group_name, const gchar * even cmd = g_strconcat (clipboard_paste_path, " > ", tmp, " 2>/dev/null", (char *) NULL); if (cmd != NULL) - res = my_system (EXECUTE_AS_SHELL, shell, cmd); + res = my_system (EXECUTE_AS_SHELL, mc_global.tty.shell, cmd); g_free (cmd); g_free (tmp); diff --git a/src/execute.c b/src/execute.c index 5d4f250e3..30fc0f8b4 100644 --- a/src/execute.c +++ b/src/execute.c @@ -129,7 +129,7 @@ do_possible_cd (const vfs_path_t * new_dir_vpath) /* --------------------------------------------------------------------------------------------- */ static void -do_execute (const char *lc_shell, const char *command, int flags) +do_execute (const char *shell, const char *command, int flags) { #ifdef ENABLE_SUBSHELL vfs_path_t *new_dir_vpath = NULL; @@ -161,7 +161,7 @@ do_execute (const char *lc_shell, const char *command, int flags) } else #endif /* ENABLE_SUBSHELL */ - my_system (flags, lc_shell, command); + my_system (flags, shell, command); if (!(flags & EXECUTE_INTERNAL)) { @@ -291,12 +291,12 @@ shell_execute (const char *command, int flags) #ifdef ENABLE_SUBSHELL if (mc_global.tty.use_subshell) if (subshell_state == INACTIVE) - do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); + do_execute (mc_global.tty.shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); else message (D_ERROR, MSG_ERROR, _("The shell is already running a command")); else #endif /* ENABLE_SUBSHELL */ - do_execute (shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); + do_execute (mc_global.tty.shell, cmd ? cmd : command, flags | EXECUTE_AS_SHELL); g_free (cmd); } @@ -306,7 +306,7 @@ shell_execute (const char *command, int flags) void exec_shell (void) { - do_execute (shell, 0, 0); + do_execute (mc_global.tty.shell, 0, 0); } /* --------------------------------------------------------------------------------------------- */ @@ -355,7 +355,7 @@ toggle_panels (void) fprintf (stderr, _("Type `exit' to return to the Midnight Commander")); fprintf (stderr, "\n\r\n\r"); - my_system (EXECUTE_INTERNAL, shell, NULL); + my_system (EXECUTE_INTERNAL, mc_global.tty.shell, NULL); } else get_key_code (0); diff --git a/src/main.c b/src/main.c index 1123624a5..535968c24 100644 --- a/src/main.c +++ b/src/main.c @@ -129,17 +129,18 @@ OS_Setup (void) if ((shell_env == NULL) || (shell_env[0] == '\0')) { struct passwd *pwd; + pwd = getpwuid (geteuid ()); if (pwd != NULL) - shell = g_strdup (pwd->pw_shell); + mc_global.tty.shell = g_strdup (pwd->pw_shell); } else - shell = g_strdup (shell_env); + mc_global.tty.shell = g_strdup (shell_env); - if ((shell == NULL) || (shell[0] == '\0')) + if ((mc_global.tty.shell == NULL) || (mc_global.tty.shell[0] == '\0')) { - g_free (shell); - shell = g_strdup ("/bin/sh"); + g_free (mc_global.tty.shell); + mc_global.tty.shell = g_strdup ("/bin/sh"); } /* This is the directory, where MC was installed, on Unix this is DATADIR */ @@ -257,7 +258,7 @@ main (int argc, char *argv[]) startup_exit_falure: fprintf (stderr, _("Failed to run:\n%s\n"), error->message); g_error_free (error); - g_free (shell); + g_free (mc_global.tty.shell); startup_exit_ok: str_uninit_strings (); return exit_code; @@ -435,7 +436,7 @@ main (int argc, char *argv[]) } g_free (last_wd_string); - g_free (shell); + g_free (mc_global.tty.shell); done_key (); diff --git a/src/setup.c b/src/setup.c index 3ac68af02..3002bb85c 100644 --- a/src/setup.c +++ b/src/setup.c @@ -197,9 +197,6 @@ char *last_wd_string = NULL; /* Set when main loop should be terminated */ int quit = 0; -/* The user's shell */ -char *shell = NULL; - /* Set to TRUE to suppress printing the last directory */ int print_last_revert = FALSE; diff --git a/src/setup.h b/src/setup.h index 21e8592c6..234821b51 100644 --- a/src/setup.h +++ b/src/setup.h @@ -124,8 +124,6 @@ extern int quit; /* Set to TRUE to suppress printing the last directory */ extern gboolean print_last_revert; -extern char *shell; - /* index to record_macro_buf[], -1 if not recording a macro */ extern int macro_index; diff --git a/src/subshell.c b/src/subshell.c index e5175cec1..576219ca0 100644 --- a/src/subshell.c +++ b/src/subshell.c @@ -329,22 +329,22 @@ init_subshell_child (const char *pty_name) switch (subshell_type) { case BASH: - execl (shell, "bash", "-rcfile", init_file, (char *) NULL); + execl (mc_global.tty.shell, "bash", "-rcfile", init_file, (char *) NULL); break; case TCSH: - execl (shell, "tcsh", (char *) NULL); + execl (mc_global.tty.shell, "tcsh", (char *) NULL); break; case ZSH: /* Use -g to exclude cmds beginning with space from history * and -Z to use the line editor on non-interactive term */ - execl (shell, "zsh", "-Z", "-g", (char *) NULL); + execl (mc_global.tty.shell, "zsh", "-Z", "-g", (char *) NULL); break; case FISH: - execl (shell, "fish", (char *) NULL); + execl (mc_global.tty.shell, "fish", (char *) NULL); break; } @@ -790,15 +790,15 @@ init_subshell (void) { /* First time through */ /* Find out what type of shell we have */ - if (strstr (shell, "/zsh") || getenv ("ZSH_VERSION")) + if (strstr (mc_global.tty.shell, "/zsh") || getenv ("ZSH_VERSION")) subshell_type = ZSH; - else if (strstr (shell, "/tcsh")) + else if (strstr (mc_global.tty.shell, "/tcsh")) subshell_type = TCSH; - else if (strstr (shell, "/csh")) + else if (strstr (mc_global.tty.shell, "/csh")) subshell_type = TCSH; - else if (strstr (shell, "/bash") || getenv ("BASH")) + else if (strstr (mc_global.tty.shell, "/bash") || getenv ("BASH")) subshell_type = BASH; - else if (strstr (shell, "/fish")) + else if (strstr (mc_global.tty.shell, "/fish")) subshell_type = FISH; else { diff --git a/src/vfs/extfs/extfs.c b/src/vfs/extfs/extfs.c index 2bab28644..945a36ff4 100644 --- a/src/vfs/extfs/extfs.c +++ b/src/vfs/extfs/extfs.c @@ -58,7 +58,6 @@ #include "lib/util.h" #include "lib/widget.h" /* message() */ -#include "src/setup.h" /* shell */ #include "src/execute.h" /* For shell_execute */ #include "lib/vfs/vfs.h" @@ -851,7 +850,7 @@ extfs_cmd (const char *str_extfs_cmd, struct archive *archive, g_free (quoted_archive_name); open_error_pipe (); - retval = my_system (EXECUTE_AS_SHELL, shell, cmd); + retval = my_system (EXECUTE_AS_SHELL, mc_global.tty.shell, cmd); g_free (cmd); close_error_pipe (D_ERROR, NULL); return retval; -- 2.11.4.GIT