File: spawn_console.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 (55 lines) | stat: -rw-r--r-- 1,273 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
49
50
51
52
53
54
55
/*
 * Tiny test program for the `spawn console' key
 * (should not use signal; should not use sleep)
 * aeb - 941025
 *
 * Note: this functionality will probably go away and become
 * part of init. For the time being, be very careful when
 * you use this - if you have this in /etc/rc.local you should
 * start getty, not openvt, or anybody will have a root shell
 * with a single keystroke.
 */
#include "config.h"

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

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

static void
sighup(int n __attribute__((unused)))
{
	if (system("openvt -s -l bash") == -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;
}