+static int
+flush_nfsd_cache(char *path, time_t now)
+{
+ int fd;
+ char stime[20];
+
+ sprintf(stime, "%ld\n", now);
+ fd = open(path, O_RDWR);
+ if (fd == -1)
+ return -1;
+ write(fd, stime, strlen(stime));
+ close(fd);
+ return 0;
+}
+
+static int
+flush_nfsd_idmap_cache(void)
+{
+ time_t now = time(NULL);
+ int ret;
+
+ ret = flush_nfsd_cache(IC_IDNAME_FLUSH, now);
+ if (ret)
+ return ret;
+ ret = flush_nfsd_cache(IC_NAMEID_FLUSH, now);
+ return ret;
+}
+
+static void
+msg_format(char *rtnbuff, int rtnbuffsize, int errval,
+ const char *fmt, va_list args)
+{
+ char buff[1024];
+ int n;
+
+ vsnprintf(buff, sizeof(buff), fmt, args);
+
+ if ((n = strlen(buff)) > 0 && buff[n-1] == '\n')
+ buff[--n] = '\0';
+
+ snprintf(rtnbuff, rtnbuffsize, "%s: %s", buff, strerror(errval));
+}
+
+static void
+idmapd_warn(const char *fmt, ...)
+{
+ int errval = errno; /* save this! */
+ char buff[1024];
+ va_list args;
+
+ va_start(args, fmt);
+ msg_format(buff, sizeof(buff), errval, fmt, args);
+ va_end(args);
+
+ syslog(LOG_WARNING, "%s", buff);
+}
+
+static void
+idmapd_warnx(const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsyslog(LOG_WARNING, fmt, args);
+ va_end(args);
+}
+
+static void
+idmapd_err(int eval, const char *fmt, ...)
+{
+ int errval = errno; /* save this! */
+ char buff[1024];
+ va_list args;
+
+ va_start(args, fmt);
+ msg_format(buff, sizeof(buff), errval, fmt, args);
+ va_end(args);
+
+ syslog(LOG_ERR, "%s", buff);
+ exit(eval);
+}
+
+static void
+idmapd_errx(int eval, const char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vsyslog(LOG_ERR, fmt, args);
+ va_end(args);
+ exit(eval);
+}
+