Skip to content

Commit ba2e63c

Browse files
committed
librc: don't create /run/openrc itself on demand.
this is a temporary fix, in a system that boots with / as rw, /run unmounted, and has rc_parallel on, openrc would create a dirfd to /run/openrc before mounting /run, thus keeping an open fd to the old /run mountpoint, and creating 'exclusive' lockfiles under it, that subsequent services can't see nor lock on. Fixes: #859 Fixes: 07d6f4d
1 parent 7fce206 commit ba2e63c

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/librc/librc.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ static int dirfds[RC_DIR_MAX];
5050

5151
int rc_dirfd(enum rc_dir dir) {
5252
int flags = O_RDONLY | O_CLOEXEC | O_DIRECTORY;
53-
int dirfd = AT_FDCWD;
54-
const char *dirname;
53+
int dirfd;
5554

5655
if (dir >= RC_DIR_MAX)
5756
return -1;
@@ -66,20 +65,17 @@ int rc_dirfd(enum rc_dir dir) {
6665
case RC_DIR_RUNLEVEL:
6766
return dirfds[dir] = open(rc_runleveldir(), flags);
6867
case RC_DIR_SVCDIR:
69-
dirname = rc_svcdir();
70-
break;
68+
return dirfds[dir] = open(rc_svcdir(), flags);
7169
default:
7270
assert(dirnames[dir]);
73-
dirname = dirnames[dir];
7471
dirfd = rc_dirfd(RC_DIR_SVCDIR);
72+
if ((dirfds[dir] = openat(dirfd, dirnames[dir], flags)) == -1 && errno == ENOENT) {
73+
if (mkdirat(dirfd, dirnames[dir], 0755) == -1 && errno != EEXIST)
74+
return -1;
75+
dirfds[dir] = openat(dirfd, dirnames[dir], flags);
76+
}
7577
break;
7678
}
77-
78-
if ((dirfds[dir] = openat(dirfd, dirname, flags)) == -1 && errno == ENOENT) {
79-
if (mkdirat(dirfd, dirname, 0755) == -1 && errno != EEXIST)
80-
return -1;
81-
dirfds[dir] = openat(dirfd, dirname, flags);
82-
}
8379
}
8480
return dirfds[dir];
8581
}

0 commit comments

Comments
 (0)