EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: ProcServ patch
From: Bruce Hill <[email protected]>
To: Ralph Lange <[email protected]>, Techtalk <[email protected]>
Date: Tue, 26 Feb 2013 12:10:26 -0800
Hi Ralph,
I made a couple of changes to our procServ code here at SLAC
that I thought might be useful to the community.

The changes allow support for log files > 2G on 64 bit systems,
and adds some mutex protection on the logging to keep
messages from different threads from being interspersed.
We also changed the defaulttimeFormat, but that's minor
and just makes it easier for us to deploy.

I've attached a patch file with the diffs.

Regards,
- Bruce

--
Bruce Hill
Member Technical Staff
SLAC National Accelerator Lab
2575 Sand Hill Road M/S 10
Menlo Park, CA  94025

--- /reg/g/pcds/package/procServ-2.6.0/procServ.cc	2012-04-13 06:32:19.000000000 -0700
+++ procServ.cc	2013-02-26 11:48:32.813426443 -0800
@@ -28,6 +28,11 @@
 const bool enableAllow = false;  // Default: NO
 #endif
 
+#ifdef _USE_POSIX_SOURCE
+#include <pthread.h>
+pthread_mutex_t	logMutex	= PHTREAD_MUTEX_INITIALIZER;
+#endif	// _USE_POSIX_SOURCE
+
 bool   inDebugMode;              // This enables a lot of printfs
 bool   inFgMode = false;         // This keeps child in the foreground, tty connected
 bool   logPortLocal;             // This restricts log port access to localhost
@@ -58,7 +63,8 @@
 char   *pidFile;                 // File name for server PID
 char   defaultpidFile[] = "pid.txt";  // default
 char   *timeFormat;              // Time format string
-char   defaulttimeFormat[] = "%c";    // default
+//char   defaulttimeFormat[] = "[%c] ";	// default
+char   defaulttimeFormat[] = "[%b %d %H:%M:%S] ";	// default
 bool   stampLog = false;         // Prefix log lines with time stamp
 char   *stampFormat;             // Log time stamp format string
 
@@ -166,6 +172,7 @@
     printf(PROCSERV_VERSION_STRING "\n");
 }
 
+
 int main(int argc,char * argv[])
 {
     int c;
@@ -421,7 +428,7 @@
 
     if (stampLog && !stampFormat) {
         stampFormat = (char*) calloc(strlen(timeFormat)+4, 1);
-        sprintf(stampFormat, "[%s] ", timeFormat);
+        sprintf(stampFormat, "%s", timeFormat);
     }
 
     if (checkCommandFile(childExec)) exit(errno);
@@ -597,11 +604,19 @@
     // Log the traffic to file / stdout (debug)
     if (sender==NULL || sender->isProcess())
     {
-        if (logFileFD > 0) {
-            if (stampLog) write(logFileFD, stamp, len);
-            write(logFileFD, message, count);
+#ifdef _USE_POSIX_SOURCE
+		pthread_mutex_lock( &logMutex );
+#endif	// _USE_POSIX_SOURCE
+        if ( logFileFD > 0 )
+        {
+			if ( stampLog && count > 1 ) write( logFileFD, stamp, len );
+			write( logFileFD, message, count );
+			fdatasync( logFileFD );
         }
         if (false == inFgMode && debugFD > 0) write(debugFD, message, count);
+#ifdef _USE_POSIX_SOURCE
+		pthread_mutex_unlock( &logMutex );
+#endif	// _USE_POSIX_SOURCE
     }
 
     while ( p ) {
@@ -614,7 +629,7 @@
 	{
 	    // Null senders and processes can send to non-processes (ie connections)
         if (sender==NULL || sender->isProcess()) {
-            if (stampLog && p->isLogger()) p->Send(stamp, len);
+            if ( stampLog && p->isLogger() && count > 1 ) p->Send(stamp, len);
             p->Send(message, count);
         }
 	}
@@ -807,7 +822,11 @@
         close(logFileFD);
     }
     if (logFile) {
-        logFileFD = open(logFile, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
+		int	mode	= O_CREAT|O_WRONLY|O_APPEND;
+#if _FILE_OFFSET_BITS == 64
+		mode |= O_LARGEFILE;
+#endif
+        logFileFD = open(logFile, mode, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
         if (-1 == logFileFD) {         // Don't stop here - just go without
             fprintf(stderr,
                     "%s: unable to open log file %s\n",

Navigate by Date:
Prev: Re: caClient with PCAS pthomas
Next: Question about epid record Bruce Hill
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: CA client on iOS? Xiaoqiang Wang
Next: Question about epid record Bruce Hill
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  <20132014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 20 Apr 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·