]>
Commit | Line | Data |
---|---|---|
5ba2dc25 KS |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010-2012 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include <errno.h> | |
5ba2dc25 | 21 | #include <stdlib.h> |
5ba2dc25 KS |
22 | #include <unistd.h> |
23 | ||
b5efdb8a | 24 | #include "alloc-util.h" |
ee104e11 | 25 | #include "dev-setup.h" |
5ba2dc25 | 26 | #include "label.h" |
a8fbdf54 | 27 | #include "log.h" |
03cfe0d5 | 28 | #include "path-util.h" |
ee104e11 LP |
29 | #include "user-util.h" |
30 | #include "util.h" | |
5ba2dc25 | 31 | |
03cfe0d5 | 32 | int dev_setup(const char *prefix, uid_t uid, gid_t gid) { |
5ba2dc25 | 33 | static const char symlinks[] = |
696fee7d | 34 | "-/proc/kcore\0" "/dev/core\0" |
5ba2dc25 KS |
35 | "/proc/self/fd\0" "/dev/fd\0" |
36 | "/proc/self/fd/0\0" "/dev/stdin\0" | |
37 | "/proc/self/fd/1\0" "/dev/stdout\0" | |
38 | "/proc/self/fd/2\0" "/dev/stderr\0"; | |
39 | ||
03cfe0d5 LP |
40 | const char *j, *k; |
41 | int r; | |
42 | ||
8f0e73f2 | 43 | NULSTR_FOREACH_PAIR(j, k, symlinks) { |
03cfe0d5 LP |
44 | _cleanup_free_ char *link_name = NULL; |
45 | const char *n; | |
46 | ||
696fee7d ZJS |
47 | if (j[0] == '-') { |
48 | j++; | |
49 | ||
2b85f4e1 | 50 | if (access(j, F_OK) < 0) |
696fee7d ZJS |
51 | continue; |
52 | } | |
8f0e73f2 | 53 | |
01ed0e23 | 54 | if (prefix) { |
03cfe0d5 | 55 | link_name = prefix_root(prefix, k); |
7f112f50 LP |
56 | if (!link_name) |
57 | return -ENOMEM; | |
8f0e73f2 | 58 | |
03cfe0d5 | 59 | n = link_name; |
01ed0e23 | 60 | } else |
03cfe0d5 LP |
61 | n = k; |
62 | ||
63 | r = symlink_label(j, n); | |
64 | if (r < 0) | |
65 | log_debug_errno(r, "Failed to symlink %s to %s: %m", j, n); | |
66 | ||
67 | if (uid != UID_INVALID || gid != GID_INVALID) | |
68 | if (lchown(n, uid, gid) < 0) | |
69 | log_debug_errno(errno, "Failed to chown %s: %m", n); | |
8f0e73f2 | 70 | } |
7f112f50 LP |
71 | |
72 | return 0; | |
5ba2dc25 | 73 | } |