[pisa-src] r1507 - in trunk: libpisa/util.c pisacd/cdctx.c pisacd/cdctx.h pisacd/cdmain.c pisasd/sdctx.c pisasd/sdctx.h pisasd/sdmain.c

  • From: René Hummen <rene.hummen@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 03 Nov 2009 17:51:43 +0100

Author: hummen
Date: Tue Nov  3 17:51:43 2009
New Revision: 1507

Log:
Initial kill switch implementation. Needs further improvement...

Modified:
   trunk/libpisa/util.c
   trunk/pisacd/cdctx.c
   trunk/pisacd/cdctx.h
   trunk/pisacd/cdmain.c
   trunk/pisasd/sdctx.c
   trunk/pisasd/sdctx.h
   trunk/pisasd/sdmain.c

Modified: trunk/libpisa/util.c
==============================================================================
--- trunk/libpisa/util.c        Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/libpisa/util.c        Tue Nov  3 17:51:43 2009        (r1507)
@@ -302,7 +302,6 @@
        PISA_IFEL((new_pid_str_len <= 0), -1, "pID length error.\n");
 
        /* Read old pid */
-
        fd = PISA_CREATE_FILE(filename);
        PISA_IFEL((fd <= 0), -1, "opening lock file failed\n");
 
@@ -314,6 +313,8 @@
        }
        old_pid = atoi(old_pid_str);
 
+       // TODO we should exit in this case, if the kill switch is not set
+
        if (lockf(fd, F_TLOCK, 0) < 0)
        {
                PISA_IFEL(!killold, -12,

Modified: trunk/pisacd/cdctx.c
==============================================================================
--- trunk/pisacd/cdctx.c        Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/pisacd/cdctx.c        Tue Nov  3 17:51:43 2009        (r1507)
@@ -31,6 +31,7 @@
        cd_ctx.flag_running = FALSE;
        cd_ctx.flag_background = FALSE;
        cd_ctx.flag_pending = 0;
+       cd_ctx.flag_kill_running = FALSE;
 
        cd_ctx.fd_tunnel = -1;
        cd_ctx.fd_control = -1;

Modified: trunk/pisacd/cdctx.h
==============================================================================
--- trunk/pisacd/cdctx.h        Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/pisacd/cdctx.h        Tue Nov  3 17:51:43 2009        (r1507)
@@ -31,6 +31,7 @@
        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 
*/
+       int flag_kill_running;  /* should the daemon kill an already running 
instance */
 
        /**
         * File descriptors and sockets:

Modified: trunk/pisacd/cdmain.c
==============================================================================
--- trunk/pisacd/cdmain.c       Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/pisacd/cdmain.c       Tue Nov  3 17:51:43 2009        (r1507)
@@ -34,7 +34,7 @@
 
 extern pisa_conf_handle_func_set conf_handle_func_set;
 
-#define OPTS "f:i:p:q:bdvh"
+#define OPTS "f:i:p:q:btdvh"
 
 /**
  * A set of options, including each long option and single-letter option
@@ -152,6 +152,7 @@
                "\t-p|--control-port <port> : Give a control port number to 
listen for incoming connections. (default: %d)\n"
                "\t-q|--data-port <port>    : Give a data port number to listen 
for incoming connections. (default: %d)\n"
                "\t-b|--background          : Run in background\n"
+               "\t-k|--kill-running        : Kill a running daemon\n"
                "\t-d|--debug               : Enable Debug mode\n"
                "\t-v|--version             : Print the version number\n"
                "\t-h|--help                : display this usage\n"
@@ -238,6 +239,9 @@
                case 'b':
                        cd_ctx.flag_background = TRUE;
                        break;
+               case 'k':
+                       cd_ctx.flag_kill_running = TRUE;
+                       break;
                case 'd':
                        strncpy(cd_cfg.debuglevel, "all", 
sizeof(cd_cfg.debuglevel));
                        break;
@@ -349,11 +353,13 @@
        signal(SIGPIPE, SIG_IGN);
        signal(SIGBUS, cd_quit);
 
-       /* Check and create lockfile */
-       pisa_create_lock_file(PISACD_LOCK_FILE, 0);
-
        /* Set default values in context and config */
        cdctx_init();
+
+       /* Check and create lockfile */
+       pisa_create_lock_file(PISACD_LOCK_FILE, cd_ctx.flag_kill_running);
+
+       /* Set default values in config */
        cdconf_init();
 
        /* Receive and parse command line arguments.

Modified: trunk/pisasd/sdctx.c
==============================================================================
--- trunk/pisasd/sdctx.c        Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/pisasd/sdctx.c        Tue Nov  3 17:51:43 2009        (r1507)
@@ -27,6 +27,7 @@
 {
        sd_ctx.flag_running = FALSE;
        sd_ctx.flag_background = FALSE;
+       sd_ctx.flag_kill_running = FALSE;
 
        sd_ctx.fd_control = -1;
        sd_ctx.fd_data = -1;

Modified: trunk/pisasd/sdctx.h
==============================================================================
--- trunk/pisasd/sdctx.h        Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/pisasd/sdctx.h        Tue Nov  3 17:51:43 2009        (r1507)
@@ -30,6 +30,7 @@
        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 
*/
+       int flag_kill_running;  /* should the daemon kill an already running 
instance */
 
        /**
         * File descriptors and sockets:

Modified: trunk/pisasd/sdmain.c
==============================================================================
--- trunk/pisasd/sdmain.c       Tue Nov  3 16:52:58 2009        (r1506)
+++ trunk/pisasd/sdmain.c       Tue Nov  3 17:51:43 2009        (r1507)
@@ -252,6 +252,10 @@
                                sd_ctx.flag_background = TRUE;
                                break;
 
+                       case 'k':
+                               sd_ctx.flag_kill_running = TRUE;
+                               break;
+
                        case 'd':
                                strncpy(sd_cfg.debuglevel, "all", 
sizeof(sd_cfg.debuglevel));
                                break;
@@ -359,11 +363,13 @@
        signal(SIGPIPE, SIG_IGN);
        signal(SIGBUS, sd_quit);
 
+       /* Set default values in context */
+       sdctx_init();
+
        /* Check and create lockfile */
-       pisa_create_lock_file(PISASD_LOCK_FILE, 0);
+       pisa_create_lock_file(PISASD_LOCK_FILE, sd_ctx.flag_kill_running);
 
-       /* Set default values in context and config */
-       sdctx_init();
+       /* Set default values in config */
        sdconf_init();
 
        /* Receive and parse command line arguments.

Other related posts: