dbchange.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * COMPONENT_NAME: austext
  25. *
  26. * FUNCTIONS: database_has_changed
  27. * file_has_changed
  28. *
  29. * ORIGINS: 27
  30. *
  31. *
  32. * (C) COPYRIGHT International Business Machines Corp. 1995
  33. * All Rights Reserved
  34. * Licensed Materials - Property of IBM
  35. * US Government Users Restricted Rights - Use, duplication or
  36. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  37. */
  38. /******************************* DBCHANGE.C ********************************
  39. * $XConsortium: dbchange.c /main/4 1996/05/07 13:26:54 drk $
  40. * March 1995.
  41. * Extracted from oe.c so it could also be called by server daemon.
  42. * When called only in the engine it was only called by a child
  43. * of the daemon, so the original daemon was never updated and
  44. * every single engine call resulted in an engine reinitialization.
  45. *
  46. * $Log$
  47. * Revision 2.2 1995/10/26 15:31:24 miker
  48. * Added prolog.
  49. *
  50. * Revision 2.1 1995/09/22 19:47:12 miker
  51. * Freeze DtSearch 0.1, AusText 2.1.8
  52. *
  53. * Revision 1.2 1995/08/31 22:18:48 miker
  54. * Minor changes for DtSearch including msg catalogs and
  55. * replacing socblk with usrblk for head of dblist.
  56. */
  57. #include "SearchE.h"
  58. #include <errno.h>
  59. #include <sys/stat.h>
  60. #define PROGNAME "DBCHANGE"
  61. void oe_uninitialize (void);
  62. /************************************************/
  63. /* */
  64. /* file_has_changed */
  65. /* */
  66. /************************************************/
  67. /* If site config file or any d99 file has changed
  68. * since program initialization, close all databases and reinitialize.
  69. * This usually happens when the administrator has updated
  70. * a copy of one of the databases in a different directory.
  71. * He then changes the PATH parameter for that database in the
  72. * site config file. By closing databases and reinitializing,
  73. * an administrator can swap databases without bringing the users down.
  74. * The test for the d99 files is included because in some systems,
  75. * like cose, a database may change without a corresponding
  76. * change in the site config file.
  77. * Databases cannot be swapped during an ongoing search.
  78. * If the passed file's mod time is unaccessible or has changed,
  79. * appends msg to msglist, reinitializes engine if necessary,
  80. * sets up usrblk.retncode, and returns TRUE.
  81. * Otherwise returns FALSE.
  82. */
  83. static int file_has_changed (char *fname, time_t origtime)
  84. {
  85. struct stat statbuf;
  86. char sprintbuf[1024];
  87. if (stat (fname, &statbuf) == -1) {
  88. sprintf (sprintbuf, CATGETS(dtsearch_catd, 10, 1300,
  89. "%s Unable to comply with request; cannot access status\n"
  90. " of database file '%s': %s"),
  91. PROGNAME "1300", fname, strerror (errno));
  92. DtSearchAddMessage (sprintbuf);
  93. usrblk.retncode = OE_NOOP;
  94. return TRUE;
  95. }
  96. if (origtime != statbuf.st_mtime) {
  97. strcpy (sprintbuf, nowstring (&origtime));
  98. fprintf (aa_stderr,
  99. "%s %s reinitialized AusText engine:\n"
  100. " changed file: %s\n"
  101. " old file time: %s\n"
  102. " current file time: %s.\n",
  103. PROGNAME "1312", aa_argv0, fname,
  104. sprintbuf, nowstring (&statbuf.st_mtime));
  105. if (!(usrblk.flags & USR_NO_INFOMSGS)) {
  106. sprintf (sprintbuf, CATGETS(dtsearch_catd, 10, 1313,
  107. "%s *** REQUEST CANCELED *** %s Engine reinitialized\n"
  108. " due to modification of file %s, probably caused by\n"
  109. " update to one or more databases."),
  110. PROGNAME "1313", OE_prodname, fname);
  111. DtSearchAddMessage (sprintbuf);
  112. }
  113. oe_uninitialize ();
  114. oe_initialize ();
  115. usrblk.retncode = OE_REINIT;
  116. return TRUE;
  117. }
  118. return FALSE;
  119. } /* file_has_changed() */
  120. /************************************************/
  121. /* */
  122. /* database_has_changed */
  123. /* */
  124. /************************************************/
  125. /* Verify that none of the databases has changed since the last call.
  126. * Don't check until after first initialize.
  127. * Returns TRUE if any changes, else FALSE.
  128. */
  129. int database_has_changed (void)
  130. {
  131. char fnamebuf[256];
  132. DBLK *db;
  133. if (OE_sitecnfg_mtime == 0L)
  134. return FALSE;
  135. if (file_has_changed (OE_sitecnfg_fname, OE_sitecnfg_mtime))
  136. return TRUE;
  137. for (db = usrblk.dblist; db != NULL; db = db->link) {
  138. sprintf (fnamebuf, "%s%s" EXT_DTBS, db->path, db->name);
  139. if (file_has_changed (fnamebuf, db->iimtime))
  140. return TRUE;
  141. }
  142. return FALSE;
  143. } /* database_has_changed() */
  144. /******************************* DBCHANGE.C ********************************/