]> sourceware.org Git - systemtap.git/commitdiff
PR 9821: Use genuine strftime in staprun/stapio
authorMasami Hiramatsu <mhiramat@redhat.com>
Wed, 22 Apr 2009 17:16:25 +0000 (13:16 -0400)
committerMasami Hiramatsu <mhiramat@redhat.com>
Wed, 22 Apr 2009 17:16:25 +0000 (13:16 -0400)
* Makefile.am: Add -fno-builtin-strftime to stapio_CFLAGS.
* Makefile.in: Ditto.
* runtime/staprun/common.c (stap_strfloctime): Use strftime(3).
  (parse_args): Remove strftime format limitation message.
* main.cxx (usage): Ditto.
* stap.1.in: Ditto.
* staprun.8.in: Ditto.

Makefile.am
Makefile.in
main.cxx
runtime/staprun/common.c
stap.1.in
staprun.8.in

index 33563719f05ebf80dc035ccdb782f71947411d50..c9e123fb37a7a4141a2125799637ed1efc05d719 100644 (file)
@@ -133,7 +133,7 @@ staprun_SOURCES = runtime/staprun/staprun.c runtime/staprun/staprun_funcs.c\
        runtime/staprun/ctl.c runtime/staprun/common.c
 
 staprun_CPPFLAGS = $(AM_CPPFLAGS)
-staprun_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -DSINGLE_THREADED -fno-strict-aliasing
+staprun_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -DSINGLE_THREADED -fno-strict-aliasing -fno-builtin-strftime
 staprun_LDFLAGS = $(AM_LDFLAGS) @PIELDFLAGS@
 staprun_LDADD = @PROCFLAGS@
 
@@ -141,7 +141,7 @@ stapio_SOURCES = runtime/staprun/stapio.c \
        runtime/staprun/mainloop.c runtime/staprun/common.c \
        runtime/staprun/ctl.c \
        runtime/staprun/relay.c runtime/staprun/relay_old.c
-stapio_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -fno-strict-aliasing
+stapio_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -fno-strict-aliasing -fno-builtin-strftime
 stapio_LDFLAGS = $(AM_LDFLAGS) @PIELDFLAGS@
 stapio_LDADD = @PROCFLAGS@ -lpthread
 
index 9c80e321f398cd3c3aa17b9454e9629519ea1c8f..4fc0c8ffcf909a348c9da795f8b1f7381d5b12ff 100644 (file)
@@ -342,7 +342,7 @@ staprun_SOURCES = runtime/staprun/staprun.c runtime/staprun/staprun_funcs.c\
        runtime/staprun/ctl.c runtime/staprun/common.c
 
 staprun_CPPFLAGS = $(AM_CPPFLAGS)
-staprun_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -DSINGLE_THREADED -fno-strict-aliasing
+staprun_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -DSINGLE_THREADED -fno-strict-aliasing -fno-builtin-strftime
 staprun_LDFLAGS = $(AM_LDFLAGS) @PIELDFLAGS@
 staprun_LDADD = @PROCFLAGS@
 stapio_SOURCES = runtime/staprun/stapio.c \
@@ -350,7 +350,7 @@ stapio_SOURCES = runtime/staprun/stapio.c \
        runtime/staprun/ctl.c \
        runtime/staprun/relay.c runtime/staprun/relay_old.c
 
-stapio_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -fno-strict-aliasing
+stapio_CFLAGS = @PROCFLAGS@ $(AM_CFLAGS) @PIECFLAGS@ -fno-strict-aliasing -fno-builtin-strftime
 stapio_LDFLAGS = $(AM_LDFLAGS) @PIELDFLAGS@
 stapio_LDADD = @PROCFLAGS@ -lpthread
 @BUILD_SERVER_TRUE@stap_client_connect_SOURCES = stap-client-connect.c
index 37c5b13533309f81e7b36b58b797f8bf432a3926..1111b316c14683b8247f48066837104de02b07e6 100644 (file)
--- a/main.cxx
+++ b/main.cxx
@@ -109,8 +109,7 @@ usage (systemtap_session& s, int exitcode)
     << "   -m MODULE  set probe module name, instead of " << endl
     << "              " << s.module_name << endl
     << "   -o FILE    send script output to file, instead of stdout. This supports" << endl
-    << "              a subset of strftime(3) (%%,%C,%Y,%y,%m,%d,%e,%F,%H,%I,%j,%k," << endl
-    << "              %l,%M,%S,%R,%T,%u,%w) for FILE." << endl
+    << "              strftime(3) formats for FILE" << endl
     << "   -c CMD     start the probes, run CMD, and exit when it finishes" << endl
     << "   -x PID     sets target() to PID" << endl
     << "   -F         run as on-file flight recorder with -o." << endl
