+#ifdef HAVE_RUN_DIR
+ /* on some dists rundir gets purged on startup. so we need to recreate it. */
+
+ if (stat(ctdl_run_dir, &filestats)==-1){
+#ifdef HAVE_GETPWUID_R
+#ifdef SOLARIS_GETPWUID
+ pwp = getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf));
+#else // SOLARIS_GETPWUID
+ getpwuid_r(config.c_ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
+#endif // SOLARIS_GETPWUID
+#else // HAVE_GETPWUID_R
+ pwp = NULL;
+#endif // HAVE_GETPWUID_R
+
+ if ((mkdir(ctdl_run_dir, 0755) != 0) && (errno != EEXIST))
+ syslog(LOG_EMERG,
+ "unable to create run directory [%s]: %s",
+ ctdl_run_dir, strerror(errno));
+
+ if (chown(ctdl_run_dir, config.c_ctdluid, (pwp==NULL)?-1:pw.pw_gid) != 0)
+ syslog(LOG_EMERG,
+ "unable to set the access rights for [%s]: %s",
+ ctdl_run_dir, strerror(errno));
+ }
+
+
+#endif
+