123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390 |
- #include <stdio.h>
- #include <sys/param.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/wait.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <X11/Xlib.h>
- #include <X11/Xlibint.h>
- #include <X11/Intrinsic.h>
- #include <Dt/DtNlUtils.h>
- #include <Dt/DtPStrings.h>
- #include <Dt/WsmP.h>
- static int
- GetShortHostname (
- char*,
- unsigned int);
- static char *
- GetSessionDirProperty (
- Display *display);
- static char *
- GetDisplayName (
- Display *display);
- char *
- _DtCreateDtDirs(
- Display *display )
- {
- char *tmpPath = NULL;
- Boolean needSessionsDir = False;
- Boolean useOldSession = False;
- struct stat buf;
- int status;
- char *home = NULL;
- char *sessionDir = NULL;
- char *displayName = NULL;
-
- if(!display)
- return(NULL);
- if ((home = getenv("HOME")) == NULL)
- home = "";
- tmpPath = XtCalloc(1, MAXPATHLEN);
- if(tmpPath == NULL)
- return(NULL);
-
- snprintf(tmpPath, MAXPATHLEN, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
- status = stat(tmpPath, &buf);
- if (status == -1) {
- status = mkdir(tmpPath, 0000);
- if (status == -1) {
- XtFree(tmpPath);
- return(NULL);
- }
- (void)chmod(tmpPath, 0755);
- }
-
- snprintf(tmpPath, MAXPATHLEN, "%s/%s", home, DtPERSONAL_DB_DIRECTORY);
- if ((status = stat (tmpPath, &buf)) == -1) {
- if ((status = mkdir (tmpPath, 0000)) != -1)
- (void) chmod (tmpPath, 0755);
- }
-
- snprintf(tmpPath, MAXPATHLEN, "%s/%s", home, DtPERSONAL_TMP_DIRECTORY);
- if ((status = stat (tmpPath, &buf)) == -1) {
- if ((status = mkdir (tmpPath, 0000)) != -1)
- (void) chmod (tmpPath, 0755);
- }
-
- if ((sessionDir = GetSessionDirProperty (display)) != NULL) {
- if (!strcmp (sessionDir, DtSM_SESSION_DIRECTORY)) {
-
- needSessionsDir = True;
- } else if (!strcmp (sessionDir, DtSM_SESSION_DISPLAY_DIRECTORY)) {
-
- if ((displayName = GetDisplayName (display)) != NULL) {
- snprintf(tmpPath, MAXPATHLEN, "%s/%s/%s",
- home,
- DtPERSONAL_CONFIG_DIRECTORY,
- displayName);
- free(displayName);
- displayName = NULL;
- if ((status = stat (tmpPath, &buf)) == -1) {
- if ((status = mkdir (tmpPath, 0000)) != -1)
- (void) chmod (tmpPath, 0755);
- else
- useOldSession = True;
- }
- }
- else {
-
- useOldSession = True;
- }
- } else {
-
- useOldSession = True;
- }
- XFree (sessionDir);
- }
- else
- useOldSession = True;
-
- if (useOldSession) {
-
- if ((displayName = GetDisplayName (display)) != NULL) {
- snprintf(tmpPath, MAXPATHLEN, "%s/%s/%s",
- home,
- DtPERSONAL_CONFIG_DIRECTORY,
- displayName);
- free(displayName);
- displayName = NULL;
- if ((status = stat(tmpPath, &buf)) != 0)
-
- needSessionsDir = True;
- }
- else
- needSessionsDir = True;
- }
- if(needSessionsDir)
- {
-
- snprintf(tmpPath, MAXPATHLEN, "%s/%s/%s",
- home,
- DtPERSONAL_CONFIG_DIRECTORY,
- DtSM_SESSION_DIRECTORY);
- if ((status = stat(tmpPath, &buf)) == -1) {
- if ((status = mkdir(tmpPath, 0000)) == -1) {
- XtFree(tmpPath);
- return(NULL);
- }
- (void)chmod(tmpPath, 0755);
- }
- }
- return(tmpPath);
- }
- static int
- GetShortHostname(
- char *buffer,
- unsigned int bufsize )
- {
- char * ptr;
- int status;
- if ((status = gethostname(buffer, bufsize)))
- return status;
- if ((ptr = strstr(buffer, (char *)".")))
- *ptr = '\0';
- return 0;
- }
- static char *
- GetSessionDirProperty (
- Display *display)
- {
- int propStatus;
- Atom actualType;
- int actualFormat;
- unsigned long nitems;
- unsigned long leftover;
- char *property = NULL;
- Atom tmpAtom;
- tmpAtom = XInternAtom(display, _XA_DT_RESTORE_DIR, False);
- propStatus = XGetWindowProperty (display, RootWindow(display, 0),
- (Atom) tmpAtom, 0L,
- 1000000L, False,
- AnyPropertyType, &actualType,
- &actualFormat, &nitems, &leftover,
- (unsigned char **)&property);
- if (propStatus == Success && actualType != None &&
- actualFormat == 8 && nitems != 0)
- return(property);
- if (property)
- XFree(property);
- return (NULL);
- }
- static char *
- GetDisplayName (
- Display *display)
- {
- char *tmpPath;
- char hostName[101], displayName[101];
- char *pch, *tmpNumber = NULL;
- char *returnPath;
-
- snprintf(hostName, sizeof(hostName), "%s", display->display_name);
- snprintf(displayName, sizeof(displayName), "%s", display->display_name);
-
-
-
- if ((pch = DtStrchr(hostName, ':')))
- *pch = '\0';
- if ((pch = DtStrchr(hostName, '.')))
- *pch = '\0';
- if((!strcmp(hostName, "unix")) || (!strcmp(hostName, "local"))
- || (!strcmp(hostName, "")))
- {
-
- (void) GetShortHostname(hostName, 25);
- }
-
-
- if ((tmpNumber = DtStrchr(displayName, ':')))
- if ((pch = DtStrchr(tmpNumber, '.')))
- *pch = '\0';
-
- if((strlen(tmpNumber) + strlen(hostName)) > (size_t)14)
- {
- size_t tnLen;
- int lastChLen;
- char *lastCh;
-
- while ((tnLen = strlen(tmpNumber)) > (size_t)12)
- {
-
- DtLastChar(tmpNumber, &lastCh, &lastChLen);
- *lastCh = '\0';
- }
-
- while ((strlen(hostName) + tnLen) > (size_t)14)
- {
-
- DtLastChar(hostName, &lastCh, &lastChLen);
- *lastCh = '\0';
- }
- }
-
- strcat (hostName, tmpNumber);
- returnPath = strdup (hostName);
- return (returnPath);
- }
|