Lines 1-208
Link Here
|
1 |
--- src/ck-sysdeps-freebsd.c.orig 2010-09-03 15:54:31.000000000 +0200 |
|
|
2 |
+++ src/ck-sysdeps-freebsd.c 2015-03-23 09:28:20.476513000 +0100 |
3 |
@@ -27,6 +27,7 @@ |
4 |
#include <unistd.h> |
5 |
#include <string.h> |
6 |
#include <errno.h> |
7 |
+#include <glob.h> |
8 |
#include <paths.h> |
9 |
#include <ttyent.h> |
10 |
#include <kvm.h> |
11 |
@@ -202,7 +203,6 @@ ck_process_stat_new_for_unix_pid (pid_t |
12 |
GError **error) |
13 |
{ |
14 |
gboolean res; |
15 |
- GError *local_error; |
16 |
CkProcessStat *proc; |
17 |
|
18 |
g_return_val_if_fail (pid > 1, FALSE); |
19 |
@@ -217,7 +217,6 @@ ck_process_stat_new_for_unix_pid (pid_t |
20 |
if (res) { |
21 |
*stat = proc; |
22 |
} else { |
23 |
- g_propagate_error (error, local_error); |
24 |
*stat = NULL; |
25 |
} |
26 |
|
27 |
@@ -233,24 +232,28 @@ ck_process_stat_free (CkProcessStat *sta |
28 |
GHashTable * |
29 |
ck_unix_pid_get_env_hash (pid_t pid) |
30 |
{ |
31 |
- GHashTable *hash; |
32 |
+ GHashTable *hash = NULL; |
33 |
char **penv; |
34 |
+ char errbuf[_POSIX2_LINE_MAX]; |
35 |
kvm_t *kd; |
36 |
struct kinfo_proc p; |
37 |
int i; |
38 |
|
39 |
- kd = kvm_openfiles (_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, NULL); |
40 |
+ kd = kvm_openfiles (_PATH_DEVNULL, _PATH_DEVNULL, NULL, O_RDONLY, errbuf); |
41 |
if (kd == NULL) { |
42 |
+ g_warning ("kvm_openfiles failed: %s", errbuf); |
43 |
return NULL; |
44 |
} |
45 |
|
46 |
if (! get_kinfo_proc (pid, &p)) { |
47 |
- return NULL; |
48 |
+ g_warning ("get_kinfo_proc failed: %s", g_strerror (errno)); |
49 |
+ goto fail; |
50 |
} |
51 |
|
52 |
penv = kvm_getenvv (kd, &p, 0); |
53 |
if (penv == NULL) { |
54 |
- return NULL; |
55 |
+ g_warning ("kvm_getenvv failed: %s", kvm_geterr (kd)); |
56 |
+ goto fail; |
57 |
} |
58 |
|
59 |
hash = g_hash_table_new_full (g_str_hash, |
60 |
@@ -261,6 +264,9 @@ ck_unix_pid_get_env_hash (pid_t pid) |
61 |
for (i = 0; penv[i] != NULL; i++) { |
62 |
char **vals; |
63 |
|
64 |
+ if (!penv[i][0]) |
65 |
+ continue; |
66 |
+ |
67 |
vals = g_strsplit (penv[i], "=", 2); |
68 |
if (vals != NULL) { |
69 |
g_hash_table_insert (hash, |
70 |
@@ -270,6 +276,7 @@ ck_unix_pid_get_env_hash (pid_t pid) |
71 |
} |
72 |
} |
73 |
|
74 |
+fail: |
75 |
kvm_close (kd); |
76 |
|
77 |
return hash; |
78 |
@@ -280,7 +287,7 @@ ck_unix_pid_get_env (pid_t pid, |
79 |
const char *var) |
80 |
{ |
81 |
GHashTable *hash; |
82 |
- char *val; |
83 |
+ char *val = NULL; |
84 |
|
85 |
/* |
86 |
* Would probably be more efficient to just loop through the |
87 |
@@ -288,6 +295,8 @@ ck_unix_pid_get_env (pid_t pid, |
88 |
* table, but this works for now. |
89 |
*/ |
90 |
hash = ck_unix_pid_get_env_hash (pid); |
91 |
+ if (hash == NULL) |
92 |
+ return val; |
93 |
val = g_strdup (g_hash_table_lookup (hash, var)); |
94 |
g_hash_table_destroy (hash); |
95 |
|
96 |
@@ -327,38 +336,38 @@ gboolean |
97 |
ck_get_max_num_consoles (guint *num) |
98 |
{ |
99 |
int max_consoles; |
100 |
- int res; |
101 |
- gboolean ret; |
102 |
- struct ttyent *t; |
103 |
+ int i; |
104 |
+ glob_t g; |
105 |
|
106 |
- ret = FALSE; |
107 |
max_consoles = 0; |
108 |
|
109 |
- res = setttyent (); |
110 |
- if (res == 0) { |
111 |
- goto done; |
112 |
- } |
113 |
+ g.gl_offs = 0; |
114 |
+ glob ("/dev/ttyv*", GLOB_DOOFFS | GLOB_NOSORT, NULL, &g); |
115 |
+ for (i = 0; i < g.gl_pathc && g.gl_pathv[i] != NULL; i++) { |
116 |
+ struct stat sb; |
117 |
+ char *cdev; |
118 |
|
119 |
- while ((t = getttyent ()) != NULL) { |
120 |
- if (t->ty_status & TTY_ON && strncmp (t->ty_name, "ttyv", 4) == 0) |
121 |
+ cdev = g.gl_pathv[i]; |
122 |
+ if (stat (cdev, &sb) > -1 && S_ISCHR (sb.st_mode)) { |
123 |
max_consoles++; |
124 |
+ } else { |
125 |
+ break; |
126 |
+ } |
127 |
} |
128 |
|
129 |
- /* Increment one more so that all consoles are properly counted |
130 |
+ globfree (&g); |
131 |
+ |
132 |
+ /* |
133 |
+ * Increment one more so that all consoles are properly counted |
134 |
* this is arguable a bug in vt_add_watches(). |
135 |
*/ |
136 |
max_consoles++; |
137 |
|
138 |
- ret = TRUE; |
139 |
- |
140 |
- endttyent (); |
141 |
- |
142 |
-done: |
143 |
if (num != NULL) { |
144 |
*num = max_consoles; |
145 |
} |
146 |
|
147 |
- return ret; |
148 |
+ return TRUE; |
149 |
} |
150 |
|
151 |
gboolean |
152 |
@@ -375,7 +384,12 @@ ck_get_console_device_for_num (guint num |
153 |
/* The device number is always one less than the VT number. */ |
154 |
num--; |
155 |
|
156 |
- device = g_strdup_printf ("/dev/ttyv%u", num); |
157 |
+ if (num < 10) |
158 |
+ device = g_strdup_printf ("/dev/ttyv%i", num); |
159 |
+ else if (num < 32) |
160 |
+ device = g_strdup_printf ("/dev/ttyv%c", num - 10 + 'a'); |
161 |
+ else |
162 |
+ device = NULL; |
163 |
|
164 |
return device; |
165 |
} |
166 |
@@ -385,6 +399,7 @@ ck_get_console_num_from_device (const ch |
167 |
guint *num) |
168 |
{ |
169 |
guint n; |
170 |
+ char c; |
171 |
gboolean ret; |
172 |
|
173 |
n = 0; |
174 |
@@ -394,7 +409,11 @@ ck_get_console_num_from_device (const ch |
175 |
return FALSE; |
176 |
} |
177 |
|
178 |
- if (sscanf (device, "/dev/ttyv%u", &n) == 1) { |
179 |
+ if (sscanf (device, "/dev/ttyv%c", &c) == 1) { |
180 |
+ if (c < 58) |
181 |
+ n = c - 48; |
182 |
+ else |
183 |
+ n = c - 'a' + 10; |
184 |
/* The VT number is always one more than the device number. */ |
185 |
n++; |
186 |
ret = TRUE; |
187 |
@@ -414,6 +433,7 @@ ck_get_active_console_num (int consol |
188 |
gboolean ret; |
189 |
int res; |
190 |
int active; |
191 |
+ char ttyn; |
192 |
|
193 |
g_assert (console_fd != -1); |
194 |
|
195 |
@@ -426,7 +446,12 @@ ck_get_active_console_num (int consol |
196 |
goto out; |
197 |
} |
198 |
|
199 |
- g_debug ("Active VT is: %d (ttyv%d)", active, active - 1); |
200 |
+ if (active - 1 < 10) |
201 |
+ ttyn = active - 1 + '0'; |
202 |
+ else |
203 |
+ ttyn = active - 11 + 'a'; |
204 |
+ |
205 |
+ g_debug ("Active VT is: %d (ttyv%c)", active, ttyn); |
206 |
ret = TRUE; |
207 |
|
208 |
out: |