diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-18 09:45:36 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-05-18 09:45:36 +0000 |
commit | 6d709972cdad4848908813c673b2f5fdc9e3c4c0 (patch) | |
tree | 77c14cf3279dd5e2d2536477ee6eff4884cd3bcc | |
parent | 4500c58a0766b9cc86dd8ddd25094593a8977197 (diff) | |
download | busybox-w32-6d709972cdad4848908813c673b2f5fdc9e3c4c0.tar.gz busybox-w32-6d709972cdad4848908813c673b2f5fdc9e3c4c0.tar.bz2 busybox-w32-6d709972cdad4848908813c673b2f5fdc9e3c4c0.zip |
cttyhack: new applet.
-rw-r--r-- | coreutils/sleep.c | 2 | ||||
-rw-r--r-- | include/applets.h | 1 | ||||
-rw-r--r-- | shell/Config.in | 20 | ||||
-rw-r--r-- | shell/Kbuild | 2 | ||||
-rw-r--r-- | shell/cttyhack.c | 73 |
5 files changed, 96 insertions, 2 deletions
diff --git a/coreutils/sleep.c b/coreutils/sleep.c index b758de33b..592005bab 100644 --- a/coreutils/sleep.c +++ b/coreutils/sleep.c | |||
@@ -61,8 +61,6 @@ int sleep_main(int argc, char **argv) | |||
61 | #endif /* FEATURE_FANCY_SLEEP */ | 61 | #endif /* FEATURE_FANCY_SLEEP */ |
62 | 62 | ||
63 | if (sleep(duration)) { | 63 | if (sleep(duration)) { |
64 | //for hush debugging: | ||
65 | sleep(1); | ||
66 | bb_perror_nomsg_and_die(); | 64 | bb_perror_nomsg_and_die(); |
67 | } | 65 | } |
68 | 66 | ||
diff --git a/include/applets.h b/include/applets.h index 99e6aceb5..e4dff119a 100644 --- a/include/applets.h +++ b/include/applets.h | |||
@@ -102,6 +102,7 @@ USE_CPIO(APPLET(cpio, _BB_DIR_BIN, _BB_SUID_NEVER)) | |||
102 | USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | 102 | USE_CROND(APPLET(crond, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) |
103 | USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) | 103 | USE_CRONTAB(APPLET(crontab, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS)) |
104 | USE_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 104 | USE_CRYPTPW(APPLET(cryptpw, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
105 | USE_CTTYHACK(APPLET_NOUSAGE(cttyhack, cttyhack, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | ||
105 | USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut)) | 106 | USE_CUT(APPLET_NOEXEC(cut, cut, _BB_DIR_USR_BIN, _BB_SUID_NEVER, cut)) |
106 | USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER)) | 107 | USE_DATE(APPLET(date, _BB_DIR_BIN, _BB_SUID_NEVER)) |
107 | USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 108 | USE_DC(APPLET(dc, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
diff --git a/shell/Config.in b/shell/Config.in index 027993483..253752bc3 100644 --- a/shell/Config.in +++ b/shell/Config.in | |||
@@ -270,4 +270,24 @@ config FEATURE_SH_STANDALONE | |||
270 | # that exact location with that exact name, this option will not work at | 270 | # that exact location with that exact name, this option will not work at |
271 | # all. | 271 | # all. |
272 | 272 | ||
273 | config CTTYHACK | ||
274 | bool "cttyhack" | ||
275 | default n | ||
276 | help | ||
277 | One common problem reported on the mailing list is "can't access tty; | ||
278 | job control turned off" error message which typically appears when | ||
279 | one tries to use shell with stdin/stdout opened to /dev/console. | ||
280 | This device is special - it cannot be a controlling tty. | ||
281 | |||
282 | Proper solution is to use correct device instead of /dev/console. | ||
283 | |||
284 | cttyhack provides "quick and dirty" solution to this problem. | ||
285 | It analyzes stdin with various ioctls, trying to determine whether | ||
286 | it is a /dev/ttyN or /dev/ttySN (virtual terminal or serial line). | ||
287 | If it detects one, it closes stdin/out/err and reopens that device. | ||
288 | Then it executes given program. Usage example for /etc/inittab | ||
289 | (for busybox init): | ||
290 | |||
291 | ::respawn:/bin/cttyhack /bin/sh | ||
292 | |||
273 | endmenu | 293 | endmenu |
diff --git a/shell/Kbuild b/shell/Kbuild index 6b58040fc..944eaff51 100644 --- a/shell/Kbuild +++ b/shell/Kbuild | |||
@@ -9,3 +9,5 @@ lib-$(CONFIG_ASH) += ash.o | |||
9 | lib-$(CONFIG_HUSH) += hush.o | 9 | lib-$(CONFIG_HUSH) += hush.o |
10 | lib-$(CONFIG_LASH) += lash.o | 10 | lib-$(CONFIG_LASH) += lash.o |
11 | lib-$(CONFIG_MSH) += msh.o | 11 | lib-$(CONFIG_MSH) += msh.o |
12 | |||
13 | lib-$(CONFIG_CTTYHACK) += cttyhack.o | ||
diff --git a/shell/cttyhack.c b/shell/cttyhack.c new file mode 100644 index 000000000..cdd0ed1d6 --- /dev/null +++ b/shell/cttyhack.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* This code is adapted from busybox project | ||
2 | * | ||
3 | * Licensed under GPLv2 | ||
4 | */ | ||
5 | #include "libbb.h" | ||
6 | |||
7 | /* From <linux/vt.h> */ | ||
8 | struct vt_stat { | ||
9 | unsigned short v_active; /* active vt */ | ||
10 | unsigned short v_signal; /* signal to send */ | ||
11 | unsigned short v_state; /* vt bitmask */ | ||
12 | }; | ||
13 | enum { VT_GETSTATE = 0x5603 }; /* get global vt state info */ | ||
14 | |||
15 | /* From <linux/serial.h> */ | ||
16 | struct serial_struct { | ||
17 | int type; | ||
18 | int line; | ||
19 | unsigned int port; | ||
20 | int irq; | ||
21 | int flags; | ||
22 | int xmit_fifo_size; | ||
23 | int custom_divisor; | ||
24 | int baud_base; | ||
25 | unsigned short close_delay; | ||
26 | char io_type; | ||
27 | char reserved_char[1]; | ||
28 | int hub6; | ||
29 | unsigned short closing_wait; /* time to wait before closing */ | ||
30 | unsigned short closing_wait2; /* no longer used... */ | ||
31 | unsigned char *iomem_base; | ||
32 | unsigned short iomem_reg_shift; | ||
33 | unsigned int port_high; | ||
34 | unsigned long iomap_base; /* cookie passed into ioremap */ | ||
35 | int reserved[1]; | ||
36 | }; | ||
37 | |||
38 | int cttyhack_main(int argc, char **argv) ATTRIBUTE_NORETURN; | ||
39 | int cttyhack_main(int argc, char **argv) | ||
40 | { | ||
41 | int fd; | ||
42 | char console[sizeof(int)*3 + 16]; | ||
43 | union { | ||
44 | struct vt_stat vt; | ||
45 | struct serial_struct sr; | ||
46 | char paranoia[sizeof(struct serial_struct) * 3]; | ||
47 | } u; | ||
48 | |||
49 | if (!*++argv) { | ||
50 | bb_show_usage(); | ||
51 | } | ||
52 | |||
53 | strcpy(console, "/dev/tty"); | ||
54 | if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) { | ||
55 | /* this is a serial console */ | ||
56 | sprintf(console + 8, "S%d", u.sr.line); | ||
57 | } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) { | ||
58 | /* this is linux virtual tty */ | ||
59 | sprintf(console + 8, "S%d" + 1, u.vt.v_active); | ||
60 | } | ||
61 | |||
62 | if (console[8]) { | ||
63 | fd = xopen(console, O_RDWR); | ||
64 | //bb_error_msg("switching to '%s'", console); | ||
65 | dup2(fd, 0); | ||
66 | dup2(fd, 1); | ||
67 | dup2(fd, 2); | ||
68 | while (fd > 2) close(fd--); | ||
69 | } | ||
70 | |||
71 | execvp(argv[0], argv); | ||
72 | bb_perror_msg_and_die("cannot exec '%s'", argv[0]); | ||
73 | } | ||