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