Index: /trunk/pbs_drmaa/log_reader.c
===================================================================
--- /trunk/pbs_drmaa/log_reader.c	(revision 7)
+++ /trunk/pbs_drmaa/log_reader.c	(revision 8)
@@ -53,14 +53,14 @@
 
 static void
-pbsdrmaa_chose_file_wait_thread ( pbsdrmaa_log_reader_t * self);
+pbsdrmaa_select_file_wait_thread ( pbsdrmaa_log_reader_t * self);
 
 static ssize_t
-pbsdrmaa_read_line_wait_thread ( pbsdrmaa_log_reader_t * self, char * buffer, ssize_t size );
+pbsdrmaa_read_line_wait_thread ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx );
 
 static void
-pbsdrmaa_chose_file_job_on_missing ( pbsdrmaa_log_reader_t * self );
+pbsdrmaa_select_file_job_on_missing ( pbsdrmaa_log_reader_t * self );
 
 static ssize_t
-pbsdrmaa_read_line_job_on_missing ( pbsdrmaa_log_reader_t * self, char * buffer, ssize_t size );
+pbsdrmaa_read_line_job_on_missing ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx );
 
 int 
@@ -87,5 +87,5 @@
 			self->job = job;
 			self->name = "Job_on_missing";
-			self->chose_file = pbsdrmaa_chose_file_job_on_missing;
+			self->select_file = pbsdrmaa_select_file_job_on_missing;
 			self->read_line = pbsdrmaa_read_line_job_on_missing;
 		}
@@ -94,5 +94,5 @@
 			self->job = NULL;
 			self->name = "WT";
-			self->chose_file = pbsdrmaa_chose_file_wait_thread;
+			self->select_file = pbsdrmaa_select_file_wait_thread;
 			self->read_line = pbsdrmaa_read_line_wait_thread;
 		}		
@@ -179,6 +179,5 @@
 	if(self->job == NULL)
 		fsd_mutex_lock( &self->session->mutex );
