Commit d311c511 authored by Mike Hibler's avatar Mike Hibler
Browse files

New environment variable LIBNETMON_CONNECTTIMO to control how many times

libnetmon will attempt to connect to the monitor before giving up.
It used to try once and give up (still the default behavior).  Set this
to N to try N times one second apart or 0 to try forever.

If you start your app automatically from the ns/template, then you can
set a value in the ns file with either:
	set opt(LIBNETMON_CONNECTTIMO) 10
for the "old school" ns file, or:
	$ns define-template-parameter LIBNETMON_CONNECTTIMO 10
in a template.  Note that this will only work if you fire your app via
the program agent, otherwise you won't get the environment variable.
parent 142fd18e
......@@ -128,7 +128,7 @@ void lnm_init() {
filepath = getenv("LIBNETMON_OUTPUTFILE");
if (sockpath) {
int sockfd;
int sockfd, contimo;
struct sockaddr_un servaddr;
DEBUG(printf("Opening socket at path %s\n",sockpath));
......@@ -141,9 +141,23 @@ void lnm_init() {
servaddr.sun_family = AF_LOCAL;
strcpy(servaddr.sun_path,sockpath);
if (real_connect(sockfd, (struct sockaddr*) &servaddr,
sizeof(servaddr))) {
croak0("Unable to connect to netmond socket\n");
char *contimo_s = getenv("LIBNETMON_CONNECTTIMO");
if (contimo_s && sscanf(contimo_s,"%i", &contimo) == 1)
printf("libnetmon: Setting connection timeout to %i seconds\n",
contimo);
else
contimo = 1;
while (1) {
if (real_connect(sockfd, (struct sockaddr*) &servaddr,
sizeof(servaddr)) == 0) {
break;
}
if (contimo && --contimo == 0) {
croak0("Unable to connect to netmond socket\n");
}
printf("libnetmon: Failed to connect, trying again...\n");
sleep(1);
}
outstream = fdopen(sockfd,"w");
......
......@@ -6,6 +6,12 @@ LIB_SO="libnetmon.so"
SOCK="${TMPDIR}/netmon.sock";
CSOCK="${SOCK}.control";
#
# Number of times (1 second apart) to try connecting to netmond.
# (0 means try forever, unset means just one try).
#
TIMO=5
#
# Try once to build the library
#
......@@ -29,3 +35,7 @@ export LD_LIBRARY_PATH=$NETMON_DIR
export LD_PRELOAD=$LIB_SO
export LIBNETMON_SOCKPATH=$SOCK
export LIBNETMON_CONTROL_SOCKPATH=$CSOCK
# Allow this to be overridden from the environment
LIBNETMON_CONNECTTIMO=${LIBNETMON_CONNECTTIMO:=$TIMO}
export LIBNETMON_CONNECTTIMO
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment