diff options
| author | Kaleb S. KEITHLEY <kkeithle@redhat.com> | 2012-06-13 09:13:04 -0400 | 
|---|---|---|
| committer | Anand Avati <avati@redhat.com> | 2012-06-29 14:08:14 -0700 | 
| commit | 5672e77d3102a990a2aa11e7e56ebfe6a0eee369 (patch) | |
| tree | c92612a433383c70a9e4557ddaffbcdc348e0921 | |
| parent | d87bd36040128c6553e8ee06a363eeb60d16e72c (diff) | |
localtime and ctime are not MT-SAFE
There are a number of nit-level issues throughout the source with
the use of localtime and ctime. While they apparently aren't causing
too many problems, apart from the one in bz 828058, they ought to be
fixed.  Among the "real" problems that are fixed in this patch:
 1) general localtime and ctime not MT-SAFE. There's a non-zero chance
    that another thread calling localtime (or ctime) will over-write
    the static data about to be used in another thread
 2) localtime(& <64-bit-type>) or ctime(& <64-bit-type>) generally
    not a problem on 64-bit or little-endian 32-bit. But even though
    we probably have zero users on big-ending 32-bit platforms, it's
    still incorrect.
 3) multiple nested calls passed as params. Last one wins, i.e. over-
    writes result of prior calls.
 4) Inconsistent error handling. Most of these calls are for logging,
    tracing, or dumping. I submit that if an error somehow occurs in
    the call to localtime or ctime, the log/trace/dump still should
    still occur.
 5) Appliances should all have their clocks set to UTC, and all log
    entries, traces, and dumps should use GMT.
 6) fix strtok(), change to strtok_r()
Other things this patch fixes/changes (that aren't bugs per se):
 1) Change "%Y-%m-%d %H:%M:%S" and similar to their equivalent shorthand,
    e.g. "%F %T"
 2) change sizeof(timestr) to sizeof timestr. sizeof is an operator,
    not a function. You don't use i +(32), why use sizeof(<var>).
    (And yes, you do use parens with sizeof(<type>).)
 3) change 'char timestr[256]' to 'char timestr[32]' where appropriate.
    Per-thread stack is limited. Time strings are never longer than ~20
    characters, so why waste 220+ bytes on the stack?
Things this patch doesn't fix:
 1) hodgepodge of %Y-%m-%d %H:%M:%S versus %Y/%m/%d-%H%M%S and other
    variations. It's not clear to me whether this ever matters, not to
    mention 3rd party log filtering tools may already rely on a
    particular format. Still it would be nice to have a single manifest
    constant and have every call to localtime/strftime consistently use
    the same format.