-	/*else
-		fsd_mutex_lock( &self->job->mutex );*/
+
 	TRY
 	{		
@@ -186,11 +185,13 @@
 		TRY
 		{
-			char buffer[4096] = "";		
+			char line[4096] = "";
+			char buffer[4096] = "";
+			int idx = 0, end_idx = 0, line_idx = 0;
 			
-			self->chose_file(self);
-
-			while ((self->read_line(self, buffer, sizeof(buffer))) > 0) 			
+			self->select_file(self);
+
+			while ((self->read_line(self, line,buffer, sizeof(line), &idx,&end_idx,&line_idx)) > 0) 			
 			{
-				const char *volatile ptr = buffer;
+				const char *volatile ptr = line;
   				char field[256] = "";
 				char job_id[256] = "";
@@ -198,5 +199,5 @@
 				int volatile field_n = 0;
  				int n;
-
+				
 				bool volatile job_id_match = false;
 				bool volatile event_match = false;
@@ -286,53 +287,14 @@
 						bool state_running = false;
 
-						struct_status.name = NULL;
-						struct_status.value = NULL;
-						struct_status.next = NULL;
-						struct_status.resource = NULL;
-
-						struct_state.name = NULL;
-						struct_state.value = NULL;
-						struct_state.next = NULL;
-						struct_state.resource = NULL;
-
-						struct_resource_cput.name = NULL;
-						struct_resource_cput.value = NULL;
-						struct_resource_cput.next = NULL;
-						struct_resource_cput.resource = NULL;
-
-						struct_resource_mem.name = NULL;
-						struct_resource_mem.value = NULL;
-						struct_resource_mem.next = NULL;
-						struct_resource_mem.resource = NULL;
-
-						struct_resource_vmem.name = NULL;
-						struct_resource_vmem.value = NULL;
-						struct_resource_vmem.next = NULL;
-						struct_resource_vmem.resource = NULL;
-
-						struct_resource_walltime.name = NULL;
-						struct_resource_walltime.value = NULL;
-						struct_resource_walltime.next = NULL;
-						struct_resource_walltime.resource = NULL;
-
-						struct_start_time.name = NULL;
-						struct_start_time.value = NULL;
-						struct_start_time.next = NULL;
-						struct_start_time.resource = NULL;
-
-						struct_mtime.name = NULL;
-						struct_mtime.value = NULL;
-						struct_mtime.next = NULL;
-						struct_mtime.resource = NULL;
-
-						struct_queue.name = NULL;
-						struct_queue.value = NULL;
-						struct_queue.next = NULL;
-						struct_queue.resource = NULL;
-
-						struct_account_name.name = NULL;
-						struct_account_name.value = NULL;
-						struct_account_name.next = NULL;
-						struct_account_name.resource = NULL;
+						memset(&struct_status,0,sizeof(struct attrl)); /**/
+						memset(&struct_state,0,sizeof(struct attrl));
+						memset(&struct_resource_cput,0,sizeof(struct attrl));
+						memset(&struct_resource_mem,0,sizeof(struct attrl));
+						memset(&struct_resource_vmem,0,sizeof(struct attrl));
+						memset(&struct_resource_walltime,0,sizeof(struct attrl));
+						memset(&struct_start_time,0,sizeof(struct attrl));
+						memset(&struct_mtime,0,sizeof(struct attrl));
+						memset(&struct_queue,0,sizeof(struct attrl));
+						memset(&struct_account_name,0,sizeof(struct attrl));
 								
 						if (strcmp(event,FLD_MSG_STATE) == 0) 
@@ -507,15 +469,5 @@
 						log_event = false;
 					}
-					else if( self->job == NULL && log_match && field_n == FLD_MSG && 
-						field[0] == 'L' && 
-						field[1] == 'o' && 
-						field[2] == 'g' && 
-						field[3] == ' ' && 
-						field[4] == 'c' && 
-						field[5] == 'l' && 
-						field[6] == 'o' && 
-						field[7] == 's' && 
-						field[8] == 'e' && 
-						field[9] == 'd' )  /* last field in the file - strange bahaviour*/
+					else if( self->job == NULL && log_match && field_n == FLD_MSG && strncmp(field,"Log closed",10) == 0) 
 					{
 						fsd_log_debug(("%s - Date changed. Closing log file",self->name));
@@ -532,8 +484,4 @@
 					++ptr;
 				}		
-
-				if( strlcpy(buffer,"",sizeof(buffer)) > sizeof(buffer) ) {
-					fsd_log_error(("%s - strlcpy error",self->name));
-				}
 
 				fsd_free(temp_date);			
@@ -577,5 +525,5 @@
 
 void
-pbsdrmaa_chose_file_wait_thread ( pbsdrmaa_log_reader_t * self )
+pbsdrmaa_select_file_wait_thread ( pbsdrmaa_log_reader_t * self )
 {
 	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*) self->session;
@@ -648,7 +596,7 @@
 
 ssize_t
-pbsdrmaa_read_line_wait_thread ( pbsdrmaa_log_reader_t * self, char * buffer, ssize_t size )
-{
-	return fsd_getline(buffer,size,self->fd);
+pbsdrmaa_read_line_wait_thread ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx )
+{
+	return fsd_getline_buffered(line,buffer,size,self->fd,idx,end_idx,line_idx);
 }
 
@@ -663,5 +611,5 @@
 
 void
-pbsdrmaa_chose_file_job_on_missing( pbsdrmaa_log_reader_t * self )
+pbsdrmaa_select_file_job_on_missing( pbsdrmaa_log_reader_t * self )
 {
 	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*) self->session;	
@@ -769,7 +717,7 @@
 
 ssize_t
-pbsdrmaa_read_line_job_on_missing ( pbsdrmaa_log_reader_t * self, char * buffer, ssize_t size )
-{
-	int n = fsd_getline(buffer,size,self->fd);
+pbsdrmaa_read_line_job_on_missing ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx )
+{
+	int n = fsd_getline_buffered(line,buffer,size,self->fd, idx, end_idx, line_idx);
 	
 	if(n >= 0)
@@ -789,5 +737,5 @@
 	char *rest = NULL;
 	char *token = NULL;
-	char *ptr = strdup(s1);
+	char *ptr = fsd_strdup(s1);
 	token = strtok_r(ptr, ".", &rest);
 	job1 = atoi(token);
@@ -795,5 +743,5 @@
 	fsd_free(token);
 	
-	ptr = strdup(s2);
+	ptr = fsd_strdup(s2);
 	token = strtok_r(ptr,".",&rest);
 	job2 = atoi(token);
Index: /trunk/pbs_drmaa/log_reader.h
===================================================================
--- /trunk/pbs_drmaa/log_reader.h	(revision 7)
+++ /trunk/pbs_drmaa/log_reader.h	(revision 8)
@@ -44,8 +44,9 @@
 	
 	void (*
-	chose_file) ( pbsdrmaa_log_reader_t * self );
+	select_file) ( pbsdrmaa_log_reader_t * self );
 	
+	/* line - read line, buffer - keeps read but not returned lines, idx, end_idx and line_idx values needed to be kept outside the function */
 	ssize_t (*
-	read_line) ( pbsdrmaa_log_reader_t * self , char * buffer , ssize_t size );
+	read_line) ( pbsdrmaa_log_reader_t * self, char * line, char * buffer, ssize_t size, int * idx, int * end_idx, int * line_idx );
 	
 	/* specifies if function should run */
Index: /trunk/pbs_drmaa/util.c
===================================================================
--- /trunk/pbs_drmaa/util.c	(revision 7)
+++ /trunk/pbs_drmaa/util.c	(revision 8)
@@ -286,2 +286,57 @@
 } 
 
