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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
--- src/ck-sysdeps-freebsd.c.orig 2008-01-23 09:30:44.000000000 -0500
+++ src/ck-sysdeps-freebsd.c 2008-02-04 20:56:57.000000000 -0500
@@ -43,6 +43,10 @@
( (M&0xfff) << 8) | ( (m&0xfff00) << 12) | (m&0xff) \
)
+#ifndef MAXCONS
+#define MAXCONS 16
+#endif
+
#include "ck-sysdeps.h"
#ifndef ERROR
@@ -202,7 +206,6 @@ ck_process_stat_new_for_unix_pid (pid_t
GError **error)
{
gboolean res;
- GError *local_error;
CkProcessStat *proc;
g_return_val_if_fail (pid > 1, FALSE);
@@ -217,7 +220,6 @@ ck_process_stat_new_for_unix_pid (pid_t
if (res) {
*stat = proc;
} else {
- g_propagate_error (error, local_error);
*stat = NULL;
}
@@ -318,38 +320,36 @@ gboolean
ck_get_max_num_consoles (guint *num)
{
int max_consoles;
- int res;
- gboolean ret;
- struct ttyent *t;
+ int i;
- ret = FALSE;
- max_consoles = 0;
-
- res = setttyent ();
- if (res == 0) {
- goto done;
- }
+ max_consoles = 0;
- while ((t = getttyent ()) != NULL) {
- if (t->ty_status & TTY_ON && strncmp (t->ty_name, "ttyv", 4) == 0)
- max_consoles++;
- }
+ for (i = 0; i < MAXCONS; i++) {
+ int fd;
+ char *cdev;
+
+ cdev = g_strdup_printf ("/dev/ttyv%x", i);
+ fd = open (cdev, O_RDONLY | O_NOCTTY);
+ g_free (cdev);
+ if (fd > -1) {
+ close (fd);
+ max_consoles++;
+ } else {
+ break;
+ }
+ }
+
+ /*
+ * Increment one more so that all consoles are properly counted
+ * this is arguable a bug in vt_add_watches().
+ */
+ max_consoles++;
- /* Increment one more so that all consoles are properly counted
- * this is arguable a bug in vt_add_watches().
- */
- max_consoles++;
-
- ret = TRUE;
-
- endttyent ();
-
-done:
if (num != NULL) {
*num = max_consoles;
}
- return ret;
+ return TRUE;
}
char *
@@ -360,7 +360,7 @@ ck_get_console_device_for_num (guint num
/* The device number is always one less than the VT number. */
num--;
- device = g_strdup_printf ("/dev/ttyv%u", num);
+ device = g_strdup_printf ("/dev/ttyv%x", num);
return device;
}
@@ -379,7 +379,7 @@ ck_get_console_num_from_device (const ch
return FALSE;
}
- if (sscanf (device, "/dev/ttyv%u", &n) == 1) {
+ if (sscanf (device, "/dev/ttyv%x", &n) == 1) {
/* The VT number is always one more than the device number. */
n++;
ret = TRUE;
@@ -411,7 +411,7 @@ ck_get_active_console_num (int consol
goto out;
}
- g_debug ("Active VT is: %d (ttyv%d)", active, active - 1);
+ g_debug ("Active VT is: %d (ttyv%x)", active, active - 1);
ret = TRUE;
out:
|