Change-Id: I827cad7bf53e57b69c0173f67abe72884249c1a9
BUG: 832173
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: http://review.gluster.com/3568
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
22 files changed, 227 insertions, 265 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 931d89ae..8c16588a 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1581,12 +1581,10 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)                          if (strcmp (words[cmdi + 1], "checkpoint") == 0 &&                              strcmp (append_str, "now") == 0) {                                  struct timeval tv = {0,}; -                                struct tm     *tm = NULL;                                  ret = gettimeofday (&tv, NULL);                                  if (ret == -1) -                                         goto out; -                                tm = localtime (&tv.tv_sec); +                                         goto out; /* FIXME: free append_str? */                                  GF_FREE (append_str);                                  append_str = GF_CALLOC (1, 300, cli_mt_append_str); @@ -1595,9 +1593,9 @@ cli_cmd_gsync_set_parse (const char **words, int wordcount, dict_t **options)                                          goto out;                                  }                                  strcpy (append_str, "as of "); -                                strftime (append_str + strlen ("as of "), -                                          300 - strlen ("as of "), -                                          "%Y-%m-%d %H:%M:%S", tm); +                                gf_time_fmt (append_str + strlen ("as of "), +                                             300 - strlen ("as of "), +                                             tv.tv_sec, gf_timefmt_FT);                          }                          ret = dict_set_dynstr (dict, "op_value", append_str); diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 0b64758f..492be438 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -4069,15 +4069,15 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov,  {          gf_cli_rsp                        rsp   = {0,};          int                               ret   = -1; -        dict_t                            *dict = NULL; +        dict_t                           *dict = NULL;          gf1_cli_stats_op                  op = GF_CLI_STATS_NONE;          char                              key[256] = {0};          int                               i = 0;          int32_t                           brick_count = 0;          char                              brick[1024];          int32_t                           members = 0; -        char                              *filename; -        char                              *bricks; +        char                             *filename; +        char                             *bricks;          uint64_t                          value = 0;          int32_t                           j = 0;          gf1_cli_top_op                    top_op = GF_CLI_TOP_NONE; @@ -4085,11 +4085,10 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov,          uint64_t                          max_nr_open = 0;          double                            throughput = 0;          double                            time = 0; -        long int                          time_sec = 0; +        int32_t                           time_sec = 0;          long int                          time_usec = 0; -        struct tm                         *tm = NULL;          char                              timestr[256] = {0, }; -        char                              *openfd_str = NULL; +        char                             *openfd_str = NULL;          gf_boolean_t                      nfs = _gf_false;          gf_boolean_t                      clear_stats = _gf_false;          int                               stats_cleared = 0; @@ -4262,11 +4261,9 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov,                                  ret = dict_get_int32 (dict, key, (int32_t *)&time_usec);                                  if (ret)                                          goto out; -                                tm    = localtime (&time_sec); -                                if (!tm) -                                        goto out; -                                strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -                                snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +                                gf_time_fmt (timestr, sizeof timestr, +                                             time_sec, gf_timefmt_FT); +                                snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                                    ".%"GF_PRI_SUSECONDS, time_usec);                                  if (strlen (filename) < VOL_TOP_PERF_FILENAME_DEF_WIDTH)                                          cli_out ("%*"PRIu64" %-*s %-*s", @@ -5854,52 +5851,43 @@ cmd_heal_volume_brick_out (dict_t *dict, int brick)          uint64_t        num_entries = 0;          int             ret = 0;          char            key[256] = {0}; -        char            *hostname = NULL; -        char            *path = NULL; -        char            *status = NULL; +        char           *hostname = NULL; +        char           *path = NULL; +        char           *status = NULL;          uint64_t        i = 0;          uint32_t        time = 0; -        char            timestr[256] = {0}; -        struct tm       tm = {0}; -        time_t          ltime = 0; +        char            timestr[32] = {0}; -        snprintf (key, sizeof (key), "%d-hostname", brick); +        snprintf (key, sizeof key, "%d-hostname", brick);          ret = dict_get_str (dict, key, &hostname);          if (ret)                  goto out; -        snprintf (key, sizeof (key), "%d-path", brick); +        snprintf (key, sizeof key, "%d-path", brick);          ret = dict_get_str (dict, key, &path);          if (ret)                  goto out;          cli_out ("\nBrick %s:%s", hostname, path); -        snprintf (key, sizeof (key), "%d-count", brick); +        snprintf (key, sizeof key, "%d-count", brick);          ret = dict_get_uint64 (dict, key, &num_entries);          cli_out ("Number of entries: %"PRIu64, num_entries); -        snprintf (key, sizeof (key), "%d-status", brick); +        snprintf (key, sizeof key, "%d-status", brick);          ret = dict_get_str (dict, key, &status);          if (status && strlen (status))                  cli_out ("Status: %s", status);          for (i = 0; i < num_entries; i++) { -                snprintf (key, sizeof (key), "%d-%"PRIu64, brick, i); +                snprintf (key, sizeof key, "%d-%"PRIu64, brick, i);                  ret = dict_get_str (dict, key, &path);                  if (ret)                          continue;                  time = 0; -                snprintf (key, sizeof (key), "%d-%"PRIu64"-time", brick, i); +                snprintf (key, sizeof key, "%d-%"PRIu64"-time", brick, i);                  ret = dict_get_uint32 (dict, key, &time);                  if (!time) {                          cli_out ("%s", path);                  } else { -                        ltime = time; -                        memset (&tm, 0, sizeof (tm)); -                        if (!localtime_r (<ime, &tm)) { -                                snprintf (timestr, sizeof (timestr), -                                          "Invalid time"); -                        } else { -                                strftime (timestr, sizeof (timestr), -                                          "%Y-%m-%d %H:%M:%S", &tm); -                        } -                        if (i ==0) { +                        gf_time_fmt (timestr, sizeof timestr, +                                     time, gf_timefmt_FT); +                        if (i == 0) {                                  cli_out ("at                    path on brick");                                  cli_out ("-----------------------------------");                          } diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 702a7f7f..510ad010 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -1429,14 +1429,13 @@ int  cli_xml_output_vol_top_rw_perf (xmlTextWriterPtr writer, dict_t *dict,                                  int brick_index, int member_index)  { -        int             ret = -1; -        char            *filename = NULL; -        uint64_t        throughput = 0; -        long int        time_sec = 0; -        long int        time_usec = 0; -        struct tm       *tm = NULL; -        char            timestr[256] = {0,}; -        char            key[1024] = {0,}; +        int        ret = -1; +        char      *filename = NULL; +        uint64_t   throughput = 0; +        long int   time_sec = 0; +        long int   time_usec = 0; +        char       timestr[256] = {0,}; +        char       key[1024] = {0,};          /* <file> */          ret = xmlTextWriterStartElement (writer, (xmlChar *)"file"); @@ -1474,14 +1473,9 @@ cli_xml_output_vol_top_rw_perf (xmlTextWriterPtr writer, dict_t *dict,          if (ret)                  goto out; -        tm = localtime (&time_sec); -        if (!tm) { -                ret = -1; -                goto out; -        } -        strftime (timestr, sizeof (timestr), "%Y-%m-%d %H:%M:%S", tm); +        gf_time_fmt (timestr, sizeof timestr, time_sec, gf_timefmt_FT);          snprintf (timestr + strlen (timestr), -                  sizeof (timestr) - strlen (timestr), +                  sizeof timestr - strlen (timestr),                    ".%"GF_PRI_SUSECONDS, time_usec);          ret = xmlTextWriterWriteFormatElement (writer, (xmlChar *)"time",                                                 "%s", timestr); diff --git a/cli/src/cli.c b/cli/src/cli.c index 0d66ff28..16e434f0 100644 --- a/cli/src/cli.c +++ b/cli/src/cli.c @@ -108,7 +108,6 @@ generate_uuid ()          char           tmp_str[1024] = {0,};          char           hostname[256] = {0,};          struct timeval tv = {0,}; -        struct tm      now = {0, };          char           now_str[32];          if (gettimeofday (&tv, NULL) == -1) { @@ -123,9 +122,8 @@ generate_uuid ()                          strerror (errno));          } -        localtime_r (&tv.tv_sec, &now); -        strftime (now_str, 32, "%Y/%m/%d-%H:%M:%S", &now); -        snprintf (tmp_str, 1024, "%s-%d-%s:%" +        gf_time_fmt (now_str, sizeof now_str, tv.tv_sec, gf_timefmt_Ymd_T); +        snprintf (tmp_str, sizeof tmp_str, "%s-%d-%s:%"  #ifdef GF_DARWIN_HOST_OS                    PRId32,  #else diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c index c6285b2e..433cabef 100644 --- a/glusterfsd/src/glusterfsd.c +++ b/glusterfsd/src/glusterfsd.c @@ -910,7 +910,6 @@ generate_uuid ()          char           tmp_str[1024] = {0,};          char           hostname[256] = {0,};          struct timeval tv = {0,}; -        struct tm      now = {0, };          char           now_str[32];          if (gettimeofday (&tv, NULL) == -1) { @@ -919,15 +918,14 @@ generate_uuid ()                          strerror (errno));          } -        if (gethostname (hostname, 256) == -1) { +        if (gethostname (hostname, sizeof hostname) == -1) {                  gf_log ("glusterfsd", GF_LOG_ERROR,                          "gethostname: failed %s",                          strerror (errno));          } -        localtime_r (&tv.tv_sec, &now); -        strftime (now_str, 32, "%Y/%m/%d-%H:%M:%S", &now); -        snprintf (tmp_str, 1024, "%s-%d-%s:%" GF_PRI_SUSECONDS, +        gf_time_fmt (now_str, sizeof now_str, tv.tv_sec, gf_timefmt_Ymd_T); +        snprintf (tmp_str, sizeof tmp_str, "%s-%d-%s:%" GF_PRI_SUSECONDS,                    hostname, getpid(), now_str, tv.tv_usec);          return gf_strdup (tmp_str); @@ -1197,16 +1195,14 @@ gf_check_and_set_mem_acct (int argc, char *argv[], glusterfs_ctx_t *ctx)  int  parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx)  { -        int               process_mode = 0; -        int               ret = 0; -        struct stat       stbuf = {0, }; -        struct tm        *tm = NULL; -        time_t            utime; -        char              timestr[256]; -        char              tmp_logfile[1024] = { 0 }; -        char              *tmp_logfile_dyn = NULL; -        char              *tmp_logfilebase = NULL; -        cmd_args_t        *cmd_args = NULL; +        int          process_mode = 0; +        int          ret = 0; +        struct stat  stbuf = {0, }; +        char         timestr[32]; +        char         tmp_logfile[1024] = { 0 }; +        char        *tmp_logfile_dyn = NULL; +        char        *tmp_logfilebase = NULL; +        cmd_args_t  *cmd_args = NULL;          cmd_args = &ctx->cmd_args; @@ -1263,8 +1259,8 @@ parse_cmdline (int argc, char *argv[], glusterfs_ctx_t *ctx)                       (S_ISREG (stbuf.st_mode) || S_ISLNK (stbuf.st_mode))) ||                      (ret == -1)) {                          /* Have separate logfile per run */ -                        tm = localtime (&utime); -                        strftime (timestr, 256, "%Y%m%d.%H%M%S", tm); +                        gf_time_fmt (timestr, sizeof timestr, time (NULL), +                                     gf_timefmt_FT);                          sprintf (tmp_logfile, "%s.%s.%d",                                   cmd_args->log_file, timestr, getpid ()); diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 280cf218..82a49366 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -396,10 +396,8 @@ void  gf_print_trace (int32_t signum)  {          extern FILE *gf_log_logfile; -        struct tm   *tm = NULL;          char         msg[1024] = {0,}; -        char         timestr[256] = {0,}; -        time_t       utime = 0; +        char         timestr[64] = {0,};          int          ret = 0;          int          fd = 0; @@ -448,9 +446,7 @@ gf_print_trace (int32_t signum)          {                  /* Dump the timestamp of the crash too, so the previous logs                     can be related */ -                utime = time (NULL); -                tm    = localtime (&utime); -                strftime (timestr, 256, "%Y-%m-%d %H:%M:%S\n", tm); +                gf_time_fmt (timestr, sizeof timestr, time (NULL), gf_timefmt_FT);                  ret = write (fd, "time of crash: ", 15);                  if (ret < 0)                          goto out; @@ -2134,3 +2130,26 @@ gf_canonicalize_path (char *path)          return ret;  } + +static const char *__gf_timefmts[] = { +        "%F %T", +        "%Y/%m/%d-%T", +        "%b %d %T", +        "%F %H%M%S" +}; + +static const char *__gf_zerotimes[] = { +        "0000-00-00 00:00:00", +        "0000/00/00-00:00:00", +        "xxx 00 00:00:00", +        "0000-00-00 000000" +}; + +void +_gf_timestuff (gf_timefmts *fmt, const char ***fmts, const char ***zeros) +{ +        *fmt = gf_timefmt_last; +        *fmts = __gf_timefmts; +        *zeros = __gf_zerotimes; +} + diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 9903edad..86e4e53c 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -392,6 +392,34 @@ memdup (const void *ptr, size_t size)  	return newptr;  } +typedef enum { +        gf_timefmt_default = 0, +        gf_timefmt_FT = 0,  /* YYYY-MM-DD hh:mm:ss */ +        gf_timefmt_Ymd_T,   /* YYYY/MM-DD-hh:mm:ss */ +        gf_timefmt_bdT,     /* ddd DD hh:mm:ss */ +        gf_timefmt_F_HMS,   /* YYYY-MM-DD hhmmss */ +        gf_timefmt_last +} gf_timefmts; + +static inline void +gf_time_fmt (char *dst, size_t sz_dst, time_t utime, unsigned int fmt) +{ +        extern void _gf_timestuff (gf_timefmts *, const char ***, const char ***); +        static gf_timefmts timefmt_last = (gf_timefmts) -1; +        static const char **fmts; +        static const char **zeros; +        struct tm tm; + +        if (timefmt_last == -1) +                _gf_timestuff (&timefmt_last, &fmts, &zeros); +        if (timefmt_last < fmt) fmt = gf_timefmt_default; +        if (gmtime_r (&utime, &tm) != NULL) { +                strftime (dst, sz_dst, fmts[fmt], &tm); +        } else { +                strncpy (dst, zeros[fmt], sz_dst); +        } +} +  int  mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks);  /* diff --git a/libglusterfs/src/graph.c b/libglusterfs/src/graph.c index 65cbb2e8..a42ae7cd 100644 --- a/libglusterfs/src/graph.c +++ b/libglusterfs/src/graph.c @@ -28,20 +28,17 @@ _gf_dump_details (int argc, char **argv)  {          extern FILE *gf_log_logfile;          int          i = 0; -        char         timestr[256]; +        char         timestr[64];          time_t       utime = 0; -        struct tm   *tm = NULL;          pid_t        mypid = 0;          struct utsname uname_buf = {{0, }, };          int            uname_ret = -1; -        utime = time (NULL); -        tm    = localtime (&utime);          mypid = getpid ();          uname_ret   = uname (&uname_buf); -        /* Which git? What time? */ -        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); +        utime = time (NULL); +        gf_time_fmt (timestr, sizeof timestr, utime, gf_timefmt_FT);          fprintf (gf_log_logfile,                   "========================================"                   "========================================\n"); @@ -340,8 +337,7 @@ fill_uuid (char *uuid, int size)  {          char           hostname[256] = {0,};          struct timeval tv = {0,}; -        struct tm      now = {0, }; -        char           now_str[32]; +        char           now_str[64];          if (gettimeofday (&tv, NULL) == -1) {                  gf_log ("graph", GF_LOG_ERROR, @@ -355,8 +351,7 @@ fill_uuid (char *uuid, int size)                          strerror (errno));          } -        localtime_r (&tv.tv_sec, &now); -        strftime (now_str, 32, "%Y/%m/%d-%H:%M:%S", &now); +        gf_time_fmt (now_str, sizeof now_str, tv.tv_sec, gf_timefmt_Ymd_T);          snprintf (uuid, size, "%s-%d-%s:%"GF_PRI_SUSECONDS,                    hostname, getpid(), now_str, tv.tv_usec); diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 6e3757e1..6071269e 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -206,13 +206,12 @@ _gf_log_nomem (const char *domain, const char *file,                 size_t size)  {          const char     *basename        = NULL; -        struct tm      *tm              = NULL;          xlator_t       *this            = NULL;          struct timeval  tv              = {0,};          int             ret             = 0; -        char            msg[8092]; -        char            timestr[256]; -        char            callstr[4096]; +        char            msg[8092]       = {0,}; +        char            timestr[256]    = {0,}; +        char            callstr[4096]   = {0,};          this = THIS; @@ -271,11 +270,8 @@ _gf_log_nomem (const char *domain, const char *file,          ret = gettimeofday (&tv, NULL);          if (-1 == ret)                  goto out; - -        tm    = localtime (&tv.tv_sec); - -        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -        snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +        gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); +        snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                    ".%"GF_PRI_SUSECONDS, tv.tv_usec);          basename = strrchr (file, '/'); @@ -320,7 +316,6 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,                     int line, gf_loglevel_t level, const char *fmt, ...)  {          const char     *basename        = NULL; -        struct tm      *tm              = NULL;          xlator_t       *this            = NULL;          char           *str1            = NULL;          char           *str2            = NULL; @@ -389,13 +384,9 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function,          ret = gettimeofday (&tv, NULL);          if (-1 == ret)                  goto out; - -        tm    = localtime (&tv.tv_sec); -          va_start (ap, fmt); - -        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -        snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +        gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); +        snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                    ".%"GF_PRI_SUSECONDS, tv.tv_usec);          basename = strrchr (file, '/'); @@ -461,20 +452,18 @@ int  _gf_log (const char *domain, const char *file, const char *function, int line,           gf_loglevel_t level, const char *fmt, ...)  { -        const char  *basename = NULL; -        FILE        *new_logfile = NULL; -        va_list      ap; -        struct tm   *tm = NULL; -        char         timestr[256]; +        const char    *basename = NULL; +        FILE          *new_logfile = NULL; +        va_list        ap; +        char           timestr[256] = {0,};          struct timeval tv = {0,}; - -        char        *str1 = NULL; -        char        *str2 = NULL; -        char        *msg  = NULL; -        size_t       len  = 0; -        int          ret  = 0; -        int          fd   = -1; -        xlator_t    *this = NULL; +        char          *str1 = NULL; +        char          *str2 = NULL; +        char          *msg  = NULL; +        size_t         len  = 0; +        int            ret  = 0; +        int            fd   = -1; +        xlator_t      *this = NULL;          this = THIS; @@ -539,13 +528,9 @@ log:          ret = gettimeofday (&tv, NULL);          if (-1 == ret)                  goto out; - -        tm    = localtime (&tv.tv_sec); -          va_start (ap, fmt); - -        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -        snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +        gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT); +        snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                    ".%"GF_PRI_SUSECONDS, tv.tv_usec);          basename = strrchr (file, '/'); @@ -667,15 +652,14 @@ gf_cmd_log_init (const char *filename)  int  gf_cmd_log (const char *domain, const char *fmt, ...)  { -        va_list      ap; -        struct tm   *tm = NULL; -        char         timestr[256]; +        va_list        ap; +        char           timestr[64];          struct timeval tv = {0,}; -        char        *str1 = NULL; -        char        *str2 = NULL; -        char        *msg  = NULL; -        size_t       len  = 0; -        int          ret  = 0; +        char          *str1 = NULL; +        char          *str2 = NULL; +        char          *msg  = NULL; +        size_t         len  = 0; +        int            ret  = 0;          if (!cmdlogfile)                  return -1; @@ -690,11 +674,8 @@ gf_cmd_log (const char *domain, const char *fmt, ...)          ret = gettimeofday (&tv, NULL);          if (ret == -1)                  goto out; - -        tm = localtime (&tv.tv_sec); -          va_start (ap, fmt); -        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); +        gf_time_fmt (timestr, sizeof timestr, tv.tv_sec, gf_timefmt_FT);          snprintf (timestr + strlen (timestr), 256 - strlen (timestr),                    ".%"GF_PRI_SUSECONDS, tv.tv_usec); diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index aaff4941..39b5bea5 100755 --- a/libglusterfsclient/src/libglusterfsclient.c +++ b/libglusterfsclient/src/libglusterfsclient.c @@ -110,7 +110,6 @@ zr_build_process_uuid ()  	char           tmp_str[1024] = {0,};  	char           hostname[256] = {0,};  	struct timeval tv = {0,}; -	struct tm      now = {0, };  	char           now_str[32];  	if (-1 == gettimeofday(&tv, NULL)) { @@ -125,9 +124,8 @@ zr_build_process_uuid ()  			strerror (errno));  	} -	localtime_r (&tv.tv_sec, &now); -	strftime (now_str, 32, "%Y/%m/%d-%H:%M:%S", &now); -	snprintf (tmp_str, 1024, "%s-%d-%s:%ld",  +        gf_time_fmt (now_str, sizeof now_str, tv.tv_sec, gf_timefmt_Ymd_T); +	snprintf (tmp_str, sizeof tmp_str, "%s-%d-%s:%ld",   		  hostname, getpid(), now_str, tv.tv_usec);  	return strdup (tmp_str); diff --git a/rpc/rpc-lib/src/rpc-clnt.c b/rpc/rpc-lib/src/rpc-clnt.c index 356b10c2..21066dfc 100644 --- a/rpc/rpc-lib/src/rpc-clnt.c +++ b/rpc/rpc-lib/src/rpc-clnt.c @@ -144,7 +144,6 @@ call_bail (void *data)          struct saved_frame    *saved_frame = NULL;          struct saved_frame    *trav = NULL;          struct saved_frame    *tmp = NULL; -        struct tm              frame_sent_tm;          char                   frame_sent[256] = {0,};          struct timeval         timeout = {0,};          struct iovec           iov = {0,}; @@ -191,8 +190,8 @@ call_bail (void *data)          pthread_mutex_unlock (&conn->lock);          list_for_each_entry_safe (trav, tmp, &list, list) { -                localtime_r (&trav->saved_at.tv_sec, &frame_sent_tm); -                strftime (frame_sent, 32, "%Y-%m-%d %H:%M:%S", &frame_sent_tm); +                gf_time_fmt (frame_sent, sizeof frame_sent, +                             trav->saved_at.tv_sec, gf_timefmt_FT);                  snprintf (frame_sent + strlen (frame_sent),                            256 - strlen (frame_sent),                            ".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec); @@ -343,17 +342,15 @@ saved_frames_unwind (struct saved_frames *saved_frames)          struct rpc_clnt      *clnt = NULL;  	struct saved_frame   *trav = NULL;  	struct saved_frame   *tmp = NULL; -        struct tm            *frame_sent_tm = NULL; -        char                 timestr[256] = {0,}; +        char                  timestr[1024] = {0,};          struct iovec          iov = {0,};          list_splice_init (&saved_frames->lk_sf.list, &saved_frames->sf.list);  	list_for_each_entry_safe (trav, tmp, &saved_frames->sf.list, list) { -                frame_sent_tm = localtime (&trav->saved_at.tv_sec); -                strftime (timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", -                          frame_sent_tm); +                gf_time_fmt (timestr, sizeof timestr, +                             trav->saved_at.tv_sec, gf_timefmt_FT);                  snprintf (timestr + strlen (timestr),                            sizeof(timestr) - strlen (timestr),                            ".%"GF_PRI_SUSECONDS, trav->saved_at.tv_usec); diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index bb6151ed..2cf28f1c 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -568,19 +568,16 @@ ios_dump_throughput_stats (struct ios_stat_head *list_head, xlator_t *this,                              FILE* logfp, ios_stats_type_t type)  {          struct ios_stat_list *entry = NULL; -        struct timeval        time = {0, }; -        struct tm             *tm = NULL; +        struct timeval        time  = {0, };          char                  timestr[256] = {0, };          LOCK (&list_head->lock);          {                  list_for_each_entry (entry, &list_head->iosstats->list, list) { -                        time = entry->iosstat->thru_counters[type].time; -                        tm    = localtime (&time.tv_sec); -                        if (!tm) -                                continue; -                        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -                        snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +                        gf_time_fmt (timestr, sizeof timestr, +                                     entry->iosstat->thru_counters[type].time.tv_sec, +                                     gf_timefmt_FT); +                        snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                            ".%"GF_PRI_SUSECONDS, time.tv_usec);                          ios_log (this, logfp, "%s \t %-10.2f  \t  %s", @@ -600,7 +597,6 @@ io_stats_dump_global_to_logfp (xlator_t *this, struct ios_global_stats *stats,          int                   index = 0;          struct ios_stat_head *list_head = NULL;          struct ios_conf      *conf = NULL; -        struct tm            *tm = NULL;          char                  timestr[256] = {0, };          char                  str_header[128] = {0};          char                  str_read[128] = {0}; @@ -694,9 +690,10 @@ io_stats_dump_global_to_logfp (xlator_t *this, struct ios_global_stats *stats,          if (interval == -1) {                  LOCK (&conf->lock);                  { -                        tm = localtime (&conf->cumulative.max_openfd_time.tv_sec); -                        strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -                        snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +                        gf_time_fmt (timestr, sizeof timestr, +                                     conf->cumulative.max_openfd_time.tv_sec, +                                     gf_timefmt_FT); +                        snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                                    ".%"GF_PRI_SUSECONDS,                                    conf->cumulative.max_openfd_time.tv_usec);                          ios_log (this, logfp, "Current open fd's: %"PRId64 @@ -1080,7 +1077,6 @@ io_stats_dump_stats_to_dict (xlator_t *this, dict_t *resp,          struct ios_stat_list    *entry = NULL;          int                      ret = -1;          ios_stats_thru_t         index = IOS_STATS_THRU_MAX; -        struct tm               *tm = NULL;          char                     timestr[256] = {0, };          char                    *dict_timestr = NULL; @@ -1098,9 +1094,10 @@ io_stats_dump_stats_to_dict (xlator_t *this, dict_t *resp,                                  ret = dict_set_uint64 (resp, "max-open",                                                         conf->cumulative.max_nr_opens); -                                tm = localtime (&conf->cumulative.max_openfd_time.tv_sec); -                                strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -                                snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +                                gf_time_fmt (timestr, sizeof timestr, +                                             conf->cumulative.max_openfd_time.tv_sec, +                                             gf_timefmt_FT); +                                snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                                            ".%"GF_PRI_SUSECONDS,                                            conf->cumulative.max_openfd_time.tv_usec); diff --git a/xlators/debug/trace/src/trace.c b/xlators/debug/trace/src/trace.c index d9c292c0..a1136a2e 100644 --- a/xlators/debug/trace/src/trace.c +++ b/xlators/debug/trace/src/trace.c @@ -46,30 +46,20 @@ int trace_log_level = GF_LOG_INFO;  static char *  trace_stat_to_str (struct iatt *buf)  { -        char    *statstr           = NULL; -        char     atime_buf[256]    = {0,}; -        char     mtime_buf[256]    = {0,}; -        char     ctime_buf[256]    = {0,}; -        int      asprint_ret_value = 0; -        uint64_t ia_time           = 0; +        char     *statstr           = NULL; +        char      atime_buf[64]     = {0,}; +        char      mtime_buf[64]     = {0,}; +        char      ctime_buf[64]     = {0,}; +        int       asprint_ret_value = 0;          if (!buf) {                  statstr = NULL;                  goto out;          } -        ia_time = buf->ia_atime; -        strftime (atime_buf, 256, "[%b %d %H:%M:%S]", -                  localtime ((time_t *)&ia_time)); - -        ia_time = buf->ia_mtime; -        strftime (mtime_buf, 256, "[%b %d %H:%M:%S]", -                  localtime ((time_t *)&ia_time)); - -        ia_time = buf->ia_ctime; -        strftime (ctime_buf, 256, "[%b %d %H:%M:%S]", -                  localtime ((time_t *)&ia_time)); - +        gf_time_fmt (atime_buf, sizeof atime_buf, buf->ia_atime, gf_timefmt_bdT); +        gf_time_fmt (mtime_buf, sizeof mtime_buf, buf->ia_mtime, gf_timefmt_bdT); +        gf_time_fmt (ctime_buf, sizeof ctime_buf, buf->ia_ctime, gf_timefmt_bdT);          asprint_ret_value = gf_asprintf (&statstr,                                           "gfid=%s ino=%"PRIu64", mode=%o, "                                           "nlink=%"GF_PRI_NLINK", uid=%u, " @@ -1665,9 +1655,8 @@ int  trace_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,                 struct iatt *stbuf, int32_t valid, dict_t *xdata)  { -        uint64_t ia_time          = 0; -        char     actime_str[256]  = {0,}; -        char     modtime_str[256] = {0,}; +        char      actime_str[64]   = {0,}; +        char      modtime_str[64]  = {0,};          if (trace_fop_names[GF_FOP_SETATTR].enabled) {                  if (valid & GF_SET_ATTR_MODE) { @@ -1685,13 +1674,10 @@ trace_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc,                  }                  if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { -                        ia_time = stbuf->ia_atime; -                        strftime (actime_str, 256, "[%b %d %H:%M:%S]", -                                  localtime ((time_t *)&ia_time)); - -                        ia_time = stbuf->ia_mtime; -                        strftime (modtime_str, 256, "[%b %d %H:%M:%S]", -                                  localtime ((time_t *)&ia_time)); +                        gf_time_fmt (actime_str, sizeof actime_str, +                                     stbuf->ia_atime, gf_timefmt_bdT); +                        gf_time_fmt (modtime_str, sizeof modtime_str, +                                     stbuf->ia_mtime, gf_timefmt_bdT);                          gf_log (this->name, GF_LOG_INFO,                                  "%"PRId64": gfid=%s path=%s ia_atime=%s, ia_mtime=%s", @@ -1714,9 +1700,8 @@ int  trace_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,                  struct iatt *stbuf, int32_t valid, dict_t *xdata)  { -        uint64_t ia_time          = 0; -        char     actime_str[256]  = {0,}; -        char     modtime_str[256] = {0,}; +        char      actime_str[64]  = {0,}; +        char      modtime_str[64] = {0,};          if (trace_fop_names[GF_FOP_FSETATTR].enabled) {                  if (valid & GF_SET_ATTR_MODE) { @@ -1734,13 +1719,10 @@ trace_fsetattr (call_frame_t *frame, xlator_t *this, fd_t *fd,                  }                  if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) { -                        ia_time = stbuf->ia_atime; -                        strftime (actime_str, 256, "[%b %d %H:%M:%S]", -                                  localtime ((time_t *)&ia_time)); - -                        ia_time = stbuf->ia_mtime; -                        strftime (modtime_str, 256, "[%b %d %H:%M:%S]", -                                  localtime ((time_t *)&ia_time)); +                        gf_time_fmt (actime_str, sizeof actime_str, +                                     stbuf->ia_atime, gf_timefmt_bdT); +                        gf_time_fmt (modtime_str, sizeof modtime_str, +                                     stbuf->ia_mtime, gf_timefmt_bdT);                          gf_log (this->name, GF_LOG_INFO,                                  "%"PRId64": gfid=%s fd=%p ia_atime=%s, ia_mtime=%s", diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c index 90caadb0..3da40ffa 100644 --- a/xlators/features/locks/src/posix.c +++ b/xlators/features/locks/src/posix.c @@ -1739,7 +1739,9 @@ pl_dump_lock (char *str, int size, struct gf_flock *flock,                gf_lkowner_t *owner, void *trans, time_t *granted_time,                time_t *blkd_time, gf_boolean_t active)  { -        char *type_str = NULL; +        char  *type_str    = NULL; +        char   granted[32] = {0,}; +        char   blocked[32] = {0,};          switch (flock->l_type) {          case F_RDLCK: @@ -1763,16 +1765,17 @@ pl_dump_lock (char *str, int size, struct gf_flock *flock,                                    (unsigned long long) flock->l_start,                                    (unsigned long long) flock->l_len,                                    (unsigned long long) flock->l_pid, -                                  lkowner_utoa (owner), -                                  trans, ctime (granted_time)); +                                  lkowner_utoa (owner), trans, +                                  ctime_r (granted_time, granted));                  } else {                          snprintf (str, size, RANGE_BLKD_GRNTD_FMT,                                    type_str, flock->l_whence,                                    (unsigned long long) flock->l_start,                                    (unsigned long long) flock->l_len,                                    (unsigned long long) flock->l_pid, -                                  lkowner_utoa (owner), -                                  trans, ctime (blkd_time), ctime (granted_time)); +                                  lkowner_utoa (owner), trans, +                                  ctime_r (blkd_time, blocked), +                                  ctime_r (granted_time, granted));                  }          }          else { @@ -1781,8 +1784,8 @@ pl_dump_lock (char *str, int size, struct gf_flock *flock,                            (unsigned long long) flock->l_start,                            (unsigned long long) flock->l_len,                            (unsigned long long) flock->l_pid, -                          lkowner_utoa (owner), -                          trans, ctime (blkd_time)); +                          lkowner_utoa (owner), trans, +                          ctime_r (blkd_time, blocked));          }  } @@ -1792,8 +1795,10 @@ __dump_entrylks (pl_inode_t *pl_inode)  {          pl_dom_list_t   *dom  = NULL;          pl_entry_lock_t *lock = NULL; -        int             count = 0; -        char            key[GF_DUMP_MAX_BUF_LEN]; +        char             blocked[32] = {0,}; +        char             granted[32] = {0,}; +        int              count = 0; +        char             key[GF_DUMP_MAX_BUF_LEN] = {0,};          char tmp[256]; @@ -1817,15 +1822,15 @@ __dump_entrylks (pl_inode_t *pl_inode)                                            "ENTRYLK_WRLCK", lock->basename,                                            (unsigned long long) lock->client_pid,                                            lkowner_utoa (&lock->owner), lock->trans, -                                          ctime (&lock->granted_time.tv_sec)); +                                          ctime_r (&lock->granted_time.tv_sec, granted));                          } else {                                  snprintf (tmp, 256, ENTRY_BLKD_GRNTD_FMT,                                            lock->type == ENTRYLK_RDLCK ? "ENTRYLK_RDLCK" :                                            "ENTRYLK_WRLCK", lock->basename,                                            (unsigned long long) lock->client_pid,                                            lkowner_utoa (&lock->owner), lock->trans, -                                          ctime (&lock->blkd_time.tv_sec), -                                          ctime (&lock->granted_time.tv_sec)); +                                          ctime_r (&lock->blkd_time.tv_sec, blocked), +                                          ctime_r (&lock->granted_time.tv_sec, granted));                          }                          gf_proc_dump_write(key, tmp); @@ -1843,7 +1848,7 @@ __dump_entrylks (pl_inode_t *pl_inode)                                    "ENTRYLK_WRLCK", lock->basename,                                    (unsigned long long) lock->client_pid,                                    lkowner_utoa (&lock->owner), lock->trans, -                                  ctime (&lock->blkd_time.tv_sec)); +                                  ctime_r (&lock->blkd_time.tv_sec, blocked));                          gf_proc_dump_write(key, tmp); diff --git a/xlators/features/marker/utils/src/gsyncd.c b/xlators/features/marker/utils/src/gsyncd.c index 9c598ce6..7da2c983 100644 --- a/xlators/features/marker/utils/src/gsyncd.c +++ b/xlators/features/marker/utils/src/gsyncd.c @@ -61,6 +61,7 @@ static int  str2argv (char *str, char ***argv)  {          char *p         = NULL; +        char *savetok   = NULL;          int argc        = 0;          size_t argv_len = 32;          int ret         = 0; @@ -74,7 +75,7 @@ str2argv (char *str, char ***argv)          if (!*argv)                  goto error; -        while ((p = strtok (str, " "))) { +        while ((p = strtok_r (str, " ", &savetok))) {                  str = NULL;                  argc++; diff --git a/xlators/features/trash/src/trash.c b/xlators/features/trash/src/trash.c index 15d9a429..92ea19a5 100644 --- a/xlators/features/trash/src/trash.c +++ b/xlators/features/trash/src/trash.c @@ -504,9 +504,7 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,          trash_elim_pattern_t  *trav  = NULL;          trash_private_t *priv = NULL;          trash_local_t   *local = NULL; -        struct tm       *tm = NULL; -        char             timestr[256] = {0,}; -        time_t           utime = 0; +        char             timestr[64] = {0,};          int32_t          match = 0;          priv = this->private; @@ -553,9 +551,8 @@ trash_rename (call_frame_t *frame, xlator_t *this, loc_t *oldloc,          {                  /* append timestamp to file name */                  /* TODO: can we make it optional? */ -                utime = time (NULL); -                tm    = localtime (&utime); -                strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); +                gf_time_ftm (timestr, sizeof timestr, time (NULL), +                             gf_timefmt_F_HMS);                  strcat (local->newpath, timestr);          } @@ -574,9 +571,7 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc)          trash_elim_pattern_t  *trav  = NULL;          trash_private_t *priv = NULL;          trash_local_t   *local = NULL; -        struct tm       *tm = NULL; -        char             timestr[256] = {0,}; -        time_t           utime = 0; +        char             timestr[64] = {0,};          int32_t          match = 0;          priv = this->private; @@ -625,9 +620,8 @@ trash_unlink (call_frame_t *frame, xlator_t *this, loc_t *loc)          {                  /* append timestamp to file name */                  /* TODO: can we make it optional? */ -                utime = time (NULL); -                tm    = localtime (&utime); -                strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); +                gf_time_fmt (timestr, sizeof timestr, time (NULL), +                             gf_timefmt_F_HMS);                  strcat (local->newpath, timestr);          } @@ -943,10 +937,8 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,  {          trash_private_t     *priv  = NULL;          trash_local_t       *local = NULL; -        struct tm           *tm = NULL; -        char                 timestr[256] = {0,}; +        char                 timestr[64] = {0,};          char                 loc_newname[PATH_MAX] = {0,}; -        time_t               utime = 0;          int32_t              flags = 0;          priv = this->private; @@ -978,9 +970,8 @@ trash_truncate_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this,          strcat (local->newpath, local->loc.path);          { -                utime = time (NULL); -                tm    = localtime (&utime); -                strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); +                gf_time_fmt (timestr, sizeof timestr, time (NULL), +                             gf_timefmt_F_HMS);                  strcat (local->newpath, timestr);          }          strcpy (loc_newname,local->loc.name); @@ -1346,11 +1337,9 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset)          trash_private_t       *priv = NULL;          trash_local_t         *local = NULL;          dentry_t              *dir_entry = NULL; -        struct tm             *tm = NULL;          char                  *pathbuf = NULL;          inode_t               *newinode = NULL; -        time_t                 utime = 0; -        char                   timestr[256]; +        char                   timestr[64];          int32_t                retval = 0;          int32_t                match = 0; @@ -1389,10 +1378,7 @@ trash_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset)                  return 0;          } -        utime = time (NULL); -        tm    = localtime (&utime); -        strftime (timestr, 256, ".%Y-%m-%d-%H%M%S", tm); - +        gf_time_fmt (timestr, sizeof timestr, time (NULL), gf_timefmt_F_HMS);          strcpy (local->newpath, priv->trash_dir);          strcat (local->newpath, pathbuf);          strcat (local->newpath, timestr); diff --git a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c index 14cbb3d5..50ce1484 100644 --- a/xlators/mgmt/glusterd/src/glusterd-mountbroker.c +++ b/xlators/mgmt/glusterd/src/glusterd-mountbroker.c @@ -276,6 +276,7 @@ make_georep_mountspec (gf_mount_spec_t *mspec, const char *volnames,          char *vols            = NULL;          char *vol             = NULL;          char *p               = NULL; +        char *savetok         = NULL;          char *fa[3]           = {0,};          size_t siz            = 0;          int vc                = 0; @@ -296,7 +297,7 @@ make_georep_mountspec (gf_mount_spec_t *mspec, const char *volnames,                  goto out;          for (p = vols;;) { -                vol = strtok (p, ","); +                vol = strtok_r (p, ",", &savetok);                  if (!vol) {                          GF_ASSERT (vc == 0);                          break; diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index 83122cde..06719695 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -199,15 +199,16 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,          glusterd_brickinfo_t                    *src_brickinfo = NULL;          char                                    *host          = NULL;          char                                    *path          = NULL; -        char                                    msg[2048]      = {0}; +        char                                     msg[2048]     = {0};          char                                    *dup_dstbrick  = NULL;          glusterd_peerinfo_t                     *peerinfo = NULL;          glusterd_brickinfo_t                    *dst_brickinfo = NULL; -        gf_boolean_t                            is_run         = _gf_false; +        gf_boolean_t                             is_run        = _gf_false;          dict_t                                  *ctx           = NULL;          glusterd_conf_t                         *priv          = NULL; -        char                                    voldir[PATH_MAX] = {0}; -        char                                    pidfile[PATH_MAX] = {0}; +        char                                    *savetok       = NULL; +        char                                     voldir[PATH_MAX] = {0}; +        char                                     pidfile[PATH_MAX] = {0};          priv = THIS->private;          GF_ASSERT (priv); @@ -422,8 +423,8 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,                  gf_log ("", GF_LOG_ERROR, "Memory allocation failed");                  goto out;          } -        host = strtok (dup_dstbrick, ":"); -        path = strtok (NULL, ":"); +        host = strtok_r (dup_dstbrick, ":", &savetok); +        path = strtok_r (NULL, ":", &savetok);          if (!host || !path) {                  gf_log ("", GF_LOG_ERROR, diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index db26bbf2..173cf244 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -1108,6 +1108,7 @@ glusterd_store_read_and_tokenize (FILE *file, char *str,                                    glusterd_store_op_errno_t *store_errno)  {          int32_t  ret = -1; +        char *savetok = NULL;          GF_ASSERT (file);          GF_ASSERT (str); @@ -1122,14 +1123,14 @@ glusterd_store_read_and_tokenize (FILE *file, char *str,                  goto out;          } -        *iter_key = strtok (str, "="); +        *iter_key = strtok_r (str, "=", &savetok);          if (*iter_key == NULL) {                  ret = -1;                  *store_errno = GD_STORE_KEY_NULL;                  goto out;          } -        *iter_val = strtok (NULL, "="); +        *iter_val = strtok_r (NULL, "=", &savetok);          if (*iter_key == NULL) {                  ret = -1;                  *store_errno = GD_STORE_VALUE_NULL; diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 58b35cbd..6650043c 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -4552,9 +4552,8 @@ glusterd_sm_tr_log_transition_add_to_dict (dict_t *dict,  {          int     ret = -1;          char    key[512] = {0}; -	char    timestr[256] = {0,}; +	char    timestr[64] = {0,};          char    *str = NULL; -	struct tm   tm = {0};          GF_ASSERT (dict);          GF_ASSERT (log); @@ -4583,9 +4582,8 @@ glusterd_sm_tr_log_transition_add_to_dict (dict_t *dict,          memset (key, 0, sizeof (key));          snprintf (key, sizeof (key), "log%d-time", count); -	localtime_r ((const time_t*)&log->transitions[i].time, &tm); -        memset (timestr, 0, sizeof (timestr)); -	strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", &tm); +        gf_time_fmt (timestr, sizeof timestr, log->transitions[i].time, +                     gf_timefmt_FT);          str = gf_strdup (timestr);          ret = dict_set_dynstr (dict, key, str);          if (ret) diff --git a/xlators/performance/io-cache/src/io-cache.c b/xlators/performance/io-cache/src/io-cache.c index 4dbb1aa0..85e87653 100644 --- a/xlators/performance/io-cache/src/io-cache.c +++ b/xlators/performance/io-cache/src/io-cache.c @@ -1816,7 +1816,6 @@ __ioc_cache_dump (ioc_inode_t *ioc_inode, char *prefix)          ioc_table_t *table                    = NULL;          ioc_page_t  *page                     = NULL;          int          i                        = 0; -        struct tm   *tm                       = NULL;          char         key[GF_DUMP_MAX_BUF_LEN] = {0, };          char         timestr[256]             = {0, }; @@ -1827,9 +1826,9 @@ __ioc_cache_dump (ioc_inode_t *ioc_inode, char *prefix)          table = ioc_inode->table;          if (ioc_inode->cache.tv.tv_sec) { -                tm = localtime (&ioc_inode->cache.tv.tv_sec); -                strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); -                snprintf (timestr + strlen (timestr), 256 - strlen (timestr), +                gf_time_fmt (timestr, sizeof timestr, +                             ioc_inode->cache.tv.tv_sec, gf_timefmt_FT); +                snprintf (timestr + strlen (timestr), sizeof timestr - strlen (timestr),                            ".%"GF_PRI_SUSECONDS, ioc_inode->cache.tv.tv_usec);                  gf_proc_dump_write ("last-cache-validation-time", "%s", diff --git a/xlators/performance/quick-read/src/quick-read.c b/xlators/performance/quick-read/src/quick-read.c index 05130878..6e4ce816 100644 --- a/xlators/performance/quick-read/src/quick-read.c +++ b/xlators/performance/quick-read/src/quick-read.c @@ -3435,7 +3435,6 @@ qr_inodectx_dump (xlator_t *this, inode_t *inode)          int32_t     ret      = -1;          char        key_prefix[GF_DUMP_MAX_BUF_LEN] = {0, };          char        buf[256]                        = {0, }; -        struct tm  *tm                              = NULL;          ret = inode_ctx_get (inode, this, &value);          if (ret != 0) {                  goto out; @@ -3453,9 +3452,9 @@ qr_inodectx_dump (xlator_t *this, inode_t *inode)          gf_proc_dump_write ("entire-file-cached", "%s", qr_inode->xattr ? "yes" : "no");          if (qr_inode->tv.tv_sec) { -                tm = localtime (&qr_inode->tv.tv_sec); -                strftime (buf, 256, "%Y-%m-%d %H:%M:%S", tm); -                snprintf (buf + strlen (buf), 256 - strlen (buf), +                gf_time_fmt (buf, sizeof buf, qr_inode->tv.tv_sec, +                             gf_timefmt_FT); +                snprintf (buf + strlen (buf), sizeof buf - strlen (buf),                            ".%"GF_PRI_SUSECONDS, qr_inode->tv.tv_usec);                  gf_proc_dump_write ("last-cache-validation-time", "%s", buf);  | 
