+
+static void
+load_state_number(void)
+{
+ int fd;
+ const char *file = "/proc/sys/fs/nfs/nsm_local_state";
+
+ if ((fd = open(SM_STAT_PATH, O_RDONLY)) == -1)
+ return;
+
+ if (read(fd, &MY_STATE, sizeof(MY_STATE)) != sizeof(MY_STATE)) {
+ note(N_WARNING, "Unable to read state from '%s': errno %d (%s)",
+ SM_STAT_PATH, errno, strerror(errno));
+ }
+ close(fd);
+ fd = open(file, O_WRONLY);
+ if (fd >= 0) {
+ char buf[20];
+ snprintf(buf, sizeof(buf), "%d", MY_STATE);
+ if (write(fd, buf, strlen(buf)) != strlen(buf))
+ note(N_WARNING, "Writing to '%s' failed: errno %d (%s)",
+ file, errno, strerror(errno));
+ close(fd);
+ }
+
+}