[rrd-developers] rrdtool update patch

Kimball, Conrad conrad.kimball at boeing.com
Thu Nov 6 19:48:41 MET 2003


I am brand-new to rrdtool and don't know the accepted process for developing changes.  Any pointers would be welcome.

I offer for your consideration this patch I developed against rrdtool-1.0.45.  Note that the patch only modifies the code files; I haven't figured out how to modify the documentation files.

Conrad Kimball
Associate Technical Fellow
Client Server IT Services, Shared Services Group
conrad.kimball at boeing.com
P.O.Box 24346, MS 7M-HC
Seattle, WA  98124-0346
Bellevue 33-12 bldg, cube 37C3
Phone: (425) 865-6410
Pager:  (206) 797-3112
Cell:      (425) 591-7802

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This patch to rrdtool-1.0.45 does three things:

1. AT-STYLE time specifications now allow HH:MM:SS as well as HH:MM for
   TIME-OF-DAY-SPEC (provides granularity down to the second).

2. "rrdtool update" now uses parsetime() to parse the <timestamp> field
   of the new data arguments, which allows the timestamp to be specified
   in AT-STYLE form as well in the form of as seconds since 1970-01-01.

3. Because AT-STYLE time specifications may need to use colons to specify
   HH:MM or HH:MM:SS, "rrdtool update" now allows the <timestamp> field
   of the new data arguments to be quoted.  Quoting is accomplished by
   enclosing the <timestamp> field within a pair of single quote (') or
   double quote (") characters.


Nov 11, 2003 by Conrad Kimball, The Boeing Company
conrad.kimball at boeing.com


*** src/rrd_update.c.orig	Mon Jul 21 11:24:57 2003
--- src/rrd_update.c	Wed Nov  5 21:48:01 2003
***************
*** 237,242 ****
--- 237,243 ----
      for(arg_i=optind+1; arg_i<argc;arg_i++) {
  	char *stepper = malloc((strlen(argv[arg_i])+1)*sizeof(char));
          char *step_start = stepper;
+ 	char in_quotes = '\0';
          if (stepper == NULL){
                  rrd_set_error("faild duplication argv entry");
                  free(updvals);
***************
*** 251,259 ****
  	for(ii=1;ii<=rrd.stat_head->ds_cnt;ii++) updvals[ii] = "U";
  	ii=0;
  	strcpy(stepper,argv[arg_i]);
  	updvals[0]=stepper;
  	while (*stepper) {
! 	    if (*stepper == ':') {
  		*stepper = '\0';
  		ii++;
  		if (ii<tmpl_cnt){		    
--- 252,272 ----
  	for(ii=1;ii<=rrd.stat_head->ds_cnt;ii++) updvals[ii] = "U";
  	ii=0;
  	strcpy(stepper,argv[arg_i]);
+ 	if (*stepper == '"' || *stepper == '\'') {
+ 	    in_quotes = *stepper;
+ 	    stepper++;
+ 	}
  	updvals[0]=stepper;
  	while (*stepper) {
! 	    if (in_quotes) {
! 		if (*stepper == in_quotes) {
! 		    char *s;
! 		    for (s = stepper; *s; s++) *s = *(s+1);
! 		    in_quotes = '\0';
! 		    continue;
! 		}
! 	    }
! 	    else if (*stepper == ':') {
  		*stepper = '\0';
  		ii++;
  		if (ii<tmpl_cnt){		    
***************
*** 274,280 ****
  	if (strcmp(updvals[0],"N")==0){
  	    current_time = time(NULL);
  	} else {
! 	    current_time = atol(updvals[0]);
  	}
  	
  	if(current_time <= rrd.live_head->last_up){
--- 287,306 ----
  	if (strcmp(updvals[0],"N")==0){
  	    current_time = time(NULL);
  	} else {
! 	    struct time_value updtime;
! 	    char *parsetime_error = NULL;
! 
! 	    if ((parsetime_error = parsetime(updvals[0], &updtime))) {
! 	    	rrd_set_error( "update time: %s", parsetime_error);
! 		free(step_start);
! 		break;
! 	    }
! 	    if (updtime.type != ABSOLUTE_TIME) {
! 	    	rrd_set_error( "update time must be absolute: %s", updvals[0]);
! 		free(step_start);
! 		break;
! 	    }
! 	    current_time = mktime(&(updtime.tm));
  	}
  	
  	if(current_time <= rrd.live_head->last_up){
*** src/parsetime.c.orig	Mon Jul 21 11:24:54 2003
--- src/parsetime.c	Wed Nov  5 21:38:13 2003
***************
*** 47,53 ****
   * TIME-REFERENCE ::= NOW | TIME-OF-DAY-SPEC [ DAY-SPEC-1 ] |
   *                        [ TIME-OF-DAY-SPEC ] DAY-SPEC-2
   *
!  * TIME-OF-DAY-SPEC ::= NUMBER (':') NUMBER [am|pm] | # HH:MM
   *                     'noon' | 'midnight' | 'teatime'
   *
   * DAY-SPEC-1 ::= NUMBER '/' NUMBER '/' NUMBER |  # MM/DD/[YY]YY
--- 47,53 ----
   * TIME-REFERENCE ::= NOW | TIME-OF-DAY-SPEC [ DAY-SPEC-1 ] |
   *                        [ TIME-OF-DAY-SPEC ] DAY-SPEC-2
   *
!  * TIME-OF-DAY-SPEC ::= NUMBER (':') NUMBER [(':') NUMBER] [am|pm] | # HH:MM:SS
   *                     'noon' | 'midnight' | 'teatime'
   *
   * DAY-SPEC-1 ::= NUMBER '/' NUMBER '/' NUMBER |  # MM/DD/[YY]YY
***************
*** 450,456 ****
  
  
  /* 
!  * expect2() gets a token and complins if it's not the token we want
   */
  static char *
  expect2(int desired, char *complain_fmt, ...)
--- 450,456 ----
  
  
  /* 
!  * expect2() gets a token and complains if it's not the token we want
   */
  static char *
  expect2(int desired, char *complain_fmt, ...)
***************
*** 469,475 ****
  /*
   * plus_minus() is used to parse a single NUMBER TIME-UNIT pair
   *              for the OFFSET-SPEC.
!  *              It allso applies those m-guessing euristics.
   */
  static char *
  plus_minus(struct time_value *ptv, int doop)
--- 469,475 ----
  /*
   * plus_minus() is used to parse a single NUMBER TIME-UNIT pair
   *              for the OFFSET-SPEC.
!  *              It also applies those m-guessing heuristics.
   */
  static char *
  plus_minus(struct time_value *ptv, int doop)
***************
*** 554,560 ****
  static char *
  tod(struct time_value *ptv)
  {
!     int hour, minute = 0;
      int tlen;
      /* save token status in  case we must abort */
      int scc_sv = scc; 
--- 554,560 ----
  static char *
  tod(struct time_value *ptv)
  {
!     int hour, minute, second = 0;
      int tlen;
      /* save token status in  case we must abort */
      int scc_sv = scc; 
***************
*** 581,593 ****
        return TIME_OK;
      }
      if (sc_tokid == COLON ) {
!        try(expect2(NUMBER,
!             "Parsing HH:MM syntax, expecting MM as number, got none"));
  	minute = atoi(sc_token);
  	if (minute > 59) {
  	    panic(e("parsing HH:MM syntax, got MM = %d (>59!)", minute ));
  	}
  	token();
      }
  
      /* check if an AM or PM specifier was given
--- 581,602 ----
        return TIME_OK;
      }
      if (sc_tokid == COLON ) {
! 	try(expect2(NUMBER,
!             "Parsing HH:MM[:SS] syntax, expecting MM as number, got none"));
  	minute = atoi(sc_token);
  	if (minute > 59) {
  	    panic(e("parsing HH:MM syntax, got MM = %d (>59!)", minute ));
  	}
  	token();
+ 	if (sc_tokid == COLON) {
+ 	    try(expect2(NUMBER,
+ 		"Parsing HH:MM:SS syntax, expecting SS as number, got none"));
+ 	    second = atoi(sc_token);
+ 	    if (second > 59) {
+ 		panic(e("parsing HH:MM:SS syntax, got SS = %d (>59!)", second ));
+ 	    }
+ 	    token();
+ 	}
      }
  
      /* check if an AM or PM specifier was given
***************
*** 615,621 ****
      }
      ptv->tm.tm_hour = hour;
      ptv->tm.tm_min = minute;
!     ptv->tm.tm_sec = 0;
      if (ptv->tm.tm_hour == 24) {
  	ptv->tm.tm_hour = 0;
  	ptv->tm.tm_mday++;
--- 624,630 ----
      }
      ptv->tm.tm_hour = hour;
      ptv->tm.tm_min = minute;
!     ptv->tm.tm_sec = second;
      if (ptv->tm.tm_hour == 24) {
  	ptv->tm.tm_hour = 0;
  	ptv->tm.tm_mday++;


--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list