2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 * COMPONENT_NAME: austext
26 * FUNCTIONS: database_has_changed
32 * (C) COPYRIGHT International Business Machines Corp. 1995
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.
38 /******************************* DBCHANGE.C ********************************
39 * $XConsortium: dbchange.c /main/4 1996/05/07 13:26:54 drk $
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.
47 * Revision 2.2 1995/10/26 15:31:24 miker
50 * Revision 2.1 1995/09/22 19:47:12 miker
51 * Freeze DtSearch 0.1, AusText 2.1.8
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.
61 #define PROGNAME "DBCHANGE"
63 /************************************************/
65 /* file_has_changed */
67 /************************************************/
68 /* If site config file or any d99 file has changed
69 * since program initialization, close all databases and reinitialize.
70 * This usually happens when the administrator has updated
71 * a copy of one of the databases in a different directory.
72 * He then changes the PATH parameter for that database in the
73 * site config file. By closing databases and reinitializing,
74 * an administrator can swap databases without bringing the users down.
75 * The test for the d99 files is included because in some systems,
76 * like cose, a database may change without a corresponding
77 * change in the site config file.
78 * Databases cannot be swapped during an ongoing search.
79 * If the passed file's mod time is unaccessible or has changed,
80 * appends msg to msglist, reinitializes engine if necessary,
81 * sets up usrblk.retncode, and returns TRUE.
82 * Otherwise returns FALSE.
84 static int file_has_changed (char *fname, time_t origtime)
89 if (stat (fname, &statbuf) == -1) {
90 sprintf (sprintbuf, catgets (dtsearch_catd, 10, 1300,
91 "%s Unable to comply with request; cannot access status\n"
92 " of database file '%s': %s"),
93 PROGNAME "1300", fname, strerror (errno));
94 DtSearchAddMessage (sprintbuf);
95 usrblk.retncode = OE_NOOP;
98 if (origtime != statbuf.st_mtime) {
99 strcpy (sprintbuf, nowstring (&origtime));
101 "%s %s reinitialized AusText engine:\n"
102 " changed file: %s\n"
103 " old file time: %s\n"
104 " current file time: %s.\n",
105 PROGNAME "1312", aa_argv0, fname,
106 sprintbuf, nowstring (&statbuf.st_mtime));
107 if (!(usrblk.flags & USR_NO_INFOMSGS)) {
108 sprintf (sprintbuf, catgets (dtsearch_catd, 10, 1313,
109 "%s *** REQUEST CANCELED *** %s Engine reinitialized\n"
110 " due to modification of file %s, probably caused by\n"
111 " update to one or more databases."),
112 PROGNAME "1313", OE_prodname, fname);
113 DtSearchAddMessage (sprintbuf);
117 usrblk.retncode = OE_REINIT;
121 } /* file_has_changed() */
124 /************************************************/
126 /* database_has_changed */
128 /************************************************/
129 /* Verify that none of the databases has changed since the last call.
130 * Don't check until after first initialize.
131 * Returns TRUE if any changes, else FALSE.
133 int database_has_changed (void)
138 if (OE_sitecnfg_mtime == 0L)
140 if (file_has_changed (OE_sitecnfg_fname, OE_sitecnfg_mtime))
142 for (db = usrblk.dblist; db != NULL; db = db->link) {
143 sprintf (fnamebuf, "%s%s" EXT_DTBS, db->path, db->name);
144 if (file_has_changed (fnamebuf, db->iimtime))
148 } /* database_has_changed() */
150 /******************************* DBCHANGE.C ********************************/