62bdb08a80130a82ba0819c08635f8181bb01188
[platform/upstream/kbd.git] / src / spawn_login.c
1 /*
2  * Tiny test program for the `spawn console' key
3  * (should not use signal; should not use sleep)
4  * aeb - 941025
5  *
6  */
7 #include "config.h"
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <signal.h>
12 #include <errno.h>
13 #include <unistd.h>
14 #include <fcntl.h>
15 #include <sys/ioctl.h>
16 #include <linux/kd.h>
17
18 #include "version.h"
19 #include "kbd.h"
20 #include "kbd_error.h"
21
22 static void
23 sighup(int n __attribute__((unused)))
24 {
25         if (system("openvt -s -l -- login -h spawn") == -1) {
26                 kbd_error(EXIT_FAILURE, errno, "system");
27         }
28         signal(SIGHUP, sighup);
29 }
30
31 int main(int argc __attribute__((unused)), char *argv[])
32 {
33         int fd;
34
35         set_progname(argv[0]);
36
37         fd = open("/dev/tty0", 0);
38         if (fd < 0 && errno == ENOENT)
39                 fd = open("/dev/vc/0", 0);
40         if (fd < 0)
41                 fd = 0;
42         signal(SIGHUP, sighup);
43         if (ioctl(fd, KDSIGACCEPT, (long)SIGHUP))
44                 kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
45         while (1)
46                 sleep(3600);
47         return EXIT_SUCCESS;
48 }