commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jfcl...@apache.org
Subject svn commit: r164252 - in /jakarta/commons/proper/daemon/trunk/src/native/unix/native: arguments.c arguments.h jsvc-unix.c
Date Fri, 22 Apr 2005 16:34:57 GMT
Author: jfclere
Date: Fri Apr 22 09:34:52 2005
New Revision: 164252

URL: http://svn.apache.org/viewcvs?rev=164252&view=rev
Log:
Try to implement wait until JVM is started...

Modified:
    jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.c
    jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.h
    jakarta/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c

Modified: jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.c
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.c?rev=164252&r1=164251&r2=164252&view=diff
==============================================================================
--- jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.c (original)
+++ jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.c Fri Apr 22 09:34:52
2005
@@ -42,6 +42,8 @@
     args->vers=false;           /* Don't display version */
     args->help=false;           /* Don't display help */
     args->chck=false;           /* Don't do a check-only startup */
+    args->stop=false;           /* Stop a running jsvc */
+    args->wait=false;           /* Wait until jsvc has started the JVM */
     args->install=false;        /* Don't install as a service */
     args->remove=false;         /* Don't remove the installed service */
     args->service=false;        /* Don't run as a service */
@@ -112,6 +114,12 @@
 
         } else if (strcmp(argv[x],"-debug")==0) {
             log_debug_flag=true;
+
+        } else if (strcmp(argv[x],"-wait")==0) {
+            args->wait=true;
+
+        } else if (strcmp(argv[x],"-stop")==0) {
+            args->wait=true;
 
         } else if (strcmp(argv[x],"-check")==0) {
             args->chck=true;

Modified: jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.h
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.h?rev=164252&r1=164251&r2=164252&view=diff
==============================================================================
--- jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.h (original)
+++ jakarta/commons/proper/daemon/trunk/src/native/unix/native/arguments.h Fri Apr 22 09:34:52
2005
@@ -51,6 +51,10 @@
     bool help;
     /** Only check environment without running the service. */
     bool chck;
+    /** Stop running jsvc */
+    bool stop;
+    /** Wait until service started */
+    bool wait;
     /** Install as a service (win32) */
     bool install;
     /** Remove when installed as a service (win32) */

Modified: jakarta/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c?rev=164252&r1=164251&r2=164252&view=diff
==============================================================================
--- jakarta/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c (original)
+++ jakarta/commons/proper/daemon/trunk/src/native/unix/native/jsvc-unix.c Fri Apr 22 09:34:52
2005
@@ -294,6 +294,107 @@
 }
 
 /*
+ * read the pid from the pidfile
+ */
+static int get_pidf(arg_data *args) {
+    int fd;
+    int i;
+    char buff[80];
+
+    fd = open(args->pidf, O_RDONLY, 0);
+    log_debug("get_pidf: %d in %s", fd, args->pidf);
+    if (fd<0)
+        return(-1); /* something has gone wrong the JVM has stopped */
+    lockf(fd,F_LOCK,0);
+    i = read(fd,buff,sizeof(buff));
+    lockf(fd,F_ULOCK,0);
+    close(fd);
+    if (i>0) {
+        buff[i] = '\0';
+        i = atoi(buff);
+        log_debug("get_pidf: pid %d", i);
+        if (kill(i, 0)==0)
+            return(i);
+    }
+    return(-1);
+}
+
+/*
+ * Check temporatory file created by controller
+ * /tmp/pid.jsvc_up
+ */
+static int check_tmp_file(arg_data *args) {
+    int pid;
+    char buff[80];
+    int fd;
+    pid = get_pidf(args);
+    if (pid<0)
+        return(-1);
+    sprintf(buff,"/tmp/%d.jsvc_up", pid);
+    log_debug("check_tmp_file: %s", buff);
+    fd = open(buff, O_RDONLY);
+    if (fd<0)
+        return(-1);
+    close(fd);
+    return(0);
+}
+static void create_tmp_file(arg_data *args) {
+    char buff[80];
+    int fd;
+    sprintf(buff,"/tmp/%d.jsvc_up", getpid());
+    log_debug("create_tmp_file: %s", buff);
+    fd = open(buff, O_RDWR|O_CREAT,S_IRUSR|S_IWUSR);
+    if (fd<0)
+        return;
+    close(fd);
+}
+static void remove_tmp_file(arg_data *args) {
+    char buff[80];
+    sprintf(buff,"/tmp/%d.jsvc_up", getpid());
+    log_debug("remove_tmp_file: %s", buff);
+    unlink(buff);
+}
+
+/*
+ * wait until jsvc create the I am ready file
+ * pid is the controller and args->pidf the JVM itself.
+ */
+static int wait_child(arg_data *args, int pid) {
+    int count=10;
+    bool havejvm=false;
+    int fd;
+    char buff[80];
+    int i;
+    log_debug("wait_child %d", pid);
+    while (count>0) {
+        /* check if the controler is still running */
+        if (kill(pid, 0)!=0)
+            return(1);
+        /* check if the pid file process exists */
+        fd = open(args->pidf, O_RDONLY);
+        if (fd<0 && havejvm)
+            return(1); /* something has gone wrong the JVM has stopped */
+        lockf(fd,F_LOCK,0);
+        i = read(fd,buff,sizeof(buff));
+        lockf(fd,F_ULOCK,0);
+        close(fd);
+        if (i>0) {
+            buff[i] = '\0';
+            i = atoi(buff);
+            if (kill(i, 0)==0) {
+                /* the JVM process has started */
+                havejvm=true;
+                if (check_tmp_file(args)==0)
+                    return(0); /* ready JVM started */
+            }
+        }
+        sleep(6);
+        count--;
+    }
+    return(1);
+}
+
+/*
  * son process logic.
  */
 
@@ -361,7 +462,9 @@
     handler_int=signal_set(SIGINT,handler);
     controlled = getpid();
     log_debug("Waiting for a signal to be delivered");
+    create_tmp_file(args);
     while (!stopping) sleep(60); /* pause() not threadsafe */
+    remove_tmp_file(args);
     log_debug("Shutdown or reload requested: exiting");
 
     /* Stop the service */
@@ -496,8 +599,13 @@
             log_error("Cannot detach from parent process");
             return(1);
         }
-        /* If we're in the parent process, we siply quit */
-        if (pid!=0) return(0);
+        /* If we're in the parent process */
+        if (pid!=0) {
+            if (args->wait==true)
+                return(wait_child(args,pid));
+            else
+                return(0);
+        }
 #ifndef NO_SETSID
         setsid();
 #endif



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message