summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--utils/utils.c45
1 files changed, 18 insertions, 27 deletions
diff --git a/utils/utils.c b/utils/utils.c
index e782e44..c0d1cd5 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -129,36 +129,27 @@ blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2)
char* get_cmdline_val(const char* name, char* out, int len)
{
- char pattern[CMDLINE_SIZE + 1];
- char line[CMDLINE_SIZE + 1];
- char *res = NULL, *tty;
- int r, fd;
- regex_t pat_cmdline;
- regmatch_t matches[2];
-
- fd = open("/proc/cmdline", O_RDONLY);
- if (fd < 0)
- return NULL;
+ char line[CMDLINE_SIZE + 1], *c, *sptr;
+ int fd = open("/proc/cmdline", O_RDONLY);
+ ssize_t r = read(fd, line, sizeof(line) - 1);
+ close(fd);
- r = read(fd, line, CMDLINE_SIZE);
- if ( r <= 0 ) {
- close(fd);
+ if (r <= 0)
return NULL;
- }
- line[r] = '\0';
- close(fd);
- sprintf( pattern, "%s=([^ \n]*)", name);
- regcomp(&pat_cmdline, pattern, REG_EXTENDED);
- if (!regexec(&pat_cmdline, line, 2, matches, 0)) {
- line[matches[1].rm_eo] = '\0';
- tty = (line + matches[1].rm_so);
- strncpy(out, tty, len);
- tty[len-1] = '\0';
- res = out;
- }
+ line[r] = 0;
+
+ for (c = strtok_r(line, " \t\n", &sptr); c;
+ c = strtok_r(NULL, " \t\n", &sptr)) {
+ char *sep = strchr(c, '=');
+ ssize_t klen = sep - c;
+ if (klen < 0 || strncmp(name, c, klen) || name[klen] != 0)
+ continue;
- regfree(&pat_cmdline);
+ strncpy(out, &sep[1], len);
+ out[len-1] = 0;
+ return out;
+ }
- return res;
+ return NULL;
}