X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=utils%2Fstatd%2Fstatd.c;h=8337b64b993918fb8704daeb49cae711447779d3;hb=4b2f63a5e581ecfa12abb2419310c4e62eb27134;hp=157de853bf5aa4fbab1d6cc655f40beb6b806bca;hpb=3482b1145c2c9a39f1dcaabc32e36eb234b91447;p=nfs-utils.git diff --git a/utils/statd/statd.c b/utils/statd/statd.c index 157de85..8337b64 100644 --- a/utils/statd/statd.c +++ b/utils/statd/statd.c @@ -76,6 +76,7 @@ static struct option longopts[] = extern void sm_prog_1 (struct svc_req *, register SVCXPRT *); extern int statd_get_socket(void); +static void load_state_number(void); #ifdef SIMULATIONS extern void simulator (int, char **); @@ -230,12 +231,10 @@ static void run_sm_notify(int outport) av[ac++] = op; } if (run_mode & STATIC_HOSTNAME) { - av[ac++] = "-N"; + av[ac++] = "-v"; av[ac++] = MY_NAME; } av[ac] = NULL; - fprintf(stderr, "%s: -N deprecated, consider using /usr/sbin/sm-notify directly\n", - name_p); execv(av[0], av); fprintf(stderr, "%s: failed to run %s\n", name_p, av[0]); exit(2); @@ -251,7 +250,6 @@ int main (int argc, char **argv) int arg; int port = 0, out_port = 0; struct rlimit rlim; - int once = 1; int pipefds[2] = { -1, -1}; char status; @@ -369,8 +367,11 @@ int main (int argc, char **argv) exit(-1); } - if (run_mode & MODE_NOTIFY_ONLY) + if (run_mode & MODE_NOTIFY_ONLY) { + fprintf(stderr, "%s: -N deprecated, consider using /usr/sbin/sm-notify directly\n", + name_p); run_sm_notify(out_port); + } if (!(run_mode & MODE_NODAEMON)) { @@ -475,25 +476,31 @@ int main (int argc, char **argv) waitpid(pid, NULL, 0); } + /* Make sure we have a privilege port for calling into the kernel */ + statd_get_socket(); - for (;;) { - pmap_unset (SM_PROG, SM_VERS); + /* If sm-notify didn't take all the state files, load + * state information into our notify-list so we can + * pass on any SM_NOTIFY that arrives + */ + load_state(); + load_state_number(); + pmap_unset (SM_PROG, SM_VERS); - /* If we got this far, we have successfully started, so notify parent */ - if (pipefds[1] > 0) { - status = 0; - write(pipefds[1], &status, 1); - close(pipefds[1]); - pipefds[1] = -1; - } + /* this registers both UDP and TCP services */ + rpc_init("statd", SM_PROG, SM_VERS, sm_prog_1, port); - /* this registers both UDP and TCP services */ - rpc_init("statd", SM_PROG, SM_VERS, sm_prog_1, port); + /* If we got this far, we have successfully started, so notify parent */ + if (pipefds[1] > 0) { + status = 0; + write(pipefds[1], &status, 1); + close(pipefds[1]); + pipefds[1] = -1; + } - if (once) { - once = 0; - drop_privs(); - } + drop_privs(); + + for (;;) { /* * Handle incoming requests: SM_NOTIFY socket requests, as * well as callbacks from lockd. @@ -520,3 +527,23 @@ int main (int argc, char **argv) } return 0; } + +static void +load_state_number(void) +{ + int fd; + + if ((fd = open(SM_STAT_PATH, O_RDONLY)) == -1) + return; + + read(fd, &MY_STATE, sizeof(MY_STATE)); + close(fd); + fd = open("/proc/sys/fs/nfs/nsm_local_state",O_WRONLY); + if (fd >= 0) { + char buf[20]; + snprintf(buf, sizeof(buf), "%d", MY_STATE); + write(fd, buf, strlen(buf)); + close(fd); + } + +}