summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2003-02-24 21:28:34 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2003-02-24 21:28:34 +0000
commit8e1205f98c949982c7b5bbb18bc9c8c2bcb31780 (patch)
tree57e8bc713ec013c72203f4f5b08747aa2e7d28f0 /misc
parentf5bb451bedc85727216b8b5b3014386c38b5de68 (diff)
downloadlibapr-8e1205f98c949982c7b5bbb18bc9c8c2bcb31780.tar.gz
Several good changes. We replaced the following functions:
apr_proc_other_child_check [Unix] -> apr_proc_other_child_refresh_all(APR_OC_REASON_RESTART); apr_proc_other_child_check [Win32] -> apr_proc_other_child_refresh_all(APR_OC_REASON_RUNNING); apr_proc_other_child_read [Unix MPMs] -> apr_proc_other_child_alert(pid, APR_OC_REASON_DEATH and introduce a single checkup flavor apr_proc_other_child_refresh to update just a single child process. _alert() is an assertion that some health transition just occurred, while _refresh() checks the health and provides notification to any still-running processes. This code is nominially vetted, but I'm bringing it back down on OSX after this commit to begin vetting the Unix side. Helpers welcomed!!! Now it's possible for the MPMs to be rewritten so they are legible, however the patch is binary compatible. Finally, we always export all entry points even if they aren't implemented to ensure binary compatibility. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64373 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc')
-rw-r--r--misc/unix/otherchild.c182
1 files changed, 117 insertions, 65 deletions
diff --git a/misc/unix/otherchild.c b/misc/unix/otherchild.c
index eb47228ea..4cd770b59 100644
--- a/misc/unix/otherchild.c
+++ b/misc/unix/otherchild.c
@@ -90,7 +90,7 @@ static apr_status_t other_child_cleanup(void *data)
return APR_SUCCESS;
}
-APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *pid,
+APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
void (*maintenance) (int reason, void *, int status),
void *data, apr_file_t *write_fd, apr_pool_t *p)
{
@@ -98,7 +98,7 @@ APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *pid,
ocr = apr_palloc(p, sizeof(*ocr));
ocr->p = p;
- ocr->proc = pid;
+ ocr->proc = proc;
ocr->maintenance = maintenance;
ocr->data = data;
if (write_fd == NULL) {
@@ -138,91 +138,143 @@ APR_DECLARE(void) apr_proc_other_child_unregister(void *data)
other_child_cleanup(data);
}
-APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *pid, int status)
+APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
+ int reason,
+ int status)
{
apr_other_child_rec_t *ocr, *nocr;
for (ocr = other_children; ocr; ocr = nocr) {
nocr = ocr->next;
- if (ocr->proc->pid != pid->pid)
+ if (ocr->proc->pid != proc->pid)
continue;
ocr->proc = NULL;
- (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
- return 0;
+ (*ocr->maintenance) (reason, ocr->data, status);
+ return APR_SUCCESS;
}
- return APR_CHILD_NOTDONE;
+ return APR_EPROC_UNKNOWN;
}
-#ifdef WIN32
-/*
- * Run the list of Other Children and restart the ones that have died.
- * ToDo: APR'ize this function so it will serve Unix and Win32.
- * Not clear to me how to make the Win32 function behave exactly like
- * the non-win32 branch. wgs
- */
-APR_DECLARE(void) apr_proc_other_child_check(void)
-{
- apr_other_child_rec_t *ocr, *nocr;
- DWORD status;
+APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
+ int reason)
+{
/* Todo:
- * Implement code to detect if a pipe is still alive on Windows.
+ * Implement code to detect if pipes are still alive.
*/
- if (other_children == NULL)
- return;
+#ifdef WIN32
+ DWORD status;
- for (ocr = other_children; ocr; ocr = nocr) {
- nocr = ocr->next;
- if (ocr->proc == NULL)
- continue;
+ if (ocr->proc == NULL)
+ return;
- if (!ocr->proc->hproc) {
- /* Already mopped up, perhaps we apr_proc_kill'ed it */
- (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, -1);
- }
- else if (!GetExitCodeProcess(ocr->proc->hproc, &status)) {
- CloseHandle(ocr->proc->hproc);
- ocr->proc = NULL;
- (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
- }
- else if (status == STILL_ACTIVE) {
- (*ocr->maintenance) (APR_OC_REASON_RESTART, ocr->data, -1);
- }
- else {
- CloseHandle(ocr->proc->hproc);
- ocr->proc->hproc = NULL;
- ocr->proc = NULL;
- (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
- }
+ if (!ocr->proc->hproc) {
+ /* Already mopped up, perhaps we apr_proc_kill'ed it */
+ (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, -1);
}
-}
+ else if (!GetExitCodeProcess(ocr->proc->hproc, &status)) {
+ CloseHandle(ocr->proc->hproc);
+ ocr->proc = NULL;
+ (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
+ }
+ else if (status == STILL_ACTIVE) {
+ (*ocr->maintenance) (reason, ocr->data, -1);
+ }
+ else {
+ CloseHandle(ocr->proc->hproc);
+ ocr->proc->hproc = NULL;
+ ocr->proc = NULL;
+ (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
+ }
+
#else /* ndef Win32 */
-APR_DECLARE(void) apr_proc_other_child_check(void)
-{
- apr_other_child_rec_t *ocr, *nocr;
pid_t waitret;
int status;
- for (ocr = other_children; ocr; ocr = nocr) {
- nocr = ocr->next;
- if (ocr->proc == NULL)
- continue;
+ if (ocr->proc == NULL)
+ return;
- waitret = waitpid(ocr->proc->pid, &status, WNOHANG);
- if (waitret == ocr->proc->pid) {
- ocr->proc = NULL;
- (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
- }
- else if (waitret == 0) {
- (*ocr->maintenance) (APR_OC_REASON_RESTART, ocr->data, -1);
- }
- else if (waitret == -1) {
- /* uh what the heck? they didn't call unregister? */
- ocr->proc = NULL;
- (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
- }
+ waitret = waitpid(ocr->proc->pid, &status, WNOHANG);
+ if (waitret == ocr->proc->pid) {
+ ocr->proc = NULL;
+ (*ocr->maintenance) (APR_OC_REASON_DEATH, ocr->data, status);
+ }
+ else if (waitret == 0) {
+ (*ocr->maintenance) (reason, ocr->data, -1);
+ }
+ else if (waitret == -1) {
+ /* uh what the heck? they didn't call unregister? */
+ ocr->proc = NULL;
+ (*ocr->maintenance) (APR_OC_REASON_LOST, ocr->data, -1);
}
-}
#endif
+}
+
+APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason)
+{
+ apr_other_child_rec_t *ocr, *next_ocr;
+
+ for (ocr = other_children; ocr; ocr = next_ocr) {
+ next_ocr = ocr->next;
+ apr_proc_other_child_refresh(ocr, reason);
+ }
+}
+
+#else /* !APR_HAS_OTHER_CHILD */
+
+APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc,
+ void (*maintenance) (int reason, void *, int status),
+ void *data, apr_file_t *write_fd, apr_pool_t *p)
+{
+ return;
+}
+
+APR_DECLARE(void) apr_proc_other_child_unregister(void *data)
+{
+ return;
+}
+
+APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc,
+ int reason,
+ int status)
+{
+ return APR_ENOTIMPL;
+}
+
+APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
+ int reason)
+{
+ return;
+}
+
+APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason)
+{
+ return;
+}
#endif /* APR_HAS_OTHER_CHILD */
+
+
+/* XXX: deprecated for removal in 1.0
+ * The checks behaved differently between win32 and unix, while
+ * the old win32 code did a health check, the unix code called
+ * other_child_check only at restart.
+ */
+APR_DECLARE(void) apr_proc_other_child_check(void)
+{
+#ifdef WIN32
+ apr_proc_other_child_refresh_all(APR_OC_REASON_RUNNING);
+#else
+ apr_proc_other_child_refresh_all(APR_OC_REASON_RESTART);
+#endif
+}
+
+/* XXX: deprecated for removal in 1.0
+ * This really didn't test any sort of read - it simply notified
+ * the maintenance function that the process had died.
+ */
+APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status)
+{
+ return apr_proc_other_child_alert(proc, APR_OC_REASON_DEATH, status);
+}
+