+ssize_t fsd_getline_buffered(char * line,char * buf, ssize_t size, int fd, int * idx, int * end_idx, int * line_idx)
+{
+	int i = -1;
+	int rc = -1;
+
+	memset(line,0,size);
+	
+start:
+	/* idx - start of data to parse (in buffer)
+	   end_idx - end of data read from log (in buffer)
+	   line_idx - place to write data in output line */
+	if(*idx < *end_idx)
+	{
+		/* take line from buffer */
+		for(i = *idx; i<= *end_idx;i++)
+		{		
+			if(buf[i] == '\n')
+			{
+				int tmp = i - *idx;
+				strncpy(line + *line_idx,buf + *idx,tmp);				
+				*idx = i + 1;
+			
+				tmp+= *line_idx;
+				*line_idx = 0;
+				
+				return tmp;
+			}
+		}
+		
+		/* there was no '\n' so next part of log needs to be read. save lines beginning */
+		if(*line_idx + i - *idx > size )
+			fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Line longer than %d unsupported",size);
+		
+		strncpy(line + *line_idx,buf + *idx,i - *idx);
+		*line_idx += i - *idx;
+		*idx = 0;
+		*end_idx = 0;
+		goto start;
+	}
+	else
+	{		
+		/* read log */
+		if((rc = read(fd,buf,size)) > 0)
+		{		
+			*end_idx = rc - 1;
+			*idx = 0;
+			goto start;
+		}
+		else if (rc == 0) 
+			return 0;
+		else
+			return -1;
+	}
+} 
+
Index: /trunk/pbs_drmaa/job.h
===================================================================
--- /trunk/pbs_drmaa/job.h	(revision 1)
+++ /trunk/pbs_drmaa/job.h	(revision 8)
@@ -42,4 +42,7 @@
 };
 
+void
+pbsdrmaa_job_on_missing_standard( fsd_job_t *self );
+
 #endif /* __PBS_DRMAA__JOB_H */
 
Index: /trunk/pbs_drmaa/util.h
===================================================================
--- /trunk/pbs_drmaa/util.h	(revision 7)
+++ /trunk/pbs_drmaa/util.h	(revision 8)
@@ -46,4 +46,7 @@
 fsd_getline(char * line,ssize_t size, int fd);
 
+ssize_t 
+fsd_getline_buffered(char * line,char * buf, ssize_t size, int fd, int * idx, int * end_idx, int * line_idx);
+
 #endif /* __PBS_DRMAA__UTIL_H */
 
