Skip to content

Commit 6bd3523

Browse files
committed
Use O_PATH to indicate we want to use the fd for unlinkat() only
The O_PATH flag tells open() that we only need a path reference, not a file descriptor that we can do I/O through. That should make the operation a lot cheaper to perform. Also remove third argument to open(): since we are not creating a file, this argument has no effect.
1 parent 04523d2 commit 6bd3523

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

initramfs.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define _BSD_SOURCE
2+
#define _GNU_SOURCE
23

34
#include <sys/mount.h>
45
#include <sys/types.h>
@@ -13,6 +14,10 @@
1314
#define MS_MOVE 8192
1415
#endif
1516

17+
#ifndef O_PATH
18+
#define O_PATH 010000000
19+
#endif
20+
1621
#include "debug.h"
1722
#include "mininit.h"
1823

@@ -74,7 +79,7 @@ const char *mount_boot()
7479

7580
int open_dir_to_clean()
7681
{
77-
int fd = open("/", O_RDONLY, 0);
82+
int fd = open("/", O_PATH | O_DIRECTORY);
7883
if (fd < 0) {
7984
DEBUG("Failed to open '/' before switch: %d\n", errno);
8085
}

0 commit comments

Comments
 (0)