aboutsummaryrefslogtreecommitdiff
path: root/console-tools/openvt.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-05-19 08:18:50 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2008-05-19 08:18:50 +0000
commitae4342ca3e30f7b11732ecda3ad15821e81bc314 (patch)
tree1878104940eac4649bc8add4d0b2893ab1cb0a94 /console-tools/openvt.c
parentee56e013cfb6304f66129afee7978b0864699419 (diff)
downloadbusybox-w32-ae4342ca3e30f7b11732ecda3ad15821e81bc314.tar.gz
busybox-w32-ae4342ca3e30f7b11732ecda3ad15821e81bc314.tar.bz2
busybox-w32-ae4342ca3e30f7b11732ecda3ad15821e81bc314.zip
- Rename getpty() to xgetpty() and adjust callers.
- Rewrite kbd_mode and setconsole - Introduce and use console_make_active() and xopen_xwrite_close() - honour buffer-reservation method as set by the user (dumpkmap, loadkmap) - shrink rtcwake and some console-tools Saves about 270 Bytes
Diffstat (limited to 'console-tools/openvt.c')
-rw-r--r--console-tools/openvt.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/console-tools/openvt.c b/console-tools/openvt.c
index c4746dfd3..208522418 100644
--- a/console-tools/openvt.c
+++ b/console-tools/openvt.c
@@ -61,7 +61,8 @@ static int get_vt_fd(void)
61 for (fd = 0; fd < 3; fd++) 61 for (fd = 0; fd < 3; fd++)
62 if (!not_vt_fd(fd)) 62 if (!not_vt_fd(fd))
63 return fd; 63 return fd;
64 /* _only_ O_NONBLOCK: ask for neither read not write perms */ 64 /* _only_ O_NONBLOCK: ask for neither read nor write perms */
65 /*FIXME: use? device_open(DEV_CONSOLE,0); */
65 fd = open(DEV_CONSOLE, O_NONBLOCK); 66 fd = open(DEV_CONSOLE, O_NONBLOCK);
66 if (fd >= 0 && !not_vt_fd(fd)) 67 if (fd >= 0 && !not_vt_fd(fd))
67 return fd; 68 return fd;
@@ -93,7 +94,7 @@ static NOINLINE void vfork_child(char **argv)
93 /* CHILD */ 94 /* CHILD */
94 /* Try to make this VT our controlling tty */ 95 /* Try to make this VT our controlling tty */
95 setsid(); /* lose old ctty */ 96 setsid(); /* lose old ctty */
96 ioctl(0, TIOCSCTTY, 0 /* 0: don't forcibly steal */); 97 ioctl(STDIN_FILENO, TIOCSCTTY, 0 /* 0: don't forcibly steal */);
97 //bb_error_msg("our sid %d", getsid(0)); 98 //bb_error_msg("our sid %d", getsid(0));
98 //bb_error_msg("our pgrp %d", getpgrp()); 99 //bb_error_msg("our pgrp %d", getpgrp());
99 //bb_error_msg("VT's sid %d", tcgetsid(0)); 100 //bb_error_msg("VT's sid %d", tcgetsid(0));
@@ -135,14 +136,13 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
135 sprintf(vtname, VC_FORMAT, vtno); 136 sprintf(vtname, VC_FORMAT, vtno);
136 /* (Try to) clean up stray open fds above fd 2 */ 137 /* (Try to) clean up stray open fds above fd 2 */
137 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL); 138 bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
138 close(0); 139 close(STDIN_FILENO);
139 /*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */ 140 /*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
140 xopen(vtname, O_RDWR); 141 xopen(vtname, O_RDWR);
141 xioctl(0, VT_GETSTATE, &vtstat); 142 xioctl(STDIN_FILENO, VT_GETSTATE, &vtstat);
142 143
143 if (flags & OPT_s) { 144 if (flags & OPT_s) {
144 xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)vtno); 145 console_make_active(STDIN_FILENO, vtno);
145 xioctl(0, VT_WAITACTIVE, (void*)(ptrdiff_t)vtno);
146 } 146 }
147 147
148 if (!argv[0]) { 148 if (!argv[0]) {
@@ -153,14 +153,16 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
153 /*argv[1] = NULL; - already is */ 153 /*argv[1] = NULL; - already is */
154 } 154 }
155 155
156 xdup2(0, STDOUT_FILENO); 156 xdup2(STDIN_FILENO, STDOUT_FILENO);
157 xdup2(0, STDERR_FILENO); 157 xdup2(STDIN_FILENO, STDERR_FILENO);
158 158
159#ifdef BLOAT 159#ifdef BLOAT
160 {
160 /* Handle -l (login shell) option */ 161 /* Handle -l (login shell) option */
161 const char *prog = argv[0]; 162 const char *prog = argv[0];
162 if (flags & OPT_l) 163 if (flags & OPT_l)
163 argv[0] = xasprintf("-%s", argv[0]); 164 argv[0] = xasprintf("-%s", argv[0]);
165 }
164#endif 166#endif
165 167
166 vfork_child(argv); 168 vfork_child(argv);
@@ -168,12 +170,11 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
168 /* We have only one child, wait for it */ 170 /* We have only one child, wait for it */
169 safe_waitpid(-1, NULL, 0); /* loops on EINTR */ 171 safe_waitpid(-1, NULL, 0); /* loops on EINTR */
170 if (flags & OPT_s) { 172 if (flags & OPT_s) {
171 xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)(vtstat.v_active)); 173 console_make_active(STDIN_FILENO, vtstat.v_active);
172 xioctl(0, VT_WAITACTIVE, (void*)(ptrdiff_t)(vtstat.v_active));
173 // Compat: even with -c N (try to) disallocate: 174 // Compat: even with -c N (try to) disallocate:
174 // # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5 175 // # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5
175 // openvt: could not deallocate console 9 176 // openvt: could not deallocate console 9
176 xioctl(0, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno); 177 xioctl(STDIN_FILENO, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno);
177 } 178 }
178 } 179 }
179 return EXIT_SUCCESS; 180 return EXIT_SUCCESS;