libndr: Avoid assigning duplicate versions to symbols
[amitay/samba.git] / source3 / lib / cleanupdb.c
index 8832abe27d691c553e849a357da0de1063ff166e..93d6acc9e44db4506562ff9586c1918decd56dad 100644 (file)
@@ -24,8 +24,6 @@ struct cleanup_key {
 };
 
 struct cleanup_rec {
-       /* Storing the pid here as well saves a few lines of code */
-       pid_t pid;
        bool unclean;
 };
 
@@ -40,7 +38,7 @@ static struct tdb_wrap *cleanup_db(void)
                return db;
        }
 
-       db_path = lock_path("smbd_cleanupd.tdb");
+       db_path = lock_path(talloc_tos(), "smbd_cleanupd.tdb");
        if (db_path == NULL) {
                return NULL;
        }
@@ -59,9 +57,9 @@ bool cleanupdb_store_child(const pid_t pid, const bool unclean)
 {
        struct tdb_wrap *db;
        struct cleanup_key key = { .pid = pid };
-       struct cleanup_rec rec = { .pid = pid, .unclean = unclean };
+       struct cleanup_rec rec = { .unclean = unclean };
        TDB_DATA tdbkey = { .dptr = (uint8_t *)&key, .dsize = sizeof(key) };
-       TDB_DATA tdbdata = { .dptr = (uint8_t *)&key, .dsize = sizeof(rec) };
+       TDB_DATA tdbdata = { .dptr = (uint8_t *)&rec, .dsize = sizeof(rec) };
        int result;
 
        db = cleanup_db();
@@ -99,20 +97,6 @@ bool cleanupdb_delete_child(const pid_t pid)
        return true;
 }
 
-static bool cleanup_rec_parse(TDB_DATA tdbdata,
-                             struct cleanup_rec *cleanup_rec)
-{
-       if (tdbdata.dsize != sizeof(struct cleanup_rec)) {
-               DBG_ERR("Found invalid value length %d in cleanup.tdb\n",
-                       (int)tdbdata.dsize);
-               return false;
-       }
-
-       memcpy(cleanup_rec, tdbdata.dptr, sizeof(struct cleanup_rec));
-
-       return true;
-}
-
 struct cleanup_read_state {
        int (*fn)(const pid_t pid, const bool cleanup, void *private_data);
        void *private_data;
@@ -124,16 +108,25 @@ static int cleanup_traverse_fn(struct tdb_context *tdb,
 {
        struct cleanup_read_state *state =
                (struct cleanup_read_state *)private_data;
+       struct cleanup_key ckey;
        struct cleanup_rec rec;
-       bool ok;
        int result;
 
-       ok = cleanup_rec_parse(value, &rec);
-       if (!ok) {
+       if (key.dsize != sizeof(struct cleanup_key)) {
+               DBG_ERR("Found invalid key length %zu in cleanup.tdb\n",
+                       key.dsize);
+               return -1;
+       }
+       memcpy(&ckey, key.dptr, sizeof(struct cleanup_key));
+
+       if (value.dsize != sizeof(struct cleanup_rec)) {
+               DBG_ERR("Found invalid value length %zu in cleanup.tdb\n",
+                       value.dsize);
                return -1;
        }
+       memcpy(&rec, value.dptr, sizeof(struct cleanup_rec));
 
-       result = state->fn(rec.pid, rec.unclean, state->private_data);
+       result = state->fn(ckey.pid, rec.unclean, state->private_data);
        if (result != 0) {
                return -1;
        }