Send Linux-ha-cvs mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
or, via email, send a message with subject or body 'help' to
[EMAIL PROTECTED]
You can reach the person managing the list at
[EMAIL PROTECTED]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Linux-ha-cvs digest..."
Today's Topics:
1. Linux-HA CVS: lib by alan from ([email protected])
2. Linux-HA CVS: include by alan from
([email protected])
3. Linux-HA CVS: lib by alan from ([email protected])
----------------------------------------------------------------------
Message: 1
Date: Tue, 7 Feb 2006 14:55:35 -0700 (MST)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: lib by alan from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : alan
Host :
Project : linux-ha
Module : lib
Dir : linux-ha/lib/plugins/HBcomm
Modified Files:
mcast.c
Log Message:
Clarified a few error messages.
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/lib/plugins/HBcomm/mcast.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- mcast.c 15 Oct 2005 02:37:52 -0000 1.25
+++ mcast.c 7 Feb 2006 21:55:35 -0000 1.26
@@ -1,4 +1,4 @@
-/* $Id: mcast.c,v 1.25 2005/10/15 02:37:52 gshi Exp $ */
+/* $Id: mcast.c,v 1.26 2006/02/07 21:55:35 alan Exp $ */
/*
* mcast.c: implements hearbeat API for UDP multicast communication
*
@@ -211,7 +211,7 @@
if (*dev != EOS) {
if (!is_valid_dev(dev)) {
- PILCallLog(LOG, PIL_CRIT, "mcast bad device [%s]", dev);
+ PILCallLog(LOG, PIL_CRIT, "mcast device [%s] is invalid
or not set up properly", dev);
return HA_FAIL;
}
/* Skip over white space, then grab the multicast group */
@@ -398,7 +398,7 @@
mcp = (struct mcast_private *) hbm->pd;
if ((numbytes=recvfrom(mcp->rsocket, mcast_pkt, MAXMSG-1, 0
- ,(struct sockaddr *)&their_addr, &addr_len)) <
0) {
+ , (struct sockaddr *)&their_addr, &addr_len)) < 0) {
if (errno != EINTR) {
PILCallLog(LOG, PIL_CRIT, "Error receiving from socket:
%s"
, strerror(errno));
@@ -419,8 +419,6 @@
*lenp = numbytes + 1 ;
return mcast_pkt;;
-
-
}
/*
@@ -497,7 +495,7 @@
* Set up socket for listening to heartbeats (UDP multicasts)
*/
-#define MAXBINDTRIES 10
+#define MAXBINDTRIES 50
static int
mcast_make_receive_sock(struct hb_media * hbm)
{
@@ -722,8 +720,10 @@
, if_info.ifr_name);
}
if (ioctl(fd, SIOCGIFADDR, &if_info) < 0) {
- PILCallLog(LOG, PIL_CRIT, "Error ioctl(SIOCGIFADDR): %s"
- , strerror(errno));
+ PILCallLog(LOG, PIL_CRIT
+ , "Unable to retrieve local interface address"
+ " for interface [%s] using ioctl(SIOCGIFADDR): %s"
+ , ifname, strerror(errno));
close(fd);
return -1;
}
@@ -800,6 +800,9 @@
/*
* $Log: mcast.c,v $
+ * Revision 1.26 2006/02/07 21:55:35 alan
+ * Clarified a few error messages.
+ *
* Revision 1.25 2005/10/15 02:37:52 gshi
* change MAXLINE to MAXMSG
*
------------------------------
Message: 2
Date: Tue, 7 Feb 2006 22:25:16 -0700 (MST)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: include by alan from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : alan
Host :
Project : linux-ha
Module : include
Dir : linux-ha/include/clplumbing
Modified Files:
GSource.h
Log Message:
Added code to support the creation and tracking of temporary child
processes for things like writing files to disk.
This is a generalization of code I put in heartbeat - but will eventually
move to using this code.
NOTE: noone is using this code yet, so it's safe to add - even during
a code freeze. Please don't start using it until the code freeze
is over. I just don't want to lose the changes.
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/include/clplumbing/GSource.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -3 -r1.16 -r1.17
--- GSource.h 2 Feb 2006 15:12:27 -0000 1.16
+++ GSource.h 8 Feb 2006 05:25:15 -0000 1.17
@@ -1,4 +1,4 @@
-/* $Id: GSource.h,v 1.16 2006/02/02 15:12:27 alan Exp $ */
+/* $Id: GSource.h,v 1.17 2006/02/08 05:25:15 alan Exp $ */
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -188,4 +188,47 @@
void G_main_set_trigger(GTRIGSource* man_src);
+/*
+ * Create a trigger for triggering an action in a short-lived (temporary)
+ * child process.
+ *
+ * The name isn't wonderful, but we couldn't think of a better one.
+ */
+GTRIGSource* G_main_add_tempproc_trigger(int priority
+, int (*fun)(gpointer p) /* What to do? */
+ /* Called in child process */
+, const char * procname /* What do we call this process? */
+, gpointer userdata /* Passed to 'triggerfun' */
+, void (*prefork)(gpointer p) /* Called before fork */
+, void (*postfork)(gpointer p)); /* Called by parent process
+ * after fork(2) call.
+ * Each has 'userdata'
+ * passed to it.
+ */
+/*
+ * Special notes:
+ * - No more than one child process will be active at a time per trigger
+ * object.
+ *
+ * - If you trigger the action while this object has a child active,
+ * then it will be re-triggered after the currently running child
+ * completes. There is no necessary correlation between the
+ * number of times a the action is triggered and how many
+ * times it is executed. What is guaranteed is that after you
+ * trigger the action, it will happen (at least) once - as soon
+ * as the scheduler gets around to it at the priority you've
+ * assigned it. But if several are triggered while a child
+ * process is running, only one process will be instantiated to
+ * take the action requested by all the trigger calls.
+ *
+ * - Child processes are forked off at the priority of the trigger,
+ * not the priority of the SIGCHLD handler.
+ *
+ * - This is useful for writing out updates to a file for example.
+ * While we're writing one copy out, subsequent updates are
+ * held off until this one completes. When it completes, then
+ * the file is written again - but not "n" times - just the
+ * latest version available at the time the trigger is
+ * activated (run).
+ */
#endif
------------------------------
Message: 3
Date: Tue, 7 Feb 2006 22:25:16 -0700 (MST)
From: [email protected]
Subject: [Linux-ha-cvs] Linux-HA CVS: lib by alan from
To: [EMAIL PROTECTED]
Message-ID: <[EMAIL PROTECTED]>
linux-ha CVS committal
Author : alan
Host :
Project : linux-ha
Module : lib
Dir : linux-ha/lib/clplumbing
Modified Files:
GSource.c
Log Message:
Added code to support the creation and tracking of temporary child
processes for things like writing files to disk.
This is a generalization of code I put in heartbeat - but will eventually
move to using this code.
NOTE: noone is using this code yet, so it's safe to add - even during
a code freeze. Please don't start using it until the code freeze
is over. I just don't want to lose the changes.
===================================================================
RCS file: /home/cvs/linux-ha/linux-ha/lib/clplumbing/GSource.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -3 -r1.73 -r1.74
--- GSource.c 7 Feb 2006 15:44:33 -0000 1.73
+++ GSource.c 8 Feb 2006 05:25:15 -0000 1.74
@@ -1,4 +1,4 @@
-/* $Id: GSource.c,v 1.73 2006/02/07 15:44:33 alan Exp $ */
+/* $Id: GSource.c,v 1.74 2006/02/08 05:25:15 alan Exp $ */
/*
* Copyright (c) 2002 Alan Robertson <[EMAIL PROTECTED]>
*
@@ -23,6 +23,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <unistd.h>
#include <errno.h>
#include <clplumbing/cl_log.h>
@@ -1331,6 +1332,10 @@
g_assert(IS_TRIGSOURCE(trig_src));
+ if (trig_src->manual_trigger
+ && cmp_longclock(trig_src->detecttime, zero_longclock) == 0) {
+ trig_src->detecttime = time_longclock();
+ }
return trig_src->manual_trigger;
}
@@ -1345,6 +1350,10 @@
GTRIGSource* trig_src = (GTRIGSource*)source;
g_assert(IS_TRIGSOURCE(trig_src));
+ if (trig_src->manual_trigger
+ && cmp_longclock(trig_src->detecttime, zero_longclock) == 0) {
+ trig_src->detecttime = time_longclock();
+ }
return trig_src->manual_trigger;
}
@@ -1620,3 +1629,185 @@
G_main_setmaxdispatchdelay_id(id, delay);
G_main_setmaxdispatchtime_id(id, delay);
}
+
+static void TempProcessRegistered(ProcTrack* p);
+static void TempProcessDied(ProcTrack* p, int status, int signo
+, int exitcode, int waslogged);
+static const char* TempProcessName(ProcTrack* p);
+
+/***********************************************************************
+ * Track our temporary child processes...
+ *
+ * We run no more than one of each type at once.
+ * If we need to run some and one is still running we run another one
+ * when this one exits.
+ *
+ * Requests to run a child process don't add up. So, 3 requests to run
+ * a child while one is running only cause it to be run once more, not
+ * three times.
+ *
+ * The only guarantee is that a new child process will run after a request
+ * was made.
+ *
+ * To create the possibility of running a particular type of child process
+ * call G_main_add_tempproc_trigger().
+ *
+ * To cause it to be run, call G_main_set_trigger().
+ *
+ ***********************************************************************/
+
+static ProcTrack_ops TempProcessTrackOps = {
+ TempProcessDied,
+ TempProcessRegistered,
+ TempProcessName
+};
+
+/*
+ * Information for tracking our generic temporary child processes.
+ */
+struct tempproc_track {
+ const char * procname; /* name of the process*/
+ GTRIGSource* trigger; /* Trigger for this event */
+ int (*fun)(gpointer userdata); /* Function to call
+ * in child process */
+ void (*prefork)(gpointer userdata);/* Call before fork */
+ void (*postfork)(gpointer userdata);/* Call after fork */
+ gpointer userdata; /* Info to pass 'fun' */
+ gboolean isrunning; /* TRUE if child is running */
+ gboolean runagain; /* TRUE if we need to run
+ * again after child process
+ * finishes.
+ */
+};
+static void
+TempProcessRegistered(ProcTrack* p)
+{
+ return; /* Don't need to do much here... */
+}
+
+static void
+TempProcessDied(ProcTrack* p, int status, int signo, int exitcode
+, int waslogged)
+{
+ struct tempproc_track * pt = p->privatedata;
+
+ pt->isrunning=FALSE;
+ if (pt->runagain) {
+ pt->runagain=FALSE;
+
+ /* Do it again, Sam! */
+ G_main_set_trigger(pt->trigger);
+
+ /* Note that we set the trigger for this, we don't
+ * fork or call the function now.
+ *
+ * This allows the mainloop scheduler to decide
+ * when the fork should happen according to the priority
+ * of this trigger event - NOT according to the priority
+ * of general SIGCHLD handling.
+ */
+ }
+ p->privatedata = NULL; /* Don't free until trigger is destroyed */
+ return;
+}
+
+static const char *
+TempProcessName(ProcTrack* p)
+{
+ struct tempproc_track * pt = p->privatedata;
+ return pt->procname;
+}
+/*
+ * Make sure only one copy is running at a time...
+ */
+static gboolean
+TempProcessTrigger(gpointer ginfo)
+{
+ struct tempproc_track* info = ginfo;
+ int pid;
+
+ /* Make sure only one copy is running at a time. */
+ /* This avoids concurrency problems. */
+ if (info->isrunning) {
+ info->runagain = TRUE;
+ return TRUE;
+ }
+ info->isrunning = TRUE;
+
+ if (info->prefork) {
+ info->prefork(info->userdata);
+ }
+ switch ((pid=fork())) {
+ int rc;
+ case -1: cl_perror("%s: Can't fork temporary child"
+ " process [%s]!", __FUNCTION__
+ , info->procname);
+ info->isrunning = FALSE;
+ break;
+
+ case 0: /* Child */
+ if ((rc=info->fun(info->userdata)) == HA_OK) {
+ exit(0);
+ }
+ cl_log(LOG_WARNING
+ , "%s: %s returns %d", __FUNCTION__
+ , info->procname, rc);
+ exit(1);
+ break;
+ default:
+ /* Fall out */;
+
+ }
+ if (pid > 0) {
+ NewTrackedProc(pid,0,PT_LOGNORMAL,ginfo,&TempProcessTrackOps);
+ }
+ if (info->postfork) {
+ info->postfork(info->userdata);
+ }
+ return TRUE;
+}
+
+static void
+tempproc_destroy_notify(gpointer userdata)
+{
+ if (userdata != NULL) {
+ cl_free(userdata);
+ userdata = NULL;
+ }
+}
+
+GTRIGSource*
+G_main_add_tempproc_trigger(int priority
+, int (*triggerfun) (gpointer p)
+, const char * procname
+, gpointer userdata
+, void (*prefork)(gpointer p)
+, void (*postfork)(gpointer p))
+{
+
+ struct tempproc_track* p;
+ GTRIGSource* ret;
+
+ p = (struct tempproc_track *) cl_malloc(sizeof(struct tempproc_track));
+ if (p == NULL) {
+ return NULL;
+ }
+
+ memset(p, 0, sizeof(*p));
+ p->procname = procname;
+ p->fun = triggerfun;
+ p->userdata = userdata;
+ p->prefork = prefork;
+ p->postfork = postfork;
+
+ ret = G_main_add_TriggerHandler(priority
+ , TempProcessTrigger, p, tempproc_destroy_notify);
+
+ if (ret == NULL) {
+ cl_free(p);
+ p = NULL;
+ }else{
+ p->trigger = ret;
+ }
+ return ret;
+}
------------------------------
_______________________________________________
Linux-ha-cvs mailing list
[email protected]
http://lists.community.tummy.com/mailman/listinfo/linux-ha-cvs
End of Linux-ha-cvs Digest, Vol 27, Issue 34
********************************************