X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbus-proxyd%2Fbus-proxyd.c;h=72e11467bda144dc12d43a24c6d70bda1567e2de;hb=c4bc1a8434f2a34840ea6f63064fa998ecfae738;hp=15a79fc427946b7e5b6026792fa53d5aa948431e;hpb=b58d857136496ee463223cd90af46512e9eef152;p=elogind.git diff --git a/src/bus-proxyd/bus-proxyd.c b/src/bus-proxyd/bus-proxyd.c index 15a79fc42..72e11467b 100644 --- a/src/bus-proxyd/bus-proxyd.c +++ b/src/bus-proxyd/bus-proxyd.c @@ -61,6 +61,7 @@ static char **arg_configuration = NULL; typedef struct { int fd; + SharedPolicy *policy; } ClientContext; static ClientContext *client_context_free(ClientContext *c) { @@ -75,14 +76,14 @@ static ClientContext *client_context_free(ClientContext *c) { DEFINE_TRIVIAL_CLEANUP_FUNC(ClientContext*, client_context_free); -static int client_context_new(ClientContext **out, int fd) { +static int client_context_new(ClientContext **out) { _cleanup_(client_context_freep) ClientContext *c = NULL; c = new0(ClientContext, 1); if (!c) return log_oom(); - c->fd = fd; + c->fd = -1; *out = c; c = NULL; @@ -105,7 +106,7 @@ static void *run_client(void *userdata) { comm[sizeof(comm) - 2] = '*'; (void) prctl(PR_SET_NAME, comm); - r = proxy_load_policy(p, arg_configuration); + r = proxy_set_policy(p, c->policy, arg_configuration); if (r < 0) goto exit; @@ -120,6 +121,7 @@ exit: } static int loop_clients(int accept_fd) { + _cleanup_(shared_policy_freep) SharedPolicy *sp = NULL; pthread_attr_t attr; int r; @@ -135,6 +137,10 @@ static int loop_clients(int accept_fd) { goto exit_attr; } + r = shared_policy_new(&sp); + if (r < 0) + goto exit_attr; + for (;;) { ClientContext *c; pthread_t tid; @@ -149,13 +155,16 @@ static int loop_clients(int accept_fd) { break; } - r = client_context_new(&c, fd); + r = client_context_new(&c); if (r < 0) { log_oom(); close(fd); continue; } + c->fd = fd; + c->policy = sp; + r = pthread_create(&tid, &attr, run_client, c); if (r < 0) { log_error("Cannot spawn thread: %m");