[flow-tools] flow-capture post rotate exec patch

Mark Fullmer maf@eng.oar.net
Wed, 5 Sep 2001 00:50:13 -0400


Thanks.  Will in in 0.56.

On Wed, Aug 29, 2001 at 04:21:07PM +0300, Stefan Stefanov wrote:
> Hi,
> 
> Here is a patch to flow-capture that will add the post rotate program
> execution capability. The -R option is the program to execute, that will
> take as an argument the file that has just been rotated. I hope the
> patch is clear enough. Any comments are welcome.
> 
> -- 
> Best Regards,
> 
> Stefan Stefanov
> CTO
> Orbitel - the Internet Company
> tel.: +359 2 937 07 20 fax: +359 2 980 42 58
> --- flow-tools-0.55/src/flow-capture.c	Tue Jul 17 07:13:37 2001
> +++ flow-tools-0.55-modified/src/flow-capture.c	Wed Aug 29 15:45:30 2001
> @@ -37,6 +37,7 @@
>  #include <sys/socket.h>
>  #include <sys/param.h>
>  #include <sys/stat.h>
> +#include <sys/wait.h>
>  #include <netinet/in.h>
>  #include <arpa/inet.h>
>  #include <unistd.h>
> @@ -162,6 +163,7 @@
>    struct ftipmask ftipmask;
>    time_t now;
>    char work_dir[MAXPATHLEN+1];
> +  char post_rotate_exec[MAXPATHLEN+1];
>    int i, n, len, invalid, enable_unlink, offset, detach, nest, one;
>    unsigned int v1, v2;
>    u_int32 privacy_mask, hash;
> @@ -174,6 +176,7 @@
>    bzero (&ftnet, sizeof ftnet);
>    bzero (&tv, sizeof tv);
>    bzero (&work_dir, sizeof work_dir);
> +  bzero (&post_rotate_exec, sizeof post_rotate_exec);
>    bzero (&fte, sizeof fte);
>    bzero (&client, sizeof client);
>    bzero (&ftpdu, sizeof ftpdu);
> @@ -216,7 +219,7 @@
>    /* year/month/day nesting */
>    nest = 3;
>  
> -  while ((i = getopt(argc, argv, "A:b:c:C:d:De:E:hm:n:N:S:V:w:z:")) != -1)
> +  while ((i = getopt(argc, argv, "A:b:c:C:d:De:E:hm:n:N:S:V:w:z:R:")) != -1)
>    
>      switch (i) {
>  
> @@ -317,6 +320,14 @@
>          fterr_errx(1, "Compression level must be between 0 and 9");
>        break;
>  
> +    case 'R': /* Post rotate exec */
> +      if (strlen(optarg) > MAXPATHLEN)
> +        fterr_errx(1, "Post rotate argument too long");
> + 
> +      strcpy(post_rotate_exec,optarg);
> +      break;
> +
> +
>      default:
>        usage();
>        exit (1);
> @@ -947,7 +958,20 @@
>          if (debug)
>            ftfile_dump(&fte);
>  
> -        /* reset */
> +	/* Do the post rotate exec */
> +
> +        if(post_rotate_exec[0]) {
> +         
> +          if(fork()==0) {
> +            if(fork()==0) {
> +		execl(post_rotate_exec,cap_file.nname);
> +            }
> +            exit(0);
> +          }  
> +          wait(NULL);
> +        }
> +        
> +	/* reset */
>          bzero(&cap_file, sizeof cap_file);
>  
>          /* invalidate file descriptor */