diff options
author | Ron Yorston <rmy@pobox.com> | 2012-03-23 11:13:23 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2012-03-23 11:13:23 +0000 |
commit | 40514a0309939f2446f0d4ed9600cad5de396e7f (patch) | |
tree | 0f5f4a57d4bb7893418b5bb11d482858eb17ba8b /shell | |
parent | 9db164d6e39050d09f38288c6045cd2a2cbf6d63 (diff) | |
parent | c0cae52662ccced9df19f19ec94238d1b1e3bd71 (diff) | |
download | busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.gz busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.tar.bz2 busybox-w32-40514a0309939f2446f0d4ed9600cad5de396e7f.zip |
Merge commit 'c0cae52662ccced9df19f19ec94238d1b1e3bd71' into merge
Conflicts:
Makefile.flags
scripts/basic/fixdep.c
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash.c | 6 | ||||
-rw-r--r-- | shell/cttyhack.c | 71 | ||||
-rw-r--r-- | shell/hush.c | 41 |
3 files changed, 73 insertions, 45 deletions
diff --git a/shell/ash.c b/shell/ash.c index a809bf181..a79099bc5 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -13431,6 +13431,10 @@ exitshell(void) | |||
13431 | char *p; | 13431 | char *p; |
13432 | int status; | 13432 | int status; |
13433 | 13433 | ||
13434 | #if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT | ||
13435 | save_history(line_input_state); | ||
13436 | #endif | ||
13437 | |||
13434 | status = exitstatus; | 13438 | status = exitstatus; |
13435 | TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); | 13439 | TRACE(("pid %d, exitshell(%d)\n", getpid(), status)); |
13436 | if (setjmp(loc.loc)) { | 13440 | if (setjmp(loc.loc)) { |
@@ -13816,7 +13820,7 @@ int ash_main(int argc UNUSED_PARAM, char **argv) | |||
13816 | } | 13820 | } |
13817 | 13821 | ||
13818 | if (sflag || minusc == NULL) { | 13822 | if (sflag || minusc == NULL) { |
13819 | #if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY | 13823 | #if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY |
13820 | if (iflag) { | 13824 | if (iflag) { |
13821 | const char *hp = lookupvar("HISTFILE"); | 13825 | const char *hp = lookupvar("HISTFILE"); |
13822 | if (hp) | 13826 | if (hp) |
diff --git a/shell/cttyhack.c b/shell/cttyhack.c index 4261289b4..6ff867413 100644 --- a/shell/cttyhack.c +++ b/shell/cttyhack.c | |||
@@ -50,9 +50,12 @@ | |||
50 | //config: | 50 | //config: |
51 | //config: # exec setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1' | 51 | //config: # exec setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1' |
52 | //config: | 52 | //config: |
53 | //config: Starting getty on a controlling tty from a shell script: | ||
54 | //config: | ||
55 | //config: # getty 115200 $(cttyhack) | ||
53 | 56 | ||
54 | //usage:#define cttyhack_trivial_usage | 57 | //usage:#define cttyhack_trivial_usage |
55 | //usage: "PROG ARGS" | 58 | //usage: "[PROG ARGS]" |
56 | //usage:#define cttyhack_full_usage "\n\n" | 59 | //usage:#define cttyhack_full_usage "\n\n" |
57 | //usage: "Give PROG a controlling tty if possible." | 60 | //usage: "Give PROG a controlling tty if possible." |
58 | //usage: "\nExample for /etc/inittab (for busybox init):" | 61 | //usage: "\nExample for /etc/inittab (for busybox init):" |
@@ -108,59 +111,71 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv) | |||
108 | char paranoia[sizeof(struct serial_struct) * 3]; | 111 | char paranoia[sizeof(struct serial_struct) * 3]; |
109 | } u; | 112 | } u; |
110 | 113 | ||
111 | if (!*++argv) { | ||
112 | bb_show_usage(); | ||
113 | } | ||
114 | |||
115 | strcpy(console, "/dev/tty"); | 114 | strcpy(console, "/dev/tty"); |
116 | fd = open(console, O_RDWR); | 115 | fd = open(console, O_RDWR); |
117 | if (fd >= 0) { | 116 | if (fd < 0) { |
118 | /* We already have ctty, nothing to do */ | ||
119 | close(fd); | ||
120 | } else { | ||
121 | /* We don't have ctty (or don't have "/dev/tty" node...) */ | 117 | /* We don't have ctty (or don't have "/dev/tty" node...) */ |
122 | do { | 118 | do { |
123 | #ifdef __linux__ | 119 | #ifdef __linux__ |
120 | /* Note that this method does not use _stdin_. | ||
121 | * Thus, "cttyhack </dev/something" can't be used. | ||
122 | * However, this method is more reliable than | ||
123 | * TIOCGSERIAL check, which assumes that all | ||
124 | * serial lines follow /dev/ttySn convention - | ||
125 | * which is not always the case. | ||
126 | * Therefore, we use this methos first: | ||
127 | */ | ||
124 | int s = open_read_close("/sys/class/tty/console/active", | 128 | int s = open_read_close("/sys/class/tty/console/active", |
125 | console + 5, sizeof(console) - 5 - 1); | 129 | console + 5, sizeof(console) - 5); |
126 | if (s > 0) { | 130 | if (s > 0) { |
127 | /* found active console via sysfs (Linux 2.6.38+) */ | 131 | /* found active console via sysfs (Linux 2.6.38+) |
128 | console[5 + s] = '\0'; | 132 | * sysfs string looks like "ttyS0\n" so zap the newline: |
133 | */ | ||
134 | console[4 + s] = '\0'; | ||
129 | break; | 135 | break; |
130 | } | 136 | } |
131 | 137 | ||
132 | if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { | 138 | if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { |
133 | /* this is linux virtual tty */ | 139 | /* this is linux virtual tty */ |
134 | sprintf(console + 8, "S%d" + 1, u.vt.v_active); | 140 | sprintf(console + 8, "S%u" + 1, (int)u.vt.v_active); |
135 | break; | 141 | break; |
136 | } | 142 | } |
137 | #endif | 143 | #endif |
138 | #ifdef TIOCGSERIAL | 144 | #ifdef TIOCGSERIAL |
139 | if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) { | 145 | if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) { |
140 | /* this is a serial console, asuming it is named /dev/ttySn */ | 146 | /* this is a serial console; assuming it is named /dev/ttySn */ |
141 | sprintf(console + 8, "S%d", u.sr.line); | 147 | sprintf(console + 8, "S%u", (int)u.sr.line); |
142 | break; | 148 | break; |
143 | } | 149 | } |
144 | #endif | 150 | #endif |
145 | /* nope, could not find it */ | 151 | /* nope, could not find it */ |
146 | goto ret; | 152 | console[0] = '\0'; |
147 | } while (0); | 153 | } while (0); |
154 | } | ||
155 | |||
156 | argv++; | ||
157 | if (!argv[0]) { | ||
158 | if (!console[0]) | ||
159 | return EXIT_FAILURE; | ||
160 | puts(console); | ||
161 | return EXIT_SUCCESS; | ||
162 | } | ||
148 | 163 | ||
164 | if (fd < 0) { | ||
149 | fd = open_or_warn(console, O_RDWR); | 165 | fd = open_or_warn(console, O_RDWR); |
150 | if (fd < 0) | 166 | if (fd < 0) |
151 | goto ret; | 167 | goto ret; |
152 | //bb_error_msg("switching to '%s'", console); | ||
153 | dup2(fd, 0); | ||
154 | dup2(fd, 1); | ||
155 | dup2(fd, 2); | ||
156 | while (fd > 2) | ||
157 | close(fd--); | ||
158 | /* Some other session may have it as ctty, | ||
159 | * steal it from them: | ||
160 | */ | ||
161 | ioctl(0, TIOCSCTTY, 1); | ||
162 | } | 168 | } |
163 | 169 | //bb_error_msg("switching to '%s'", console); | |
164 | ret: | 170 | dup2(fd, 0); |
171 | dup2(fd, 1); | ||
172 | dup2(fd, 2); | ||
173 | while (fd > 2) | ||
174 | close(fd--); | ||
175 | /* Some other session may have it as ctty, | ||
176 | * try to steal it from them: | ||
177 | */ | ||
178 | ioctl(0, TIOCSCTTY, 1); | ||
179 | ret: | ||
165 | BB_EXECVP_or_die(argv); | 180 | BB_EXECVP_or_die(argv); |
166 | } | 181 | } |
diff --git a/shell/hush.c b/shell/hush.c index e4138adf7..7a34f59ae 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1541,6 +1541,10 @@ static sighandler_t pick_sighandler(unsigned sig) | |||
1541 | static void hush_exit(int exitcode) NORETURN; | 1541 | static void hush_exit(int exitcode) NORETURN; |
1542 | static void hush_exit(int exitcode) | 1542 | static void hush_exit(int exitcode) |
1543 | { | 1543 | { |
1544 | #if ENABLE_FEATURE_EDITING_SAVE_ON_EXIT | ||
1545 | save_history(G.line_input_state); | ||
1546 | #endif | ||
1547 | |||
1544 | fflush_all(); | 1548 | fflush_all(); |
1545 | if (G.exiting <= 0 && G.traps && G.traps[0] && G.traps[0][0]) { | 1549 | if (G.exiting <= 0 && G.traps && G.traps[0] && G.traps[0][0]) { |
1546 | char *argv[3]; | 1550 | char *argv[3]; |
@@ -7817,22 +7821,6 @@ int hush_main(int argc, char **argv) | |||
7817 | 7821 | ||
7818 | #if ENABLE_FEATURE_EDITING | 7822 | #if ENABLE_FEATURE_EDITING |
7819 | G.line_input_state = new_line_input_t(FOR_SHELL); | 7823 | G.line_input_state = new_line_input_t(FOR_SHELL); |
7820 | # if defined MAX_HISTORY && MAX_HISTORY > 0 && ENABLE_HUSH_SAVEHISTORY | ||
7821 | { | ||
7822 | const char *hp = get_local_var_value("HISTFILE"); | ||
7823 | if (!hp) { | ||
7824 | hp = get_local_var_value("HOME"); | ||
7825 | if (hp) { | ||
7826 | G.line_input_state->hist_file = concat_path_file(hp, ".hush_history"); | ||
7827 | //set_local_var(xasprintf("HISTFILE=%s", ...)); | ||
7828 | } | ||
7829 | } | ||
7830 | # if ENABLE_FEATURE_SH_HISTFILESIZE | ||
7831 | hp = get_local_var_value("HISTFILESIZE"); | ||
7832 | G.line_input_state->max_history = size_from_HISTFILESIZE(hp); | ||
7833 | # endif | ||
7834 | } | ||
7835 | # endif | ||
7836 | #endif | 7824 | #endif |
7837 | 7825 | ||
7838 | /* Initialize some more globals to non-zero values */ | 7826 | /* Initialize some more globals to non-zero values */ |
@@ -8104,6 +8092,27 @@ int hush_main(int argc, char **argv) | |||
8104 | /* -1 is special - makes xfuncs longjmp, not exit | 8092 | /* -1 is special - makes xfuncs longjmp, not exit |
8105 | * (we reset die_sleep = 0 whereever we [v]fork) */ | 8093 | * (we reset die_sleep = 0 whereever we [v]fork) */ |
8106 | enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */ | 8094 | enable_restore_tty_pgrp_on_exit(); /* sets die_sleep = -1 */ |
8095 | |||
8096 | # if ENABLE_HUSH_SAVEHISTORY && MAX_HISTORY > 0 | ||
8097 | { | ||
8098 | const char *hp = get_local_var_value("HISTFILE"); | ||
8099 | if (!hp) { | ||
8100 | hp = get_local_var_value("HOME"); | ||
8101 | if (hp) | ||
8102 | hp = concat_path_file(hp, ".hush_history"); | ||
8103 | } else { | ||
8104 | hp = xstrdup(hp); | ||
8105 | } | ||
8106 | if (hp) { | ||
8107 | G.line_input_state->hist_file = hp; | ||
8108 | //set_local_var(xasprintf("HISTFILE=%s", ...)); | ||
8109 | } | ||
8110 | # if ENABLE_FEATURE_SH_HISTFILESIZE | ||
8111 | hp = get_local_var_value("HISTFILESIZE"); | ||
8112 | G.line_input_state->max_history = size_from_HISTFILESIZE(hp); | ||
8113 | # endif | ||
8114 | } | ||
8115 | # endif | ||
8107 | } else { | 8116 | } else { |
8108 | install_special_sighandlers(); | 8117 | install_special_sighandlers(); |
8109 | } | 8118 | } |