]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/statd/sm-notify.c
sm-notify - fix bugs related to run-only-once.
[nfs-utils.git] / utils / statd / sm-notify.c
index 0ea3977d4c047f48e3ce31cb34f6089405da08de..0eb0b09e5cdf28ca70ee7eb4030af634db594833 100644 (file)
 #include <grp.h>
 
 #ifndef BASEDIR
-#define BASEDIR                "/var/lib/nfs"
+# ifdef NFS_STATEDIR
+#  define BASEDIR              NFS_STATEDIR
+# else
+#  define BASEDIR              "/var/lib/nfs"
+# endif
 #endif
 
 #define DEFAULT_SM_STATE_PATH  BASEDIR "/state"
@@ -140,12 +144,12 @@ main(int argc, char **argv)
        if (optind < argc) {
 usage:         fprintf(stderr,
                        "Usage: sm-notify [-dfq] [-m max-retry-minutes] [-p srcport]\n"
-                       "            [-P /path/to/state/directory] [-N my_host_name\n");
+                       "            [-P /path/to/state/directory] [-v my_host_name]\n");
                return 1;
        }
 
        if (strcmp(_SM_BASE_PATH, BASEDIR) == 0) {
-               if (record_pid() == 0 && force == 0 && opt_update_state == 0)
+               if (record_pid() == 0 && force == 0 && opt_update_state == 1)
                        /* already run, don't try again */
                        exit(0);
        }
@@ -709,7 +713,7 @@ static int record_pid()
 
        snprintf(pid, 20, "%d\n", getpid());
        fd = open("/var/run/sm-notify.pid", O_CREAT|O_EXCL|O_WRONLY, 0600);
-       if (!fd)
+       if (fd < 0)
                return 0;
        write(fd, pid, strlen(pid));
        close(fd);