Use rc_getline instead of assuming a fixed kernel cmdline length.
This is now requires as COMMAND_LINE_SIZE isn't exposed by kernel headers anymore. Fixes #177.
This commit is contained in:
parent
fbb78022f9
commit
6abeec7430
@ -72,8 +72,6 @@
|
|||||||
#define librc_hidden_proto(x) hidden_proto(x)
|
#define librc_hidden_proto(x) hidden_proto(x)
|
||||||
#define librc_hidden_def(x) hidden_def(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_list)
|
||||||
librc_hidden_proto(rc_config_load)
|
librc_hidden_proto(rc_config_load)
|
||||||
librc_hidden_proto(rc_config_value)
|
librc_hidden_proto(rc_config_value)
|
||||||
|
@ -517,5 +517,9 @@ typedef LIST_HEAD(rc_pidlist, rc_pid) RC_PIDLIST;
|
|||||||
* @return NULL terminated list of pids */
|
* @return NULL terminated list of pids */
|
||||||
RC_PIDLIST *rc_find_pids(const char *, const char *const *, uid_t, pid_t);
|
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
|
__END_DECLS
|
||||||
#endif
|
#endif
|
||||||
|
@ -12,6 +12,7 @@ global:
|
|||||||
rc_deptree_update_needed;
|
rc_deptree_update_needed;
|
||||||
rc_environ_fd;
|
rc_environ_fd;
|
||||||
rc_find_pids;
|
rc_find_pids;
|
||||||
|
rc_getline;
|
||||||
rc_newer_than;
|
rc_newer_than;
|
||||||
rc_older_than;
|
rc_older_than;
|
||||||
rc_runlevel_exists;
|
rc_runlevel_exists;
|
||||||
|
21
src/rc/rc.c
21
src/rc/rc.c
@ -43,10 +43,6 @@ const char rc_copyright[] = "Copyright (c) 2007-2008 Roy Marples";
|
|||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
#ifdef __linux__
|
|
||||||
# include <asm/setup.h> /* for COMMAND_LINE_SIZE */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -177,10 +173,8 @@ static char *
|
|||||||
proc_getent(const char *ent)
|
proc_getent(const char *ent)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char proc[COMMAND_LINE_SIZE];
|
char *proc, *p, *value = NULL;
|
||||||
char *p;
|
size_t i;
|
||||||
char *value = NULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!exists("/proc/cmdline"))
|
if (!exists("/proc/cmdline"))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -190,11 +184,11 @@ proc_getent(const char *ent)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(proc, 0, sizeof(proc));
|
proc = NULL;
|
||||||
p = fgets(proc, sizeof(proc), fp);
|
i = 0;
|
||||||
if (p == NULL)
|
if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
|
||||||
eerror("fgets: %s", strerror(errno));
|
eerror("rc_getline: %s", strerror(errno));
|
||||||
else if (*proc && (p = strstr(proc, ent))) {
|
if (*proc && (p = strstr(proc, ent))) {
|
||||||
i = p - proc;
|
i = p - proc;
|
||||||
if (i == '\0' || proc[i - 1] == ' ') {
|
if (i == '\0' || proc[i - 1] == ' ') {
|
||||||
p += strlen(ent);
|
p += strlen(ent);
|
||||||
@ -205,6 +199,7 @@ proc_getent(const char *ent)
|
|||||||
} else
|
} else
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
free(proc);
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,8 @@ rc_deptree_update_needed
|
|||||||
rc_deptree_update_needed@@RC_1.0
|
rc_deptree_update_needed@@RC_1.0
|
||||||
rc_find_pids
|
rc_find_pids
|
||||||
rc_find_pids@@RC_1.0
|
rc_find_pids@@RC_1.0
|
||||||
|
rc_getline
|
||||||
|
rc_getline@@RC_1.0
|
||||||
rc_newer_than
|
rc_newer_than
|
||||||
rc_newer_than@@RC_1.0
|
rc_newer_than@@RC_1.0
|
||||||
rc_older_than
|
rc_older_than
|
||||||
|
Loading…
Reference in New Issue
Block a user