Skip to content

Commit d5c180b

Browse files
poetteringbluca
authored andcommitted
Revert "tree-wide: Mount file descriptors via /proc/<pid>/fd"
(cherry picked from commit 7b9da38)
1 parent 93bb992 commit d5c180b

File tree

8 files changed

+16
-32
lines changed

8 files changed

+16
-32
lines changed

src/basic/fd-util.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <sys/socket.h>
99

1010
#include "macro.h"
11-
#include "format-util.h"
12-
#include "process-util.h"
1311
#include "stdio-util.h"
1412

1513
/* maximum length of fdname */
@@ -114,17 +112,14 @@ static inline int dir_fd_is_root_or_cwd(int dir_fd) {
114112
return dir_fd == AT_FDCWD ? true : path_is_root_at(dir_fd, NULL);
115113
}
116114

117-
/* The maximum length a buffer for a /proc/<pid>/fd/<fd> path needs. We intentionally don't use /proc/self/fd
118-
* as these paths might be read by other programs (for example when mounting file descriptors the source path
119-
* ends up in /proc/mounts and related files) for which /proc/self/fd will be interpreted differently than
120-
* /proc/<pid>/fd. */
115+
/* The maximum length a buffer for a /proc/self/fd/<fd> path needs */
121116
#define PROC_FD_PATH_MAX \
122-
(STRLEN("/proc//fd/") + DECIMAL_STR_MAX(pid_t) + DECIMAL_STR_MAX(int))
117+
(STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int))
123118

124119
static inline char *format_proc_fd_path(char buf[static PROC_FD_PATH_MAX], int fd) {
125120
assert(buf);
126121
assert(fd >= 0);
127-
assert_se(snprintf_ok(buf, PROC_FD_PATH_MAX, "/proc/" PID_FMT "/fd/%i", getpid_cached(), fd));
122+
assert_se(snprintf_ok(buf, PROC_FD_PATH_MAX, "/proc/self/fd/%i", fd));
128123
return buf;
129124
}
130125

src/libsystemd-network/sd-dhcp6-client.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
#include <errno.h>
77
#include <sys/ioctl.h>
8-
#include <net/if.h>
9-
#include <linux/if_arp.h> /* Must be included after <net/if.h> */
10-
#include <linux/if_infiniband.h> /* Must be included after <net/if.h> */
8+
#include <linux/if_arp.h>
9+
#include <linux/if_infiniband.h>
1110

1211
#include "sd-dhcp6-client.h"
1312

src/network/networkd-dhcp-server.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

33
#include <netinet/in.h>
4-
#include <net/if.h>
5-
#include <linux/if_arp.h> /* Must be included after <net/if.h> */
6-
#include <linux/if.h> /* Must be included after <net/if.h> */
4+
#include <linux/if_arp.h>
5+
#include <linux/if.h>
76

87
#include "sd-dhcp-server.h"
98

src/network/networkd-manager.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#include <netinet/in.h>
44
#include <sys/socket.h>
55
#include <unistd.h>
6-
#include <net/if.h>
7-
#include <linux/if.h> /* Must be included after <net/if.h> */
6+
#include <linux/if.h>
87
#include <linux/fib_rules.h>
98
#include <linux/nexthop.h>
109
#include <linux/nl80211.h>

src/network/networkd-state-file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

33
#include <netinet/in.h>
4-
#include <net/if.h>
5-
#include <linux/if.h> /* Must be included after <net/if.h> */
4+
#include <linux/if.h>
65

76
#include "alloc-util.h"
87
#include "dns-domain.h"

src/resolve/resolved-link.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3-
#include <net/if.h>
4-
#include <linux/if.h> /* Must be included after <net/if.h> */
3+
#include <linux/if.h>
54
#include <unistd.h>
65

76
#include "sd-network.h"

src/test/test-fd-util.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,11 @@ TEST(close_all_fds) {
382382
}
383383

384384
TEST(format_proc_fd_path) {
385-
_cleanup_free_ char *expected = NULL;
386-
387-
for (int i = 0; i < 4; i++) {
388-
assert_se(asprintf(&expected, "/proc/" PID_FMT "/fd/%i", getpid_cached(), i) >= 0);
389-
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(i), expected));
390-
expected = mfree(expected);
391-
}
392-
393-
assert_se(asprintf(&expected, "/proc/" PID_FMT "/fd/2147483647", getpid_cached()) >= 0);
394-
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(2147483647), expected));
385+
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(0), "/proc/self/fd/0"));
386+
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(1), "/proc/self/fd/1"));
387+
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(2), "/proc/self/fd/2"));
388+
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(3), "/proc/self/fd/3"));
389+
assert_se(streq_ptr(FORMAT_PROC_FD_PATH(2147483647), "/proc/self/fd/2147483647"));
395390
}
396391

397392
TEST(fd_reopen) {

src/udev/net/link-config.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22

3-
#include <net/if.h>
4-
#include <linux/netdevice.h> /* Must be included after <net/if.h> */
3+
#include <linux/netdevice.h>
54
#include <netinet/ether.h>
65
#include <unistd.h>
76

0 commit comments

Comments
 (0)