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
|
diff -ru a/src/librc/librc.h b/src/librc/librc.h
--- a/src/librc/librc.h 2009-09-01 11:42:31.000000000 +0000
+++ b/src/librc/librc.h 2009-09-01 11:42:47.000000000 +0000
@@ -72,8 +72,6 @@
#define librc_hidden_proto(x) hidden_proto(x)
#define librc_hidden_def(x) hidden_def(x)
-ssize_t rc_getline(char **, size_t *, FILE *);
-
librc_hidden_proto(rc_config_list)
librc_hidden_proto(rc_config_load)
librc_hidden_proto(rc_config_value)
diff -ru a/src/librc/rc.h.in b/src/librc/rc.h.in
--- a/src/librc/rc.h.in 2009-09-01 11:42:31.000000000 +0000
+++ b/src/librc/rc.h.in 2009-09-01 11:42:47.000000000 +0000
@@ -517,5 +517,9 @@
* @return NULL terminated list of pids */
RC_PIDLIST *rc_find_pids(const char *, const char *const *, uid_t, pid_t);
+/* getline is a handy glibc function that not all libcs have, so
+ * we have our own */
+ssize_t rc_getline(char **, size_t *, FILE *);
+
__END_DECLS
#endif
diff -ru a/src/librc/rc.map b/src/librc/rc.map
--- a/src/librc/rc.map 2009-09-01 11:42:31.000000000 +0000
+++ b/src/librc/rc.map 2009-09-01 11:42:47.000000000 +0000
@@ -12,6 +12,7 @@
rc_deptree_update_needed;
rc_environ_fd;
rc_find_pids;
+ rc_getline;
rc_newer_than;
rc_older_than;
rc_runlevel_exists;
diff -ru a/src/rc/rc.c b/src/rc/rc.c
--- a/src/rc/rc.c 2009-09-01 11:42:31.000000000 +0000
+++ b/src/rc/rc.c 2009-09-01 11:47:00.000000000 +0000
@@ -43,10 +43,6 @@
#include <sys/utsname.h>
#include <sys/wait.h>
-#ifdef __linux__
-# include <asm/setup.h> /* for COMMAND_LINE_SIZE */
-#endif
-
#include <errno.h>
#include <dirent.h>
#include <ctype.h>
@@ -177,10 +173,8 @@
proc_getent(const char *ent)
{
FILE *fp;
- char proc[COMMAND_LINE_SIZE];
- char *p;
- char *value = NULL;
- int i;
+ char *proc, *p, *value = NULL;
+ size_t i;
if (!exists("/proc/cmdline"))
return NULL;
@@ -190,11 +184,11 @@
return NULL;
}
- memset(proc, 0, sizeof(proc));
- p = fgets(proc, sizeof(proc), fp);
- if (p == NULL)
- eerror("fgets: %s", strerror(errno));
- else if (*proc && (p = strstr(proc, ent))) {
+ proc = NULL;
+ i = 0;
+ if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
+ eerror("rc_getline: %s", strerror(errno));
+ if (*proc && (p = strstr(proc, ent))) {
i = p - proc;
if (i == '\0' || proc[i - 1] == ' ') {
p += strlen(ent);
@@ -205,6 +199,7 @@
} else
errno = ENOENT;
fclose(fp);
+ free(proc);
return value;
}
diff -ru a/src/test/rc.funcs.list b/src/test/rc.funcs.list
--- a/src/test/rc.funcs.list 2009-09-01 11:42:31.000000000 +0000
+++ b/src/test/rc.funcs.list 2009-09-01 11:42:57.000000000 +0000
@@ -20,6 +20,8 @@
rc_deptree_update_needed@@RC_1.0
rc_find_pids
rc_find_pids@@RC_1.0
+rc_getline
+rc_getline@@RC_1.0
rc_newer_than
rc_newer_than@@RC_1.0
rc_older_than
|