]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/dev-setup.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010-2012 Lennart Poettering
12 #include "alloc-util.h"
13 #include "dev-setup.h"
16 #include "path-util.h"
17 #include "user-util.h"
20 int dev_setup(const char *prefix
, uid_t uid
, gid_t gid
) {
21 static const char symlinks
[] =
22 "-/proc/kcore\0" "/dev/core\0"
23 "/proc/self/fd\0" "/dev/fd\0"
24 "/proc/self/fd/0\0" "/dev/stdin\0"
25 "/proc/self/fd/1\0" "/dev/stdout\0"
26 "/proc/self/fd/2\0" "/dev/stderr\0";
31 NULSTR_FOREACH_PAIR(j
, k
, symlinks
) {
32 _cleanup_free_
char *link_name
= NULL
;
38 if (access(j
, F_OK
) < 0)
43 link_name
= prefix_root(prefix
, k
);
51 r
= symlink_label(j
, n
);
53 log_debug_errno(r
, "Failed to symlink %s to %s: %m", j
, n
);
55 if (uid
!= UID_INVALID
|| gid
!= GID_INVALID
)
56 if (lchown(n
, uid
, gid
) < 0)
57 log_debug_errno(errno
, "Failed to chown %s: %m", n
);