unix_msg: remove cookie from unix_msg_init
authorVolker Lendecke <vl@samba.org>
Sun, 14 Sep 2014 15:52:07 +0000 (17:52 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 13 Feb 2015 22:32:06 +0000 (23:32 +0100)
"pid" and "sock" are sufficient I guess as randomizers to distinguish messages.
In theory, a pid could be recycled very quickly, which might mix up in-flight
messages. But once a few messages have passed, "cookie" would be incremented as
another indicator of a fresh message.

Why? Remove messages_dgm dependency on samba-util

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/messages_dgm.c
source3/lib/unix_msg/test_drain.c
source3/lib/unix_msg/test_source.c
source3/lib/unix_msg/tests.c
source3/lib/unix_msg/unix_msg.c
source3/lib/unix_msg/unix_msg.h

index b64b2b0a752c11b0992b1dc94d7f3a620534c2a7..1602caf9bd0487714a7208347d633d5b7e71ea02 100644 (file)
@@ -144,7 +144,6 @@ int messaging_dgm_init(struct tevent_context *ev,
        struct messaging_dgm_context *ctx;
        int ret;
        struct sockaddr_un socket_address;
-       uint64_t cookie;
        size_t len;
        static bool have_dgm_context = false;
 
@@ -205,9 +204,7 @@ int messaging_dgm_init(struct tevent_context *ev,
 
        unlink(socket_address.sun_path);
 
-       generate_random_buffer((uint8_t *)&cookie, sizeof(cookie));
-
-       ret = unix_msg_init(&socket_address, ctx->msg_callbacks, 1024, cookie,
+       ret = unix_msg_init(&socket_address, ctx->msg_callbacks, 1024,
                            messaging_dgm_recv, ctx, &ctx->dgm_ctx);
        if (ret != 0) {
                DEBUG(1, ("unix_msg_init failed: %s\n", strerror(ret)));
index 9d740421f32bcf74063d470d32162869fb0d7c8a..675ac6f94e51b4cbc0887b0eb1f3c3e4b5eac668 100644 (file)
@@ -52,7 +52,7 @@ int main(int argc, const char *argv[])
                exit(1);
        }
 
-       ret = unix_msg_init(&addr, funcs, 256, 1, recv_cb, &state, &ctx);
+       ret = unix_msg_init(&addr, funcs, 256, recv_cb, &state, &ctx);
        if (ret != 0) {
                fprintf(stderr, "unix_msg_init failed: %s\n",
                        strerror(ret));
index 5224ebff6f6f247d6cb3f35a7412b2501c7f436f..3b6526763a2936ca1420eb6ed85143ea5df21cd2 100644 (file)
@@ -46,7 +46,7 @@ int main(int argc, const char *argv[])
        }
 
        for (i=0; i<num_ctxs; i++) {
-               ret = unix_msg_init(NULL, funcs, 256, 1, NULL, NULL,
+               ret = unix_msg_init(NULL, funcs, 256, NULL, NULL,
                                    &ctxs[i]);
                if (ret != 0) {
                        fprintf(stderr, "unix_msg_init failed: %s\n",
index df094afb3d811bc3300387f9d68a0a231a1f83ff..9a15f9dff1e01559279a472cf66145f7bccab216 100644 (file)
@@ -70,16 +70,14 @@ int main(void)
                return 1;
        }
 
-       ret = unix_msg_init(&addr1, funcs, 256, 1,
-                           recv_cb, &state, &ctx1);
+       ret = unix_msg_init(&addr1, funcs, 256, recv_cb, &state, &ctx1);
        if (ret != 0) {
                fprintf(stderr, "unix_msg_init failed: %s\n",
                        strerror(ret));
                return 1;
        }
 
-       ret = unix_msg_init(&addr1, funcs, 256, 1,
-                           recv_cb, &state, &ctx1);
+       ret = unix_msg_init(&addr1, funcs, 256, recv_cb, &state, &ctx1);
        if (ret == 0) {
                fprintf(stderr, "unix_msg_init succeeded unexpectedly\n");
                return 1;
@@ -90,8 +88,7 @@ int main(void)
                return 1;
        }
 
-       ret = unix_msg_init(&addr2, funcs, 256, 1,
-                           recv_cb, &state, &ctx2);
+       ret = unix_msg_init(&addr2, funcs, 256, recv_cb, &state, &ctx2);
        if (ret != 0) {
                fprintf(stderr, "unix_msg_init failed: %s\n",
                        strerror(ret));
index e4eed1c2bc377fe4c224bc42c55d8cc27c21fc16..6714f0d312c8a2b90eb210d8e39181c3be398690 100644 (file)
@@ -744,7 +744,7 @@ static void unix_msg_recv(struct unix_dgram_ctx *dgram_ctx,
 
 int unix_msg_init(const struct sockaddr_un *addr,
                  const struct poll_funcs *ev_funcs,
-                 size_t fragment_len, uint64_t cookie,
+                 size_t fragment_len,
                  void (*recv_callback)(struct unix_msg_ctx *ctx,
                                        uint8_t *msg, size_t msg_len,
                                        int *fds, size_t num_fds,
@@ -762,7 +762,7 @@ int unix_msg_init(const struct sockaddr_un *addr,
 
        *ctx = (struct unix_msg_ctx) {
                .fragment_len = fragment_len,
-               .cookie = cookie,
+               .cookie = 1,
                .recv_callback = recv_callback,
                .private_data = private_data
        };
index 83d7067408405f0476160449c37f052f6c4e1e5a..34c166bc666bdebab7ac51614c1c2f05a5555985 100644 (file)
@@ -75,7 +75,6 @@ struct unix_msg_ctx;
  * @param[in] path The socket path
  * @param[in] ev_funcs The event callback functions to use
  * @param[in] fragment_size Maximum datagram size to send/receive
- * @param[in] cookie Random number to identify this context
  * @param[in] recv_callback Function called when a message is received
  * @param[in] private_data Private pointer for recv_callback
  * @param[out] result The new struct unix_msg_ctx
@@ -85,7 +84,7 @@ struct unix_msg_ctx;
 
 int unix_msg_init(const struct sockaddr_un *addr,
                  const struct poll_funcs *ev_funcs,
-                 size_t fragment_size, uint64_t cookie,
+                 size_t fragment_size,
                  void (*recv_callback)(struct unix_msg_ctx *ctx,
                                        uint8_t *msg, size_t msg_len,
                                        int *fds, size_t num_fds,