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/zsh", X_OK) == 0)
72 mc_shell->path = g_strdup ("/bin/zsh");
73 else if (access ("/bin/oksh", X_OK) == 0)
74 mc_shell->path = g_strdup ("/bin/oksh");
75 else if (access ("/bin/ksh", X_OK) == 0)
76 mc_shell->path = g_strdup ("/bin/ksh");
77 else if (access ("/bin/ksh93", X_OK) == 0)
78 mc_shell->path = g_strdup ("/bin/ksh93");
79 else if (access ("/bin/ash", X_OK) == 0)
80 mc_shell->path = g_strdup ("/bin/ash");
81 else if (access ("/bin/dash", X_OK) == 0)
82 mc_shell->path = g_strdup ("/bin/dash");
83 else if (access ("/bin/busybox", X_OK) == 0)
84 mc_shell->path = g_strdup ("/bin/busybox");
85 else if (access ("/bin/tcsh", X_OK) == 0)
86 mc_shell->path = g_strdup ("/bin/tcsh");
87 else if (access ("/bin/csh", X_OK) == 0)
88 mc_shell->path = g_strdup ("/bin/csh");
89 else if (access ("/bin/mksh", X_OK) == 0)
90 mc_shell->path = g_strdup ("/bin/mksh");
91 else if (access ("/bin/lksh", X_OK) == 0)
92 mc_shell->path = g_strdup ("/bin/lksh");
93
94
95
96
97
98
99
100 else
101
102 mc_shell->path = g_strdup ("/bin/sh");
103
104 return mc_shell;
105 }
106
107
108
109 static char *
110 mc_shell_get_name_env (void)
111 {
112 char *shell_name = NULL;
113 const char *shell_env = g_getenv ("SHELL");
114
115 if ((shell_env == NULL) || (shell_env[0] == '\0'))
116 {
117
118 const struct passwd *pwd = getpwuid (geteuid ());
119
120 if (pwd != NULL)
121 shell_name = g_strdup (pwd->pw_shell);
122 }
123 else
124
125 shell_name = g_strdup (shell_env);
126
127 return shell_name;
128 }
129
130
131
132 static mc_shell_t *
133 mc_shell_get_from_env (void)
134 {
135 char *shell_name;
136
137 shell_name = mc_shell_get_name_env ();
138 if (shell_name != NULL)
139 {
140 mc_shell_t *mc_shell;
141
142 mc_shell = g_new0 (mc_shell_t, 1);
143 mc_shell->path = shell_name;
144 return mc_shell;
145 }
146
147 return NULL;
148 }
149
150
151
152 static void
153 mc_shell_recognize_real_path (mc_shell_t *mc_shell)
154 {
155 if (strstr (mc_shell->path, "/zsh") != NULL || strstr (mc_shell->real_path, "/zsh") != NULL
156 || getenv ("ZSH_VERSION") != NULL)
157 {
158
159 mc_shell->type = SHELL_ZSH;
160 mc_shell->name = "zsh";
161 }
162 else if (strstr (mc_shell->path, "/tcsh") != NULL
163 || strstr (mc_shell->real_path, "/tcsh") != NULL)
164 {
165
166 mc_shell->type = SHELL_TCSH;
167 mc_shell->name = "tcsh";
168 }
169 else if (strstr (mc_shell->path, "/csh") != NULL
170 || strstr (mc_shell->real_path, "/csh") != NULL)
171 {
172 mc_shell->type = SHELL_TCSH;
173 mc_shell->name = "csh";
174 }
175 else if (strstr (mc_shell->path, "/fish") != NULL
176 || strstr (mc_shell->real_path, "/fish") != NULL)
177 {
178 mc_shell->type = SHELL_FISH;
179 mc_shell->name = "fish";
180 }
181 else if (strstr (mc_shell->path, "/dash") != NULL
182 || strstr (mc_shell->real_path, "/dash") != NULL)
183 {
184
185 mc_shell->type = SHELL_DASH;
186 mc_shell->name = "dash";
187 }
188 else if (strstr (mc_shell->real_path, "/busybox") != NULL)
189 {
190
191
192
193
194
195
196
197 mc_shell->type = SHELL_ASH_BUSYBOX;
198 mc_shell->name = mc_shell->path;
199 }
200 else if (strstr (mc_shell->path, "/ksh") != NULL || strstr (mc_shell->real_path, "/ksh") != NULL
201 || strstr (mc_shell->path, "/ksh93") != NULL
202 || strstr (mc_shell->real_path, "/ksh93") != NULL
203 || strstr (mc_shell->path, "/oksh") != NULL
204 || strstr (mc_shell->real_path, "/oksh") != NULL)
205 {
206 mc_shell->type = SHELL_KSH;
207 mc_shell->name = "ksh";
208 }
209 else if (strstr (mc_shell->path, "/mksh") != NULL
210 || strstr (mc_shell->real_path, "/mksh") != NULL
211 || strstr (mc_shell->path, "/lksh") != NULL
212 || strstr (mc_shell->real_path, "/lksh") != NULL)
213 {
214
215
216
217 mc_shell->type = SHELL_MKSH;
218 mc_shell->name = "mksh";
219 }
220 else
221 mc_shell->type = SHELL_NONE;
222 }
223
224
225
226 static void
227 mc_shell_recognize_path (mc_shell_t *mc_shell)
228 {
229
230 if (strstr (mc_shell->path, "/bash") != NULL || getenv ("BASH_VERSION") != NULL)
231 {
232 mc_shell->type = SHELL_BASH;
233 mc_shell->name = "bash";
234 }
235 else if (strstr (mc_shell->path, "/sh") != NULL)
236 {
237 mc_shell->type = SHELL_SH;
238 mc_shell->name = "sh";
239 }
240 else if (strstr (mc_shell->path, "/ash") != NULL || getenv ("BB_ASH_VERSION") != NULL)
241 {
242 mc_shell->type = SHELL_ASH_BUSYBOX;
243 mc_shell->name = "ash";
244 }
245 else if (strstr (mc_shell->path, "/ksh") != NULL || strstr (mc_shell->path, "/ksh93") != NULL
246 || strstr (mc_shell->path, "/oksh") != NULL
247 || (getenv ("KSH_VERSION") != NULL
248 && strstr (getenv ("KSH_VERSION"), "PD KSH") != NULL))
249 {
250 mc_shell->type = SHELL_KSH;
251 mc_shell->name = "ksh";
252 }
253 else if (strstr (mc_shell->path, "/mksh") != NULL || strstr (mc_shell->path, "/lksh") != NULL
254 || (getenv ("KSH_VERSION") != NULL
255 && strstr (getenv ("KSH_VERSION"), "MIRBSD KSH") != NULL))
256 {
257 mc_shell->type = SHELL_MKSH;
258 mc_shell->name = "mksh";
259 }
260 else
261 mc_shell->type = SHELL_NONE;
262 }
263
264
265
266
267
268 void
269 mc_shell_init (void)
270 {
271 mc_shell_t *mc_shell;
272
273 mc_shell = mc_shell_get_from_env ();
274 if (mc_shell == NULL)
275 mc_shell = mc_shell_get_installed_in_system ();
276
277 mc_shell->real_path = mc_realpath (mc_shell->path, rp_shell);
278
279
280
281 if (mc_shell->real_path != NULL)
282 mc_shell_recognize_real_path (mc_shell);
283
284 if (mc_shell->type == SHELL_NONE)
285 mc_shell_recognize_path (mc_shell);
286
287 if (mc_shell->type == SHELL_NONE)
288 mc_global.tty.use_subshell = FALSE;
289
290 mc_global.shell = mc_shell;
291 }
292
293
294
295 void
296 mc_shell_deinit (void)
297 {
298 if (mc_global.shell != NULL)
299 {
300 g_free (mc_global.shell->path);
301 MC_PTR_FREE (mc_global.shell);
302 }
303 }
304
305