osaf/services/saf/logsv/lgs/lgs_filehdl.c |  17 ++++++++++++-----
 osaf/services/saf/logsv/lgs/lgs_stream.c  |  19 +++++++++++++++----
 2 files changed, 27 insertions(+), 9 deletions(-)


- Open log files with O_NONBLOCK. Answer client with AIS_ERR_TIMEOUT
  if EWOULDBLOCK/EAGAIN (record may be parially written)

diff --git a/osaf/services/saf/logsv/lgs/lgs_filehdl.c 
b/osaf/services/saf/logsv/lgs/lgs_filehdl.c
--- a/osaf/services/saf/logsv/lgs/lgs_filehdl.c
+++ b/osaf/services/saf/logsv/lgs/lgs_filehdl.c
@@ -379,7 +379,13 @@ done:
 }
 
 /**
- * Open/create a file for append
+ * Open/create a file for append in non blocking mode.
+ * Note: The file is opened in NONBLOCK mode directly. This makes it possible
+ *       that the open succeeds but the following write will fail. To avoid
+ *       this the file can be opened without the O_NONBLOCK flag and set this
+ *       flag using fcntl(). But write handling is done so that if a write
+ *       fails the log file will always be reopened.
+ *
  * @param indata[in], Null-terminated string containing filename to open
  * @param outdata[out], int errno, 0 if no error
  * @param max_outsize[in], always sizeof(int)
@@ -387,18 +393,19 @@ done:
  */
 int fileopen_hdl(void *indata, void *outdata, size_t max_outsize)
 {
-       int fd_out;
        int errno_save = 0;
        char *filepath = (char *) indata;
        int *errno_out_p = (int *) outdata;
+       int fd;
        
        TRACE_ENTER();
        
        TRACE("%s - filepath \"%s\"",__FUNCTION__,filepath);
 open_retry:
-       fd_out = open(filepath, O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR 
| S_IRGRP);
+       fd = open(filepath, O_CREAT | O_RDWR | O_APPEND | O_NONBLOCK,
+                                                       S_IRUSR | S_IWUSR | 
S_IRGRP);
 
-       if (fd_out == -1) {
+       if (fd == -1) {
                if (errno == EINTR)
                        goto open_retry;
                /* save errno for caller logging */
@@ -410,7 +417,7 @@ open_retry:
 
        *errno_out_p = errno_save;
        TRACE_LEAVE();
-       return fd_out;
+       return fd;
 }
 
 /**
diff --git a/osaf/services/saf/logsv/lgs/lgs_stream.c 
b/osaf/services/saf/logsv/lgs/lgs_stream.c
--- a/osaf/services/saf/logsv/lgs/lgs_stream.c
+++ b/osaf/services/saf/logsv/lgs/lgs_stream.c
@@ -48,7 +48,7 @@ static int lgs_stream_array_remove(int i
 static int get_number_of_log_files_h(log_stream_t *logStream, char 
*oldest_file);
 
 /**
- * Open/Create a file
+ * Open/create a file for append in non blocking mode.
  * @param filepath[in]
  * @param errno_save[out], errno if error
  * @return File descriptor or -1 if error
@@ -674,7 +674,8 @@ log_stream_t *log_stream_new_2(SaNameT *
 }
 
 /**
- * Open file associated with stream
+ * Open log file associated with stream
+ * The file is opened in non blocking mode.
  * @param stream
  * @param errno_save - errno from open() returned here if supplied
  *
@@ -881,7 +882,7 @@ done:
  * 
  * @return int 0 No error
  *            -1 on error
- *            -2 Write failed because of write timeout
+ *            -2 Write failed because of write timeout or EWOULDBLOCK/EAGAIN
  */
 int log_stream_write_h(log_stream_t *stream, const char *buf, size_t count)
 {
@@ -956,7 +957,17 @@ int log_stream_write_h(log_stream_t *str
                LOG_IN("write '%s' failed \"%s\"", stream->logFileCurrent,
                                strerror(write_errno));
                
-               stream->fd = -1;
+               if (stream->fd != -1) {
+                       /* Try to close the file and invalidate the stream fd */
+                       fileclose_h(stream->fd);
+                       stream->fd = -1;
+               }
+               
+               if ((write_errno == EAGAIN) || (write_errno == EWOULDBLOCK)) {
+                       /* Change return code to timeout if EAGAIN (would 
block) */
+                       TRACE("Write would block");
+                       rc = -2;
+               }
                goto done;
        }
  

------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to