summaryrefslogtreecommitdiff
path: root/server/confdb
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2009-04-16 11:37:22 -0400
committerSimo Sorce <ssorce@redhat.com>2009-04-16 12:17:28 -0400
commit400204ad90917fd1d9fe63a273b9372d042fed30 (patch)
tree750e779a2c32bd48ccb7a5314ffdf6f12bf9bf65 /server/confdb
parent6ff8473bf537af9bb34e46842374e4eef2288968 (diff)
downloadsssd-400204ad90917fd1d9fe63a273b9372d042fed30.tar.gz
sssd-400204ad90917fd1d9fe63a273b9372d042fed30.tar.bz2
sssd-400204ad90917fd1d9fe63a273b9372d042fed30.zip
Avoid unnecessary reloads of config.ldb
Add code to check if the file has changed since the last update was performed. Avoid dumping and reloading the config ldb if the modification time of the configuration file has not changed at all.
Diffstat (limited to 'server/confdb')
-rw-r--r--server/confdb/confdb.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c
index 1f642ca1..fcb4c8ab 100644
--- a/server/confdb/confdb.c
+++ b/server/confdb/confdb.c
@@ -21,11 +21,9 @@
#define _GNU_SOURCE
-#include "talloc.h"
-#include "tevent.h"
+#include <sys/stat.h>
#include "config.h"
#include "ldb.h"
-#include "ldb_errors.h"
#include "util/util.h"
#include "confdb/confdb.h"
#include "confdb/confdb_private.h"
@@ -875,9 +873,36 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
char *config_ldif;
struct ldb_ldif *ldif;
TALLOC_CTX *tmp_ctx;
+ char *lasttimestr, timestr[21];
+ const char *vals[2] = { timestr, NULL };
+ struct stat cstat;
tmp_ctx = talloc_new(cdb);
- if(tmp_ctx == NULL) return ENOMEM;
+ if (tmp_ctx == NULL) return ENOMEM;
+
+ /* ok, first of all stat conf file */
+ ret = stat(config_file, &cstat);
+ if (ret != 0) {
+ DEBUG(0, ("Unable to stat config file [%s]! (%d [%s])\n",
+ config_file, errno, strerror(errno)));
+ return errno;
+ }
+ ret = snprintf(timestr, 21, "%llu", (long long unsigned)cstat.st_mtime);
+ if (ret <= 0 || ret >= 21) {
+ DEBUG(0, ("Failed to convert time_t to string ??\n"));
+ return errno ? errno: EFAULT;
+ }
+
+ /* check if we need to re-init the db */
+ ret = confdb_get_string(cdb, tmp_ctx, "config", "lastUpdate", NULL, &lasttimestr);
+ if (ret == EOK && lasttimestr != NULL) {
+
+ /* now check if we lastUpdate and last file modification change differ*/
+ if (strcmp(lasttimestr, timestr) == 0) {
+ /* not changed, get out, nothing more to do */
+ return EOK;
+ }
+ }
/* Set up a transaction to replace the configuration */
ret = ldb_transaction_start(cdb->ldb);
@@ -927,6 +952,14 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
ldb_ldif_read_free(cdb->ldb, ldif);
}
+ /* now store the lastUpdate time so that we do not re-init if nothing
+ * changed on restart */
+
+ ret = confdb_add_param(cdb, true, "config", "lastUpdate", vals);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to set last update time on db!\n"));
+ }
+
ret = EOK;
done: