diff options
author | Alan Coopersmith <alan.coopersmith@sun.com> | 2009-09-22 13:41:38 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@sun.com> | 2009-09-22 13:41:38 -0700 |
commit | 619af82effb9125c904d34c9fbc4bf93385d7b9e (patch) | |
tree | f51bfdd041c9a3a891779b7db42aacbd7bbf515b | |
parent | 6061722888eab858888dac2499194393299872e4 (diff) |
Create piddir if needed on startup
Allows setting piddir to /var/run/xdm/
Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
-rw-r--r-- | dm.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -863,7 +863,29 @@ StorePid (void) if (pidFile[0] != '\0') { pidFd = open (pidFile, O_RDWR); if (pidFd == -1 && errno == ENOENT) + { + /* Make sure directory exists if needed + Allows setting pidDir to /var/run/xdm + */ + char *pidDir = strdup(pidFile); + + if (pidDir != NULL) + { + char *p = strrchr(pidDir, '/'); + int r; + + if ((p != NULL) && (p != pidDir)) { + *p = '\0'; + } + r = mkdir(pidDir, 0755); + if ( (r < 0) && (errno != EEXIST) ) { + LogError ("process-id directory %s cannot be created\n", + pidDir); + } + } + pidFd = open (pidFile, O_RDWR|O_CREAT, 0666); + } if (pidFd == -1 || !(pidFilePtr = fdopen (pidFd, "r+"))) { LogError ("process-id file %s cannot be opened\n", |