From patchwork Mon Nov 11 22:21:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35808 Received: (qmail 125735 invoked by alias); 11 Nov 2019 22:22:02 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 125727 invoked by uid 89); 11 Nov 2019 22:22:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Nov 2019 22:22:00 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id C4E27204A7; Mon, 11 Nov 2019 17:21:57 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 20DA6203C3; Mon, 11 Nov 2019 17:21:54 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 005A128171; Mon, 11 Nov 2019 17:21:54 -0500 (EST) X-Gerrit-PatchSet: 4 Date: Mon, 11 Nov 2019 17:21:53 -0500 From: "Christian Biesinger (Code Review)" To: Christian Biesinger , Kevin Buettner , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [review v4] Use ctime_r and localtime_r if available X-Gerrit-Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd X-Gerrit-Change-Number: 475 X-Gerrit-ChangeURL: X-Gerrit-Commit: c88e2a8503aabf92e2c791de5fe985978db1a609 In-Reply-To: References: Reply-To: cbiesinger@google.com, cbiesinger@google.com, kevinb@redhat.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-76-gf8b6da0ab5 Message-Id: <20191111222154.005A128171@gnutoolchain-gerrit.osci.io> Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/475 ...................................................................... Use ctime_r and localtime_r if available To make these calls threadsafe. gdb/ChangeLog: 2019-10-31 Christian Biesinger * config.in: Regenerate. * configure: Regenerate. * gdbsupport/common.m4: Check for ctime_r. * maint.c (scoped_command_stats::print_time): Use localtime_r instead of localtime (provided through gnulib if necessary). * nat/linux-osdata.c (time_from_time_t): Use ctime_r if available instead of ctime. gdb/gdbserver/ChangeLog: 2019-10-31 Christian Biesinger * config.in: Regenerate. * configure: Regenerate. Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd --- M gdb/config.in M gdb/configure M gdb/gdbserver/config.in M gdb/gdbserver/configure M gdb/gdbsupport/common.m4 M gdb/maint.c M gdb/nat/linux-osdata.c 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gdb/config.in b/gdb/config.in index fc05f15..19b18d1 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -78,6 +78,9 @@ /* Define to 1 if you have the `btowc' function. */ #undef HAVE_BTOWC +/* Define to 1 if you have the `ctime_r' function. */ +#undef HAVE_CTIME_R + /* Define to 1 if you have the header file. */ #undef HAVE_CURSESX_H diff --git a/gdb/configure b/gdb/configure index e805903..78c0f34 100755 --- a/gdb/configure +++ b/gdb/configure @@ -13480,7 +13480,7 @@ for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \ - sigprocmask + sigprocmask ctime_r do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/gdb/gdbserver/config.in b/gdb/gdbserver/config.in index 0bce18d..efa2ea0 100644 --- a/gdb/gdbserver/config.in +++ b/gdb/gdbserver/config.in @@ -21,6 +21,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_ARPA_INET_H +/* Define to 1 if you have the `ctime_r' function. */ +#undef HAVE_CTIME_R + /* define if the compiler supports basic C++11 syntax */ #undef HAVE_CXX11 diff --git a/gdb/gdbserver/configure b/gdb/gdbserver/configure index e513fc5..0414aa7 100755 --- a/gdb/gdbserver/configure +++ b/gdb/gdbserver/configure @@ -6822,7 +6822,7 @@ for ac_func in fdwalk getrlimit pipe pipe2 socketpair sigaction \ - sigprocmask + sigprocmask ctime_r do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" diff --git a/gdb/gdbsupport/common.m4 b/gdb/gdbsupport/common.m4 index 471d705..d86fc92 100644 --- a/gdb/gdbsupport/common.m4 +++ b/gdb/gdbsupport/common.m4 @@ -33,7 +33,7 @@ dlfcn.h) AC_CHECK_FUNCS([fdwalk getrlimit pipe pipe2 socketpair sigaction \ - sigprocmask]) + sigprocmask ctime_r]) AC_CHECK_DECLS([strerror, strstr]) diff --git a/gdb/maint.c b/gdb/maint.c index ec9f4ab..a253584 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -1039,10 +1039,11 @@ auto millis = ticks % 1000; std::time_t as_time = system_clock::to_time_t (now); - struct tm *tm = localtime (&as_time); + struct tm tm; + localtime_r (&as_time, &tm); char out[100]; - strftime (out, sizeof (out), "%F %H:%M:%S", tm); + strftime (out, sizeof (out), "%F %H:%M:%S", &tm); printf_unfiltered ("%s.%03d - %s\n", out, (int) millis, msg); } diff --git a/gdb/nat/linux-osdata.c b/gdb/nat/linux-osdata.c index 84357e2..cfa245a 100644 --- a/gdb/nat/linux-osdata.c +++ b/gdb/nat/linux-osdata.c @@ -913,7 +913,13 @@ { time_t t = (time_t) seconds; - strncpy (time, ctime (&t), maxlen); +#ifdef HAVE_CTIME_R + char buf[30]; + const char *time_str = ctime_r (&t, buf); +#else + const char *time_str = ctime (&t); +#endif + strncpy (time, time_str, maxlen); time[maxlen - 1] = '\0'; } }