|
From: <jsa...@us...> - 2008-10-10 11:22:19
|
Revision: 1265
http://como.svn.sourceforge.net/como/?rev=1265&view=rev
Author: jsanjuas
Date: 2008-10-10 10:50:06 +0000 (Fri, 10 Oct 2008)
Log Message:
-----------
. bug fix on child process death handler
. implemented the '-e' switch which makes como exit as soon as capture finishes
. many ipc notices degraded to debug messages
Modified Paths:
--------------
src/branches/2.0/base/capture.c
src/branches/2.0/base/export.c
src/branches/2.0/base/ipc.c
src/branches/2.0/base/supervisor.c
src/branches/2.0/base/util-process.c
src/branches/2.0/include/comopriv.h
Modified: src/branches/2.0/base/capture.c
===================================================================
--- src/branches/2.0/base/capture.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/capture.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -1822,7 +1822,10 @@
mdl_t *mdl = array_at(como_ca.mdls, mdl_t *, idx);
mdl_icapture_t *ic = mdl_get_icapture(mdl);
ipc_send(ic->export, CA_EX_DONE, NULL, 0);
+ break; /* for now there is only 1 export */
}
+
+ exit(0);
}
capture_profiler_notify(CP_END_SNIFFERS);
Modified: src/branches/2.0/base/export.c
===================================================================
--- src/branches/2.0/base/export.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/export.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -383,6 +383,9 @@
ie->running_state = EX_MDL_STATE_FLUSHED;
}
+
+ ipc_finish(1);
+ exit(0);
/*
* we are done
Modified: src/branches/2.0/base/ipc.c
===================================================================
--- src/branches/2.0/base/ipc.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/ipc.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -60,6 +60,7 @@
#include <sys/types.h>
#include <sys/select.h>
+#define LOG_DEBUG_DISABLE
#define LOG_DOMAIN "IPC"
#include "como.h"
@@ -303,7 +304,7 @@
assert(s_me->fd == -1);
s_me->fd = ipc_create_socket(s_me, TRUE);
if (s_me->fd != -1) {
- notice("Listening connections on %s@%s.\n", s_me->name, s_me->at);
+ debug("Listening connections on %s@%s.\n", s_me->name, s_me->at);
}
return s_me->fd;
}
@@ -369,7 +370,7 @@
dst->connected = 1;
- notice("Connected to peer %s@%s.\n", dst->name, dst->at);
+ debug("Connected to peer %s@%s.\n", dst->name, dst->at);
/* add to existing list of destinations */
ipc_peer_list_insert_head(&s_peers, dst);
@@ -532,14 +533,14 @@
if (s_on_connect != NULL) {
ic = s_on_connect((ipc_peer_t *) x, s_user_data);
if (ic == IPC_CLOSE || ic == IPC_ERR) {
- notice("Connection from peer %s on fd %d refused by "
+ debug("Connection from peer %s on fd %d refused by "
"on_connect handler.\n", x->name, fd);
ipc_peer_destroy(x); /* calls close */
return ic;
}
}
ipc_peer_list_insert_head(&s_peers, x);
- notice("New connection from peer %s on fd %d\n", x->name, fd);
+ debug("New connection from peer %s on fd %d\n", x->name, fd);
return IPC_OK;
}
@@ -554,7 +555,7 @@
ic = s_handlers[msg.type]((ipc_peer_t *) x, buf, msg.len, swap,
s_user_data);
if (ic == IPC_CLOSE || ic == IPC_ERR) {
- notice("Closing connection to peer %s on fd %d\n", x->name, fd);
+ debug("Closing connection to peer %s on fd %d\n", x->name, fd);
ipc_peer_list_remove(&s_peers, x);
ipc_peer_destroy(x); /* calls close */
}
@@ -564,7 +565,7 @@
//free(buf);
return ic;
} else {
- notice("Unhandled IPC message type %hd.\n", msg.type);
+ debug("Unhandled IPC message type %hd.\n", msg.type);
//free(buf);
return IPC_OK;
Modified: src/branches/2.0/base/supervisor.c
===================================================================
--- src/branches/2.0/base/supervisor.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/supervisor.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -206,12 +206,12 @@
if (ca_done && st_done && !ex_started) { /* CA && ST done, can go for EX */
ipc_peer_full_t *ex;
- pid_t pid;
debug("CA and ST initialized, starting export\n");
ex = ipc_peer_child(COMO_EX, 0);
- pid = start_child(ex, export_main, como_su->memmap, NULL, node0);
- if (pid < 0) {
+ como_su->ex_pid = start_child(ex, export_main, como_su->memmap,
+ NULL, node0);
+ if (como_su->ex_pid < 0) {
warn("Can't start EXPORT\n");
}
ex_started = 1;
@@ -294,7 +294,32 @@
static void
defchld(UNUSED int si_code)
{
- handle_children();
+ pid_t pid;
+ int ret;
+
+ /*
+ * we need to collect as many children as
+ * possible, since only one signal may be
+ * received for many defuncts.
+ */
+ for(;;) {
+ ret = handle_children(&pid);
+ if (ret == -1)
+ break;
+
+ /* if CA and EX have exited, we are done, we may want to exit */
+ if (pid == s_como_su->ca_pid)
+ s_como_su->ca_pid = 0;
+ if (pid == s_como_su->ex_pid)
+ s_como_su->ex_pid = 0;
+
+ if (como_config->exit_when_done == 1 &&
+ s_como_su->ca_pid == 0 &&
+ s_como_su->ex_pid == 0) {
+ msg("Done, exiting..\n");
+ exit(0);
+ }
+ }
}
/*
@@ -1073,8 +1098,9 @@
if (main_node->sniffers_count > 0) {
/* start the CAPTURE process */
ca = ipc_peer_child(COMO_CA, 0);
- pid = start_child(ca, capture_main, como_su->memmap, NULL, main_node);
- if (pid < 0)
+ como_su->ca_pid = start_child(ca, capture_main, como_su->memmap,
+ NULL, main_node);
+ if (como_su->ca_pid < 0)
error("Can't start CAPTURE\n");
}
Modified: src/branches/2.0/base/util-process.c
===================================================================
--- src/branches/2.0/base/util-process.c 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/base/util-process.c 2008-10-10 10:50:06 UTC (rev 1265)
@@ -37,6 +37,7 @@
#include <sys/types.h> /* fork */
#include <sys/wait.h> /* wait3() */
+#define LOG_DEBUG_DISABLE
#include "como.h"
#include "comopriv.h"
#include "ipc.h"
@@ -155,10 +156,11 @@
*
* Waits for children that have terminate and reports on the
* exit status with logmsg and returning 1 if the process didn't
- * terminate with an EXIT_SUCCESS and 0 otherwise.
+ * terminate with an EXIT_SUCCESS and 0 otherwise. If there was
+ * nothing to do, returns -1.
*/
int
-handle_children()
+handle_children(pid_t *ret_pid)
{
int j;
ipc_peer_t * who = NULL;
@@ -166,9 +168,11 @@
int statbuf;
pid = wait3(&statbuf, WNOHANG, NULL);
+ *ret_pid = pid;
+
if (pid <= 0) {
debug("handle_children -- nothing to do\n", pid);
- return 0;
+ return -1;
}
debug("handle_children (pid=%d)\n", pid);
Modified: src/branches/2.0/include/comopriv.h
===================================================================
--- src/branches/2.0/include/comopriv.h 2008-10-09 15:04:34 UTC (rev 1264)
+++ src/branches/2.0/include/comopriv.h 2008-10-10 10:50:06 UTC (rev 1265)
@@ -198,7 +198,7 @@
pid_t start_child (ipc_peer_full_t * child, mainloop_fn mainloop,
memmap_t * shmemmap, FILE *client_stream, como_node_t * node);
-int handle_children ();
+int handle_children (pid_t *pid);
void sighdlr_exit(int);
@@ -460,6 +460,8 @@
ipc_peer_t * ex; /* EXPORT */
ipc_peer_t * st; /* STORAGE */
ipc_peer_t * qu; /* QUERY, for use only in inline mode */
+ pid_t ca_pid;
+ pid_t ex_pid;
pid_t su_pid;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|