summaryrefslogtreecommitdiff
path: root/src/librc/librc-misc.c
diff options
context:
space:
mode:
authorChristian Ruppert <idl0r@gentoo.org>2011-12-31 00:33:49 +0100
committerChristian Ruppert <idl0r@gentoo.org>2012-01-15 01:02:11 +0100
commitc3be42006b78809f1087b6a8262caba01f2c7fc1 (patch)
tree0e31d1ebb9382d0292784aa1dc2b3b51abbfc05e /src/librc/librc-misc.c
parent6fcc55cef80dfaab449b2e5379cb737988f68c24 (diff)
downloadopenrc-c3be42006b78809f1087b6a8262caba01f2c7fc1.tar.gz
openrc-c3be42006b78809f1087b6a8262caba01f2c7fc1.tar.bz2
openrc-c3be42006b78809f1087b6a8262caba01f2c7fc1.tar.xz
Rename proc_getent to rc_proc_getent and make it global
Diffstat (limited to 'src/librc/librc-misc.c')
-rw-r--r--src/librc/librc-misc.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/librc/librc-misc.c b/src/librc/librc-misc.c
index 97fa54c..cebc9e8 100644
--- a/src/librc/librc-misc.c
+++ b/src/librc/librc-misc.c
@@ -29,6 +29,7 @@
*/
#include "librc.h"
+#include "einfo.h"
bool
rc_yesno(const char *value)
@@ -127,6 +128,53 @@ rc_getline(char **line, size_t *len, FILE *fp)
}
librc_hidden_def(rc_getline)
+#ifdef __linux__
+char *
+rc_proc_getent(const char *ent)
+{
+ FILE *fp;
+ char *proc, *p, *value = NULL;
+ size_t i, len;
+
+ if (!exists("/proc/cmdline"))
+ return NULL;
+
+ if (!(fp = fopen("/proc/cmdline", "r"))) {
+ eerror("failed to open `/proc/cmdline': %s", strerror(errno));
+ return NULL;
+ }
+
+ proc = NULL;
+ i = 0;
+ if (rc_getline(&proc, &i, fp) == -1 || proc == NULL)
+ eerror("rc_getline: %s", strerror(errno));
+
+ if (proc != NULL) {
+ len = strlen(ent);
+
+ while ((p = strsep(&proc, " "))) {
+ if (strncmp(ent, p, len) == 0 && (p[len] == '\0' || p[len] == ' ' || p[len] == '=')) {
+ p += len;
+
+ if (*p == '=')
+ p++;
+
+ value = xstrdup(p);
+ }
+ }
+ }
+
+ if (!value)
+ errno = ENOENT;
+
+ fclose(fp);
+ free(proc);
+
+ return value;
+}
+librc_hidden_def(rc_proc_getent)
+#endif
+
RC_STRINGLIST *
rc_config_list(const char *file)
{