Obsolete golang-120
[oi-userland.git] / components / library / ConsoleKit / patches / 15-bootadm-parse.patch
blob055cb6e2d46e97546f6eebaddb8868789509f813
1 --- ConsoleKit-0.4.1/src/ck-manager.c-orig Fri Jun 15 10:43:58 2012
2 +++ ConsoleKit-0.4.1/src/ck-manager.c Fri Jun 15 10:44:03 2012
3 @@ -41,6 +41,7 @@
5 #if (defined(sun) && defined(__SVR4))
6 #include <libscf_priv.h>
7 +#include <ctype.h>
8 #endif
10 #if defined HAVE_POLKIT
11 @@ -1282,10 +1283,36 @@
13 #if (defined(sun) && defined(__SVR4))
14 static gint
15 +is_decimal_string(gchar *token, gint *indexp)
17 + gint i;
19 + for (i = 0; token[i] != 0; i++)
20 + if (!isdigit(token[i]))
21 + return (0);
23 + if (i > 0) {
24 + if (indexp)
25 + *indexp = strtol(token, 0, 10);
26 + return (1);
27 + }
29 + /* If the string is empty, return failure */
30 + return (0);
33 +/*
34 + * The output of bootadm should be parsed intelligently; not based on
35 + * the order of lines, but based on the line semantics. We look for
36 + * the keyword "default" when looking for the default entry. Lines
37 + * that start with a number specify boot entries that should be
38 + * captured for display in the dialog's boot entry list.
39 + */
40 +static gint
41 parse_output (const gchar *output, GPtrArray **systems)
43 gchar **lines;
44 - gint default_id = -1;
45 + gint id, default_id = -1;
47 if (output == NULL)
48 return default_id;
49 @@ -1292,45 +1319,40 @@
51 lines = g_strsplit (output, "\n", 0);
52 for (int i = 0; lines[i] != NULL; i++) {
53 - gchar *index;
54 + gchar **tokens;
56 - if (i == 0 || i == 2) {
57 - /* We do not care 1st & 2nd line. */
58 - continue;
59 - } else if (i == 1) {
60 - /* default boot menu entry */
61 - index = strchr (lines[i], ' ');
62 - if (index && (index + 1)) {
63 - default_id = atol (index + 1);
64 - } else {
65 - continue;
66 - }
67 - } else if (lines[i][0] != NULL && systems) {
68 - /* boot menu entries */
69 - GValue elem = {0};
70 + /* Split lines into 2 tokens maximum */
71 + tokens = g_strsplit_set(lines[i], " \t", 2);
72 + if (tokens == 0) {
73 + continue;
74 + } else if (tokens[0] == 0) {
75 + g_strfreev(tokens);
76 + continue;
77 + }
79 - index = strchr (lines[i], ' ');
80 - if (index && (index + 1)) {
81 - gint id;
82 + if (tokens[1] != 0 && strcmp(tokens[0], "default") == 0) {
83 + errno = 0;
84 + default_id = strtol (tokens[1], 0, 10);
85 + if (errno != 0)
86 + default_id = 0;
87 + } else if (is_decimal_string(tokens[0], &id) && systems) {
89 - *index = '\0';
90 - id = atoi (lines[i]);
91 - g_value_init (&elem, OS_STRUCT_TYPE);
92 - g_value_take_boxed (&elem,
93 - dbus_g_type_specialized_construct (OS_STRUCT_TYPE));
94 - dbus_g_type_struct_set (&elem,
95 + /* boot menu entries */
96 + GValue elem = {0};
98 + g_value_init (&elem, OS_STRUCT_TYPE);
99 + g_value_take_boxed (&elem,
100 + dbus_g_type_specialized_construct (OS_STRUCT_TYPE));
101 + dbus_g_type_struct_set (&elem,
102 0, id,
103 1, "",
104 2, "",
105 - 3, (index + 1),
106 + 3, (tokens[1] && tokens[1][0]) ? tokens[1] : "<no title specified>",
107 4, (default_id == id),
108 G_MAXUINT);
109 - g_ptr_array_add (*systems,
110 - g_value_get_boxed (&elem));
111 - } else {
112 - continue;
114 + g_ptr_array_add (*systems, g_value_get_boxed (&elem));
116 + g_strfreev(tokens);
118 g_strfreev (lines);
119 return default_id;