]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - nscd/dbg_log.c
powerpc64: Fix by using the configure value $libc_cv_cc_submachine [BZ #31629]
[thirdparty/glibc.git] / nscd / dbg_log.c
index bcd94260208558edab30ac7c0ca48526e73c1923..2369f39799dc9bc67c0ec28d17b2f53ef0b377a4 100644 (file)
@@ -1,21 +1,18 @@
-/* Copyright (c) 1998, 2000, 2004 Free Software Foundation, Inc.
+/* Copyright (c) 1998-2024 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
-   Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
 
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published
+   by the Free Software Foundation; version 2 of the License, or
+   (at your option) any later version.
 
-   The GNU C Library is distributed in the hope that it will be useful,
+   This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
 
 #include <stdarg.h>
 #include <stdio.h>
@@ -44,7 +41,7 @@ init_logfile (void)
 {
   if (logfilename)
     {
-      dbgout = fopen (logfilename, "a");
+      dbgout = fopen64 (logfilename, "a");
       return dbgout == NULL ? 0 : 1;
     }
   return 1;
@@ -54,14 +51,24 @@ void
 dbg_log (const char *fmt,...)
 {
   va_list ap;
-  char msg[512], msg2[512];
+  char msg2[512];
 
   va_start (ap, fmt);
-  vsnprintf (msg2, sizeof (msg), fmt, ap);
+  vsnprintf (msg2, sizeof (msg2), fmt, ap);
 
   if (debug_level > 0)
     {
-      snprintf (msg, sizeof (msg), "%d: %s\n", getpid (), msg2);
+      time_t t = time (NULL);
+
+      struct tm now;
+      localtime_r (&t, &now);
+
+      char buf[256];
+      strftime (buf, sizeof (buf), "%c", &now);
+
+      char msg[1024];
+      snprintf (msg, sizeof (msg), "%s - %d: %s%s", buf, getpid (), msg2,
+               msg2[strlen (msg2) - 1] == '\n' ? "" : "\n");
       if (dbgout)
        {
          fputs (msg, dbgout);
@@ -71,9 +78,7 @@ dbg_log (const char *fmt,...)
        fputs (msg, stderr);
     }
   else
-    {
-      snprintf (msg, sizeof (msg), "%d: %s", getpid (), msg2);
-      syslog (LOG_NOTICE, "%s", msg);
-    }
+    syslog (LOG_NOTICE, "%d %s", getpid (), msg2);
+
   va_end (ap);
 }