#include "lib/param/param.h"
#include "poll_funcs/poll_funcs_tevent.h"
#include "unix_msg/unix_msg.h"
+#include "lib/util/genrand.h"
struct sun_path_buf {
/*
static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
pid_t pid, int *plockfile_fd,
- uint64_t unique)
+ uint64_t *punique)
{
char buf[64];
int lockfile_fd;
struct sun_path_buf lockfile_name;
struct flock lck;
+ uint64_t unique;
int unique_len, ret;
ssize_t written;
goto fail_close;
}
+ /*
+ * Directly using the binary value for
+ * SERVERID_UNIQUE_ID_NOT_TO_VERIFY is a layering
+ * violation. But including all of ndr here just for this
+ * seems to be a bit overkill to me. Also, messages_dgm might
+ * be replaced sooner or later by something streams-based,
+ * where unique_id generation will be handled differently.
+ */
+
+ do {
+ generate_random_buffer((uint8_t *)&unique, sizeof(unique));
+ } while (unique == UINT64_C(0xFFFFFFFFFFFFFFFF));
+
unique_len = snprintf(buf, sizeof(buf), "%ju\n", (uintmax_t)unique);
/* shorten a potentially preexisting file */
}
*plockfile_fd = lockfile_fd;
+ *punique = unique;
return 0;
fail_unlink:
}
int messaging_dgm_init(struct tevent_context *ev,
- uint64_t unique,
+ uint64_t *punique,
const char *socket_dir,
const char *lockfile_dir,
void (*recv_cb)(const uint8_t *msg,
}
ret = messaging_dgm_lockfile_create(ctx, ctx->pid, &ctx->lockfile_fd,
- unique);
+ punique);
if (ret != 0) {
DEBUG(1, ("%s: messaging_dgm_create_lockfile failed: %s\n",
__func__, strerror(ret)));