Skip to content

Commit c9249ae

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 c9249ae

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/librc/librc-depend.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,8 @@ rc_deptree_update_needed(time_t *newest, char *file)
693693

694694
/* Quick test to see if anything we use has changed and we have
695695
* data in our deptree. */
696+
if (mkdir(rc_svcdir(), 0755) != 0 && errno != EEXIST)
697+
fprintf(stderr, "mkdir '%s': %s\n", rc_svcdir(), strerror(errno));
696698

697699
if (fstatat(rc_dirfd(RC_DIR_SVCDIR), "deptree", &buf, 0) == 0) {
698700
mtime = buf.st_mtime;

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)