Index: trunk/docs/Changelog
===================================================================
--- trunk/docs/Changelog	(revision 245)
+++ trunk/docs/Changelog	(revision 246)
@@ -1,3 +1,6 @@
 2.5.9:
+	* added code to generate directory for pid file, since it
+	  would get cleaned if /var/run is a tmpfs mount (problem
+	  reported by M. Athanasiou)
 	* fixed a bug that prevented reporting of user/executable path
 	  for open UDP ports (issue reported by N. Rath)
Index: trunk/src/sh_unix.c
===================================================================
--- trunk/src/sh_unix.c	(revision 245)
+++ trunk/src/sh_unix.c	(revision 246)
@@ -4051,4 +4051,42 @@
 }
 
+int sh_unix_check_piddir (char * pidfile)
+{
+  static        struct stat   buf;
+  int           status = 0;
+  char        * pid_dir;
+  
+  SL_ENTER(_("sh_unix_check_piddir"));
+
+  pid_dir = sh_util_dirname (pidfile);
+
+  status = retry_lstat (FIL__, __LINE__, pid_dir, &buf);
+
+  if (status < 0 && errno == ENOENT)
+    {
+      status = mkdir (pid_dir, 0777);
+      if (status < 0)
+	{
+	  sh_error_handle ((-1), FIL__, __LINE__, status,
+			   MSG_E_SUBGEN, 
+			   _("Cannot create PID directory"),
+			   _("sh_unix_check_piddir"));
+	  SH_FREE(pid_dir);
+	  SL_RETURN((-1),_("sh_unix_check_piddir"));
+	}
+    }
+  else if (!S_ISDIR(buf.st_mode))
+    {
+      sh_error_handle ((-1), FIL__, __LINE__, status,
+		       MSG_E_SUBGEN, 
+		       _("Path of PID directory refers to a non-directory object"),
+		       _("sh_unix_check_piddir"));
+      SH_FREE(pid_dir);
+      SL_RETURN((-1),_("sh_unix_check_piddir"));
+    }
+  SH_FREE(pid_dir);
+  SL_RETURN((0),_("sh_unix_check_piddir"));
+}
+
 int sh_unix_lock (char * lockfile, char * flag)
 {
@@ -4063,4 +4101,12 @@
   sprintf (myPid, "%ld\n", (long) sh.pid);             /* known to fit  */
 
+  if (flag == NULL) /* PID file, check for directory */
+    {
+      if (0 != sh_unix_check_piddir (lockfile))
+	{
+	  SL_RETURN((-1),_("sh_unix_lock"));
+	}
+    }
+
   fd = sl_open_safe_rdwr (lockfile, SL_YESPRIV);       /* fails if file exists */
 
@@ -4119,5 +4165,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, status,
 			   MSG_E_SUBGEN, 
-			   (filename == NULL) ? _("Cannot create PID file") : _("Cannot create lock file"),
+			   (filename == NULL) ? _("Cannot create PID file (1)") : _("Cannot create lock file (1)"),
 			   _("sh_unix_test_and_lock"));
 	  SL_RETURN((-1),_("sh_unix_test_and_lock"));
@@ -4141,5 +4187,5 @@
 	  sh_error_handle ((-1), FIL__, __LINE__, status,
 			   MSG_E_SUBGEN, 
-			   (filename == NULL) ? _("Cannot create PID file") : _("Cannot create lock file"),
+			   (filename == NULL) ? _("Cannot create PID file (2)") : _("Cannot create lock file (2)"),
 			   _("sh_unix_test_and_lock"));
 	  SL_RETURN((-1),_("sh_unix_test_and_lock"));
@@ -4230,5 +4276,5 @@
 		       sh_error_handle ((-1), FIL__, __LINE__, status,
 					MSG_E_SUBGEN, 
-					(filename == NULL) ? _("Cannot create PID file") : _("Cannot create lock file"),
+					(filename == NULL) ? _("Cannot create PID file (3)") : _("Cannot create lock file (3)"),
 					_("sh_unix_test_and_lock"));
 		    }
