mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
lib: Push down unique generation one level
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
a788fd3065
commit
01d7e26f7f
@ -303,7 +303,6 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
|
|||||||
ctx->id = (struct server_id) {
|
ctx->id = (struct server_id) {
|
||||||
.pid = getpid(), .vnn = NONCLUSTER_VNN
|
.pid = getpid(), .vnn = NONCLUSTER_VNN
|
||||||
};
|
};
|
||||||
ctx->id.unique_id = serverid_get_random_unique_id();
|
|
||||||
|
|
||||||
ctx->event_ctx = ev;
|
ctx->event_ctx = ev;
|
||||||
|
|
||||||
@ -340,7 +339,7 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx->msg_dgm_ref = messaging_dgm_ref(
|
ctx->msg_dgm_ref = messaging_dgm_ref(
|
||||||
ctx, ctx->event_ctx, ctx->id.unique_id,
|
ctx, ctx->event_ctx, &ctx->id.unique_id,
|
||||||
priv_path, lck_path, messaging_recv_cb, ctx, &ret);
|
priv_path, lck_path, messaging_recv_cb, ctx, &ret);
|
||||||
|
|
||||||
if (ctx->msg_dgm_ref == NULL) {
|
if (ctx->msg_dgm_ref == NULL) {
|
||||||
@ -400,10 +399,9 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
|
|||||||
msg_ctx->id = (struct server_id) {
|
msg_ctx->id = (struct server_id) {
|
||||||
.pid = getpid(), .vnn = msg_ctx->id.vnn
|
.pid = getpid(), .vnn = msg_ctx->id.vnn
|
||||||
};
|
};
|
||||||
msg_ctx->id.unique_id = serverid_get_random_unique_id();
|
|
||||||
|
|
||||||
msg_ctx->msg_dgm_ref = messaging_dgm_ref(
|
msg_ctx->msg_dgm_ref = messaging_dgm_ref(
|
||||||
msg_ctx, msg_ctx->event_ctx, msg_ctx->id.unique_id,
|
msg_ctx, msg_ctx->event_ctx, &msg_ctx->id.unique_id,
|
||||||
private_path("msg.sock"), lock_path("msg.lock"),
|
private_path("msg.sock"), lock_path("msg.lock"),
|
||||||
messaging_recv_cb, msg_ctx, &ret);
|
messaging_recv_cb, msg_ctx, &ret);
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "lib/param/param.h"
|
#include "lib/param/param.h"
|
||||||
#include "poll_funcs/poll_funcs_tevent.h"
|
#include "poll_funcs/poll_funcs_tevent.h"
|
||||||
#include "unix_msg/unix_msg.h"
|
#include "unix_msg/unix_msg.h"
|
||||||
|
#include "lib/util/genrand.h"
|
||||||
|
|
||||||
struct sun_path_buf {
|
struct sun_path_buf {
|
||||||
/*
|
/*
|
||||||
@ -67,12 +68,13 @@ static int messaging_dgm_context_destructor(struct messaging_dgm_context *c);
|
|||||||
|
|
||||||
static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
|
static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
|
||||||
pid_t pid, int *plockfile_fd,
|
pid_t pid, int *plockfile_fd,
|
||||||
uint64_t unique)
|
uint64_t *punique)
|
||||||
{
|
{
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int lockfile_fd;
|
int lockfile_fd;
|
||||||
struct sun_path_buf lockfile_name;
|
struct sun_path_buf lockfile_name;
|
||||||
struct flock lck;
|
struct flock lck;
|
||||||
|
uint64_t unique;
|
||||||
int unique_len, ret;
|
int unique_len, ret;
|
||||||
ssize_t written;
|
ssize_t written;
|
||||||
|
|
||||||
@ -104,6 +106,19 @@ static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
|
|||||||
goto fail_close;
|
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);
|
unique_len = snprintf(buf, sizeof(buf), "%ju\n", (uintmax_t)unique);
|
||||||
|
|
||||||
/* shorten a potentially preexisting file */
|
/* shorten a potentially preexisting file */
|
||||||
@ -124,6 +139,7 @@ static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*plockfile_fd = lockfile_fd;
|
*plockfile_fd = lockfile_fd;
|
||||||
|
*punique = unique;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
fail_unlink:
|
fail_unlink:
|
||||||
@ -134,7 +150,7 @@ fail_close:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int messaging_dgm_init(struct tevent_context *ev,
|
int messaging_dgm_init(struct tevent_context *ev,
|
||||||
uint64_t unique,
|
uint64_t *punique,
|
||||||
const char *socket_dir,
|
const char *socket_dir,
|
||||||
const char *lockfile_dir,
|
const char *lockfile_dir,
|
||||||
void (*recv_cb)(const uint8_t *msg,
|
void (*recv_cb)(const uint8_t *msg,
|
||||||
@ -186,7 +202,7 @@ int messaging_dgm_init(struct tevent_context *ev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret = messaging_dgm_lockfile_create(ctx, ctx->pid, &ctx->lockfile_fd,
|
ret = messaging_dgm_lockfile_create(ctx, ctx->pid, &ctx->lockfile_fd,
|
||||||
unique);
|
punique);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
DEBUG(1, ("%s: messaging_dgm_create_lockfile failed: %s\n",
|
DEBUG(1, ("%s: messaging_dgm_create_lockfile failed: %s\n",
|
||||||
__func__, strerror(ret)));
|
__func__, strerror(ret)));
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include <tevent.h>
|
#include <tevent.h>
|
||||||
|
|
||||||
int messaging_dgm_init(struct tevent_context *ev,
|
int messaging_dgm_init(struct tevent_context *ev,
|
||||||
uint64_t unique,
|
uint64_t *unique,
|
||||||
const char *socket_dir,
|
const char *socket_dir,
|
||||||
const char *lockfile_dir,
|
const char *lockfile_dir,
|
||||||
void (*recv_cb)(const uint8_t *msg,
|
void (*recv_cb)(const uint8_t *msg,
|
||||||
|
@ -40,7 +40,7 @@ static void msg_dgm_ref_recv(const uint8_t *msg, size_t msg_len,
|
|||||||
int *fds, size_t num_fds, void *private_data);
|
int *fds, size_t num_fds, void *private_data);
|
||||||
|
|
||||||
void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
||||||
uint64_t unique,
|
uint64_t *unique,
|
||||||
const char *socket_dir,
|
const char *socket_dir,
|
||||||
const char *lockfile_dir,
|
const char *lockfile_dir,
|
||||||
void (*recv_cb)(const uint8_t *msg, size_t msg_len,
|
void (*recv_cb)(const uint8_t *msg, size_t msg_len,
|
||||||
@ -82,6 +82,14 @@ void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
|||||||
}
|
}
|
||||||
dgm_pid = getpid();
|
dgm_pid = getpid();
|
||||||
} else {
|
} else {
|
||||||
|
int ret;
|
||||||
|
ret = messaging_dgm_get_unique(getpid(), unique);
|
||||||
|
if (ret != 0) {
|
||||||
|
TALLOC_FREE(result);
|
||||||
|
*err = ret;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
result->tevent_handle = messaging_dgm_register_tevent_context(
|
result->tevent_handle = messaging_dgm_register_tevent_context(
|
||||||
result, ev);
|
result, ev);
|
||||||
if (result->tevent_handle == NULL) {
|
if (result->tevent_handle == NULL) {
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
#include "replace.h"
|
#include "replace.h"
|
||||||
|
|
||||||
void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
|
||||||
uint64_t unique,
|
uint64_t *unique,
|
||||||
const char *socket_dir,
|
const char *socket_dir,
|
||||||
const char *lockfile_dir,
|
const char *lockfile_dir,
|
||||||
void (*recv_cb)(const uint8_t *msg, size_t msg_len,
|
void (*recv_cb)(const uint8_t *msg, size_t msg_len,
|
||||||
|
@ -299,7 +299,8 @@ bld.SAMBA3_SUBSYSTEM('TDB_LIB',
|
|||||||
|
|
||||||
bld.SAMBA3_LIBRARY('messages_dgm',
|
bld.SAMBA3_LIBRARY('messages_dgm',
|
||||||
source='''lib/messages_dgm.c lib/messages_dgm_ref.c''',
|
source='''lib/messages_dgm.c lib/messages_dgm_ref.c''',
|
||||||
deps='talloc UNIX_MSG POLL_FUNCS_TEVENT samba-debug',
|
deps='''talloc UNIX_MSG POLL_FUNCS_TEVENT samba-debug
|
||||||
|
genrand''',
|
||||||
private_library=True)
|
private_library=True)
|
||||||
|
|
||||||
bld.SAMBA3_LIBRARY('messages_util',
|
bld.SAMBA3_LIBRARY('messages_util',
|
||||||
|
@ -342,7 +342,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
msg->msg_dgm_ref = messaging_dgm_ref(
|
msg->msg_dgm_ref = messaging_dgm_ref(
|
||||||
msg, ev, server_id.unique_id, msg->sock_dir, msg->lock_dir,
|
msg, ev, &server_id.unique_id, msg->sock_dir, msg->lock_dir,
|
||||||
imessaging_dgm_recv, msg, &ret);
|
imessaging_dgm_recv, msg, &ret);
|
||||||
|
|
||||||
if (msg->msg_dgm_ref == NULL) {
|
if (msg->msg_dgm_ref == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user