summaryrefslogtreecommitdiff
path: root/src/libudev/util.c
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2014-01-13 18:16:50 -0500
committerAnthony G. Basile <blueness@gentoo.org>2014-01-13 18:16:50 -0500
commite33d2cfc5e0bafb10eb82bb32776c41e558a026c (patch)
tree619ae0451cd40f169d740a02f26bf46a17c854b1 /src/libudev/util.c
parent248ea81923ce671979ccbe0bca5683d4239feb70 (diff)
src/udev: bring up to date with upstream.
These commits were authored by Zbigniew Jędrzejewski-Szmek Tom Gundersen Kay Sievers Lennart Poettering Shawn Landden Daniel Buch Martin Pitt Karel Zak Yang Zhiyong Note: udev_builtin_net_setup_link has *not* been imported. Also still missing from udev-builtin is udev_builtin_uaccess. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev/util.c')
-rw-r--r--src/libudev/util.c137
1 files changed, 67 insertions, 70 deletions
diff --git a/src/libudev/util.c b/src/libudev/util.c
index 58377d548f..98be5307f6 100644
--- a/src/libudev/util.c
+++ b/src/libudev/util.c
@@ -69,6 +69,7 @@
#include "path-util.h"
#include "exit-status.h"
#include "hashmap.h"
+#include "fileio.h"
int saved_argc = 0;
char **saved_argv = NULL;
@@ -254,23 +255,6 @@ char* endswith(const char *s, const char *postfix) {
return (char*) s + sl - pl;
}
-char* startswith(const char *s, const char *prefix) {
- const char *a, *b;
-
- assert(s);
- assert(prefix);
-
- a = s, b = prefix;
- for (;;) {
- if (*b == 0)
- return (char*) a;
- if (*a != *b)
- return NULL;
-
- a++, b++;
- }
-}
-
int close_nointr(int fd) {
int r;
@@ -449,59 +433,6 @@ char *split_quoted(const char *c, size_t *l, char **state) {
return (char*) current;
}
-int write_one_line_file(const char *fn, const char *line) {
- _cleanup_fclose_ FILE *f = NULL;
-
- assert(fn);
- assert(line);
-
- f = fopen(fn, "we");
- if (!f)
- return -errno;
-
- errno = 0;
- if (fputs(line, f) < 0)
- return errno ? -errno : -EIO;
-
- if (!endswith(line, "\n"))
- fputc('\n', f);
-
- fflush(f);
-
- if (ferror(f))
- return errno ? -errno : -EIO;
-
- return 0;
-}
-
-int read_one_line_file(const char *fn, char **line) {
- _cleanup_fclose_ FILE *f = NULL;
- char t[LINE_MAX], *c;
-
- assert(fn);
- assert(line);
-
- f = fopen(fn, "re");
- if (!f)
- return -errno;
-
- if (!fgets(t, sizeof(t), f)) {
-
- if (ferror(f))
- return errno ? -errno : -EIO;
-
- t[0] = 0;
- }
-
- c = strdup(t);
- if (!c)
- return -ENOMEM;
- truncate_nl(c);
-
- *line = c;
- return 0;
-}
-
char *truncate_nl(char *s) {
assert(s);
@@ -794,6 +725,19 @@ bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
return endswith(de->d_name, suffix);
}
+bool nulstr_contains(const char*nulstr, const char *needle) {
+ const char *i;
+
+ if (!nulstr)
+ return false;
+
+ NULSTR_FOREACH(i, nulstr)
+ if (streq(i, needle))
+ return true;
+
+ return false;
+}
+
int execute_command(const char *command, char *const argv[])
{
@@ -1161,3 +1105,56 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
}
return NULL;
}
+
+int proc_cmdline(char **ret) {
+ int r;
+
+ /* disable containers for now
+ if (detect_container(NULL) > 0) {
+ char *buf, *p;
+ size_t sz = 0;
+
+ r = read_full_file("/proc/1/cmdline", &buf, &sz);
+ if (r < 0)
+ return r;
+
+ for (p = buf; p + 1 < buf + sz; p++)
+ if (*p == 0)
+ *p = ' ';
+
+ *p = 0;
+ *ret = buf;
+ return 1;
+ }
+ */
+
+ r = read_one_line_file("/proc/cmdline", ret);
+ if (r < 0)
+ return r;
+
+ return 1;
+}
+
+int getpeercred(int fd, struct ucred *ucred) {
+ socklen_t n = sizeof(struct ucred);
+ struct ucred u;
+ int r;
+
+ assert(fd >= 0);
+ assert(ucred);
+
+ r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &u, &n);
+ if (r < 0)
+ return -errno;
+
+ if (n != sizeof(struct ucred))
+ return -EIO;
+
+ /* Check if the data is actually useful and not suppressed due
+ * to namespacing issues */
+ if (u.pid <= 0)
+ return -ENODATA;
+
+ *ucred = u;
+ return 0;
+}