libsmbconf: change smbconf_get_seqnum() to smbconf_changed().
authorMichael Adam <obnox@samba.org>
Tue, 18 Mar 2008 22:29:11 +0000 (23:29 +0100)
committerMichael Adam <obnox@samba.org>
Fri, 21 Mar 2008 01:25:55 +0000 (02:25 +0100)
The former seqnum is hidden inside a struct smbconf_csn.
And the get_seqnum is united with a changed function that
stores the seqnum inside the given csn.

Michael

source/lib/smbconf/smbconf.c
source/lib/smbconf/smbconf.h
source/param/loadparm.c

index dc45a16c48d57961ab70264be67461879fb163e2..454056167e4a0f748162bf0b831a37b52b254b4d 100644 (file)
@@ -417,6 +417,20 @@ static int smbconf_destroy_ctx(struct smbconf_ctx *ctx)
        return regdb_close();
 }
 
+/**
+ * Get the change sequence number of the given service/parameter.
+ * service and parameter strings may be NULL.
+ */
+static void smbconf_reg_get_csn(struct smbconf_ctx *ctx,
+                               struct smbconf_csn *csn,
+                               const char *service, const char *param)
+{
+       if (csn == NULL) {
+               return;
+       }
+       csn->csn = (uint64_t)regdb_get_seqnum();
+}
+
 /**********************************************************************
  *
  * The actual net conf api functions, that are exported.
@@ -475,16 +489,24 @@ void smbconf_close(struct smbconf_ctx *ctx)
 }
 
 /**
- * Get the change sequence number of the given service/parameter.
- *
- * NOTE: Currently, for registry configuration, this is independent
- * of the service and parameter, it returns the registry-sequence
- * number.
+ * Detect changes in the configuration.
+ * The given csn struct is filled with the current csn.
+ * smbconf_changed() can also be used for initial retrieval
+ * of the csn.
  */
-uint64_t smbconf_get_seqnum(struct smbconf_ctx *ctx,
-                           const char *service, const char *param)
+bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
+                    const char *service, const char *param)
 {
-       return (uint64_t)regdb_get_seqnum();
+       struct smbconf_csn old_csn;
+
+       if (csn == NULL) {
+               return false;
+       }
+
+       old_csn = *csn;
+
+       smbconf_reg_get_csn(ctx, csn, service, param);
+       return (csn->csn != old_csn.csn);
 }
 
 /**
index d2e05045f7b819ca24808f38718cb0da7a4663d5..134dc29c09eb881eff18896bd37e7802a4d6abd9 100644 (file)
@@ -24,6 +24,11 @@ struct smbconf_ctx {
        NT_USER_TOKEN *token;
 };
 
+/* the change sequence number */
+struct smbconf_csn {
+       uint64_t csn;
+};
+
 /*
  * WARNING:
  *   Of this API, at least the open function is still subject to change.
@@ -32,8 +37,8 @@ struct smbconf_ctx {
 
 WERROR smbconf_open(TALLOC_CTX *mem_ctx, struct smbconf_ctx **conf_ctx);
 void smbconf_close(struct smbconf_ctx *ctx);
-uint64_t smbconf_get_seqnum(struct smbconf_ctx *ctx,
-                           const char *service, const char *param);
+bool smbconf_changed(struct smbconf_ctx *ctx, struct smbconf_csn *csn,
+                    const char *service, const char *param);
 WERROR smbconf_drop(struct smbconf_ctx *ctx);
 WERROR smbconf_get_config(TALLOC_CTX *mem_ctx,
                          struct smbconf_ctx *ctx, uint32_t *num_shares,
index 04fade578937d288b9eb76ce06b9df48119090d5..37d68ba4afed25ad277568df2183cb8b7500c44a 100644 (file)
@@ -71,7 +71,7 @@ extern userdom_struct current_user_info;
 #endif
 
 static bool in_client = False;         /* Not in the client by default */
-static uint64_t conf_last_seqnum = 0;
+static struct smbconf_csn conf_last_csn;
 static struct smbconf_ctx *conf_ctx = NULL;
 
 #define CONFIG_BACKEND_FILE 0
@@ -6524,7 +6524,8 @@ static bool process_registry_globals(bool (*pfunc)(const char *, const char *))
        }
 
        ret = pfunc("registry shares", "yes");
-       conf_last_seqnum = smbconf_get_seqnum(conf_ctx, NULL, NULL);
+       /* store the csn */
+       smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL);
 
 done:
        TALLOC_FREE(mem_ctx);
@@ -6604,7 +6605,6 @@ bool lp_file_list_changed(void)
        DEBUG(6, ("lp_file_list_changed()\n"));
 
        if (lp_config_backend_is_registry()) {
-               uint64_t conf_cur_seqnum;
                if (conf_ctx == NULL) {
                        WERROR werr;
                        werr = smbconf_open(NULL, &conf_ctx);
@@ -6614,12 +6614,8 @@ bool lp_file_list_changed(void)
                                return false;
                        }
                }
-               conf_cur_seqnum = smbconf_get_seqnum(conf_ctx, NULL, NULL);
-               if (conf_last_seqnum != conf_cur_seqnum) {
-                       DEBUGADD(6, ("regdb seqnum changed: old = %llu, "
-                                    "new = %llu\n",
-                                    (unsigned long long)conf_last_seqnum,
-                                    (unsigned long long)conf_cur_seqnum));
+               if (smbconf_changed(conf_ctx, &conf_last_csn, NULL, NULL)) {
+                       DEBUGADD(6, ("registry config changed\n"));
                        return true;
                }
        }