This source file includes following definitions.
- mc_shell_get_installed_in_system
- mc_shell_get_name_env
- mc_shell_get_from_env
- mc_shell_recognize_real_path
- mc_shell_recognize_path
- mc_shell_init
- mc_shell_deinit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 #include <config.h>
31
32 #include <pwd.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36
37 #include "global.h"
38 #include "util.h"
39
40
41
42
43
44
45
46
47
48
49
50 static char rp_shell[PATH_MAX];
51
52
53
54
55
56
57
58
59
60
61 static mc_shell_t *
62 mc_shell_get_installed_in_system (void)
63 {
64 mc_shell_t *mc_shell;
65
66 mc_shell = g_new0 (mc_shell_t, 1);
67
68
69 if (access ("/bin/bash", X_OK) == 0)
70 mc_shell->path = g_strdup ("/bin/bash");
71 else if (access ("/bin/ash", X_OK) == 0)
72 mc_shell->path = g_strdup ("/bin/ash");
73 else if (access ("/bin/dash", X_OK) == 0)
74 mc_shell->path = g_strdup ("/bin/dash");
75 else if (access ("/bin/busybox", X_OK) == 0)
76 mc_shell->path = g_strdup ("/bin/busybox");
77 else if (access ("/bin/zsh", X_OK) == 0)
78 mc_shell->path = g_strdup ("/bin/zsh");
79 else if (access ("/bin/tcsh", X_OK) == 0)
80 mc_shell->path = g_strdup ("/bin/tcsh");
81 else if (access ("/bin/csh", X_OK) == 0)
82 mc_shell->path = g_strdup ("/bin/csh");
83
84
85
86
87
88
89
90 else
91
92 mc_shell->path = g_strdup ("/bin/sh");
93
94 return mc_shell;
95 }
96
97
98
99 static char *
100 mc_shell_get_name_env (void)
101 {
102 const char *shell_env;
103 char *shell_name = NULL;
104
105 shell_env = g_getenv ("SHELL");
106 if ((shell_env == NULL) || (shell_env[0] == '\0'))
107 {
108
109 struct passwd *pwd;
110
111 pwd = getpwuid (geteuid ());
112 if (pwd != NULL)
113 shell_name = g_strdup (pwd->pw_shell);
114 }
115 else
116
117 shell_name = g_strdup (shell_env);
118
119 return shell_name;
120 }
121
122
123
124 static mc_shell_t *
125 mc_shell_get_from_env (void)
126 {
127 mc_shell_t *mc_shell = NULL;
128
129 char *shell_name;
130
131 shell_name = mc_shell_get_name_env ();
132
133 if (shell_name != NULL)
134 {
135 mc_shell = g_new0 (mc_shell_t, 1);
136 mc_shell->path = shell_name;
137 }
138
139 return mc_shell;
140 }
141
142
143
144 static void
145 mc_shell_recognize_real_path (mc_shell_t *mc_shell)
146 {
147 if (strstr (mc_shell->path, "/zsh") != NULL || strstr (mc_shell->real_path, "/zsh") != NULL
148 || getenv ("ZSH_VERSION") != NULL)
149 {
150
151 mc_shell->type = SHELL_ZSH;
152 mc_shell->name = "zsh";
153 }
154 else if (strstr (mc_shell->path, "/tcsh") != NULL
155 || strstr (mc_shell->real_path, "/tcsh") != NULL)
156 {
157
158 mc_shell->type = SHELL_TCSH;
159 mc_shell->name = "tcsh";
160 }
161 else if (strstr (mc_shell->path, "/csh") != NULL
162 || strstr (mc_shell->real_path, "/csh") != NULL)
163 {
164 mc_shell->type = SHELL_TCSH;
165 mc_shell->name = "csh";
166 }
167 else if (strstr (mc_shell->path, "/fish") != NULL
168 || strstr (mc_shell->real_path, "/fish") != NULL)
169 {
170 mc_shell->type = SHELL_FISH;
171 mc_shell->name = "fish";
172 }
173 else if (strstr (mc_shell->path, "/dash") != NULL
174 || strstr (mc_shell->real_path, "/dash") != NULL)
175 {
176
177 mc_shell->type = SHELL_DASH;
178 mc_shell->name = "dash";
179 }
180 else if (strstr (mc_shell->real_path, "/busybox") != NULL)
181 {
182
183
184
185
186
187
188
189 mc_shell->type = SHELL_ASH_BUSYBOX;
190 mc_shell->name = mc_shell->path;
191 }
192 else
193 mc_shell->type = SHELL_NONE;
194 }
195
196
197
198 static void
199 mc_shell_recognize_path (mc_shell_t *mc_shell)
200 {
201
202 if (strstr (mc_shell->path, "/bash") != NULL || getenv ("BASH") != NULL)
203 {
204 mc_shell->type = SHELL_BASH;
205 mc_shell->name = "bash";
206 }
207 else if (strstr (mc_shell->path, "/sh") != NULL || getenv ("SH") != NULL)
208 {
209 mc_shell->type = SHELL_SH;
210 mc_shell->name = "sh";
211 }
212 else if (strstr (mc_shell->path, "/ash") != NULL || getenv ("ASH") != NULL)
213 {
214 mc_shell->type = SHELL_ASH_BUSYBOX;
215 mc_shell->name = "ash";
216 }
217 else
218 mc_shell->type = SHELL_NONE;
219 }
220
221
222
223
224
225 void
226 mc_shell_init (void)
227 {
228 mc_shell_t *mc_shell;
229
230 mc_shell = mc_shell_get_from_env ();
231
232 if (mc_shell == NULL)
233 mc_shell = mc_shell_get_installed_in_system ();
234
235 mc_shell->real_path = mc_realpath (mc_shell->path, rp_shell);
236
237
238
239
240 if (mc_shell->real_path != NULL)
241 mc_shell_recognize_real_path (mc_shell);
242
243 if (mc_shell->type == SHELL_NONE)
244 mc_shell_recognize_path (mc_shell);
245
246 if (mc_shell->type == SHELL_NONE)
247 mc_global.tty.use_subshell = FALSE;
248
249 mc_global.shell = mc_shell;
250 }
251
252
253
254 void
255 mc_shell_deinit (void)
256 {
257 if (mc_global.shell != NULL)
258 {
259 g_free (mc_global.shell->path);
260 MC_PTR_FREE (mc_global.shell);
261 }
262 }
263
264