summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergiu Ivanov <unlimitedscolobb@gmail.com>2009-04-14 22:28:27 +0300
committerSergiu Ivanov <unlimitedscolobb@gmail.com>2009-04-14 22:28:27 +0300
commitdea12e2529ecdcab3a382fc71e7430326b74d6a6 (patch)
treeb6687c3868f668a25cf19ed1eb3159c5cd5af3ce
parentc9110f9c7d71fa9b157540a7aa2ade7f34b79968 (diff)
Made nsmux wait until dynamic translators finish
Previously, a settrans -gR on a node on which nsmux resides would only kill the dynamic translators, without shutting down nsmux, because it didn't wait for the children to close their ports, which made a check in netfs_shutdown fail. Now nsmux waits for the dynamic translator to finish, so settrans -gR does its job as expected: shuts down everything.
-rw-r--r--node.c11
-rw-r--r--nsmux.c6
-rw-r--r--trans.c31
-rw-r--r--trans.h24
4 files changed, 48 insertions, 24 deletions
diff --git a/node.c b/node.c
index a7c85fd4c..b2cefb5f6 100644
--- a/node.c
+++ b/node.c
@@ -747,6 +747,9 @@ error_t
/*The control port for the active translator */
mach_port_t active_control;
+ /*The PID of the started translator */
+ pid_t trans_pid;
+
/*A copy of the user information, supplied in `user` */
struct iouser * user;
@@ -841,6 +844,9 @@ error_t
/*Drop our reference to the port */
ports_port_deref (newpi);
+ /*Store the task ID of the new translator */
+ trans_pid = task2pid(task);
+
/*
char buf[256];
char *_buf = buf;
@@ -914,7 +920,10 @@ error_t
return err;
/*Register the new translator*/
- err = trans_register (active_control, &np->nn->dyntrans);
+ err = trans_register (active_control, trans_pid, &np->nn->dyntrans);
+ LOG_MSG ("node_set_translator: Translator PID: %d", (int)trans_pid);
+ if (err)
+ return err;
/*Obtain the port to the top of the newly-set translator */
err = fsys_getroot
diff --git a/nsmux.c b/nsmux.c
index 2eb539e07..112dd5f31 100644
--- a/nsmux.c
+++ b/nsmux.c
@@ -1675,17 +1675,13 @@ netfs_shutdown (int flags)
&& S_ISDIR (netfs_root_node->nn_stat.st_mode))
return EBUSY;
- if (flags & FSYS_GOAWAY_NOWAIT)
- LOG_MSG("NOWAIT");
- LOG_MSG("WAIT");
-
if (flags & FSYS_GOAWAY_RECURSE)
{
/*nsmux has been requested shut down recursively. Shut down all
dynamic translators. Statically set translators will not be
shut down, because libnetfs does not (yet?) do this itself, as
different from libdiskfs. */
- err = trans_shutdown_all (flags);
+ err = trans_shutdown_all (flags, 1);
#ifdef NOTYET
err = netfs_node_iterate (helper);
diff --git a/trans.c b/trans.c
index 4b77f473d..ac7d9906d 100644
--- a/trans.c
+++ b/trans.c
@@ -27,6 +27,7 @@
/*---------------------------------------------------------------------------*/
#include <stdlib.h>
#include <hurd/fsys.h>
+#include <sys/wait.h>
/*---------------------------------------------------------------------------*/
#include "trans.h"
/*---------------------------------------------------------------------------*/
@@ -39,10 +40,10 @@ trans_el_t * dyntrans = NULL;
/*---------------------------------------------------------------------------*/
/*---------Functions---------------------------------------------------------*/
-/*Adds a translator control port to the list of ports. One should use
- only this function to add a new element to the list of ports. */
+/*Adds a translator to the list of translators. One should use only
+ this function to add a new element to the list. */
error_t
-trans_register (fsys_t cntl, trans_el_t ** new_trans)
+trans_register (fsys_t cntl, pid_t pid, trans_el_t ** new_trans)
{
/*The new entry in the list */
trans_el_t * el;
@@ -52,6 +53,7 @@ trans_register (fsys_t cntl, trans_el_t ** new_trans)
return ENOMEM;
el->cntl = cntl;
+ el->pid = pid;
el->prev = NULL;
el->next = dyntrans;
@@ -63,9 +65,9 @@ trans_register (fsys_t cntl, trans_el_t ** new_trans)
} /*trans_register */
/*---------------------------------------------------------------------------*/
-/*Removes a translator control port from the list of ports. One should
- use only this function to remove an element from the list of
- ports. This function does not shut down the translator. */
+/*Removes a translator from the list. One should use only this
+ function to remove an element from the list. This function does not
+ shut down the translator. */
void
trans_unregister (trans_el_t * trans)
{
@@ -78,16 +80,21 @@ trans_unregister (trans_el_t * trans)
} /*trans_unregister */
/*---------------------------------------------------------------------------*/
-/*Gracefully shuts down all the translators registered in the
- list with `flags`. */
+/*Gracefully shuts down all the translators registered in the list
+ with `flags`. If wait is nonzero, waits for each translator to
+ finish. */
error_t
-trans_shutdown_all (int flags)
+trans_shutdown_all (int flags, int wait)
{
error_t err;
/*The element being dealt with now. */
trans_el_t * el;
+ /*The exit status of the dynamic translator, in case we are waiting
+ for it to finish. */
+ int exit_status;
+
for (el = dyntrans; el; el = el->next)
{
err = fsys_goaway (el->cntl, flags);
@@ -101,6 +108,12 @@ trans_shutdown_all (int flags)
dyntrans = el;
return err;
}
+
+ if (wait)
+ {
+ /*Wait for the translator process to stop, if needed. */
+ waitpid (el->pid, &exit_status, 0);
+ }
}
dyntrans = NULL;
diff --git a/trans.h b/trans.h
index e28060f5e..5fcd446c7 100644
--- a/trans.h
+++ b/trans.h
@@ -28,6 +28,8 @@
#include <hurd.h>
#include <error.h>
/*---------------------------------------------------------------------------*/
+#include "lib.h"
+/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*---------Types-------------------------------------------------------------*/
@@ -37,6 +39,9 @@ struct trans_el
/*the control port to the translator */
fsys_t cntl;
+ /*the PID of the translator */
+ pid_t pid;
+
/*the next and the previous elements in the list */
struct trans_el * next, * prev;
}; /*struct trans_el */
@@ -52,21 +57,22 @@ extern trans_el_t * dyntrans;
/*---------------------------------------------------------------------------*/
/*---------Functions---------------------------------------------------------*/
-/*Adds a translator control port to the list of ports. One should use
- only this function to add a new element to the list of ports. */
+/*Adds a translator to the list of translators. One should use only
+ this function to add a new element to the list. */
error_t
-trans_register (fsys_t cntl, trans_el_t ** new_trans);
+trans_register (fsys_t cntl, pid_t pid, trans_el_t ** new_trans);
/*---------------------------------------------------------------------------*/
-/*Removes a translator control port from the list of ports. One should
- use only this function to remove an element from the list of
- ports. This function does not shut down the translator. */
+/*Removes a translator from the list. One should use only this
+ function to remove an element from the list. This function does not
+ shut down the translator. */
void
trans_unregister (trans_el_t * trans);
/*---------------------------------------------------------------------------*/
-/*Gracefully shuts down all the translators registered in the
- list with `flags`. */
+/*Gracefully shuts down all the translators registered in the list
+ with `flags`. If wait is nonzero, waits for each translator to
+ finish. */
error_t
-trans_shutdown_all (int flags);
+trans_shutdown_all (int flags, int wait);
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/