535N/AFrom 619af82effb9125c904d34c9fbc4bf93385d7b9e Mon Sep 17 00:00:00 2001
535N/AFrom: Alan Coopersmith <alan.coopersmith@sun.com>
1062N/ADate: Tue, 22 Sep 2009 13:41:38 -0700
535N/ASubject: [PATCH:
app/xdm] Create piddir if needed on startup
919N/ASigned-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
919N/A 1 files changed, 22 insertions(+), 0 deletions(-)
919N/A@@ -863,7 +863,29 @@ StorePid (void)
919N/A if (pidFile[0] != '\0') {
919N/A pidFd = open (pidFile, O_RDWR);
919N/A if (pidFd == -1 && errno == ENOENT)
919N/A+ /* Make sure directory exists if needed
535N/A+ char *pidDir = strdup(pidFile);
535N/A+ char *p = strrchr(pidDir, '/');
911N/A+ if ((p != NULL) && (p != pidDir)) {
911N/A+ r = mkdir(pidDir, 0755);
535N/A+ if ( (r < 0) && (errno != EEXIST) ) {
535N/A+ LogError ("process-id directory %s cannot be created\n",
535N/A pidFd = open (pidFile, O_RDWR|O_CREAT, 0666);
if (pidFd == -1 || !(pidFilePtr = fdopen (pidFd, "r+")))
LogError ("process-id file %s cannot be opened\n",
From 748cfcc771c7f599d8087c7aa044bc5ff770da1d Mon Sep 17 00:00:00 2001
From: Alan Coopersmith <alan.coopersmith@sun.com>
Date: Tue, 22 Sep 2009 13:42:31 -0700
Subject: [PATCH:
app/xdm] Make parent authdir if needed at startup
Also refactor directory creation code for less duplication
Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
auth.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 47 insertions(+), 21 deletions(-)
@@ -270,6 +270,38 @@ CleanUpFileName (char *src, char *dst, int len)
+/* Checks to see if specified directory exists, makes it if not
+ * Returns: 0 if already exists, 1 if created, < 0 if error occured
+CheckServerAuthDir (const char *path, struct stat *statb, int mode)
+ int r = stat(path, statb);
+ LogError ("cannot make authentication directory %s: %s\n",
+ path, _SysErrorMsg (errno));
+ LogError ("cannot access authentication directory %s: %s\n",
+ path, _SysErrorMsg (errno));
+ } else { /* Directory already exists */
+ if (!S_ISDIR(statb->st_mode)) {
+ LogError ("cannot make authentication directory %s: %s\n",
+ path, "file with that name already exists");
static char authdir1[] = "authdir";
static char authdir2[] = "authfiles";
@@ -298,6 +330,13 @@ MakeServerAuthFile (struct display *d, FILE ** file)
CleanUpFileName (d->name, cleanname, NAMELEN - 8);
+ /* Make authDir if it doesn't already exist */
+ r = CheckServerAuthDir(authDir, &statb, 0755);
len = strlen (authDir) + strlen (authdir1) + strlen (authdir2)
+ strlen (cleanname) + 14;
d->authFile = malloc (len);
@@ -305,35 +344,22 @@ MakeServerAuthFile (struct display *d, FILE ** file)
snprintf (d->authFile, len, "%s/%s", authDir, authdir1);
- r = stat(d->authFile, &statb);
+ r = CheckServerAuthDir(d->authFile, &statb, 0700);
- r = mkdir(d->authFile, 0700);
- LogError ("cannot make authentication directory %s: "
- "%s\n", d->authFile, _SysErrorMsg (errno));
- LogError ("cannot access authentication directory %s: "
- "%s\n", d->authFile, _SysErrorMsg (errno));
snprintf (d->authFile, len, "%s/%s/%s",
authDir, authdir1, authdir2);
- r = mkdir(d->authFile, 0700);
- if (r < 0 && errno != EEXIST) {
- LogError ("cannot make authentication directory %s: %s\n",
- d->authFile, _SysErrorMsg (errno));
+ r = CheckServerAuthDir(d->authFile, &statb, 0700);