aboutsummaryrefslogtreecommitdiff
path: root/lib/roken/write_pid.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/roken/write_pid.c')
-rw-r--r--lib/roken/write_pid.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/roken/write_pid.c b/lib/roken/write_pid.c
index 25ee686c30dd..c01091236f2e 100644
--- a/lib/roken/write_pid.c
+++ b/lib/roken/write_pid.c
@@ -43,6 +43,8 @@ ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
pid_file_write(const char *progname)
{
const char *pidfile_dir = NULL;
+ const char *sep = "/";
+ size_t pidfile_dir_len;
char *ret = NULL;
FILE *fp;
@@ -53,12 +55,21 @@ pid_file_write(const char *progname)
*
* For now we use an environment variable.
*/
- if (!issuid())
- pidfile_dir = getenv("HEIM_PIDFILE_DIR");
+ pidfile_dir = secure_getenv("HEIM_PIDFILE_DIR");
if (pidfile_dir == NULL)
pidfile_dir = _PATH_VARRUN;
- if (asprintf(&ret, "%s%s.pid", pidfile_dir, progname) < 0 || ret == NULL)
+ pidfile_dir_len = strlen(pidfile_dir);
+ if (pidfile_dir_len > 1 &&
+ pidfile_dir[pidfile_dir_len - 1] == '/')
+ sep = "";
+#ifdef WIN32
+ if (pidfile_dir_len > 1 &&
+ pidfile_dir[pidfile_dir_len - 1] == '\\')
+ sep = "";
+#endif
+
+ if (asprintf(&ret, "%s%s%s.pid", pidfile_dir, sep, progname) < 0 || ret == NULL)
return NULL;
fp = fopen(ret, "w");
if (fp == NULL) {