Author: tjansen Date: Wed Oct 28 15:49:45 2009 New Revision: 1385 Log: Renamed the pisa{c,s}d flags. All flags have a common flag_ prefix. is_bgrun was quite cryptic and is now named flag_background. The running flag does not need sd or cd in the name, we know in which daemon we are. Modified: trunk/pisacd/cdctx.c trunk/pisacd/cdctx.h trunk/pisacd/cdmain.c trunk/pisacd/cdpending.c trunk/pisasd/sdctx.c trunk/pisasd/sdctx.h trunk/pisasd/sdmain.c Modified: trunk/pisacd/cdctx.c ============================================================================== --- trunk/pisacd/cdctx.c Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisacd/cdctx.c Wed Oct 28 15:49:45 2009 (r1385) @@ -28,9 +28,9 @@ */ void cdctx_init(cd_context *cdctx) { - cdctx->is_cd_running = FALSE; - cdctx->is_bgrun = FALSE; - cdctx->pending = 0; + cdctx->flag_running = FALSE; + cdctx->flag_background = FALSE; + cdctx->flag_pending = 0; cdctx->fd_tunnel = -1; cdctx->fd_control = -1; Modified: trunk/pisacd/cdctx.h ============================================================================== --- trunk/pisacd/cdctx.h Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisacd/cdctx.h Wed Oct 28 15:49:45 2009 (r1385) @@ -26,22 +26,12 @@ */ typedef struct { /** - * Flag for the internal packet processing loop. - * If it is set as 0, flow will exit from the main loop. + * Flags: + * 1: true, 0: false. */ - int is_cd_running; - - /** - * Flag if nd is running in background. - * If it is set as 1, nd runs in background. - */ - int is_bgrun; - - /** - * Flag for pending events. - * 1: at least one event is pending, 0: no event is pending. - */ - int pending; + int flag_running; /* should the daemon continue to run */ + int flag_background; /* is the daemon running in background mode */ + int flag_pending; /* is there at least one pending event */ /** * Sockets for the data port, control port and the tunnel device. Modified: trunk/pisacd/cdmain.c ============================================================================== --- trunk/pisacd/cdmain.c Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisacd/cdmain.c Wed Oct 28 15:49:45 2009 (r1385) @@ -91,7 +91,7 @@ int maxfd; fd_set readfds; - cd_ctx.is_cd_running = TRUE; + cd_ctx.flag_running = TRUE; pisa_servers_add_all(); @@ -100,7 +100,7 @@ maxfd = pisa_maxof(5, cd_ctx.fd_tunnel, cd_ctx.fd_pisaconf, cd_ctx.fd_control, cd_ctx.fd_data, cd_ctx.scheduler.pipe_main[0]) + 1; - while (cd_ctx.is_cd_running || cd_ctx.pending) { + while (cd_ctx.flag_running || cd_ctx.flag_pending) { /* sockets.tunnel needs to be always included in the reading fd list */ FD_ZERO(&readfds); FD_SET(cd_ctx.fd_tunnel, &readfds); @@ -110,7 +110,7 @@ FD_SET(cd_ctx.scheduler.pipe_main[0], &readfds); if (select(maxfd, &readfds, NULL, NULL, NULL) > 0) { - if (cd_ctx.is_cd_running) { + if (cd_ctx.flag_running) { if (FD_ISSET(cd_ctx.fd_tunnel, &readfds)) pisa_cd_copy_from_tun_to_sock(); @@ -118,7 +118,7 @@ pisa_cd_copy_from_sock_to_tun(); } else { /* TODO: Incoming packets after - * is_cd_running is false will cause 100% CPU + * flag_running is false will cause 100% CPU * load as select will immediately return. * Read (and ignore) from the fds mentioned * above. */ @@ -238,7 +238,7 @@ cd_cfg.port_data = atoi(optarg); break; case 'b': - cd_ctx.is_bgrun = TRUE; + cd_ctx.flag_background = TRUE; break; case 'd': strncpy(cd_cfg.debuglevel, "all", sizeof(cd_cfg.debuglevel)); @@ -268,11 +268,11 @@ switch (quitcode) { case SIGINT: PISA_INFO("WARNING: Got a SIGINT signal.\n"); - cd_ctx.is_cd_running = FALSE; + cd_ctx.flag_running = FALSE; break; case SIGQUIT: PISA_INFO("WARNING: Got a SIGQUIT signal.\n"); - cd_ctx.is_cd_running = FALSE; + cd_ctx.flag_running = FALSE; break; case SIGILL: PISA_INFO("WARNING: Got a SIGILL signal.\n"); @@ -282,11 +282,11 @@ break; case SIGBUS: PISA_INFO("WARNING: Got a SIGBUS signal.\n"); - cd_ctx.is_cd_running = FALSE; + cd_ctx.flag_running = FALSE; break; case SIGTERM: PISA_INFO("WARNING: Got a SIGTERM signal.\n"); - cd_ctx.is_cd_running = FALSE; + cd_ctx.flag_running = FALSE; break; default: PISA_INFO("WARNING: Got an unknown signal(signum=%d).\n", @@ -379,7 +379,7 @@ cdconf_set_debuglevel(&cd_cfg); /* daemonize pisacd when running background mode */ - if (cd_ctx.is_bgrun) + if (cd_ctx.flag_background) pisa_daemonize(); cd_ctx.natlist = pisa_nat_init(); Modified: trunk/pisacd/cdpending.c ============================================================================== --- trunk/pisacd/cdpending.c Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisacd/cdpending.c Wed Oct 28 15:49:45 2009 (r1385) @@ -82,7 +82,7 @@ pend->send = send; pend->fail = fail; - cd_ctx.pending = 1; + cd_ctx.flag_pending = 1; /* Schedule the first try immediately */ if (pend->task) @@ -105,7 +105,7 @@ free(pend->data); free(pend); - cd_ctx.pending = (hash_pending == NULL) ? 0 : 1; + cd_ctx.flag_pending = (hash_pending == NULL) ? 0 : 1; } /** Modified: trunk/pisasd/sdctx.c ============================================================================== --- trunk/pisasd/sdctx.c Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisasd/sdctx.c Wed Oct 28 15:49:45 2009 (r1385) @@ -28,8 +28,8 @@ */ void sdctx_init(sd_context *sdctx) { - sdctx->is_sd_running = FALSE; - sdctx->is_bgrun = FALSE; + sdctx->flag_running = FALSE; + sdctx->flag_background = FALSE; sdctx->fd_control = -1; sdctx->fd_data = -1; Modified: trunk/pisasd/sdctx.h ============================================================================== --- trunk/pisasd/sdctx.h Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisasd/sdctx.h Wed Oct 28 15:49:45 2009 (r1385) @@ -25,16 +25,12 @@ */ typedef struct sd_context { /** - * Flag for the internal packet processing loop. - * If it is set as 0, flow will exit from the main loop. + * Flags: + * 1: true, 0: false. */ - int is_sd_running; - - /** - * Flag if nd is running in background. - * If it is set as 1, nd runs in background. - */ - int is_bgrun; + int flag_running; /* should the daemon continue to run */ + int flag_background; /* is the daemon running in background mode */ + int flag_pending; /* is there at least one pending event */ /** * Sockets for the data port, control port and the tunnel device. Modified: trunk/pisasd/sdmain.c ============================================================================== --- trunk/pisasd/sdmain.c Wed Oct 28 15:30:15 2009 (r1384) +++ trunk/pisasd/sdmain.c Wed Oct 28 15:49:45 2009 (r1385) @@ -107,10 +107,10 @@ maxfd = 1 + pisa_maxof(5, sd_ctx.fd_control, sd_ctx.fd_data, sd_ctx.fd_tunnel, sd_ctx.fd_tunnel, sd_ctx.scheduler.pipe_main[0]); - sd_ctx.is_sd_running = TRUE; + sd_ctx.flag_running = TRUE; PISA_INFO("\nEntering main loop\n"); - while (sd_ctx.is_sd_running) { + while (sd_ctx.flag_running) { fd_set readfds; /* Add all sockets to the read set */ @@ -255,7 +255,7 @@ break; case 'b': - sd_ctx.is_bgrun = TRUE; + sd_ctx.flag_background = TRUE; break; case 'd': @@ -291,7 +291,7 @@ case SIGQUIT: case SIGBUS: PISA_DEBUG(PL_SHUTDOWN, "Quitting PISA server daemon...\n"); - sd_ctx.is_sd_running = FALSE; + sd_ctx.flag_running = FALSE; break; case SIGILL: @@ -391,7 +391,7 @@ sdconf_set_debuglevel(&sd_cfg); /* daemonize pisasd when running background mode */ - if (sd_ctx.is_bgrun) + if (sd_ctx.flag_background) pisa_daemonize(); sd_ctx.natlist = pisa_nat_init();