]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/notify.c
Define and use HIAVE_IFADDRS_H
[nfs-utils.git] / utils / statd / notify.c
1 /*
2  * Copyright (C) 1995, 1997-1999 Jeffrey A. Uphoff
3  * Modified by Olaf Kirch, Oct. 1996.
4  * Modified by H.J. Lu, 1998.
5  *
6  * NSM for Linux.
7  */
8
9 /*
10  * NSM notify list handling.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16
17 #include <dirent.h>
18 #include <errno.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include "misc.h"
23 #include "statd.h"
24 #include "notlist.h"
25
26 /*
27  * Initial (startup) notify list.
28  */
29 notify_list             *inl = NULL;
30
31
32 /* 
33  * Get list of hosts from stable storage, build list of hosts to
34  * contact. These hosts are added to the global RPC notify list
35  * which is processed as soon as statd enters svc_run.
36  */
37 void
38 notify_hosts(void)
39 {
40         DIR            *nld;
41         struct dirent  *de;
42         notify_list    *call;
43
44         if (!(nld = opendir(SM_BAK_DIR))) {
45                 perror("opendir");
46                 exit(errno);
47         }
48
49         while ((de = readdir(nld))) {
50                 if (de->d_name[0] == '.')
51                         continue;
52
53                 /* The following can happen for loopback NFS mounts
54                  * (e.g. with cfsd) */
55                 if (matchhostname(de->d_name, MY_NAME)
56                  || matchhostname(de->d_name, "localhost")) {
57                         char *fname;
58                         fname=xmalloc(strlen(SM_BAK_DIR)+sizeof(de->d_name)+2);
59                         dprintf(N_DEBUG, "We're on our own notify list?!?");
60                         sprintf(fname, "%s/%s",  SM_BAK_DIR, de->d_name);
61                         if (unlink(fname)) 
62                                 note(N_ERROR, "unlink(%s): %s", 
63                                         fname, strerror(errno));
64                         free(fname);
65                         continue;
66                 }
67
68                 call = nlist_new(MY_NAME, de->d_name, -1);
69                 NL_TYPE(call) = NOTIFY_REBOOT;
70                 nlist_insert(&notify, call);
71         }
72
73         if (closedir(nld) == -1) {
74                 perror("closedir");
75                 exit(1);
76         }
77 }