[SCM] Samba Shared Repository - branch master updated
Volker Lendecke
vlendec at samba.org
Mon Oct 13 04:28:01 MDT 2014
The branch, master has been updated
via bcf298e lib/util: Add RFC3339 timestamp support to timeval_str_buf()
via 1c2ae58 lib/util: Use snprintf() instead of strftime() in timeval_str_buf()
from bf0db7ec dsdb: Do not attempt to return beyond the end of the password history array
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit bcf298e7eca07a8869d184ad44c01232a11ba9ea
Author: Martin Schwenke <martin at meltin.net>
Date: Fri Oct 10 18:46:31 2014 +1100
lib/util: Add RFC3339 timestamp support to timeval_str_buf()
Note that this can't be done more simply or portably with strftime(3)
since "%z" isn't portable.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Volker Lendecke <vl at samba.org>
Autobuild-User(master): Volker Lendecke <vl at samba.org>
Autobuild-Date(master): Mon Oct 13 12:27:04 CEST 2014 on sn-devel-104
commit 1c2ae58509a19fb4590f4c71277c0f0c0a27f2fd
Author: Martin Schwenke <martin at meltin.net>
Date: Wed Oct 8 15:52:37 2014 +1100
lib/util: Use snprintf() instead of strftime() in timeval_str_buf()
This removes conditional code and ensures that the output is always as
expected.
Signed-off-by: Martin Schwenke <martin at meltin.net>
Pair-programmed-with: Amitay Isaacs <amitay at gmail.com>
Reviewed-by: Volker Lendecke <vl at samba.org>
-----------------------------------------------------------------------
Summary of changes:
lib/util/debug.c | 3 ++-
lib/util/time.c | 2 +-
lib/util/time_basic.c | 40 +++++++++++++++++++++++++++++-----------
lib/util/time_basic.h | 7 +++++--
4 files changed, 37 insertions(+), 15 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/util/debug.c b/lib/util/debug.c
index 0059595..750ad25 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -983,7 +983,8 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
}
GetTimeOfDay(&tv);
- timeval_str_buf(&tv, state.settings.debug_hires_timestamp, &tvbuf);
+ timeval_str_buf(&tv, false, state.settings.debug_hires_timestamp,
+ &tvbuf);
hs_len = snprintf(header_str, sizeof(header_str), "[%s, %2d",
tvbuf.buf, level);
diff --git a/lib/util/time.c b/lib/util/time.c
index 4b78e71..3c709af 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -341,7 +341,7 @@ char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires)
struct timeval_buf tmp;
char *result;
- result = talloc_strdup(ctx, timeval_str_buf(tp, hires, &tmp));
+ result = talloc_strdup(ctx, timeval_str_buf(tp, false, hires, &tmp));
if (result == NULL) {
return NULL;
}
diff --git a/lib/util/time_basic.c b/lib/util/time_basic.c
index b6e7317..0eeb441 100644
--- a/lib/util/time_basic.c
+++ b/lib/util/time_basic.c
@@ -40,7 +40,7 @@ _PUBLIC_ void GetTimeOfDay(struct timeval *tval)
Return the date and time as a string
****************************************************************************/
-char *timeval_str_buf(const struct timeval *tp, bool hires,
+char *timeval_str_buf(const struct timeval *tp, bool rfc5424, bool hires,
struct timeval_buf *dst)
{
time_t t;
@@ -62,18 +62,36 @@ char *timeval_str_buf(const struct timeval *tp, bool hires,
return dst->buf;
}
-#ifdef HAVE_STRFTIME
- len = strftime(dst->buf, sizeof(dst->buf), "%Y/%m/%d %H:%M:%S", tm);
-#else
- {
- const char *asct = asctime(tm);
- len = strlcpy(dst->buf, sizeof(dst->buf),
- asct ? asct : "unknown");
+ len = snprintf(dst->buf, sizeof(dst->buf),
+ (rfc5424 ?
+ "%04d-%02d-%02dT%02d:%02d:%02d" :
+ "%04d/%02d/%02d %02d:%02d:%02d"),
+ 1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+
+ if ((rfc5424 || hires) && (len < sizeof(dst->buf))) {
+ len += snprintf(dst->buf + len, sizeof(dst->buf) - len,
+ ".%06ld", (long)tp->tv_usec);
}
-#endif
- if (hires && (len < sizeof(dst->buf))) {
+
+ if (rfc5424 && (len < sizeof(dst->buf))) {
+ struct tm tm_utc, tm_local;
+ int offset;
+
+ tm_local = *tm;
+ /* It is reasonable to assume that if localtime()
+ * worked above, then gmtime() should also work
+ * without error. */
+ tm_utc = *gmtime(&t);
+
+ offset = (tm_local.tm_hour - tm_utc.tm_hour) * 60 +
+ (tm_local.tm_min - tm_utc.tm_min);
+
snprintf(dst->buf + len, sizeof(dst->buf) - len,
- ".%06ld", (long)tp->tv_usec);
+ "%c%02d:%02d",
+ (offset >=0 ? '+' : '-'),
+ abs(offset) / 60,
+ abs(offset) % 60);
}
return dst->buf;
diff --git a/lib/util/time_basic.h b/lib/util/time_basic.h
index 58bc02d..d1bb3b5 100644
--- a/lib/util/time_basic.h
+++ b/lib/util/time_basic.h
@@ -35,8 +35,11 @@ struct timeval_buf { char buf[128]; };
Put a date and time into dst->buf, return it dst->buf
(optionally with microseconds)
- format is %Y/%m/%d %H:%M:%S if strftime is available
+ If rfc5424 is true then produce the RFC5424 timestamp format (which
+ is a stricter instance of RFC3339 and is used for syslog). For
+ example: 2003-08-24T05:14:15.000003-07:00. Otherwise,
+ format is %Y/%m/%d %H:%M:%S
**/
-char *timeval_str_buf(const struct timeval *tp, bool hires,
+char *timeval_str_buf(const struct timeval *tp, bool rfc5424, bool hires,
struct timeval_buf *dst);
--
Samba Shared Repository
More information about the samba-cvs
mailing list