index 26b166c237f9f18c4ba887166587a3e517f6f9ec..c67ce34094c9a9a8545ab49e928f4f4c7090058d 100644 (file)
@@ -55,112 +55,15 @@ static char *get_abspath(char *path)
 
 int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t)
 {
-       char *c = buf;
-       const char *c2 = fmt, *end = buf + max;
-       int ret, num;
        struct tm tm;
+       size_t ret;
        if (buf == NULL || fmt == NULL || max <= 1)
                return -EINVAL;
        localtime_r(&t, &tm);
-
-       while (*c2 != '\0'){
-               if (c + 1 >= end)
-                       return -EINVAL;
-               if (*c2 != '%') {
-                       *c++ = *c2++;
-                       continue;
-               }
-               c2++;
-               switch (*c2++) {
-               case '%':
-                       *c++ = '%';
-                       break;
-               case 'Y':
-                       num = tm.tm_year + 1900;
-                       goto numbering;
-               case 'y':
-                       num = tm.tm_year % 100;
-                       goto numbering02;
-               case 'C':
-                       num = ((tm.tm_year + 1900) / 100);
-                       goto numbering;
-               case 'm':
-                       num = tm.tm_mon + 1;
-                       goto numbering02;
-               case 'd':
-                       num = tm.tm_mday;
-                       goto numbering02;
-               case 'e':
-                       num = tm.tm_mday;
-                       goto numbering;
-               case 'F':
-                       ret = snprintf(c, end - c, "%d-%02d-%02d",
-                               tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
-                       if (ret < 0) return ret;
-                       c += ret;
-                       break;
-               case 'H':
-                       num = tm.tm_hour;
-                       goto numbering02;
-               case 'I':
-                       num = tm.tm_hour % 12;
-                       if (num == 0) num = 12;
-                       goto numbering02;
-               case 'j':
-                       ret = snprintf(c, end - c, "%03d", tm.tm_yday + 1);
-                       if (ret < 0) return ret;
-                       c += ret;
-                       break;
-               case 'k':
-                       num = tm.tm_hour;
-                       goto numbering;
-               case 'l':
-                       num = tm.tm_hour % 12;
-                       if (num == 0) num = 12;
-                       ret = snprintf(c, end - c, "%2d", num);
-                       if (ret < 0) return ret;
-                       c += ret;
-                       break;
-               case 'M':
-                       num = tm.tm_min;
-                       goto numbering02;
-               case 'S':
-                       num = tm.tm_sec;
-                       goto numbering02;
-               case 'R':
-                       ret = snprintf(c, end - c, "%02d:%02d",
-                                       tm.tm_hour, tm.tm_min);
-                       if (ret < 0) return ret;
-                       c += ret;
-                       break;
-               case 'T':
-                       ret = snprintf(c, end - c, "%02d:%02d:%02d",
-                                       tm.tm_hour, tm.tm_min, tm.tm_sec);
-                       if (ret < 0) return ret;
-                       c += ret;
-                       break;
-               case 'u':
-                       num = tm.tm_wday == 0 ? 7 : tm.tm_wday;
-                       goto numbering;
-               case 'w':
-                       num = tm.tm_wday;
-                       goto numbering;
-               default:
-                       return -EINVAL;
-               }
-               continue;
-numbering:
-               ret = snprintf(c, end - c, "%d", num);
-               if (ret < 0) return ret;
-               c += ret;
-               continue;
-numbering02:
-               ret = snprintf(c, end - c, "%02d", num);
-               if (ret < 0) return ret;
-               c += ret;
-       }
-       *c = '\0';
-       return c - buf;
+       ret = strftime(buf, max, fmt, &tm);
+       if (ret == 0)
+               return -EINVAL;
+       return (int)ret;
 }
 
 void parse_args(int argc, char **argv)
@@ -309,9 +212,8 @@ void usage(char *prog)
        err("                exit when it does.  The '_stp_target' variable\n");
        err("                will contain the pid for the command.\n");
        err("-x pid          Sets the '_stp_target' variable to pid.\n");
-       err("-o FILE         Send output to FILE. This supports a subset of\n");
-       err("                strftime(3) (%%%%,%%C,%%Y,%%y,%%m,%%d,%%e,%%F,%%H,%%I\n");
-       err("                %%j,%%k,%%l,%%M,%%S,%%R,%%T,%%u,%%w) for FILE.\n");
+       err("-o FILE         Send output to FILE. This supports strftime(3)\n");
+       err("                formats for FILE.\n");
        err("-b buffer size  The systemtap module specifies a buffer size.\n");
        err("                Setting one here will override that value.  The\n");
        err("                value should be an integer between 1 and 4095 \n");
index 82a62b6d63b65fad8c0a972971a951828212d771..aed473d7fc06faf9930bf5de45be0a77a2b781ed 100644 (file)
--- a/stap.1.in
+++ b/stap.1.in
@@ -181,8 +181,7 @@ even if they do not have an explicit probe placed into them.
 .BI \-o " FILE"
 Send standard output to named file. In bulk mode, percpu files will
 start with FILE_ (FILE_cpu with -F) followed by the cpu number.
-This supports a subset of strftime(3) (%%, %C, %Y, %y, %m, %d, %e, %F,
-%H, %I, %j, %l, %M, %S, %R, %T, %u, %w) for FILE.
+This supports strftime(3) formats for FILE.
 .TP
 .BI \-c " CMD"
 Start the probes, run CMD, and exit when CMD finishes.
index 5d2a72a60c4c307c54184824a294c7a44d26abaf..b9993288cad7002c499c0abebfd6f0721faa4141 100644 (file)
@@ -53,8 +53,7 @@ The '_stp_target' variable will be set to PID.
 .B \-o FILE
 Send output to FILE. If the module uses bulk mode, the output will
 be in percpu files FILE_x(FILE_cpux in backgroud and bulk mode)
-where 'x' is the cpu number. This supports a subset of strftime(3)
-(%%, %C, %Y, %y, %m, %d, %e, %F, %H, %I, %j, %l, %M, %S, %R, %T, %u, %w)
+where 'x' is the cpu number. This supports strftime(3) formats
 for FILE.
 .TP
 .B \-b BUFFER_SIZE
This page took 0.047072 seconds and 5 git commands to generate.