X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fdev-setup.c;h=25ad918b85d16946b478a4e0b93df86a0ce0502e;hb=b733fbe7a0214eb43e402db7179697bf9c0975c1;hp=0b3d648acb879daedc77ef1aacbdd010155e3ef8;hpb=5ba2dc259f3cdd8fddef68cfd28380a32534e49a;p=elogind.git diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index 0b3d648ac..25ad918b8 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -20,46 +20,53 @@ ***/ #include -#include #include -#include -#include #include -#include "dev-setup.h" -#include "log.h" -#include "macro.h" #include "util.h" #include "label.h" +#include "path-util.h" +#include "dev-setup.h" + +int dev_setup(const char *prefix, uid_t uid, gid_t gid) { + static const char symlinks[] = + "-/proc/kcore\0" "/dev/core\0" + "/proc/self/fd\0" "/dev/fd\0" + "/proc/self/fd/0\0" "/dev/stdin\0" + "/proc/self/fd/1\0" "/dev/stdout\0" + "/proc/self/fd/2\0" "/dev/stderr\0"; -static int symlink_and_label(const char *old_path, const char *new_path) { + const char *j, *k; int r; - assert(old_path); - assert(new_path); + NULSTR_FOREACH_PAIR(j, k, symlinks) { + _cleanup_free_ char *link_name = NULL; + const char *n; - r = label_context_set(new_path, S_IFLNK); - if (r < 0) - return r; + if (j[0] == '-') { + j++; - if (symlink(old_path, new_path) < 0) - r = -errno; + if (access(j, F_OK) < 0) + continue; + } - label_context_clear(); + if (prefix) { + link_name = prefix_root(prefix, k); + if (!link_name) + return -ENOMEM; - return r; -} + n = link_name; + } else + n = k; -void dev_setup(void) { - const char *j, *k; + r = symlink_label(j, n); + if (r < 0) + log_debug_errno(r, "Failed to symlink %s to %s: %m", j, n); - static const char symlinks[] = - "/proc/kcore\0" "/dev/core\0" - "/proc/self/fd\0" "/dev/fd\0" - "/proc/self/fd/0\0" "/dev/stdin\0" - "/proc/self/fd/1\0" "/dev/stdout\0" - "/proc/self/fd/2\0" "/dev/stderr\0"; + if (uid != UID_INVALID || gid != GID_INVALID) + if (lchown(n, uid, gid) < 0) + log_debug_errno(errno, "Failed to chown %s: %m", n); + } - NULSTR_FOREACH_PAIR(j, k, symlinks) - symlink_and_label(j, k); + return 0; }