annotate toys/pending/openvt.c @ 1363:e65f9a9ba62d draft

Cleanup pass on mkpasswd.c
author Rob Landley <rob@landley.net>
date Wed, 25 Jun 2014 22:54:59 -0500
parents 310165c2f451
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
1 /* openvt.c - Run a program on a new VT
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
2 *
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
3 * Copyright 2014 Vivek Kumar Bhagat <vivek.bhagat89@gmail.com>
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
4 *
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
5 * No Standard
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
6
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
7 USE_OPENVT(NEWTOY(openvt, "c#<1>63sw", TOYFLAG_BIN|TOYFLAG_NEEDROOT))
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
8 USE_DEALLOCVT(NEWTOY(deallocvt, ">1", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NEEDROOT))
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
9
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
10 config OPENVT
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
11 bool "openvt"
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
12 default n
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
13 help
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
14 usage: openvt [-c N] [-sw] [command [command_options]]
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
15
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
16 start a program on a new virtual terminal (VT)
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
17
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
18 -c N Use VT N
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
19 -s Switch to new VT
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
20 -w Wait for command to exit
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
21
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
22 if -sw used together, switch back to originating VT when command completes
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
23
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
24 config DEALLOCVT
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
25 bool "deallocvt"
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
26 default n
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
27 help
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
28 usage: deallocvt [N]
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
29
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
30 Deallocate unused virtual terminal /dev/ttyN, or all unused consoles.
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
31 */
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
32
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
33 #define FOR_openvt
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
34 #include "toys.h"
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
35 #include <linux/vt.h>
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
36 #include <linux/kd.h>
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
37
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
38 GLOBALS(
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
39 unsigned long vt_num;
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
40 )
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
41
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
42 int open_console(void)
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
43 {
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
44 char arg, *console_name[] = {"/dev/tty", "/dev/tty0", "/dev/console"};
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
45 int i, fd;
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
46
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
47 for (i = 0; i < ARRAY_LEN(console_name); i++) {
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
48 fd = open(console_name[i], O_RDWR);
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
49 if (fd >= 0) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
50 arg = 0;
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
51 if (!ioctl(fd, KDGKBTYPE, &arg)) return fd;
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
52 close(fd);
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
53 }
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
54 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
55
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
56 /* check std fd 0, 1 and 2 */
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
57 for (fd = 0; fd < 3; fd++) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
58 arg = 0;
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
59 if (0 == ioctl(fd, KDGKBTYPE, &arg)) return fd;
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
60 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
61
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
62 return -1;
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
63 }
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
64
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
65 int xvtnum(int fd)
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
66 {
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
67 int ret;
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
68
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
69 ret = ioctl(fd, VT_OPENQRY, (int *)&TT.vt_num);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
70 if (ret != 0 || TT.vt_num <= 0) perror_exit("can't find open VT");
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
71
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
72 return TT.vt_num;
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
73 }
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
74
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
75 void openvt_main(void)
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
76 {
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
77 int fd, vt_fd, ret = 0;
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
78 struct vt_stat vstate;
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
79 pid_t pid;
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
80
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
81 if (!(toys.optflags & FLAG_c)) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
82 // check if fd 0,1 or 2 is already opened
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
83 for (fd = 0; fd < 3; fd++)
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
84 if (!ioctl(fd, VT_GETSTATE, &vstate)) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
85 ret = xvtnum(fd);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
86 break;
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
87 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
88
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
89 // find VT number using /dev/console
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
90 if (!ret) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
91 fd = xopen("/dev/console", O_RDONLY | O_NONBLOCK);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
92 xioctl(fd, VT_GETSTATE, &vstate);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
93 xvtnum(fd);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
94 }
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
95 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
96
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
97 sprintf(toybuf, "/dev/tty%lu", TT.vt_num);
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
98 fd = open_console();
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
99 xioctl(fd, VT_GETSTATE, &vstate);
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
100
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
101 close(0); //new vt becomes stdin
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
102 vt_fd = xopen(toybuf, O_RDWR);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
103 if (toys.optflags & FLAG_s) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
104 ioctl(vt_fd, VT_ACTIVATE, TT.vt_num);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
105 ioctl(vt_fd, VT_WAITACTIVE, TT.vt_num);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
106 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
107
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
108 close(1);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
109 close(2);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
110 dup2(vt_fd, 1);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
111 dup2(vt_fd, 2);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
112 while (vt_fd > 2)
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
113 close(vt_fd--);
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
114
1327
85f297591693 Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents: 1241
diff changeset
115 pid = xfork();
85f297591693 Introduce xfork() and make commands use it, and make some WEXITSTATUS() use WIFEXITED() and WTERMSIG()+127.
Rob Landley <rob@landley.net>
parents: 1241
diff changeset
116 if (!pid) {
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
117 setsid();
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
118 ioctl(vt_fd, TIOCSCTTY, 0);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
119 xexec(toys.optargs);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
120 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
121
1241
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
122 if (toys.optflags & FLAG_w) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
123 while (-1 == waitpid(pid, NULL, 0) && errno == EINTR)
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
124 ;
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
125 if (toys.optflags & FLAG_s) {
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
126 ioctl(fd, VT_ACTIVATE, vstate.v_active);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
127 ioctl(fd, VT_WAITACTIVE, vstate.v_active);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
128 //check why deallocate isn't working here
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
129 xioctl(fd, VT_DISALLOCATE, (void *)(ptrdiff_t)TT.vt_num);
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
130 }
3c855d5a75be openvt tries opening several devices to get an fd that points to the current console, without a need for read or write permissions. O_RDWR implies that both O_RDONLY and O_WRONLY would work, so skip it. Reindent.
Isaac Dunham <ibid.ag@gmail.com>
parents: 1214
diff changeset
131 }
1214
a31d747b0017 Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff changeset
132 }
1358
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
133
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
134 void deallocvt_main(void)
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
135 {
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
136 long vt_num = 0; // 0 deallocates all unused consoles
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
137 int fd;
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
138
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
139 if (*toys.optargs) vt_num = atolx_range(*toys.optargs, 1, 63);
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
140
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
141 if ((fd = open_console()) < 0) error_exit("can't open console");
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
142 xioctl(fd, VT_DISALLOCATE, (void *)vt_num);
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
143 if (CFG_TOYBOX_FREE) close(fd);
310165c2f451 Move deallocvt.c into openvt.c, cleanup both.
Rob Landley <rob@landley.net>
parents: 1327
diff changeset
144 }