aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 07:30:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-22 07:30:26 +0000
commit6258fd345465960c74892ad35f4a6926859edb64 (patch)
treed989cf56bc84eb7af354f93d4507e87bc6213607
parent8e1c71529c2bf38a04d4a117e625e59044a0785a (diff)
downloadbusybox-w32-6258fd345465960c74892ad35f4a6926859edb64.tar.gz
busybox-w32-6258fd345465960c74892ad35f4a6926859edb64.tar.bz2
busybox-w32-6258fd345465960c74892ad35f4a6926859edb64.zip
cmdedit: stop playing dirty games with atexit
-rw-r--r--shell/cmdedit.c61
1 files changed, 24 insertions, 37 deletions
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 554a4ebec..b0a5de7ac 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -1097,6 +1097,8 @@ static void parse_prompt(const char *prmt_ptr)
1097 char c; 1097 char c;
1098 char *pbuf; 1098 char *pbuf;
1099 1099
1100 cmdedit_prmt_len = 0;
1101
1100 if (!pwd_buf) { 1102 if (!pwd_buf) {
1101 pwd_buf = (char *)bb_msg_unknown; 1103 pwd_buf = (char *)bb_msg_unknown;
1102 } 1104 }
@@ -1212,14 +1214,6 @@ static void parse_prompt(const char *prmt_ptr)
1212 1214
1213static sighandler_t previous_SIGWINCH_handler; 1215static sighandler_t previous_SIGWINCH_handler;
1214 1216
1215static void cmdedit_reset_term(void)
1216{
1217 setTermSettings(STDIN_FILENO, (void *) &initial_settings);
1218 /* restore SIGWINCH handler */
1219 signal(SIGWINCH, previous_SIGWINCH_handler);
1220 fflush(stdout);
1221}
1222
1223static void cmdedit_setwidth(unsigned w, int redraw_flg) 1217static void cmdedit_setwidth(unsigned w, int redraw_flg)
1224{ 1218{
1225 cmdedit_termw = w; 1219 cmdedit_termw = w;
@@ -1241,32 +1235,6 @@ static void win_changed(int nsig)
1241 signal(SIGWINCH, win_changed); /* rearm ourself */ 1235 signal(SIGWINCH, win_changed); /* rearm ourself */
1242} 1236}
1243 1237
1244static void cmdedit_init(void)
1245{
1246 cmdedit_prmt_len = 0;
1247 previous_SIGWINCH_handler = signal(SIGWINCH, win_changed);
1248 win_changed(0); /* do initial resizing */
1249
1250#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
1251 {
1252 struct passwd *entry;
1253
1254 entry = getpwuid(geteuid());
1255 if (entry) {
1256 user_buf = xstrdup(entry->pw_name);
1257 home_pwd_buf = xstrdup(entry->pw_dir);
1258 }
1259 }
1260#endif
1261
1262#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
1263 my_uid = getuid();
1264 my_gid = getgid();
1265#endif
1266// Crap. We should be able to do it without atexit.
1267 atexit(cmdedit_reset_term); /* be sure to do this only once */
1268}
1269
1270/* 1238/*
1271 * The emacs and vi modes share much of the code in the big 1239 * The emacs and vi modes share much of the code in the big
1272 * command loop. Commands entered when in vi's command mode (aka 1240 * command loop. Commands entered when in vi's command mode (aka
@@ -1329,7 +1297,23 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t
1329 setTermSettings(0, (void *) &new_settings); 1297 setTermSettings(0, (void *) &new_settings);
1330 1298
1331 /* Now initialize things */ 1299 /* Now initialize things */
1332 cmdedit_init(); 1300 previous_SIGWINCH_handler = signal(SIGWINCH, win_changed);
1301 win_changed(0); /* do initial resizing */
1302#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR
1303 {
1304 struct passwd *entry;
1305
1306 entry = getpwuid(geteuid());
1307 if (entry) {
1308 user_buf = xstrdup(entry->pw_name);
1309 home_pwd_buf = xstrdup(entry->pw_dir);
1310 }
1311 }
1312#endif
1313#if ENABLE_FEATURE_COMMAND_TAB_COMPLETION
1314 my_uid = getuid();
1315 my_gid = getgid();
1316#endif
1333 /* Print out the command prompt */ 1317 /* Print out the command prompt */
1334 parse_prompt(prompt); 1318 parse_prompt(prompt);
1335 1319
@@ -1746,8 +1730,11 @@ int read_line_input(const char* prompt, char* command, int maxsize, line_input_t
1746#if ENABLE_FEATURE_SH_FANCY_PROMPT 1730#if ENABLE_FEATURE_SH_FANCY_PROMPT
1747 free((char*)cmdedit_prompt); 1731 free((char*)cmdedit_prompt);
1748#endif 1732#endif
1749 /* restore initial_settings and SIGWINCH handler */ 1733 /* restore initial_settings */
1750 cmdedit_reset_term(); 1734 setTermSettings(STDIN_FILENO, (void *) &initial_settings);
1735 /* restore SIGWINCH handler */
1736 signal(SIGWINCH, previous_SIGWINCH_handler);
1737 fflush(stdout);
1751 return command_len; 1738 return command_len;
1752} 1739}
1753 1740