diff options
author | Neil Brown <neilb@suse.de> | 2008-05-27 09:18:41 +1000 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2008-05-27 09:18:41 +1000 |
commit | e0d6609fe6b0fe6a74705d1f1c1cf4a0d3a71db8 (patch) | |
tree | 4e1a2f6c44d2ae2a943de26178edab3462e723c9 /monitor.c | |
parent | 5869a76c90aa0725e665d3c7bd6c7ab021d24fd4 (diff) |
Exit when there are no more arrays to manage.
Diffstat (limited to 'monitor.c')
-rw-r--r-- | monitor.c | 21 |
1 files changed, 19 insertions, 2 deletions
@@ -436,11 +436,12 @@ static int handle_pipe(struct md_generic_cmd *cmd, struct active_array *aa) return -1; } -static int wait_and_act(struct active_array **aap, int pfd, +static int wait_and_act(struct supertype *container, int pfd, int monfd, int nowait) { fd_set rfds; int maxfd = 0; + struct active_array **aap = &container->arrays; struct active_array *a, **ap; int rv; struct mdinfo *mdi; @@ -473,6 +474,22 @@ static int wait_and_act(struct active_array **aap, int pfd, ap = &(*ap)->next; } + if (manager_ready && *aap == NULL) { + /* No interesting arrays. Lets see about exiting. + * Note that blocking at this point is not a problem + * as there are no active arrays, there is nothing that + * we need to be ready to do. + */ + int fd = open(container->device_name, O_RDONLY|O_EXCL); + if (fd >= 0 || errno != EBUSY) { + /* OK, we are safe to leave */ + exit_now = 1; + signal_manager(); + remove_pidfile(container->devname); + exit(0); + } + } + if (!nowait) { rv = select(maxfd+1, &rfds, NULL, NULL, NULL); @@ -521,7 +538,7 @@ void do_monitor(struct supertype *container) int rv; int first = 1; do { - rv = wait_and_act(&container->arrays, container->mgr_pipe[0], + rv = wait_and_act(container, container->mgr_pipe[0], container->mon_pipe[1], first); first = 0; } while (rv >= 0); |