DtsMM.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * $TOG: DtsMM.c /main/16 1998/10/23 13:48:28 mgreess $
  25. *
  26. * RESTRICTED CONFIDENTIAL INFORMATION:
  27. *
  28. * (c) Copyright 1993,1994,1995 Sun Microsystems, Inc.
  29. * All rights reserved.
  30. */
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <unistd.h>
  34. #include <sys/types.h>
  35. #include <sys/stat.h>
  36. #include <fcntl.h>
  37. #define SUN_DB
  38. #ifdef SUN_DB
  39. #include <sys/utsname.h>
  40. #include <dirent.h>
  41. #include <sys/mman.h>
  42. #include <sys/param.h>
  43. #endif
  44. #include <string.h>
  45. #include <libgen.h>
  46. #define X_INCLUDE_DIRENT_H
  47. #define XOS_USE_XT_LOCKING
  48. #include <X11/Xos_r.h>
  49. #include <Dt/DbReader.h>
  50. #include "Dt/DtsMM.h"
  51. #include "Dt/DtNlUtils.h"
  52. #include <Dt/UserMsg.h>
  53. #include "DtSvcLock.h"
  54. extern char *strdup(const char *);
  55. static int MMValidateDb(DtDirPaths *dirs, char *suffix);
  56. static int _debug_print_name(char *name, char *label);
  57. typedef int (*genfunc)(const void *, const void *);
  58. static DtDtsMMDatabase *db_list;
  59. static caddr_t mmaped_db = 0;
  60. static size_t mmaped_size = 0;
  61. static int mmaped_fd = 0;
  62. static DtDtsMMHeader *head = 0;
  63. void *
  64. _DtDtsMMGetPtr(int index)
  65. {
  66. DtShmIntList int_list;
  67. _DtSvcProcessLock();
  68. if(!mmaped_db)
  69. {
  70. _DtDtsMMInit(0);
  71. }
  72. int_list = (DtShmIntList)&mmaped_db[sizeof(DtDtsMMHeader)];
  73. _DtSvcProcessUnlock();
  74. return((void *)&int_list[index]);
  75. }
  76. int
  77. _DtDtsMMGetPtrSize(int index)
  78. {
  79. DtShmIntList int_list;
  80. _DtSvcProcessLock();
  81. if(!mmaped_db)
  82. {
  83. _DtDtsMMInit(0);
  84. }
  85. int_list = (DtShmIntList)&mmaped_db[sizeof(DtDtsMMHeader)];
  86. _DtSvcProcessUnlock();
  87. return(int_list[index-1]);
  88. }
  89. int *
  90. _DtDtsMMGetDCNameIndex(int *size)
  91. {
  92. int *result;
  93. _DtSvcProcessLock();
  94. *size = _DtDtsMMGetPtrSize(head->name_list_offset);
  95. result = (int*) _DtDtsMMGetPtr(head->name_list_offset);
  96. _DtSvcProcessUnlock();
  97. return(result);
  98. }
  99. int *
  100. _DtDtsMMGetDbName(DtDtsMMDatabase *db, DtShmBoson boson)
  101. {
  102. DtShmInttab tab = (DtShmInttab)_DtDtsMMGetPtr(db->nameIndex);
  103. return((int *)_DtShmFindIntTabEntry(tab, boson));
  104. }
  105. int *
  106. _DtDtsMMGetNoNameIndex(int *size)
  107. {
  108. int *result;
  109. _DtSvcProcessLock();
  110. if(head->no_name_offset == -1)
  111. {
  112. *size = 0;
  113. _DtSvcProcessUnlock();
  114. return(0);
  115. }
  116. *size = _DtDtsMMGetPtrSize(head->no_name_offset);
  117. result = (int *) _DtDtsMMGetPtr(head->no_name_offset);
  118. _DtSvcProcessUnlock();
  119. return(result);
  120. }
  121. /* returns the pointer to buffer only name list */
  122. int *
  123. _DtDtsMMGetBufferIndex(int *size)
  124. {
  125. int *list = (int*)_DtDtsMMGetNoNameIndex(size);
  126. int *bufferIndex;
  127. _DtSvcProcessLock();
  128. *size -= head->buffer_start_index;
  129. bufferIndex = &list[head->buffer_start_index];
  130. _DtSvcProcessUnlock();
  131. return(bufferIndex);
  132. }
  133. DtShmInttab
  134. _DtDtsMMGetFileList(void)
  135. {
  136. DtShmInttab file_index;
  137. _DtSvcProcessLock();
  138. file_index = (DtShmStrtab)_DtDtsMMGetPtr(head->files_offset);
  139. _DtSvcProcessUnlock();
  140. return(file_index);
  141. }
  142. const char *
  143. _DtDtsMMBosonToString(DtShmBoson boson)
  144. {
  145. DtShmStrtab str_table;
  146. if (boson == 0)
  147. return(0);
  148. _DtSvcProcessLock();
  149. if(!mmaped_db)
  150. {
  151. _DtDtsMMInit(0);
  152. }
  153. str_table = (DtShmStrtab)_DtDtsMMGetPtr(head->str_tbl_offset);
  154. _DtSvcProcessUnlock();
  155. return(_DtShmBosonToString(str_table, boson));
  156. }
  157. DtShmBoson
  158. _DtDtsMMStringToBoson(const char *string)
  159. {
  160. DtShmStrtab str_table;
  161. if ((string == (char *)NULL) || (*string == '\0'))
  162. return(-1);
  163. _DtSvcProcessLock();
  164. if(!mmaped_db)
  165. {
  166. _DtDtsMMInit(0);
  167. }
  168. str_table = (DtShmStrtab)_DtDtsMMGetPtr(head->str_tbl_offset);
  169. _DtSvcProcessUnlock();
  170. return(_DtShmStringToBoson(str_table, string));
  171. }
  172. void
  173. _DtDtsMMPrintFld(int fld, DtDtsMMField *fld_ptr, FILE *fd_in)
  174. {
  175. const char *tmp;
  176. const char *tmpv;
  177. FILE *fd = fd_in;
  178. if(!fd) fd = stdout;
  179. tmp = _DtDtsMMBosonToString(fld_ptr->fieldName);
  180. tmpv = _DtDtsMMBosonToString(fld_ptr->fieldValue);
  181. fprintf(fd, "\t\t[%d]\t%s(%d)\t%s(%d)\n", fld, tmp,fld_ptr->fieldName,
  182. tmpv?tmpv:"(NULL)", fld_ptr->fieldValue);
  183. }
  184. void
  185. _DtDtsMMPrintRec(int rec, DtDtsMMRecord *rec_ptr, FILE *fd_in)
  186. {
  187. int fld;
  188. DtDtsMMField *fld_ptr;
  189. DtDtsMMField *fld_ptr_list;
  190. const char *tmp;
  191. FILE *fd = fd_in;
  192. if(!fd) fd = stdout;
  193. tmp = _DtDtsMMBosonToString(rec_ptr->recordName);
  194. fprintf(fd, "\tRec[%d] name = %s(%d)\n\t%d Fields\n", rec,
  195. tmp, rec_ptr->recordName,
  196. rec_ptr->fieldCount);
  197. fld_ptr_list = _DtDtsMMGetPtr(rec_ptr->fieldList);
  198. for(fld = 0; fld < rec_ptr->fieldCount; fld++)
  199. {
  200. fld_ptr = &fld_ptr_list[fld];
  201. _DtDtsMMPrintFld(fld, fld_ptr, fd);
  202. }
  203. }
  204. void
  205. _DtDtsMMPrintDb(int db, DtDtsMMDatabase *db_ptr, FILE *fd_in)
  206. {
  207. int rec;
  208. DtDtsMMRecord *rec_ptr;
  209. DtDtsMMRecord *rec_ptr_list;
  210. const char *tmp;
  211. FILE *fd = fd_in;
  212. if(!fd) fd = stdout;
  213. fprintf(fd, "DB[%d] ", db);
  214. tmp = _DtDtsMMBosonToString(db_ptr->databaseName);
  215. fprintf(fd, "name = %s(%d)\n", tmp, db_ptr->databaseName);
  216. fprintf(fd, "%d Records\n", db_ptr->recordCount);
  217. rec_ptr_list = _DtDtsMMGetPtr(db_ptr->recordList);
  218. for(rec = 0; rec < db_ptr->recordCount; rec++)
  219. {
  220. rec_ptr = &rec_ptr_list[rec];
  221. _DtDtsMMPrintRec(rec, rec_ptr, fd);
  222. }
  223. }
  224. void
  225. _DtDtsMMPrint(FILE *org_fd)
  226. {
  227. int db;
  228. DtDtsMMDatabase *db_ptr;
  229. FILE *fd = org_fd;
  230. const char *tmp;
  231. _DtSvcProcessLock();
  232. if(!mmaped_db)
  233. {
  234. _DtDtsMMInit(0);
  235. }
  236. for(db = 0; db < head->num_db; db++)
  237. {
  238. db_ptr = &db_list[db];
  239. if(fd == 0)
  240. {
  241. chdir("/tmp");
  242. tmp = _DtDtsMMBosonToString(db_ptr->databaseName);
  243. if((fd = fopen(tmp, "w")) == NULL)
  244. {
  245. _DtSimpleError(
  246. DtProgName, DtError, NULL,
  247. (char*) tmp, NULL);
  248. continue;
  249. }
  250. }
  251. _DtDtsMMPrintDb(db, db_ptr, fd);
  252. if(org_fd == 0)
  253. {
  254. fclose(fd);
  255. fd = 0;
  256. }
  257. }
  258. _DtSvcProcessUnlock();
  259. }
  260. int
  261. _DtDtsMMCompareRecordNames(DtDtsMMRecord *a, DtDtsMMRecord *b)
  262. {
  263. return (a->recordName - b->recordName);
  264. }
  265. int
  266. _DtDtsMMCompareFieldNames(DtDtsMMField *a, DtDtsMMField *b)
  267. {
  268. return (a->fieldName - b->fieldName);
  269. }
  270. #include <Dt/Dts.h>
  271. int
  272. _DtDtsMMInit(int override)
  273. {
  274. DtDirPaths *dirs = _DtGetDatabaseDirPaths();
  275. char *CacheFile = _DtDtsMMCacheName(1);
  276. if(override)
  277. {
  278. if (!_DtDtsMMCreateDb(dirs, CacheFile, override))
  279. {
  280. free(CacheFile);
  281. _DtFreeDatabaseDirPaths(dirs);
  282. return 0;
  283. }
  284. _debug_print_name(CacheFile, "Init");
  285. }
  286. else
  287. {
  288. int success = _DtDtsMMapDB(CacheFile);
  289. if(success)
  290. {
  291. if(!MMValidateDb(dirs, ".dt"))
  292. {
  293. success = 0;
  294. }
  295. else
  296. {
  297. _debug_print_name(CacheFile, "Mapped");
  298. }
  299. }
  300. if(!success)
  301. {
  302. free(CacheFile);
  303. CacheFile = _DtDtsMMCacheName(0);
  304. _debug_print_name(CacheFile, "Private");
  305. /* Check return status, and pass status to caller. */
  306. if (!_DtDtsMMCreateDb(dirs, CacheFile, override))
  307. {
  308. free(CacheFile);
  309. _DtFreeDatabaseDirPaths(dirs);
  310. return 0;
  311. }
  312. }
  313. }
  314. free(CacheFile);
  315. _DtFreeDatabaseDirPaths(dirs);
  316. return 1;
  317. }
  318. char **
  319. _DtsMMListDb()
  320. {
  321. int i;
  322. char **list;
  323. _DtSvcProcessLock();
  324. if(!mmaped_db)
  325. {
  326. _DtDtsMMInit(0);
  327. }
  328. list = (char **)malloc((head->num_db+1)*sizeof(char *));
  329. for ( i = 0; i < head->num_db; i++ )
  330. {
  331. list[i] = (char *)_DtDtsMMBosonToString(db_list[i].databaseName);
  332. }
  333. list[i] = 0;
  334. _DtSvcProcessUnlock();
  335. return(list);
  336. }
  337. DtDtsMMDatabase *
  338. _DtDtsMMGet(const char *name)
  339. {
  340. int i;
  341. DtShmBoson boson = _DtDtsMMStringToBoson(name);
  342. DtDtsMMDatabase *ret_db;
  343. _DtSvcProcessLock();
  344. if(!mmaped_db)
  345. {
  346. _DtDtsMMInit(0);
  347. }
  348. for(i = 0; i < head->num_db; i++)
  349. {
  350. if(db_list[i].databaseName == boson)
  351. {
  352. ret_db = &db_list[i];
  353. _DtSvcProcessUnlock();
  354. return(ret_db);
  355. }
  356. }
  357. _DtSvcProcessUnlock();
  358. return(NULL);
  359. }
  360. DtDtsMMField *
  361. _DtDtsMMGetField(DtDtsMMRecord *rec, const char *name)
  362. {
  363. register int i;
  364. int fld;
  365. DtDtsMMField *fld_ptr;
  366. DtDtsMMField *fld_ptr_list;
  367. /*
  368. * Field names have been quarked so quark 'name' and
  369. * do a linear search for the quark'ed field name.
  370. */
  371. DtShmBoson tmp = _DtDtsMMStringToBoson (name);
  372. fld_ptr_list = _DtDtsMMGetPtr(rec->fieldList);
  373. for (i = 0; i < rec->fieldCount; i++)
  374. {
  375. fld_ptr = &fld_ptr_list[i];
  376. if (fld_ptr->fieldName == tmp)
  377. {
  378. return (fld_ptr);
  379. }
  380. }
  381. return(NULL);
  382. }
  383. const char *
  384. _DtDtsMMGetFieldByName(DtDtsMMRecord *rec, const char *name)
  385. {
  386. DtDtsMMField *result;
  387. result = _DtDtsMMGetField(rec, name);
  388. if(result)
  389. {
  390. return(_DtDtsMMBosonToString(result->fieldValue));
  391. }
  392. else
  393. {
  394. return(NULL);
  395. }
  396. }
  397. DtDtsMMRecord *
  398. _DtDtsMMGetRecordByName(DtDtsMMDatabase *db, const char *name)
  399. {
  400. DtDtsMMRecord srch;
  401. DtDtsMMRecord *result;
  402. DtDtsMMRecord *s = &srch;
  403. register int i;
  404. DtShmBoson name_quark = _DtDtsMMStringToBoson(name);
  405. DtDtsMMRecord *rec_ptr;
  406. DtDtsMMRecord *rec_ptr_list;
  407. /*
  408. * If the fields are not sorted in alphanumeric order
  409. * by name a binary search will fail. So do the slow but
  410. * sure linear search.
  411. */
  412. rec_ptr_list = _DtDtsMMGetPtr(db->recordList);
  413. for (i = 0; i < db->recordCount; i++)
  414. {
  415. rec_ptr = &rec_ptr_list[i];
  416. if (rec_ptr->recordName == name_quark)
  417. {
  418. return (rec_ptr);
  419. }
  420. }
  421. return NULL;
  422. }
  423. int
  424. _DtDtsMMPathHash(DtDirPaths *dirs)
  425. {
  426. int pathhash = 0;
  427. DIR *dirp;
  428. struct dirent *dp = NULL;
  429. int suffixLen;
  430. int nameLen;
  431. char *file_suffix;
  432. char *next_path;
  433. char *suffix = ".dt";
  434. int i;
  435. char *cur_dir = getcwd(0,MAXPATHLEN);
  436. struct stat buf;
  437. _Xreaddirparams dirEntryBuf;
  438. struct dirent *result;
  439. for(i = 0; dirs->paths[i] ; i++)
  440. {
  441. if(chdir(dirs->paths[i]) == -1)
  442. {
  443. continue;
  444. }
  445. dirp = opendir (".");
  446. while ((result = _XReaddir(dirp, dirEntryBuf)) != NULL)
  447. {
  448. if ((int)strlen (result->d_name) >= (int)strlen(suffix))
  449. {
  450. suffixLen = DtCharCount(suffix);
  451. nameLen = DtCharCount(result->d_name);
  452. file_suffix = (char *)_DtGetNthChar(result->d_name,
  453. nameLen - suffixLen);
  454. stat(result->d_name, &buf);
  455. if (file_suffix &&
  456. (strcmp(file_suffix, suffix) == 0) &&
  457. (buf.st_mode&S_IFREG))
  458. {
  459. char *c = dirs->paths[i];
  460. while(*c)
  461. {
  462. pathhash += (int)*c;
  463. c++;
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. closedir(dirp);
  470. }
  471. chdir(cur_dir);
  472. free(cur_dir);
  473. return(pathhash);
  474. }
  475. char *
  476. _DtDtsMMCacheName(int override)
  477. {
  478. char *dsp = getenv("DISPLAY");
  479. char *results = 0;
  480. char *c;
  481. if(override && dsp)
  482. {
  483. results = malloc(strlen(_DTDTSMMTEMPDIR)+
  484. strlen(_DTDTSMMTEMPFILE)+
  485. strlen(dsp)+3);
  486. sprintf(results, "%s/%s%s\0",
  487. _DTDTSMMTEMPDIR,
  488. _DTDTSMMTEMPFILE,
  489. dsp);
  490. c = strchr(results, ':');
  491. c = strchr(c, '.');
  492. if(c)
  493. {
  494. *c = '\0';
  495. }
  496. }
  497. else
  498. {
  499. /* tempnam(3) is affected by the TMPDIR environment variable. */
  500. /* This creates problems for rename() if "tmpfile" and "cacheFile" */
  501. /* are on different file systems. Use tmpnam(3) to create the */
  502. /* unique file name instead. */
  503. char tmpnam_buf[L_tmpnam + 1];
  504. results = (char *)malloc(strlen(_DTDTSMMTEMPDIR) +
  505. strlen(_DTDTSMMTEMPFILE) +
  506. L_tmpnam + 3);
  507. tmpnam(tmpnam_buf);
  508. sprintf(results, "%s/%s%s", _DTDTSMMTEMPDIR, _DTDTSMMTEMPFILE,
  509. basename(tmpnam_buf));
  510. }
  511. return(results);
  512. }
  513. int
  514. _DtDtsMMapDB(const char *CacheFile)
  515. {
  516. struct stat buf;
  517. int success = FALSE;
  518. _DtSvcProcessLock();
  519. if (mmaped_fd > 0)
  520. {
  521. /* Already have a file memory-mapped. Unload it. */
  522. _DtDtsMMUnLoad();
  523. }
  524. mmaped_fd = open(CacheFile, O_RDONLY, 0400);
  525. if(mmaped_fd != -1)
  526. {
  527. if(fstat(mmaped_fd, &buf) == 0 && buf.st_uid == getuid())
  528. {
  529. mmaped_db = (char *)mmap(NULL,
  530. buf.st_size,
  531. PROT_READ,
  532. #if defined(sun)
  533. /* MAP_NORESERVE is only supported
  534. on sun and novell platforms */
  535. MAP_SHARED|MAP_NORESERVE,
  536. #else
  537. MAP_SHARED,
  538. #endif
  539. mmaped_fd,
  540. 0);
  541. if(mmaped_db != (void *) -1)
  542. {
  543. success = TRUE;
  544. mmaped_size = buf.st_size;
  545. head = (DtDtsMMHeader *)mmaped_db;
  546. db_list = (DtDtsMMDatabase *)_DtDtsMMGetPtr(head->db_offset);
  547. }
  548. else
  549. {
  550. _DtSimpleError(
  551. DtProgName, DtError, NULL,
  552. (char*) CacheFile, NULL);
  553. }
  554. }
  555. }
  556. if(!success)
  557. {
  558. mmaped_db = 0;
  559. }
  560. _DtSvcProcessUnlock();
  561. return(success);
  562. }
  563. static int
  564. MMValidateDb(DtDirPaths *dirs, char *suffix)
  565. {
  566. DIR *dirp;
  567. struct dirent *direntp;
  568. struct stat buf;
  569. struct stat new_buf;
  570. int size = sizeof(buf.st_mtime);
  571. DtShmBoson *boson_list = 0;
  572. time_t *mtime_list;
  573. int count = 0;
  574. int i;
  575. const char *file;
  576. int pathhash = _DtDtsMMPathHash(dirs);
  577. _DtSvcProcessLock();
  578. if(head->pathhash != pathhash)
  579. {
  580. _DtSvcProcessUnlock();
  581. return(0);
  582. }
  583. count = head->files_count;
  584. mtime_list = _DtDtsMMGetPtr(head->mtimes_offset);
  585. boson_list = _DtDtsMMGetPtr(head->files_offset);
  586. for(i = 0; i < count; i++)
  587. {
  588. file = _DtDtsMMBosonToString(boson_list[i]);
  589. stat(file, &buf);
  590. if(mtime_list[i] != buf.st_mtime)
  591. {
  592. _DtSvcProcessUnlock();
  593. return(0);
  594. }
  595. }
  596. _DtSvcProcessUnlock();
  597. return(1);
  598. }
  599. char *
  600. _DtDtsMMExpandValue(const char *value)
  601. {
  602. char *newval;
  603. if(!value)
  604. {
  605. return NULL;
  606. }
  607. newval = (char *)malloc(1024);
  608. strcpy(newval, value);
  609. _DtDbFillVariables(&newval);
  610. return(newval);
  611. }
  612. void
  613. _DtDtsMMSafeFree(char *value)
  614. {
  615. if(value && !_DtDtsMMIsMemory(value))
  616. {
  617. free(value);
  618. }
  619. }
  620. int
  621. _DtDtsMMIsMemory(const char *value)
  622. {
  623. _DtSvcProcessLock();
  624. if((caddr_t)value < mmaped_db || (caddr_t)value > mmaped_db+mmaped_size)
  625. {
  626. _DtSvcProcessUnlock();
  627. return(0);
  628. }
  629. else
  630. {
  631. _DtSvcProcessUnlock();
  632. return(1);
  633. }
  634. }
  635. int
  636. _DtDtsMMUnLoad()
  637. {
  638. int error = 0;
  639. _DtSvcProcessLock();
  640. _DtDtsClear();
  641. if(mmaped_db == 0)
  642. {
  643. _DtSvcProcessUnlock();
  644. return(error);
  645. }
  646. if(munmap(mmaped_db, mmaped_size) == -1)
  647. {
  648. _DtSimpleError(DtProgName, DtError, NULL,
  649. "munmap of dts_cache file", NULL);
  650. error = -1;
  651. }
  652. if(close(mmaped_fd) == -1)
  653. {
  654. _DtSimpleError(DtProgName, DtError, NULL,
  655. "close of dts_cache file", NULL);
  656. }
  657. db_list = 0;
  658. mmaped_db = 0;
  659. mmaped_size = 0;
  660. mmaped_fd = 0;
  661. head = 0;
  662. _DtSvcProcessUnlock();
  663. return(error);
  664. }
  665. #include "Dt/UserMsg.h"
  666. static int
  667. _debug_print_name(char *name, char *label)
  668. {
  669. #ifdef DEBUG
  670. static char *db = (char *)-1;
  671. _DtSvcProcessLock();
  672. if(db == (char *)-1)
  673. {
  674. db = getenv("MMAP_DEBUG");
  675. }
  676. _DtSvcProcessUnlock();
  677. if(db)
  678. _DtSimpleError(db,
  679. DtInformation,
  680. NULL,
  681. "%s - db name = %s\n", label,
  682. name);
  683. #endif /* DEBUG */
  684. return(0);
  685. }