Skip to content

Commit

Permalink
mxqd: Release mxqd lock in reaper
Browse files Browse the repository at this point in the history
mxqd hold a flock lock on /dev/shm/mxqd.HOST.DAEMON.lck to avoid being
run multiple times. The open file and the lock is inherited by forked
children. It is lost when the child does an execve(), because the file
is opened O_CLOEXEC. However, the reaper is a long running forked child
which doesen't do execve(), so it holds the lock as well.

Usually this isn't a problem, because if mxqd terminates via one of the
signals defined for that purpose, it will unlink the lock file before
terminating. When it is restarted, a new file is generated and the lock
on the new file is not in conflict with locks on the unlinked file.

Only if mqxd is terminated by SIGKILL (which can't be ignored or
handled) it does not clean up the lock file. In that case, trying to
restart the daemon can fail because of the locks held by jobs of the
previous daemon.

Unlock the lock in the reaper after it has been forked.
  • Loading branch information
donald committed Sep 16, 2021
1 parent f218ec2 commit 035059c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mxqd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,8 @@ unsigned long start_job(struct mxq_group_list *glist)
job->host_pid = getpid();

mx_log_debug("starting reaper process.");
mx_funlock(server->flock);
server->flock = NULL;
mx_mysql_finish(&server->mysql);

res = reaper_process(server, glist, job);
Expand Down

0 comments on commit 035059c

Please sign in to comment.