public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Christian Biesinger (Code Review)" <gerrit@gnutoolchain-gerrit.osci.io>
To: Christian Biesinger <cbiesinger@google.com>,
	Kevin Buettner <kevinb@redhat.com>,
	gdb-patches@sourceware.org
Subject: [review v4] Use ctime_r and localtime_r if available
Date: Mon, 11 Nov 2019 22:22:00 -0000	[thread overview]
Message-ID: <20191111222154.005A128171@gnutoolchain-gerrit.osci.io> (raw)
In-Reply-To: <gerrit.1572555982000.I329bbdc39d5b576f51859ba00f1617e024c30cbd@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  <cbiesinger@google.com>

	* 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  <cbiesinger@google.com>

	* 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 <cursesX.h> 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 <arpa/inet.h> 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';
     }
 }

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: I329bbdc39d5b576f51859ba00f1617e024c30cbd
Gerrit-Change-Number: 475
Gerrit-PatchSet: 4
Gerrit-Owner: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Christian Biesinger <cbiesinger@google.com>
Gerrit-Reviewer: Kevin Buettner <kevinb@redhat.com>
Gerrit-MessageType: newpatchset

  parent reply	other threads:[~2019-11-11 22:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-31 21:06 [review] " Christian Biesinger (Code Review)
2019-10-31 21:15 ` Christian Biesinger (Code Review)
2019-11-03  2:54 ` [review v2] " Christian Biesinger (Code Review)
2019-11-03  7:20   ` Andreas Schwab
2019-11-03 20:09     ` Christian Biesinger via gdb-patches
2019-11-03  2:54 ` [review] " Christian Biesinger (Code Review)
2019-11-03 20:04 ` [review v3] " Christian Biesinger (Code Review)
2019-11-06 20:30 ` Christian Biesinger (Code Review)
2019-11-08 14:09   ` Pedro Alves
2019-11-08 17:11     ` Christian Biesinger via gdb-patches
2019-11-09 20:18       ` Christian Biesinger via gdb-patches
2019-11-10  7:38 ` Kevin Buettner (Code Review)
2019-11-10  7:45 ` Kevin Buettner (Code Review)
2019-11-11 22:22 ` Christian Biesinger (Code Review) [this message]
2019-11-11 22:27 ` [review v5] Use ctime_r and localtime_r for threadsafety Christian Biesinger (Code Review)
2019-11-11 22:29 ` Christian Biesinger (Code Review)
2019-11-12 20:21 ` Kevin Buettner (Code Review)
2019-11-15 19:50 ` [review v6] " Christian Biesinger (Code Review)
2019-11-15 19:52 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-11-16 22:07 ` [review v6] " Christian Biesinger (Code Review)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191111222154.005A128171@gnutoolchain-gerrit.osci.io \
    --to=gerrit@gnutoolchain-gerrit.osci.io \
    --cc=cbiesinger@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=kevinb@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).