File: spawn_login.c

package info (click to toggle)
kbd 2.0.4-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 14,136 kB
  • sloc: sh: 12,838; ansic: 12,531; pascal: 472; lex: 466; makefile: 394; yacc: 356; perl: 126; sed: 16
file content (48 lines) | stat: -rw-r--r-- 931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 * Tiny test program for the `spawn console' key
 * (should not use signal; should not use sleep)
 * aeb - 941025
 *
 */
#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/kd.h>

#include "version.h"
#include "kbd.h"
#include "kbd_error.h"

static void
sighup(int n __attribute__((unused)))
{
	if (system("openvt -s -l -- login -h spawn") == -1) {
		kbd_error(EXIT_FAILURE, errno, "system");
	}
	signal(SIGHUP, sighup);
}

int main(int argc __attribute__((unused)), char *argv[])
{
	int fd;

	set_progname(argv[0]);

	fd = open("/dev/tty0", 0);
	if (fd < 0 && errno == ENOENT)
		fd = open("/dev/vc/0", 0);
	if (fd < 0)
		fd = 0;
	signal(SIGHUP, sighup);
	if (ioctl(fd, KDSIGACCEPT, (long)SIGHUP))
		kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
	while (1)
		sleep(3600);
	return EXIT_SUCCESS;
}