1
0
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:
Volker Lendecke 2015-10-12 21:30:30 +02:00
parent a788fd3065
commit 01d7e26f7f
7 changed files with 35 additions and 12 deletions

View File

@ -303,7 +303,6 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx,
ctx->id = (struct server_id) {
.pid = getpid(), .vnn = NONCLUSTER_VNN
};
ctx->id.unique_id = serverid_get_random_unique_id();
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, ctx->event_ctx, ctx->id.unique_id,
ctx, ctx->event_ctx, &ctx->id.unique_id,
priv_path, lck_path, messaging_recv_cb, ctx, &ret);
if (ctx->msg_dgm_ref == NULL) {
@ -400,10 +399,9 @@ NTSTATUS messaging_reinit(struct messaging_context *msg_ctx)
msg_ctx->id = (struct server_id) {
.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_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"),
messaging_recv_cb, msg_ctx, &ret);

View File

@ -29,6 +29,7 @@
#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 {
/*
@ -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,
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;
@ -104,6 +106,19 @@ static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
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 */
@ -124,6 +139,7 @@ static int messaging_dgm_lockfile_create(struct messaging_dgm_context *ctx,
}
*plockfile_fd = lockfile_fd;
*punique = unique;
return 0;
fail_unlink:
@ -134,7 +150,7 @@ fail_close:
}
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,
@ -186,7 +202,7 @@ int messaging_dgm_init(struct tevent_context *ev,
}
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)));

View File

@ -25,7 +25,7 @@
#include <tevent.h>
int messaging_dgm_init(struct tevent_context *ev,
uint64_t unique,
uint64_t *unique,
const char *socket_dir,
const char *lockfile_dir,
void (*recv_cb)(const uint8_t *msg,

View File

@ -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);
void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
uint64_t unique,
uint64_t *unique,
const char *socket_dir,
const char *lockfile_dir,
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();
} 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, ev);
if (result->tevent_handle == NULL) {

View File

@ -25,7 +25,7 @@
#include "replace.h"
void *messaging_dgm_ref(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
uint64_t unique,
uint64_t *unique,
const char *socket_dir,
const char *lockfile_dir,
void (*recv_cb)(const uint8_t *msg, size_t msg_len,

View File

@ -299,7 +299,8 @@ bld.SAMBA3_SUBSYSTEM('TDB_LIB',
bld.SAMBA3_LIBRARY('messages_dgm',
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)
bld.SAMBA3_LIBRARY('messages_util',

View File

@ -342,7 +342,7 @@ struct imessaging_context *imessaging_init(TALLOC_CTX *mem_ctx,
}
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);
if (msg->msg_dgm_ref == NULL) {