Mercurial > hg > toybox
annotate toys/pending/openvt.c @ 1276:d48bdc1cb017 draft
Switch human_readable() to just outputing decimal kilo/mega/gigabytes, make du use it, move it from lib/pending.c to lib.c.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 06 May 2014 06:31:28 -0500 |
parents | 3c855d5a75be |
children | 85f297591693 |
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)) |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
8 |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
9 config OPENVT |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
10 bool "openvt" |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
11 default n |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
12 help |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
13 usage: openvt [-c N] [-s] [-w] [--] [command [command_options]] |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
14 |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
15 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
|
16 |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
17 -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
|
18 -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
|
19 -w Wait for command to exit |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
20 if -s and -w option used together, switch back |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
21 to originating VT when command completes |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
22 */ |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
23 |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
24 #define FOR_openvt |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
25 #include "toys.h" |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
26 #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
|
27 #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
|
28 |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
29 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
|
30 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
|
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 int find_console_fd(void) |
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
34 { |
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
|
35 char *console_name[] = {"/dev/tty", "/dev/tty0", "/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
|
36 int i; |
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
|
37 int 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
|
38 char arg; |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
39 |
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
|
40 for (i = 0; i < 3; i++) { |
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
|
41 fd = open(console_name[i], O_RDONLY); |
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
|
42 if (fd < 0 && errno == EACCES) |
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
|
43 fd = open(console_name[i], O_WRONLY); |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
44 |
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
|
45 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
|
46 arg = 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
|
47 if (0 == ioctl(fd, KDGKBTYPE, &arg)) |
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
|
48 return 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
|
49 else |
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 close(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
|
51 } |
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
|
52 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
53 |
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
|
54 /* 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
|
55 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
|
56 arg = 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
|
57 if (0 == ioctl(fd, KDGKBTYPE, &arg)) |
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 return 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
|
59 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
60 |
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
|
61 return -1; |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
62 } |
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 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
|
65 { |
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
|
66 int ret; |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
67 |
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
|
68 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
|
69 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
|
70 |
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
|
71 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
|
72 } |
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 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
|
75 { |
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
|
76 int fd = -1, vt_fd = -1, pid, ret = 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
|
77 struct vt_stat vstate; |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
78 |
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
|
79 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
|
80 // 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
86 |
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
|
87 // 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 } |
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 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
94 |
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
|
95 sprintf(toybuf, "/dev/tty%lu", 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
|
96 fd = find_console_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
|
97 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
|
98 |
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 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
105 |
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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 |
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
|
113 pid = vfork(); |
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
|
114 if (pid < 0) perror_exit("Fork failed"); |
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
|
115 else if (!pid) { |
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
|
116 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
|
117 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
|
118 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
|
119 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
120 |
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
|
121 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
|
122 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
|
123 ; |
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 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
|
125 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
|
126 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
|
127 //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
|
128 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
|
129 } |
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 } |
1214
a31d747b0017
Please find the patches attached herewith for adding 3 new commands -
Vivek Bhagat <vivek.bhagat89@gmail.com>
parents:
diff
changeset
|
131 } |