]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/ha-callout.h
statd: Replace note() with xlog() in rpc.statd
[nfs-utils.git] / support / include / ha-callout.h
1 /*
2  * support/include/ha-callout.h
3  *
4  * High Availability NFS Callout support routines
5  *
6  * Copyright (c) 2004, Paul Clements, SteelEye Technology
7  *
8  * In order to implement HA NFS, we need several callouts at key
9  * points in statd and mountd. These callouts all come to ha_callout(),
10  * which, in turn, calls out to an ha-callout script (not part of nfs-utils;
11  * defined by -H argument to rpc.statd and rpc.mountd).
12  */
13 #ifndef HA_CALLOUT_H
14 #define HA_CALLOUT_H
15
16 #include <sys/wait.h>
17 #include <signal.h>
18
19 extern char *ha_callout_prog;
20
21 static inline void
22 ha_callout(char *event, char *arg1, char *arg2, int arg3)
23 {
24         char buf[16]; /* should be plenty */
25         pid_t pid;
26         int ret = -1;
27         struct sigaction oldact, newact;
28
29         if (!ha_callout_prog) /* HA callout is not enabled */
30                 return;
31
32         sprintf(buf, "%d", arg3);
33
34         /* many daemons ignore SIGCHLD as tcpwrappers will
35          * fork a child to do logging.  We need to wait
36          * for a child here, so we need to un-ignore
37          * SIGCHLD temporarily
38          */
39         newact.sa_handler = SIG_DFL;
40         newact.sa_flags = 0;
41         sigemptyset(&newact.sa_mask);
42         sigaction(SIGCHLD, &newact, &oldact);
43         pid = fork();
44         switch (pid) {
45                 case 0: execl(ha_callout_prog, ha_callout_prog,
46                                 event, arg1, arg2, 
47                               arg3 < 0 ? NULL : buf,
48                               NULL);
49                         perror("execl");
50                         exit(2);
51                 case -1: perror("fork");
52                         break;
53                 default: pid = waitpid(pid, &ret, 0);
54         }
55         sigaction(SIGCHLD, &oldact, &newact);
56         xlog(D_GENERAL, "ha callout returned %d\n", WEXITSTATUS(ret));
57 }
58
59 #endif