Invalid Sock is set to -1 instead 0 (stdin). Consequent error handling in fseek failu...
[profile/ivi/dlt-daemon.git] / src / shared / dlt_common.c
index b2324b1..b7a865e 100755 (executable)
@@ -1484,7 +1484,8 @@ int dlt_file_read_header_raw(DltFile *file,int resync,int verbose)
         else
         {
             /* go back to last file position */
-            fseek(file->handle,file->file_position,SEEK_SET);
+            if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+                return -1;
         }
     }
 
@@ -1663,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)
     {
@@ -1711,7 +1723,12 @@ 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 */
-    fseek(file->handle,file->file_position,SEEK_SET);
+    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);
+        return -1;
+    }
 
     /* get file position at start of DLT message */
     if (verbose)
@@ -1734,7 +1751,11 @@ int dlt_file_read(DltFile *file,int verbose)
         if (dlt_file_read_header_extended(file, verbose)<0)
         {
             /* go back to last position in file */
-            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);
+            }
             return-1;
         }
 
@@ -1754,9 +1775,15 @@ int dlt_file_read(DltFile *file,int verbose)
         if (fseek(file->handle,file->msg.datasize,SEEK_CUR)!=0)
         {
             /* go back to last position in file */
-            fseek(file->handle,file->file_position,SEEK_SET);
             sprintf(str,"Seek failed to skip payload data of size %d!\n",file->msg.datasize);
             dlt_log(LOG_ERR, str);
+
+            if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+            {
+                sprintf(str,"Seek back also failed!\n");
+                dlt_log(LOG_ERR, str);
+            }
+
             return -1;
         }
     }
@@ -1766,11 +1793,16 @@ int dlt_file_read(DltFile *file,int verbose)
         /* skip additional header parameters and payload data */
         if (fseek(file->handle,file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize,SEEK_CUR))
         {
-            /* go back to last position in file */
-            fseek(file->handle,file->file_position,SEEK_SET);
+
             sprintf(str,"Seek failed to skip extra header and payload data from file of size %d!\n",
                     file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize);
             dlt_log(LOG_ERR, str);
+            /* go back to last position in file */
+            if (fseek(file->handle,file->file_position,SEEK_SET))
+            {
+                sprintf(str,"Seek back also failed!\n");
+                dlt_log(LOG_ERR, str);
+            }
             return -1;
         }
 
@@ -1823,8 +1855,9 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose)
         file->index = ptr;
     }
 
-    /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
-    fseek(file->handle,file->file_position,SEEK_SET);
+    /* set to end of last successful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
+    if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+        return -1;
 
     /* get file position at start of DLT message */
     if (verbose)
@@ -1837,7 +1870,11 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose)
     if (dlt_file_read_header_raw(file,resync,verbose)<0)
     {
         /* go back to last position in file */
-        fseek(file->handle,file->file_position,SEEK_SET);
+        if (0!= fseek(file->handle,file->file_position,SEEK_SET))
+        {
+            sprintf(str,"dlt_file_read_raw, fseek failed 1\n");
+            dlt_log(LOG_ERR, str);
+        }
         return -1;
     }
 
@@ -1845,14 +1882,22 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose)
     if (dlt_file_read_header_extended(file, verbose)<0)
     {
         /* go back to last position in file */
-        fseek(file->handle,file->file_position,SEEK_SET);
+        if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+        {
+            sprintf(str,"dlt_file_read_raw, fseek failed 2\n");
+            dlt_log(LOG_ERR, str);
+        }
         return-1;
     }
 
     if (dlt_file_read_data(file,verbose)<0)
     {
         /* go back to last position in file */
-        fseek(file->handle,file->file_position,SEEK_SET);
+        if (0 != fseek(file->handle,file->file_position,SEEK_SET))
+        {
+            sprintf(str,"dlt_file_read_raw, fseek failed 3\n");
+            dlt_log(LOG_ERR, str);
+        }
         return-1;
     }
 
@@ -2349,6 +2394,7 @@ int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint
 
 int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size)
 {
+    //Do not DLT_SEM_LOCK inside here!
        char str[256];
        DltBufferHead *head;
 
@@ -3077,8 +3123,8 @@ uint32_t dlt_uptime(void)
     struct timespec ts;
 
     if (clock_gettime(CLOCK_MONOTONIC,&ts)==0)
-    {
-        return (uint32_t)((((ts.tv_sec*1000000)+(ts.tv_nsec/1000)))/100); // in 0.1 ms = 100 us
+    {        
+        return ( (uint32_t)ts.tv_sec*10000 + (uint32_t)ts.tv_nsec/100000 );// in 0.1 ms = 100 us
     }
     else
     {
@@ -3182,7 +3228,6 @@ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,
     float64_t value64f=0,value64f_tmp=0;
     int64_t value64f_tmp_int64i=0,value64f_tmp_int64i_swaped=0;
 
-    //uint32_t quantisation=0,
     uint32_t quantisation_tmp=0;
 
     if (type_info & DLT_TYPE_INFO_STRG)
@@ -3238,7 +3283,7 @@ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,
             return -1;
         sprintf(text+strlen(text),"%d",value8u);
     }
-    else if (type_info & DLT_TYPE_INFO_SINT || type_info & DLT_TYPE_INFO_UINT)
+    else if ((type_info & DLT_TYPE_INFO_SINT) || (type_info & DLT_TYPE_INFO_UINT))
     {
         /* signed or unsigned argument received */
         if (type_info & DLT_TYPE_INFO_VARI)
@@ -3262,15 +3307,11 @@ int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,
         }
         if (type_info & DLT_TYPE_INFO_FIXP)
         {
-            //quantisation=0;
-            quantisation_tmp=0;
             //compiler warning: variable ‘quantisation_tmp’ set but not used [-Wunused-but-set-variable], but: DLT_MSG_READ_VALUE wants a parameter, "0" does not work
             DLT_MSG_READ_VALUE(quantisation_tmp,*ptr,*datalength,uint32_t);
 
             if((*datalength)<0)
                 return -1;
-            //quantisation=DLT_ENDIAN_GET_32(msg->standardheader->htyp, quantisation_tmp);
-
             switch (   type_info & DLT_TYPE_INFO_TYLE)
             {
                                case DLT_TYLE_8BIT: