Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-02-22 22:35:03 +0300
committerChristopher Faylor <me@cgf.cx>2003-02-22 22:35:03 +0300
commit878e60c56146c6e8fe6530de84627bf4c3a9d20e (patch)
treec5d004573e8af4c1c2c6c7fe56e40a938e446f50 /winsup/cygwin/syslog.cc
parentfe962019355cae8aba8cb3a3e5ea8d09464509a2 (diff)
* syslog.cc (syslog): Do not print the Windows pid. Print the Cygwin pid as an
unsigned decimal. On Win95 print a timestamp and attempt to lock the file up to four times in 3 ms.
Diffstat (limited to 'winsup/cygwin/syslog.cc')
-rw-r--r--winsup/cygwin/syslog.cc31
1 files changed, 20 insertions, 11 deletions
diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc
index f424a4f4e..bde15b96f 100644
--- a/winsup/cygwin/syslog.cc
+++ b/winsup/cygwin/syslog.cc
@@ -302,8 +302,7 @@ syslog (int priority, const char *message, ...)
}
if (process_logopt & LOG_PID)
{
- if (pass.print ("Win32 Process Id = 0x%X : Cygwin Process Id = 0x%X : ",
- GetCurrentProcessId (), getpid ()) == -1)
+ if (pass.print ("PID %u : ", getpid ()) == -1)
return;
}
@@ -375,6 +374,8 @@ syslog (int priority, const char *message, ...)
else
{
/* Under Windows 95, append the message to the log file */
+ char timestamp[24];
+ time_t ctime;
FILE *fp = fopen (get_win95_event_log_path (), "a");
if (fp == NULL)
{
@@ -382,24 +383,32 @@ syslog (int priority, const char *message, ...)
get_win95_event_log_path ());
return;
}
+ strftime (timestamp, sizeof timestamp, "%Y-%m-%d %H:%M:%S : ",
+ localtime (&(ctime = time (NULL))));
+
/* Now to prevent several syslog messages from being
interleaved, we must lock the first byte of the file
This works on Win32 even if we created the file above.
*/
HANDLE fHandle = cygheap->fdtab[fileno (fp)]->get_handle ();
- if (LockFile (fHandle, 0, 0, 1, 0) == FALSE)
- {
- debug_printf ("failed to lock file %s", get_win95_event_log_path ());
- fclose (fp);
- return;
- }
+ for (int i = 0;; i++)
+ if (LockFile (fHandle, 0, 0, 1, 0) == FALSE)
+ if (i == 3)
+ {
+ debug_printf ("failed to lock file %s", get_win95_event_log_path ());
+ fclose (fp);
+ return;
+ }
+ else
+ usleep (1000);
+ else
+ break;
+ fputs (timestamp, fp);
fputs (msg_strings[0], fp);
fputc ('\n', fp);
UnlockFile (fHandle, 0, 0, 1, 0);
if (ferror (fp))
- {
- debug_printf ("error in writing syslog");
- }
+ debug_printf ("error in writing syslog");
fclose (fp);
}
}