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