1 /* This code is adapted from busybox project
7 /* From <linux/vt.h> */
9 unsigned short v_active
; /* active vt */
10 unsigned short v_signal
; /* signal to send */
11 unsigned short v_state
; /* vt bitmask */
13 enum { VT_GETSTATE
= 0x5603 }; /* get global vt state info */
15 /* From <linux/serial.h> */
16 struct serial_struct
{
25 unsigned short close_delay
;
27 char reserved_char
[1];
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 */
38 int cttyhack_main(int argc
, char **argv
) ATTRIBUTE_NORETURN
;
39 int cttyhack_main(int argc
, char **argv
)
42 char console
[sizeof(int)*3 + 16];
45 struct serial_struct sr
;
46 char paranoia
[sizeof(struct serial_struct
) * 3];
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
);
63 fd
= xopen(console
, O_RDWR
);
64 //bb_error_msg("switching to '%s'", console);
68 while (fd
> 2) close(fd
--);
71 execvp(argv
[0], argv
);
72 bb_perror_msg_and_die("cannot exec '%s'", argv
[0]);