Uploaded image for project: 'Commons Daemon'
  1. Commons Daemon
  2. DAEMON-95

jsvc log rotation support

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.0.1
    • 1.0.4
    • Jsvc
    • None
    • Linux PC i686 Fedora Core 6

    Description

      Currently, tomcat does not support proper log rotation for
      the standard output and error files produced when -outfile
      and -errfile are used at startup. The following patch
      1) upgrades jsvc-unix.c to support proper log rotation using SIGUSR1
      2) fixes a minor bug with arguments.c where the -procname argument
      can't be used because it was added after the check for the end
      of arguments
      3) some minor warnings due to missing or incorrect function declarations.

      ===================== cut here =======================
      diff -ru jsvc-src/native/arguments.c jsvc-src-logrotate/native/arguments.c
      — jsvc-src/native/arguments.c 2005-05-17 06:13:39.000000000 -0700
      +++ jsvc-src-logrotate/native/arguments.c 2007-02-27 12:00:37.000000000 -0800
      @@ -186,16 +186,17 @@
      } else if (strstr(argv[x],"-ea")==argv[x])

      { args->opts[args->onum++]=strdup(argv[x]); - }

      else if (strstr(argv[x],"-")==argv[x])

      { - log_error("Invalid option %s",argv[x]); - return(NULL); - }

      else if (strcmp(argv[x],"-procname") == 0) {
      args->procname = optional(argc, argv, x++);
      if(args->procname == NULL)

      { log_error("Invalid process name specified"); return (NULL); }

      +
      + } else if (strstr(argv[x],"-")==argv[x])

      { + log_error("Invalid option %s",argv[x]); + return(NULL); + }

      else

      { args->clas=strdup(argv[x]); break; @@ -248,7 +249,6 @@ }

      if (log_debug_flag==true)

      { - char *temp; log_debug("+-- DUMPING PARSED COMMAND LINE ARGUMENTS --------------"); diff -ru jsvc-src/native/dso.h jsvc-src-logrotate/native/dso.h --- jsvc-src/native/dso.h 2005-05-17 06:13:39.000000000 -0700 +++ jsvc-src-logrotate/native/dso.h 2007-02-27 10:52:18.000000000 -0800 @@ -25,3 +25,4 @@ dso_handle dso_link(const char *pth); bool dso_unlink(dso_handle lib); void *dso_symbol(dso_handle lib, const char *nam); +char *dso_error(void); diff -ru jsvc-src/native/java.c jsvc-src-logrotate/native/java.c --- jsvc-src/native/java.c 2005-05-17 06:13:39.000000000 -0700 +++ jsvc-src-logrotate/native/java.c 2007-02-27 10:53:55.000000000 -0800 @@ -45,7 +45,7 @@ else main_shutdown(); }

      /* Automaticly restart when the JVM crashes */
      -static void java_abort123()
      +static void java_abort123(void)

      { exit(123); }

      diff -ru jsvc-src/native/jsvc-unix.c jsvc-src-logrotate/native/jsvc-unix.c
      — jsvc-src/native/jsvc-unix.c 2005-05-17 06:13:39.000000000 -0700
      +++ jsvc-src-logrotate/native/jsvc-unix.c 2007-02-27 14:34:01.000000000 -0800
      @@ -39,7 +39,9 @@
      static bool doreload=false;
      static void (*handler_int)(int)=NULL;
      static void (*handler_hup)(int)=NULL;
      +static void (*handler_usr1)(int)=NULL;
      static void (*handler_trm)(int)=NULL;
      +static void set_output(char *, char *, uid_t, gid_t);

      static void handler(int sig) {
      switch (sig)

      { @@ -74,6 +76,12 @@ break; }

      + case SIGUSR1:

      { + log_debug("Caught SIGUSR1: Reopening logs"); + set_output(NULL,NULL,-1,-1); + break; + }

      +
      default: {
      log_debug("Caught unknown signal %d",sig);
      break;
      @@ -232,6 +240,9 @@
      #endif
      static void controller(int sig) {
      switch (sig) {
      + case SIGUSR1:
      + log_debug("Reopening logs");
      + set_output(NULL,NULL,-1,-1);
      case SIGTERM:
      case SIGINT:
      case SIGHUP:
      @@ -514,6 +525,7 @@

      /* Install signal handlers */
      handler_hup=signal_set(SIGHUP,handler);
      + handler_usr1=signal_set(SIGUSR1,handler);
      handler_trm=signal_set(SIGTERM,handler);
      handler_int=signal_set(SIGINT,handler);
      controlled = getpid();
      @@ -565,7 +577,25 @@
      /**

      • Redirect stdin, stdout, stderr.
        */
        -static void set_output(char *outfile, char *errfile) {
        +static void set_output(char *outfile_arg, char *errfile_arg,
        + uid_t uid_arg, gid_t gid_arg) {
        + static char *outfile=NULL;
        + static char *errfile=NULL;
        + static uid_t uid=0;
        + static gid_t gid=0;
        + if (outfile_arg!=NULL) { + outfile=(char *)realloc((void *)outfile, strlen(outfile_arg)+1); + strcpy(outfile,outfile_arg); + }

        + if (errfile_arg!=NULL)

        { + errfile=(char *)realloc((void *)errfile, strlen(errfile_arg)+1); + strcpy(errfile,errfile_arg); + }

        + if (uid_arg != -1)
        + uid = uid_arg;
        + if (gid_arg != -1)
        + gid = gid_arg;
        +
        freopen("/dev/null", "r", stdin);
        log_debug("redirecting stdout to %s and stderr to %s",outfile,errfile);

      @@ -579,10 +609,12 @@
      }
      if(strcmp(outfile, "&2") != 0)

      { loc_freopen(outfile, "a", stdout); + chown(outfile,uid,gid); }

      if(strcmp(errfile,"&1") != 0)

      { loc_freopen(errfile, "a", stderr); + chown(errfile,uid,gid); }

      else

      { close(2); dup(1); @@ -678,7 +710,7 @@ #endif }
      • set_output(args->outfile, args->errfile);
        + set_output(args->outfile, args->errfile,uid,gid);

      /* We have to fork: this process will become the controller and the other
      will be the child */
      @@ -693,6 +725,7 @@
      SetTerm(cygwincontroller);
      #endif
      signal(SIGHUP,controller);
      + signal(SIGUSR1,controller);
      signal(SIGTERM,controller);
      signal(SIGINT,controller);

      Attachments

        1. jsvc_reopen_usr1.diff
          2 kB
          Damien Raude-Morvan

        Issue Links

          Activity

            People

              mturk@apache.org Mladen Turk
              mike@pictage.com Mike Polek
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: