From: Philipp Tölke Date: Mon, 6 Sep 2010 09:25:41 +0000 (+0000) Subject: Get rid of the cls. Use a global. X-Git-Tag: initial-import-from-subversion-38251~20443 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e56b541b9d6fedf044335dd9d6dff6221bed9c3b;p=oweals%2Fgnunet.git Get rid of the cls. Use a global. --- diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index 3ea9180be..46a830f8d 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -51,38 +51,38 @@ struct vpn_cls { pid_t helper_pid; }; +static struct vpn_cls mycls; + static void cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { - struct vpn_cls* mycls = (struct vpn_cls*) cls; if (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) { - PLIBC_KILL(mycls->helper_pid, SIGTERM); - GNUNET_OS_process_wait(mycls->helper_pid); + PLIBC_KILL(mycls.helper_pid, SIGTERM); + GNUNET_OS_process_wait(mycls.helper_pid); } } static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx); -static void start_helper_and_schedule(struct vpn_cls* mycls) { - mycls->helper_in = GNUNET_DISK_pipe(1); - mycls->helper_out = GNUNET_DISK_pipe(1); +static void start_helper_and_schedule() { + mycls.helper_in = GNUNET_DISK_pipe(1); + mycls.helper_out = GNUNET_DISK_pipe(1); - mycls->helper_pid = GNUNET_OS_start_process(mycls->helper_in, mycls->helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); + mycls.helper_pid = GNUNET_OS_start_process(mycls.helper_in, mycls.helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); - mycls->fh_from_helper = GNUNET_DISK_pipe_handle (mycls->helper_out, GNUNET_DISK_PIPE_END_READ); + mycls.fh_from_helper = GNUNET_DISK_pipe_handle (mycls.helper_out, GNUNET_DISK_PIPE_END_READ); - GNUNET_DISK_pipe_close_end(mycls->helper_out, GNUNET_DISK_PIPE_END_WRITE); - GNUNET_DISK_pipe_close_end(mycls->helper_in, GNUNET_DISK_PIPE_END_READ); + GNUNET_DISK_pipe_close_end(mycls.helper_out, GNUNET_DISK_PIPE_END_WRITE); + GNUNET_DISK_pipe_close_end(mycls.helper_in, GNUNET_DISK_PIPE_END_READ); - GNUNET_SCHEDULER_add_read_file (mycls->sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls); + GNUNET_SCHEDULER_add_read_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_from_helper, &helper_read, NULL); } static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { // FIXME: Ratelimit this! - struct vpn_cls* mycls = (struct vpn_cls*) cls; // Kill the helper - PLIBC_KILL(mycls->helper_pid, SIGKILL); - GNUNET_OS_process_wait(mycls->helper_pid); + PLIBC_KILL(mycls.helper_pid, SIGKILL); + GNUNET_OS_process_wait(mycls.helper_pid); // Restart the helper start_helper_and_schedule(mycls); @@ -90,22 +90,21 @@ static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* } static void helper_read(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tsdkctx) { - struct vpn_cls* mycls = (struct vpn_cls*) cls; char buf[65535]; if (tsdkctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) return; - int t = GNUNET_DISK_file_read(mycls->fh_from_helper, &buf, 65535); + int t = GNUNET_DISK_file_read(mycls.fh_from_helper, &buf, 65535); if (t<=0) { fprintf(stderr, "Read error for header: %m\n"); - GNUNET_SCHEDULER_add_now(mycls->sched, restart_helper, cls); + GNUNET_SCHEDULER_add_now(mycls.sched, restart_helper, cls); return; } - /* FIXME */ GNUNET_SERVER_mst_receive(mycls->mst, NULL, buf, t, 0, 0); + /* FIXME */ GNUNET_SERVER_mst_receive(mycls.mst, NULL, buf, t, 0, 0); - GNUNET_SCHEDULER_add_read_file (mycls->sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls->fh_from_helper, &helper_read, mycls); + GNUNET_SCHEDULER_add_read_file (mycls.sched, GNUNET_TIME_UNIT_FOREVER_REL, mycls.fh_from_helper, &helper_read, NULL); } static void message_token(void *cls, void *client, const struct GNUNET_MessageHeader *message) { @@ -161,10 +160,8 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { - struct vpn_cls* mycls = cls; - - mycls->sched = sched; - mycls->mst = GNUNET_SERVER_mst_create(&message_token, mycls); + mycls.sched = sched; + mycls.mst = GNUNET_SERVER_mst_create(&message_token, NULL); GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); start_helper_and_schedule(mycls); } @@ -184,16 +181,12 @@ main (int argc, char *const *argv) GNUNET_GETOPT_OPTION_END }; - struct vpn_cls* cls = GNUNET_malloc(sizeof(struct vpn_cls)); - return (GNUNET_OK == GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-vpn", gettext_noop ("help text"), - options, &run, cls)) ? ret : 1; - - GNUNET_free(cls); /* Make clang happy */ + options, &run, NULL)) ? ret : 1; } /* end of gnunet-daemon-vpn.c */ diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 0e6648c1d..874b7ef0f 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -36,6 +36,8 @@ struct dns_cls { unsigned short dnsoutport; }; +static struct dns_cls mycls; + void hijack(unsigned short port) { char port_s[6]; @@ -60,7 +62,7 @@ static void cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - unhijack(((struct dns_cls*)cls)->dnsoutport); + unhijack(mycls.dnsoutport); } /** @@ -79,19 +81,17 @@ run (void *cls, {NULL, NULL, 0, 0} }; - struct dns_cls* mycls = (struct dns_cls*)cls; - - mycls->sched = sched; + mycls.sched = sched; - mycls->dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); + mycls.dnsout = GNUNET_NETWORK_socket_create (AF_INET, SOCK_DGRAM, 0); struct sockaddr_in * addr = alloca(sizeof(struct sockaddr_in)); memset(addr, 0, sizeof(struct sockaddr_in)); - int err = GNUNET_NETWORK_socket_bind (mycls->dnsout, (struct sockaddr*)addr, sizeof(struct sockaddr_in)); - err = getsockname(GNUNET_NETWORK_get_fd(mycls->dnsout), addr, (unsigned int[]){sizeof(struct sockaddr_in)}); + int err = GNUNET_NETWORK_socket_bind (mycls.dnsout, (struct sockaddr*)addr, sizeof(struct sockaddr_in)); + err = getsockname(GNUNET_NETWORK_get_fd(mycls.dnsout), addr, (unsigned int[]){sizeof(struct sockaddr_in)}); - mycls->dnsoutport = htons(addr->sin_port); + mycls.dnsoutport = htons(addr->sin_port); hijack(htons(addr->sin_port)); @@ -112,14 +112,10 @@ run (void *cls, int main (int argc, char *const *argv) { - struct dns_cls* cls = GNUNET_malloc(sizeof(struct dns_cls)); - return (GNUNET_OK == GNUNET_SERVICE_run (argc, argv, "gnunet-service-dns", GNUNET_SERVICE_OPTION_NONE, - &run, cls)) ? 0 : 1; - - GNUNET_free(cls); // Make clang happy + &run, NULL)) ? 0 : 1; }