]> git.decadent.org.uk Git - nfs-utils.git/blob - support/include/ha-callout.h
Support --ha-callout for high-availability callouts
[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
18 extern char *ha_callout_prog;
19
20 static inline void
21 ha_callout(char *event, char *arg1, char *arg2, int arg3)
22 {
23         char buf[16]; /* should be plenty */
24         pid_t pid;
25         int ret = -1;
26
27         if (!ha_callout_prog) /* HA callout is not enabled */
28                 return;
29
30         sprintf(buf, "%d", arg3);
31
32         pid = fork();
33         switch (pid) {
34                 case 0: execl(ha_callout_prog, ha_callout_prog,
35                                 event, arg1, arg2, 
36                               arg3 < 0 ? NULL : buf,
37                               NULL);
38                         perror("execl");
39                         exit(2);
40                 case -1: perror("fork");
41                         break;
42                 default: ret = waitpid(pid, NULL, 0);
43         }
44
45 #ifdef dprintf
46         dprintf(N_DEBUG, "ha callout returned %d\n", WEXITSTATUS(ret));
47 #else
48         xlog(D_GENERAL, "ha callout returned %d\n", WEXITSTATUS(ret));
49 #endif
50 }
51
52 #endif