]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/dev-setup.c
4f9c0f42851bafe05770344e3a0c6ff1d917f9e6
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010-2012 Lennart Poettering
10 #include "alloc-util.h"
11 #include "dev-setup.h"
14 #include "path-util.h"
15 #include "user-util.h"
18 int dev_setup(const char *prefix
, uid_t uid
, gid_t gid
) {
19 static const char symlinks
[] =
20 "-/proc/kcore\0" "/dev/core\0"
21 "/proc/self/fd\0" "/dev/fd\0"
22 "/proc/self/fd/0\0" "/dev/stdin\0"
23 "/proc/self/fd/1\0" "/dev/stdout\0"
24 "/proc/self/fd/2\0" "/dev/stderr\0";
29 NULSTR_FOREACH_PAIR(j
, k
, symlinks
) {
30 _cleanup_free_
char *link_name
= NULL
;
36 if (access(j
, F_OK
) < 0)
41 link_name
= prefix_root(prefix
, k
);
49 r
= symlink_label(j
, n
);
51 log_debug_errno(r
, "Failed to symlink %s to %s: %m", j
, n
);
53 if (uid
!= UID_INVALID
|| gid
!= GID_INVALID
)
54 if (lchown(n
, uid
, gid
) < 0)
55 log_debug_errno(errno
, "Failed to chown %s: %m", n
);