Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librc/librc-depend.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,9 @@ rc_deptree_update_needed(time_t *newest, char *file)

/* Quick test to see if anything we use has changed and we have
* data in our deptree. */
if (mkdir(rc_svcdir(), 0755) != 0 && errno != EEXIST)
if (mkdir(rc_svcdir(), 0755) == 0)
clear_dirfds(); /* clear our cached dirfds if we created a new svcdir, as a sanity check */
else if (errno != EEXIST)
fprintf(stderr, "mkdir '%s': %s\n", rc_svcdir(), strerror(errno));

if (fstatat(rc_dirfd(RC_DIR_SVCDIR), "deptree", &buf, 0) == 0) {
Expand Down
22 changes: 13 additions & 9 deletions src/librc/librc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ int rc_dirfd(enum rc_dir dir) {
return dirfds[dir];
}

void clear_dirfds(void) {
for (size_t i = 0; i < RC_DIR_MAX; i++) {
/* dirfd is zero-initialized, though zero is a valid
* FD, dirfd should never contain FDs which are <= 2. */
if (dirfds[i] <= 0)
continue;

close(dirfds[i]);
dirfds[i] = -1;
}
}

#define LS_INITD 0x01
#define LS_DIR 0x02
static RC_STRINGLIST *
Expand Down Expand Up @@ -633,15 +645,7 @@ rc_set_user(void)
rc_dirs.scriptdirs[SCRIPTDIR_USR] = rc_dirs.usrconfdir;
rc_dirs.scriptdirs[SCRIPTDIR_SVC] = rc_dirs.svcdir;

for (size_t i = 0; i < RC_DIR_MAX; i++) {
/* dirfd is zero-initialized, though zero is a valid
* FD, dirfd should never contain FDs which are <= 2. */
if (dirfds[i] <= 0)
continue;

close(dirfds[i]);
dirfds[i] = -1;
}
clear_dirfds();
}

const char * const *
Expand Down
1 change: 1 addition & 0 deletions src/librc/librc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ static const char *const dirnames[RC_DIR_SYS_MAX] =
};

RC_STRINGLIST *config_list(int dirfd, const char *pathname);
void clear_dirfds(void);

#endif
Loading