Invalid Sock is set to -1 instead 0 (stdin). Consequent error handling in fseek failu...
authorSimon Brandner <simon.brandner@partner.bmw.de>
Thu, 25 Apr 2013 11:25:35 +0000 (13:25 +0200)
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>
Fri, 19 Jul 2013 14:54:47 +0000 (16:54 +0200)
Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
src/daemon/dlt-daemon.c
src/shared/dlt_common.c

index 6871ca8..64a8acd 100644 (file)
@@ -1232,9 +1232,9 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon
 
     if (dlt_receiver_receive_socket(&(daemon_local->receiverSock))<=0)
     {
-        close(daemon_local->receiverSock.fd);
-        daemon_local->receiverSock.fd = 0;
+        close(daemon_local->receiverSock.fd);        
         FD_CLR(daemon_local->receiverSock.fd, &(daemon_local->master));
+        daemon_local->receiverSock.fd = -1;
 
         if (daemon_local->client_connections)
         {
@@ -1261,7 +1261,7 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon, DltDaemonLocal *daemon
     while (dlt_message_read(&(daemon_local->msg),(uint8_t*)daemon_local->receiverSock.buf,daemon_local->receiverSock.bytesRcvd,daemon_local->flags.nflag,daemon_local->flags.vflag)==0)
     {
         /* Check for control message */
-        if ( 0 != daemon_local->receiverSock.fd && DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)) )
+        if ( 0 < daemon_local->receiverSock.fd && DLT_MSG_IS_CONTROL_REQUEST(&(daemon_local->msg)) )
         {
             dlt_daemon_control_process_control(daemon_local->receiverSock.fd, daemon, &(daemon_local->msg), daemon_local->flags.vflag);
         }
index 19a1698..b7a865e 100755 (executable)
@@ -1484,7 +1484,7 @@ int dlt_file_read_header_raw(DltFile *file,int resync,int verbose)
         else
         {
             /* go back to last file position */
-            if (fseek(file->handle,file->file_position,SEEK_SET) < 0)
+            if (0 != fseek(file->handle,file->file_position,SEEK_SET))
                 return -1;
         }
     }
@@ -1664,9 +1664,20 @@ int dlt_file_open(DltFile *file,const char *filename,int verbose)
         return -1;
     }
 
-    fseek(file->handle,0,SEEK_END);
+    if (0 != fseek(file->handle,0,SEEK_END))
+    {
+        sprintf(str,"dlt_file_open: Seek failed to 0,SEEK_END");
+        dlt_log(LOG_ERR, str);
+        return -1;
+    }
     file->file_length = ftell(file->handle);
-    fseek(file->handle,0,SEEK_SET);
+
+    if (0 != fseek(file->handle,0,SEEK_SET))
+    {
+        sprintf(str,"dlt_file_open: Seek failed to 0,SEEK_SET");
+        dlt_log(LOG_ERR, str);
+        return -1;
+    }
 
     if (verbose)
     {
@@ -1712,7 +1723,7 @@ int dlt_file_read(DltFile *file,int verbose)
     }
 
     /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
-    if ( fseek(file->handle,file->file_position,SEEK_SET) < 0 )
+    if (0 !=  fseek(file->handle,file->file_position,SEEK_SET))
     {
         sprintf(str,"Seek failed to file_position %ld \n",file->file_position);
         dlt_log(LOG_ERR, str);
@@ -1740,7 +1751,7 @@ int dlt_file_read(DltFile *file,int verbose)
         if (dlt_file_read_header_extended(file, verbose)<0)
         {
             /* go back to last position in file */
-            if ( 0 != fseek(file->handle,file->file_position,SEEK_SET))
+            if (0 != fseek(file->handle,file->file_position,SEEK_SET))
             {
                 sprintf(str,"Seek to last file pos failed!\n");
                 dlt_log(LOG_ERR, str);
@@ -1845,7 +1856,7 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose)
     }
 
     /* set to end of last successful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
-    if (fseek(file->handle,file->file_position,SEEK_SET) < 0)
+    if (0 != fseek(file->handle,file->file_position,SEEK_SET))
         return -1;
 
     /* get file position at start of DLT message */