Index: trunk/pbs_drmaa/util.c
===================================================================
--- trunk/pbs_drmaa/util.c	(revision 85)
+++ trunk/pbs_drmaa/util.c	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: util.c 323 2010-09-21 21:31:29Z mmatloka $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -30,7 +30,4 @@
 #include <string.h>
 #include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
 
 #include <drmaa_utils/common.h>
@@ -44,5 +41,5 @@
 		__attribute__ ((unused))
 #	endif
-	= "$Id$";
+	= "$Id: util.c 323 2010-09-21 21:31:29Z mmatloka $";
 #endif
 
@@ -78,73 +75,41 @@
 }
 
-struct attrl *
-pbsdrmaa_add_attr( struct attrl *head, const char *name, const char *value)
-{
-	struct attrl *p = NULL;
-	char *resource = NULL;
-
-	fsd_malloc( p, struct attrl );
-	memset( p, 0, sizeof(struct attrl) );
-
-	resource = strchr( name, '.' );
-
-	if( resource )
-	 {
-		p->name = fsd_strndup( name, resource - name );
-		p->resource = fsd_strdup( resource+1 );
-	 }
-	else
-	 {
-		p->name = fsd_strdup( name );
-	 }
-
-	p->value = fsd_strdup(value);
-	p->op = SET;
-
-	fsd_log_debug(("set attr: %s = %s", name, value));
-
-	if (head)
-		p->next = head;
-	else
-		p->next = NULL;
-
-	return p;
-}
-
 
 void
-pbsdrmaa_exc_raise_pbs( const char *function, int connection )
+pbsdrmaa_exc_raise_pbs( const char *function )
 {
 	int _pbs_errno;
 	int fsd_errno;
 	const char *message = NULL;
-	const char *extended_message = NULL;
 
 	_pbs_errno = pbs_errno;
-
-#ifndef PBS_PROFESSIONAL_NO_LOG
+	/*
+	 * Gathering error messages differ between PBS forks.
+	 * - OpenPBS - ...
+	 * - Torque - pbse_to_txt takes PBS error code (stored in pbs_errno)
+	 *  and returns corresponding error message.
+	 * - PBS Pro - stores errno of last operation inside pbs_errno variable;
+	 *  pbse_to_txt always return NULL.
+	 * All of them define pbs_geterrmsg which returns last error message
+	 * for given connection.
+	 */
+	/* XXX: PBSPro has some link problems with pbse_to_txt function */
+#if 1
 	message = pbse_to_txt( pbs_errno );
 #else
-	message = "PBS error";
-#endif
-
-	if ( connection != -1 )
-	 {
-		extended_message = pbs_geterrmsg(connection);
-	 }
+	message = "pbs error";
+#endif
+
 
 	fsd_errno = pbsdrmaa_map_pbs_errno( _pbs_errno );
-
-	fsd_log_error(( "call to %s returned with error %d:%s(%s) mapped to %d:%s",
-					function,
-					_pbs_errno, message, extended_message,
-					fsd_errno, fsd_strerror(fsd_errno)
-			));
-
-	if (extended_message)
-		fsd_exc_raise_fmt(fsd_errno, "%s: %s ", message, extended_message);
-	else
-		fsd_exc_raise_fmt(fsd_errno, "%s", message);
-}
+	fsd_log_error((
+				"call to %s returned with error %d:%s mapped to %d:%s",
+				function,
+				_pbs_errno, message,
+				fsd_errno, fsd_strerror(fsd_errno)
+				));
+	fsd_exc_raise_fmt( fsd_errno, "%s: %s", function, message );
+}
+
 
 /** Maps PBS error code into DMRAA code. */
@@ -265,8 +230,4 @@
 		if( fd < 0 )
 			fsd_exc_raise_sys(0);
-
-		if( fchmod(fd, 0600 ) != 0)
-			fsd_exc_raise_sys(0);
-
 		while( len > 0 )
 		 {
Index: trunk/pbs_drmaa/job.h
===================================================================
--- trunk/pbs_drmaa/job.h	(revision 62)
+++ trunk/pbs_drmaa/job.h	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: job.h 2 2009-10-12 09:51:22Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -37,5 +37,4 @@
 struct pbsdrmaa_job_s {
 	fsd_job_t super;
-	time_t missing_time; /* The time when job was seen as missing for the first time */
 
 	void (*
@@ -43,5 +42,4 @@
 };
 
-
 #endif /* __PBS_DRMAA__JOB_H */
 
Index: trunk/pbs_drmaa/util.h
===================================================================
--- trunk/pbs_drmaa/util.h	(revision 85)
+++ trunk/pbs_drmaa/util.h	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: util.h 323 2010-09-21 21:31:29Z mmatloka $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -25,10 +25,5 @@
 #endif
 
-/*compatibility hack - ugly but help to keep binary compatibility :/ */
-#define PBSOLDE_PROTOCOL 15031
-#define PBSOLDE_EXPIRED 15020
-
-
-void pbsdrmaa_exc_raise_pbs( const char *function, int connection_fd );
+void pbsdrmaa_exc_raise_pbs( const char *function );
 int pbsdrmaa_map_pbs_errno( int _pbs_errno );
 
@@ -36,7 +31,6 @@
 
 void pbsdrmaa_free_attrl( struct attrl *list );
-void pbsdrmaa_dump_attrl( const struct attrl *attribute_list, const char *prefix );
-
-struct attrl *pbsdrmaa_add_attr( struct attrl *head, const char *name, const char *value);
+void pbsdrmaa_dump_attrl(
+		const struct attrl *attribute_list, const char *prefix );
 
 /**
@@ -49,5 +43,4 @@
 pbsdrmaa_write_tmpfile( const char *content, size_t len );
 
-
 #endif /* __PBS_DRMAA__UTIL_H */
 
Index: trunk/pbs_drmaa/session.c
===================================================================
--- trunk/pbs_drmaa/session.c	(revision 93)
+++ trunk/pbs_drmaa/session.c	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: session.c 385 2011-01-04 18:24:05Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -22,5 +22,4 @@
 #endif
 
-#include <pwd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -30,5 +29,4 @@
 #include <sys/types.h>
 #include <fcntl.h>
-#include <signal.h>
 
 #include <pbs_ifl.h>
@@ -43,5 +41,4 @@
 
 #include <pbs_drmaa/job.h>
-#include <pbs_drmaa/log_reader.h>
 #include <pbs_drmaa/session.h>
 #include <pbs_drmaa/submit.h>
@@ -55,5 +52,5 @@
 		__attribute__ ((unused))
 #	endif
-	= "$Id$";
+	= "$Id: session.c 385 2011-01-04 18:24:05Z mamonski $";
 #endif
 
@@ -66,4 +63,7 @@
 static fsd_job_t *
 pbsdrmaa_session_new_job( fsd_drmaa_session_t *self, const char *job_id );
+
+static bool
+pbsdrmaa_session_do_drm_keeps_completed_jobs( pbsdrmaa_session_t *self );
 
 static void
@@ -95,10 +95,8 @@
 		self = (pbsdrmaa_session_t*)fsd_drmaa_session_new(contact);
 		fsd_realloc( self, 1, pbsdrmaa_session_t );
-
-		fsd_mutex_lock( &self->super.mutex );
-
 		self->super_wait_thread = NULL;
 
 		self->log_file_initial_size = 0;
+		self->pbs_conn = -1;
 		self->pbs_home = NULL;
 
@@ -116,17 +114,20 @@
 		self->super.apply_configuration = pbsdrmaa_session_apply_configuration;
 
+		self->do_drm_keeps_completed_jobs =
+			pbsdrmaa_session_do_drm_keeps_completed_jobs;
+
 		self->status_attrl = pbsdrmaa_create_status_attrl();
-		self->max_retries_count = 3;
-		self->wait_thread_sleep_time = 1;
-		self->job_exit_status_file_prefix = NULL;
+
+		self->pbs_conn = pbs_connect( self->super.contact );
+		fsd_log_debug(( "pbs_connect(%s) =%d", self->super.contact,
+					self->pbs_conn ));
+		if( self->pbs_conn < 0 )
+			pbsdrmaa_exc_raise_pbs( "pbs_connect" );
 
 		self->super.load_configuration( &self->super, "pbs_drmaa" );
 
 		self->super.missing_jobs = FSD_IGNORE_MISSING_JOBS;
-
-		self->pbs_connection = pbsdrmaa_pbs_conn_new( (fsd_drmaa_session_t *)self, contact );
-		self->connection_max_lifetime =  30; /* 30 seconds */
-
-		fsd_mutex_unlock( &self->super.mutex );
+		if( self->do_drm_keeps_completed_jobs( self ) )
+			self->super.missing_jobs = FSD_IGNORE_QUEUED_MISSING_JOBS;
 	 }
 	EXCEPT_DEFAULT
@@ -134,10 +135,7 @@
 		if( self )
 		  {
-			fsd_mutex_unlock( &self->super.mutex );
 			self->super.destroy( &self->super );
 			self = NULL;
 		  }
-
-		fsd_exc_reraise();
 	 }
 	END_TRY
@@ -151,8 +149,7 @@
 	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self;
 	self->stop_wait_thread( self );
-	pbsdrmaa_pbs_conn_destroy(pbsself->pbs_connection);
+	if( pbsself->pbs_conn >= 0 )
+		pbs_disconnect( pbsself->pbs_conn );
 	fsd_free( pbsself->status_attrl );
-	fsd_free( pbsself->job_exit_status_file_prefix );
-
 	pbsself->super_destroy( self );	
 }
@@ -213,95 +210,50 @@
 {
 	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self;
-	fsd_conf_option_t *pbs_home = NULL;
-	fsd_conf_option_t *wait_thread_sleep_time = NULL;
-	fsd_conf_option_t *max_retries_count = NULL;
-	fsd_conf_option_t *user_state_dir = NULL;
-	fsd_conf_option_t *connection_max_lifetime = NULL;
-
-
+	fsd_conf_option_t *pbs_home;
 	pbs_home = fsd_conf_dict_get(self->configuration, "pbs_home" );
-	wait_thread_sleep_time = fsd_conf_dict_get(self->configuration, "wait_thread_sleep_time" );
-	max_retries_count = fsd_conf_dict_get(self->configuration, "max_retries_count" );
-	user_state_dir = fsd_conf_dict_get(self->configuration, "user_state_dir" );
-	connection_max_lifetime = fsd_conf_dict_get(self->configuration, "connection_max_lifetime");
-
-	if( pbs_home && pbs_home->type == FSD_CONF_STRING )
-	  {
+	if( pbs_home )
+	 {
+		if( pbs_home->type == FSD_CONF_STRING )
+		 {
 			struct stat statbuf;
 			char * volatile log_path;
-			struct tm tm;
-			
+			time_t t;
+
 			pbsself->pbs_home = pbs_home->val.string;
-			fsd_log_info(("pbs_home: %s",pbsself->pbs_home));
+			fsd_log_debug(("pbs_home: %s",pbsself->pbs_home));
 			pbsself->super_wait_thread = pbsself->super.wait_thread;
 			pbsself->super.wait_thread = pbsdrmaa_session_wait_thread;		
 			pbsself->wait_thread_log = true;
 	
-			time(&pbsself->log_file_initial_time);	
-			localtime_r(&pbsself->log_file_initial_time,&tm);
-
-			log_path = fsd_asprintf("%s/server_logs/%04d%02d%02d",
-					pbsself->pbs_home,
-					tm.tm_year + 1900,
-					tm.tm_mon + 1,
-					tm.tm_mday);
-
-			if(stat(log_path,&statbuf) == -1)
-			  {
+			time(&t);	
+			localtime_r(&t,&pbsself->log_file_initial_time);
+
+			if((log_path = fsd_asprintf("%s/server_logs/%04d%02d%02d",
+    		  		pbsself->pbs_home,	 
+  		    		pbsself->log_file_initial_time.tm_year + 1900,
+   		    		pbsself->log_file_initial_time.tm_mon + 1,
+   		   		pbsself->log_file_initial_time.tm_mday)) == NULL) {
+				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"WT - Memory allocation wasn't possible");
+			}
+
+			if(stat(log_path,&statbuf) == -1) {
 				char errbuf[256] = "InternalError";
-				(void)strerror_r(errno, errbuf, sizeof(errbuf));
-				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"stat error on file %s: %s", log_path, errbuf);
-			  }
+				(void)strerror_r(errno, errbuf, 256);
+				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"stat error: %s",errbuf);
+			}
 	
 			fsd_log_debug(("Log file %s size %d",log_path,(int) statbuf.st_size));
 			pbsself->log_file_initial_size = statbuf.st_size;
 			fsd_free(log_path);
-	  }
-
-	if ( max_retries_count && max_retries_count->type == FSD_CONF_INTEGER)
-	  {
-		pbsself->max_retries_count = max_retries_count->val.integer;
-		fsd_log_info(("Max retries count: %d", pbsself->max_retries_count));
-	  }
-
-	if ( connection_max_lifetime && connection_max_lifetime->type == FSD_CONF_INTEGER)
-	  {
-		pbsself->connection_max_lifetime = connection_max_lifetime->val.integer;
-		fsd_log_info(("Max connection lifetime: %d", pbsself->connection_max_lifetime));
-	  }
-
-	if ( wait_thread_sleep_time && wait_thread_sleep_time->type == FSD_CONF_INTEGER)
-	  {
-		pbsself->wait_thread_sleep_time = wait_thread_sleep_time->val.integer;
-		fsd_log_info(("Wait thread sleep time: %d", pbsself->wait_thread_sleep_time));
-	  }
-
-	if( user_state_dir && user_state_dir->type == FSD_CONF_STRING )
-	  {
-		struct passwd *pw = NULL;
-		uid_t uid;
-
-		uid = geteuid();
-		pw = getpwuid(uid); /* drmaa_init is always called in thread safely fashion */
-
-		if (!pw)
-			fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Failed to get pw_name of the user %d", uid);
-
-		pbsself->job_exit_status_file_prefix = fsd_asprintf(user_state_dir->val.string, pw->pw_name);
-	  }
-	else
-	  {
-		pbsself->job_exit_status_file_prefix = fsd_asprintf("%s/.drmaa", getenv("HOME"));
-	  }
-
-	fsd_log_debug(("Trying to create state directory: %s", pbsself->job_exit_status_file_prefix));
-
-	if (mkdir(pbsself->job_exit_status_file_prefix, 0700) == -1 && errno != EEXIST) /* TODO it would be much better to do stat before */
-	  {
-		fsd_log_warning(("Failed to create job state directory: %s. Valid job exit status may not be available in some cases.", pbsself->job_exit_status_file_prefix));
-	  }
-
-
-	/* TODO purge old exit statuses files */
+		 }
+		else
+		{
+			pbsself->super.enable_wait_thread = false;
+			pbsself->wait_thread_log = false;
+			fsd_log_debug(("pbs_home not configured. Running standard wait_thread (pooling)."));
+		}
+	 }
+
+
 
 	pbsself->super_apply_configuration(self); /* call method from the superclass */
@@ -312,4 +264,5 @@
 pbsdrmaa_session_update_all_jobs_status( fsd_drmaa_session_t *self )
 {
+	volatile bool conn_lock = false;
 	volatile bool jobs_lock = false;
 	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self;
@@ -321,11 +274,32 @@
 	TRY
 	 {
-
-/* TODO: query only for user's jobs pbs_selstat + ATTR_u */
+		conn_lock = fsd_mutex_lock( &self->drm_connection_mutex );
+retry:
+
 #ifdef PBS_PROFESSIONAL
-		status = pbsself->pbs_connection->statjob(pbsself->pbs_connection, NULL, NULL);
+		status = pbs_statjob( pbsself->pbs_conn, NULL, NULL, NULL );
 #else
-		status = pbsself->pbs_connection->statjob(pbsself->pbs_connection, NULL, pbsself->status_attrl);
+		status = pbs_statjob( pbsself->pbs_conn, NULL, pbsself->status_attrl, NULL );
 #endif
+		fsd_log_debug(( "pbs_statjob( fd=%d, job_id=NULL, attribs={...} ) =%p",
+				 pbsself->pbs_conn, (void*)status ));
+		if( status == NULL  &&  pbs_errno != 0 )
+		 {
+			if (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED)
+			 {
+				pbs_disconnect( pbsself->pbs_conn );
+				sleep(1);
+				pbsself->pbs_conn = pbs_connect( pbsself->super.contact );
+				if( pbsself->pbs_conn < 0 )
+					pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+				else
+					goto retry;
+			 }
+			else
+			 {
+				pbsdrmaa_exc_raise_pbs( "pbs_statjob" );
+			 }
+		 }
+		conn_lock = fsd_mutex_unlock( &self->drm_connection_mutex );
 
 		 {
@@ -388,5 +362,7 @@
 	 {
 		if( status != NULL )
-			 pbsself->pbs_connection->statjob_free(pbsself->pbs_connection, status );
+			pbs_statfree( status );
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->drm_connection_mutex );
 		if( jobs_lock )
 			jobs_lock = fsd_mutex_unlock( &jobs->mutex );
@@ -450,22 +426,560 @@
 }
 
+
+bool
+pbsdrmaa_session_do_drm_keeps_completed_jobs( pbsdrmaa_session_t *self )
+{
+
+#ifndef PBS_PROFESSIONAL
+	struct attrl default_queue_query;
+	struct attrl keep_completed_query;
+	struct batch_status *default_queue_result = NULL;
+	struct batch_status *keep_completed_result = NULL;
+	const char *default_queue = NULL;
+	const char *keep_completed = NULL;
+	volatile bool result = false;
+	volatile bool conn_lock = false;
+
+	TRY
+	 {
+		default_queue_query.next = NULL;
+		default_queue_query.name = "default_queue";
+		default_queue_query.resource = NULL;
+		default_queue_query.value = NULL;
+		keep_completed_query.next = NULL;
+		keep_completed_query.name = "keep_completed";
+		keep_completed_query.resource = NULL;
+		keep_completed_query.value = NULL;
+
+		conn_lock = fsd_mutex_lock( &self->super.drm_connection_mutex );
+
+		default_queue_result =
+				pbs_statserver( self->pbs_conn, &default_queue_query, NULL );
+		if( default_queue_result == NULL )
+			pbsdrmaa_exc_raise_pbs( "pbs_statserver" );
+		if( default_queue_result->attribs
+				&&  !strcmp( default_queue_result->attribs->name,
+					"default_queue" ) )
+			default_queue = default_queue_result->attribs->value;
+
+		fsd_log_debug(( "default_queue: %s", default_queue ));
+
+		if( default_queue )
+		 {
+			keep_completed_result = pbs_statque( self->pbs_conn,
+					(char*)default_queue, &keep_completed_query, NULL );
+			if( keep_completed_result == NULL )
+				pbsdrmaa_exc_raise_pbs( "pbs_statque" );
+			if( keep_completed_result->attribs
+					&&  !strcmp( keep_completed_result->attribs->name,
+						"keep_completed" ) )
+				keep_completed = keep_completed_result->attribs->value;
+		 }
+
+		fsd_log_debug(( "keep_completed: %s", keep_completed ));
+	 }
+	EXCEPT_DEFAULT
+	 {
+		const fsd_exc_t *e = fsd_exc_get();
+		fsd_log_warning(( "PBS server seems not to keep completed jobs\n"
+				"detail: %s", e->message(e) ));
+		result = false;
+	 }
+	ELSE
+	 {
+		result = false;
+		if( default_queue == NULL )
+			fsd_log_warning(( "no default queue set on PBS server" ));
+		else if( keep_completed == NULL && self->pbs_home == NULL )
+			fsd_log_warning(( "PBS server is not configured to keep completed jobs\n"
+						"in Torque: set keep_completed parameter of default queue\n"
+						"  $ qmgr -c 'set queue batch keep_completed = 60'\n"
+						" or configure DRMAA to utilize log files"
+						));
+		else
+			result = true;
+	 }
+	FINALLY
+	 {
+		if( default_queue_result )
+			pbs_statfree( default_queue_result );
+		if( keep_completed_result )
+			pbs_statfree( keep_completed_result );
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->super.drm_connection_mutex );
+
+	 }
+	END_TRY
+#endif
+	return false;
+}
+
+
+enum field
+  {
+  FLD_DATE = 0,
+  FLD_EVENT = 1,
+  FLD_OBJ = 2,
+  FLD_TYPE = 3,
+  FLD_ID = 4,
+  FLD_MSG = 5
+  };
+
+enum field_msg
+  {
+  FLD_MSG_EXIT_STATUS = 0,
+  FLD_MSG_CPUT = 1,
+  FLD_MSG_MEM = 2,
+  FLD_MSG_VMEM = 3,
+  FLD_MSG_WALLTIME = 4
+  };
+
+#define FLD_MSG_STATUS "0010"
+#define FLD_MSG_STATE "0008"
+#define FLD_MSG_LOG "0002"
+
+ssize_t fsd_getline(char * line,ssize_t size, int fd)
+{
+	char buf;
+	char * ptr = NULL;
+	ssize_t n = 0, rc;
+	ptr = line;
+	for(n = 1; n< size; n++)
+	{		
+		if( (rc = read(fd,&buf,1 )) == 1) {
+			*ptr++ = buf;
+			if(buf == '\n')
+			{
+				break;
+			}
+		}
+		else if (rc == 0) {
+			if (n == 1)
+				return 0;
+			else
+				break;
+		}		
+		else
+			return -1; 
+	}
+
+	return n;
+} 
+
 void *
 pbsdrmaa_session_wait_thread( fsd_drmaa_session_t *self )
 {
-	pbsdrmaa_log_reader_t *log_reader = NULL;
+	pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*) self;
+	fsd_job_t *volatile job = NULL;
+	pbsdrmaa_job_t *volatile pbsjob = NULL;
+	char job_id[256] = "";
+	char event[256] = "";
+	time_t t;
+	struct tm tm;
+
+	tm = pbsself->log_file_initial_time;
+
+	fsd_log_enter(( "" ));
+	fsd_mutex_lock( &self->mutex );
+	TRY
+	 {	
+		char * volatile log_path = NULL;
+		char buffer[4096] = "";
+		bool volatile date_changed = true;
+		int  volatile fd = -1;
+		bool first_open = true;
+
+		fsd_log_debug(("WT - reading log files"));
+
+		while( self->wait_thread_run_flag )
+		TRY
+		 {			
+			if(date_changed)
+			{
+				int num_tries = 0;
+				
+				time(&t);	
+				localtime_r(&t,&tm);
+			
+				#define DRMAA_WAIT_THREAD_MAX_TRIES (12)
+				/* generate new date, close file and open new */
+				if((log_path = fsd_asprintf("%s/server_logs/%04d%02d%02d",
+       					pbsself->pbs_home,	 
+       					tm.tm_year + 1900,
+       					tm.tm_mon + 1,
+      					tm.tm_mday)) == NULL) {
+					fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"WT - Memory allocation wasn't possible");
+				}
+
+				if(fd != -1)
+					close(fd);
+
+				fsd_log_debug(("Log file: %s",log_path));
+				
+		retry:
+				if((fd = open(log_path,O_RDONLY) ) == -1 && num_tries > DRMAA_WAIT_THREAD_MAX_TRIES )
+				{
+					fsd_log_error(("Can't open log file. Verify pbs_home. Running standard wait_thread."));
+					fsd_log_error(("Remember that without keep_completed set standard wait_thread won't run correctly"));
+					/*pbsself->super.enable_wait_thread = false;*/ /* run not wait_thread */
+					pbsself->wait_thread_log = false;
+					pbsself->super.wait_thread = pbsself->super_wait_thread;
+					pbsself->super.wait_thread(self);
+				} else if ( fd == -1 ) {
+					fsd_log_warning(("Can't open log file: %s. Retries count: %d", log_path, num_tries));
+					num_tries++;
+					sleep(5);
+					goto retry;
+				}
+
+				fsd_free(log_path);
+
+				fsd_log_debug(("Log file opened"));
+
+				if(first_open) {
+					fsd_log_debug(("Log file lseek"));
+					if(lseek(fd,pbsself->log_file_initial_size,SEEK_SET) == (off_t) -1) {
+						char errbuf[256] = "InternalError";
+						(void)strerror_r(errno, errbuf, 256);
+						fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"lseek error: %s",errbuf);
+					}
+					first_open = false;
+				}
+
+				date_changed = false;
+			}				
+			
+			while ((fsd_getline(buffer,sizeof(buffer),fd)) > 0) 			
+			{
+				const char *volatile ptr = buffer;
+  				char field[256] = "";
+				int volatile field_n = 0;
+ 				int n;
+
+				bool volatile job_id_match = false;
+				bool volatile event_match = false;
+				bool volatile log_event = false;
+				bool volatile log_match = false;
+  				char *  temp_date = NULL;
+				
+
+				struct batch_status status;
+				status.next = NULL;
+
+				if( strlcpy(job_id,"",sizeof(job_id)) > sizeof(job_id) ) {
+					fsd_log_error(("WT - strlcpy error"));
+				}
+				if( strlcpy(event,"",sizeof(event)) > sizeof(event) ) {
+					fsd_log_error(("WT - strlcpy error"));
+				}
+				while ( sscanf(ptr, "%255[^;]%n", field, &n) == 1 ) /* divide current line into fields */
+				{
+					if(field_n == FLD_DATE)
+					{
+						temp_date = fsd_strdup(field);
+					}
+					else if(field_n == FLD_EVENT && (strcmp(field,FLD_MSG_STATUS) == 0 || 
+						     		    strcmp(field,FLD_MSG_STATE) == 0 ))
+					{
+						/* event described by log line*/
+						if(strlcpy(event, field,sizeof(event)) > sizeof(event)) {
+							fsd_log_error(("WT - strlcpy error"));
+						}
+						event_match = true;									
+					}
+					else if(event_match && field_n == FLD_ID)
+					{	
+						TRY
+						{	
+							job = self->get_job( self, field );
+							pbsjob = (pbsdrmaa_job_t*) job;
+
+							if( job )
+							{
+								if(strlcpy(job_id, field,sizeof(job_id)) > sizeof(job_id)) {
+									fsd_log_error(("WT - strlcpy error"));
+								}
+								fsd_log_debug(("WT - job_id: %s",job_id));
+								status.name = fsd_strdup(job_id);
+								job_id_match = true; /* job_id is in drmaa */
+							}
+							else 
+							{
+								fsd_log_debug(("WT - Unknown job: %s", field));
+							}
+						}
+						END_TRY	
+					}
+					else if(job_id_match && field_n == FLD_MSG)
+					{						
+						/* parse msg - depends on FLD_EVENT*/
+						struct attrl struct_resource_cput,struct_resource_mem,struct_resource_vmem,
+							struct_resource_walltime, struct_status, struct_state, struct_start_time,struct_mtime, struct_queue, struct_account_name;	
+						
+						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;
+
+								
+						if (strcmp(event,FLD_MSG_STATE) == 0) 
+						{
+							/* job run, modified, queued etc */
+							int n = 0;
+							status.attribs = &struct_state;
+							struct_state.next = NULL;
+							struct_state.name = "job_state";
+							if(field[0] == 'J') /* Job Queued, Job Modified, Job Run*/
+							{
+								n = 4;								
+							}		
+							if(field[4] == 'M') {
+								struct tm temp_time_tm;
+								memset(&temp_time_tm, 0, sizeof(temp_time_tm));
+								temp_time_tm.tm_isdst = -1;
+
+								if (strptime(temp_date, "%m/%d/%Y %H:%M:%S", &temp_time_tm) == NULL) 
+								 {
+								 	fsd_log_error(("failed to parse mtime: %s", temp_date));
+								 }
+								else
+								 {
+									time_t temp_time = mktime(&temp_time_tm);
+									status.attribs = &struct_mtime; 
+									struct_mtime.name = "mtime";
+									struct_mtime.next = NULL;
+									struct_mtime.value = fsd_asprintf("%lu",temp_time);
+								 }
+							}		
+							/* != Job deleted and Job to be deleted*/
+							#ifdef PBS_PROFESSIONAL
+							else if	(field[4] != 't' && field[10] != 'd') {
+							#else	 	
+							else if(field[4] != 'd') {
+							#endif 
+
+								if ((struct_state.value = fsd_asprintf("%c",field[n]) ) == NULL ) { /* 4 first letter of state */
+									fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"WT - Memory allocation wasn't possible");
+								}
+								if(struct_state.value[0] == 'R'){
+									state_running = true;
+								}
+							}
+							else { /* job terminated - pbs drmaa detects failed as completed with exit_status !=0, aborted with status -1*/
+								struct_status.name = "exit_status";
+								struct_status.value = fsd_strdup("-1");
+								struct_status.next = NULL;
+								struct_state.next = &struct_status;
+								struct_state.value = fsd_strdup("C");								
+							}
+						} 						     
+						else /*if (strcmp(event,FLD_MSG_STATUS) == 0 )*/
+						{
+							/* exit status and rusage */
+							const char *ptr2 = field;
+							char  msg[ 256 ] = "";
+							int n2;
+							int msg_field_n = 0;
+							
+							struct_resource_cput.name = "resources_used";
+							struct_resource_mem.name = "resources_used";
+							struct_resource_vmem.name = "resources_used";
+							struct_resource_walltime.name = "resources_used";
+							struct_status.name = "exit_status";
+							struct_state.name = "job_state";
+				
+							status.attribs = &struct_resource_cput;
+							struct_resource_cput.next = &struct_resource_mem;
+							struct_resource_mem.next = &struct_resource_vmem;
+							struct_resource_vmem.next = &struct_resource_walltime;
+							struct_resource_walltime.next =  &struct_status;
+							struct_status.next = &struct_state;
+							struct_state.next = NULL;
+
+							while ( sscanf(ptr2, "%255[^ ]%n", msg, &n2) == 1 )
+							 {						
+								switch(msg_field_n) 
+								{
+									case FLD_MSG_EXIT_STATUS:
+										struct_status.value = fsd_strdup(strchr(msg,'=')+1);
+										break;
+
+									case FLD_MSG_CPUT:
+										struct_resource_cput.resource = "cput";
+										struct_resource_cput.value = fsd_strdup(strchr(msg,'=')+1);
+										break;
+
+									case FLD_MSG_MEM:
+										struct_resource_mem.resource = "mem";
+										struct_resource_mem.value  = fsd_strdup(strchr(msg,'=')+1);
+										break;
+
+									case FLD_MSG_VMEM:
+										struct_resource_vmem.resource = "vmem";
+										struct_resource_vmem.value  = fsd_strdup(strchr(msg,'=')+1);
+										break; 
+
+									case FLD_MSG_WALLTIME:
+										struct_resource_walltime.resource = "walltime";
+										struct_resource_walltime.value  = fsd_strdup(strchr(msg,'=')+1);
+										break; 
+								}
+							      
+								ptr2 += n2; 
+								msg_field_n++;
+								if ( *ptr2 != ' ' )
+							      	 {
+									 break; 
+							  	 }
+							 	++ptr2;						
+							 }
+							struct_state.value = fsd_strdup("C");	/* we got exit_status so we say that it has completed */
+						}						
+
+						if ( state_running )
+						 {
+							fsd_log_debug(("WT - forcing update of job: %s", job->job_id ));
+							job->update_status( job );
+						 }
+						else
+						 {
+							fsd_log_debug(("WT - updating job: %s", job->job_id ));
+							pbsjob->update( job, &status );
+						 }
+
+				
+						fsd_cond_broadcast( &job->status_cond);
+						fsd_cond_broadcast( &self->wait_condition );
+
+						if ( job )
+							job->release( job );
 	
-	fsd_log_enter(( "" ));
-	
-	TRY
-	{	
-		log_reader = pbsdrmaa_log_reader_new( self );
-		log_reader->read_log( log_reader );
-	}
+						fsd_free(struct_resource_cput.value);
+						fsd_free(struct_resource_mem.value);
+						fsd_free(struct_resource_vmem.value);
+						fsd_free(struct_resource_walltime.value);
+						fsd_free(struct_status.value);
+						fsd_free(struct_state.value);
+						fsd_free(struct_start_time.value);
+						fsd_free(struct_mtime.value);
+						fsd_free(struct_queue.value);
+						fsd_free(struct_account_name.value);
+
+						if ( status.name!=NULL ) 
+							fsd_free(status.name);
+					}
+					else if(field_n == FLD_EVENT && strcmp(field,FLD_MSG_LOG) == 0)
+					{
+						log_event = true;					
+					}
+					else if (log_event && field_n == FLD_ID && strcmp(field,"Log") == 0 )
+					{
+						log_match = true;
+						log_event = false;
+					}
+					else if( 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*/
+					{
+						fsd_log_debug(("WT - Date changed. Closing log file"));
+						date_changed = true;
+						log_match = false;
+					}
+					
+					ptr += n; 
+					if ( *ptr != ';' )
+					{
+						break; /* end of line */
+					}
+					field_n++;
+					++ptr;
+				}		
+
+				if( strlcpy(buffer,"",sizeof(buffer)) > sizeof(buffer) ) {
+					fsd_log_error(("WT - strlcpy error"));
+				}
+
+				fsd_free(temp_date);			
+			}
+
+			fsd_mutex_unlock( &self->mutex );	
+			usleep(1000000);
+			fsd_mutex_lock( &self->mutex );
+		 }
+		EXCEPT_DEFAULT
+		 {
+			const fsd_exc_t *e = fsd_exc_get();
+
+			fsd_log_error(( "wait thread: <%d:%s>", e->code(e), e->message(e) ));
+			fsd_exc_reraise();
+		 }
+		END_TRY
+
+		if(fd != -1)
+			close(fd);
+		fsd_log_debug(("Log file closed"));
+	 }
 	FINALLY
-	{
-		pbsdrmaa_log_reader_destroy( log_reader );
-	}
+	 {
+	 	fsd_log_debug(("WT - Terminated."));	
+	 	fsd_mutex_unlock( &self->mutex );
+	 }
 	END_TRY
-	
+
 	fsd_log_return(( " =NULL" ));
 	return NULL;
Index: trunk/pbs_drmaa/drmaa.c
===================================================================
--- trunk/pbs_drmaa/drmaa.c	(revision 23)
+++ trunk/pbs_drmaa/drmaa.c	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: drmaa.c 353 2010-10-18 13:45:14Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -124,5 +124,5 @@
 		)
 {
-	*exited = (stat <= 125) && (stat != -1);
+	*exited = (stat <= 125);
 	return DRMAA_ERRNO_SUCCESS;
 }
Index: trunk/pbs_drmaa/pbs_drmaa.conf.example
===================================================================
--- trunk/pbs_drmaa/pbs_drmaa.conf.example	(revision 12)
+++ trunk/pbs_drmaa/pbs_drmaa.conf.example	(revision 1)
@@ -1,3 +1,3 @@
-# $Id$
+# $Id: pbs_drmaa.conf.example 2420 2009-06-24 14:40:21Z lukasz $
 # pbs_drmaa.conf - Sample pbs_drmaa configuration file.
 
Index: trunk/pbs_drmaa/Makefile.am
===================================================================
--- trunk/pbs_drmaa/Makefile.am	(revision 103)
+++ trunk/pbs_drmaa/Makefile.am	(revision 1)
@@ -1,3 +1,3 @@
-# $Id$
+# $Id: Makefile.am 2420 2009-06-24 14:40:21Z lukasz $
 # 
 # FedStage DRMAA for PBS Professional
@@ -27,26 +27,10 @@
  drmaa.c \
  job.c job.h \
- pbs_attrib.h \
+ pbs_attrib.gperf pbs_attrib.h \
  session.c session.h \
  submit.c submit.h \
- util.c util.h \
- log_reader.c log_reader.h \
- pbs_conn.c pbs_conn.h 
-
-
-if PBS_PROFESSIONAL
-GPERF_INPUT= pbs_attrib_pro.gperf
-else
-GPERF_INPUT= pbs_attrib.gperf
-endif
-
-libdrmaa_la_SOURCES += $(GPERF_INPUT)
-
-BUILT_SOURCES       = $(GPERF_INPUT:.gperf=.c)
-EXTRA_DIST          = $(GPERF_INPUT:.gperf=.c)
-
-if TORQUE4
-libdrmaa_la_SOURCES += torque4.cpp torque4.h
-endif
+ util.c util.h
+BUILT_SOURCES       = pbs_attrib.c
+EXTRA_DIST          = pbs_attrib.c
 dist_sysconf_DATA   = pbs_drmaa.conf.example
 libdrmaa_la_LIBADD  = ../drmaa_utils/drmaa_utils/libdrmaa_utils.la @PBS_LIBS@
@@ -58,4 +42,4 @@
 
 if GCC
-$(GPERF_INPUT:.gperf=.lo): CFLAGS += @GCC_W_NO_MISSING_FIELD_INITIALIZERS@
+pbs_attrib.lo: CFLAGS += @GCC_W_NO_MISSING_FIELD_INITIALIZERS@
 endif
Index: trunk/pbs_drmaa/session.h
===================================================================
--- trunk/pbs_drmaa/session.h	(revision 85)
+++ trunk/pbs_drmaa/session.h	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: session.h 323 2010-09-21 21:31:29Z mmatloka $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -27,26 +27,32 @@
 #include <drmaa_utils/session.h>
 
-#include <pbs_drmaa/pbs_conn.h>
-
 typedef struct pbsdrmaa_session_s pbsdrmaa_session_t;
 
-fsd_drmaa_session_t *pbsdrmaa_session_new( const char *contact );
+fsd_drmaa_session_t *
+pbsdrmaa_session_new( const char *contact );
 
 struct pbsdrmaa_session_s {
 	fsd_drmaa_session_t super;
 
-	void (*super_destroy)( fsd_drmaa_session_t *self );
+	bool (*
+	do_drm_keeps_completed_jobs)( pbsdrmaa_session_t *self );
 
-	void (*super_apply_configuration)(fsd_drmaa_session_t *self);
+	void (*
+	super_destroy)( fsd_drmaa_session_t *self );
+
+	void (*
+	super_apply_configuration)(fsd_drmaa_session_t *self);
 
 	/*
 	 * Pointer to standard wait_thread drmaa_utils function
 	 */
-	void* (*super_wait_thread)( fsd_drmaa_session_t *self );
+        void* (*
+        super_wait_thread)( fsd_drmaa_session_t *self );
 
 	/*
-	 * PBS connection handle
+	 * PBS connection (or -1 if not connected).
+	 * A descriptor of socket conencted to PBS server.
 	 */
-	pbsdrmaa_pbs_conn_t *pbs_connection;
+	int pbs_conn;
 
 	/*
@@ -66,32 +72,12 @@
 
 	/*
-	 * Log file initial size - used by wait_thread which reads log files TODO: check if it can be safely moved to log_reader
+	 * Log file initial size - used by wait_thread which reads log files
  	 */
 	off_t log_file_initial_size;
 
 	/*
-	 * Time we checked log file initial size - used by wait_thread which reads log files TODO: check if it can be safely moved to log_reader
+	 * Time we checked log file initial size - used by wait_thread which reads log files
  	 */
-	time_t log_file_initial_time;
-
-	/*
-	 * Maximal number of retires in pbs_connect. Default 3
-	 */
-	int max_retries_count;
-
-	/*
-	 * Wait thread sleep time (in seconds). Default 1s.
-	 */
-	int wait_thread_sleep_time;
-
-	/*
-	 * The prefix of the directory where the job exit status information is stored (default: %HOME/.pbs-drmaa/
-	 */
-	char *job_exit_status_file_prefix;
-
-	/*
-	 * PBS Max connection time
-	 */
-	int connection_max_lifetime;
+	struct tm log_file_initial_time;
 };
 
Index: trunk/pbs_drmaa/pbs_drmaa.h
===================================================================
--- trunk/pbs_drmaa/pbs_drmaa.h	(revision 1)
+++ trunk/pbs_drmaa/pbs_drmaa.h	(revision 1)
@@ -0,0 +1,120 @@
+/* $Id: pbs_drmaa.h 2 2009-10-12 09:51:22Z mamonski $ */
+/*
+ *  FedStage DRMAA for PBS Pro
+ *  Copyright (C) 2006-2007  FedStage Systems
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DRMAA__PBS_DRMAA_H
+#define __DRMAA__PBS_DRMAA_H
+
+#ifdef HAVE_CONFIG_H
+#	include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <stdbool.h>
+#include <time.h>
+#include <pbs_ifl.h>
+
+#include <drmaa_utils/common.h>
+#include <pbs_drmaa/pbs_attrib.h>
+
+
+/** PBS DRMAA specific session data. */
+struct drmaa_session_impl_s {
+	int                 pbs_conn;    /**< PBS connection (or -1). */
+	drmaa_mutex_t       conn_mutex;  /**< Mutex for PBS connection. */
+	drmaa_thread_t      wait_thread;
+	bool                wait_thread_started;
+	struct attrl       *status_attrl;
+};
+
+
+enum { PBS_ATTRIBS_BITSET_SIZE = (N_PBS_DRMAA_ATTRIBS+31) / 32 };
+struct drmaa_submit_impl_s {
+	struct attrl *pbs_attribs;
+	uint32_t pbs_attribs_bitset[ PBS_ATTRIBS_BITSET_SIZE ];
+	char *script_filename;
+};
+
+
+void *
+drmaa_wait_thread( void *arg );
+
+drmaa_submit_ctx_t *
+drmaa_create_submission_context(
+		const drmaa_job_template_t *jt, int bulk_no,
+		drmaa_err_ctx_t *err
+		);
+
+void
+drmaa_free_submission_context( drmaa_submit_ctx_t *c, drmaa_err_ctx_t* );
+
+void drmaa_set_job_defaults        ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_create_job_script       ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_submit_state    ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_files           ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_file_staging        ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_resources       ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_environment     ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_set_job_email_notif     ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_apply_native_spec       ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+void drmaa_apply_job_category      ( drmaa_submit_ctx_t*, drmaa_err_ctx_t* );
+char *drmaa_translate_staging( const char *stage, drmaa_err_ctx_t* );
+
+void
+drmaa_parse_qsub_args(
+		drmaa_submit_ctx_t *ctx, const char *string,
+		drmaa_err_ctx_t *err
+		);
+
+void
+drmaa_job_missing( drmaa_job_t *job, drmaa_err_ctx_t *err );
+
+void
+drmaa_add_pbs_attr(
+		drmaa_submit_ctx_t *c,
+		int attr, char *resource, char *value,
+		unsigned set,
+		drmaa_err_ctx_t *err
+		);
+
+char *
+drmaa_write_tmpfile(
+	 const char *content, size_t len,
+	 drmaa_err_ctx_t *err
+	 );
+
+struct attrl *
+drmaa_create_pbs_attrl( drmaa_err_ctx_t *err );
+
+void
+drmaa_log_attrl( const struct attrl *attribute_list, const char *prefix );
+
+void
+drmaa_free_attrl( struct attrl *attr );
+
+void
+drmaa_err_pbs_error( drmaa_err_ctx_t *err );
+
+int
+drmaa_err_map_pbs_error( int pbs_errcode );
+
+#define RAISE_PBS() \
+	drmaa_err_pbs_error( err )
+
+#endif /* __DRMAA__PBS_DRMAA_H */
+
Index: trunk/pbs_drmaa/pbs_attrib.h
===================================================================
--- trunk/pbs_drmaa/pbs_attrib.h	(revision 104)
+++ trunk/pbs_drmaa/pbs_attrib.h	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: pbs_attrib.h 256 2010-08-10 16:31:35Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -41,5 +41,4 @@
 #define PBSDRMAA_FILE_SIZE_LIMIT        "Resource_List.file"
 #define PBSDRMAA_NICE                   "Resource_List.nice"
-#define PBSDRMAA_MEM_LIMIT              "Resource_List.mem"
 #define PBSDRMAA_VMEM_LIMIT             "Resource_List.vmem"
 #define PBSDRMAA_SINGLE_CPU_TIME_LIMIT  "Resource_List.pcput"
@@ -51,8 +50,4 @@
 #define PBSDRMAA_NODES                  "Resource_List.nodes"
 #define PBSDRMAA_SOFTWARE               "Resource_List.software"
-#define PBSDRMAA_PLACE                  "Resource_List.place"
-#define PBSDRMAA_SELECT                 "Resource_List.select"
-#define PBSDRMAA_PROCS                  "Resource_List.procs"
-#define PBSDRMAA_NCPUS                  "Resource_List.ncpus"
 #define PBSDRMAA_MAIL_POINTS            "Mail_Points"
 #define PBSDRMAA_OUTPUT_PATH            "Output_Path"
@@ -74,5 +69,4 @@
 /* additional job and general attribute names */
 #define PBSDRMAA_EXECUTION_HOST         "exec_host"
-#define PBSDRMAA_EXECUTION_VNODE        "exec_vnode" /* PBS PRO */
 #define PBSDRMAA_JOB_OWNER              "Job_Owner"
 #define PBSDRMAA_RESOURCES_USED         "resources_used"
@@ -81,16 +75,9 @@
 #define PBSDRMAA_SERVER                 "server"
 #define PBSDRMAA_COMMENT                "comment"
+#define PBSDRMAA_EXIT_STATUS            "exit_status"
 #define PBSDRMAA_START_TIME             "start_time"
 #define PBSDRMAA_EXTENSION              "extension"
-#define PBSDRMAA_SUBMIT_ARGS            "submit_args"
-#define PBSDRMAA_MTIME                  "mtime"
-#define PBSDRMAA_NODE_PROPERTIES        "pbsdrmaa.node_properties"
-#define PBSDRMAA_CUSTOM_RESOURCES       "pbsdrmaa.custom_resources"
+#define PBSDRMAA_SUBMIT_ARGS		"submit_args"
 
-#ifdef PBS_PROFESSIONAL
-#	define PBSDRMAA_EXIT_STATUS        	"Exit_status"
-#else
-#	define PBSDRMAA_EXIT_STATUS        	"exit_status"
-#endif
 
 typedef enum {
@@ -107,5 +94,4 @@
 	PBSDRMAA_ATTR_NICE,
 	PBSDRMAA_ATTR_VMEM_LIMIT,
-	PBSDRMAA_ATTR_MEM_LIMIT,
 	PBSDRMAA_ATTR_SINGLE_CPU_TIME_LIMIT,
 	PBSDRMAA_ATTR_SINGLE_RSS_LIMIT,
@@ -115,9 +101,5 @@
 	PBSDRMAA_ATTR_HOST,
 	PBSDRMAA_ATTR_NODES,
-	PBSDRMAA_ATTR_PROCS,
-	PBSDRMAA_ATTR_NCPUS,
 	PBSDRMAA_ATTR_SOFTWARE,
-	PBSDRMAA_ATTR_PLACE,
-	PBSDRMAA_ATTR_SELECT,
 	PBSDRMAA_ATTR_MAIL_POINTS,
 	PBSDRMAA_ATTR_OUTPUT_PATH,
@@ -139,5 +121,4 @@
 	/* additional job and general attribute names */
 	PBSDRMAA_ATTR_EXECUTION_HOST,
-	PBSDRMAA_ATTR_EXECUTION_VNODE, /* PBS PRO */
 	PBSDRMAA_ATTR_JOB_OWNER,
 	PBSDRMAA_ATTR_RESOURCES_USED,
@@ -151,6 +132,61 @@
 	PBSDRMAA_ATTR_SUBMIT_ARGS,
 	PBSDRMAA_ATTR_MTIME,
-	PBSDRMAA_ATTR_NODE_PROPERTIES,
-	PBSDRMAA_ATTR_CUSTOM_RESOURCES,
+
+#if 0
+	/* Additional Torque/OpenPBS attribs (not in DRMAA specification): */
+	/* Used by OpenPBS user commands: */
+	PBSDRMAA_ATTR_CHECKPOINT = DRMAA_N_ATTRIBUTES, /* MAX_DRMAA_ATTR+1, */
+	PBSDRMAA_ATTR_GROUP_LIST,
+	PBSDRMAA_ATTR_HOLD_TYPES,
+	PBSDRMAA_ATTR_KEEP_FILES,
+	PBSDRMAA_ATTR_RESOURCES,
+	PBSDRMAA_ATTR_MAIL_POINTS,
+	PBSDRMAA_ATTR_PRIORITY,
+	PBSDRMAA_ATTR_DESTINATION_QUEUE,
+	PBSDRMAA_ATTR_RERUNABLE,
+	PBSDRMAA_ATTR_USER_LIST,
+	PBSDRMAA_ATTR_ACCOUNT_NAME,
+	PBSDRMAA_ATTR_SHELL,
+	PBSDRMAA_ATTR_DEPENDENCIES,
+	PBSDRMAA_ATTR_INTERACTIVE,
+	PBSDRMAA_ATTR_STAGEIN,
+	PBSDRMAA_ATTR_STAGEOUT,
+
+	/* Additional job and general attribute names: */
+	PBSDRMAA_ATTR_JOB_STATE,
+	PBSDRMAA_ATTR_CTIME,
+	/* PBSDRMAA_ATTR_MTIME, moved to basic attributes - needed to determine job end time*/
+	PBSDRMAA_ATTR_QTIME,
+	PBSDRMAA_ATTR_ETIME,
+	PBSDRMAA_ATTR_RESOURCES_USED,
+	PBSDRMAA_ATTR_EXIT_STATUS,
+	PBSDRMAA_ATTR_JOB_OWNER,
+	PBSDRMAA_ATTR_EUSER,
+	PBSDRMAA_ATTR_EGROUP,
+	PBSDRMAA_ATTR_HOP_COUNT,
+	PBSDRMAA_ATTR_SECURITY,
+	PBSDRMAA_ATTR_SCHEDULER_HINT,
+	PBSDRMAA_ATTR_SERVER,
+	PBSDRMAA_ATTR_QUEUE,
+	PBSDRMAA_ATTR_QUEUE_RANK,
+	PBSDRMAA_ATTR_EXECUTION_HOST,
+	PBSDRMAA_ATTR_TOTAL_JOBS,
+	PBSDRMAA_ATTR_MAX_RUNNING,
+	PBSDRMAA_ATTR_COMMENT,
+	PBSDRMAA_ATTR_JOB_COOKIE,
+	PBSDRMAA_ATTR_HASHNAME,
+	PBSDRMAA_ATTR_SESSION_ID,
+	PBSDRMAA_ATTR_ALT_ID,
+
+	/* Reservation attributes */
+	PBSDRMAA_ATTR_RESERVATION_START,
+	PBSDRMAA_ATTR_RESERVATION_END,
+	PBSDRMAA_ATTR_RESERVATION_DURATION,
+	PBSDRMAA_ATTR_RESERVATION_STATE,
+	PBSDRMAA_ATTR_RESERVATION_SUBSTATE,
+
+	/* Pseudo PBS attributes */
+	PBSDRMAA_ATTR_RESERVATION_ID,
+#endif
 
 	PBSDRMAA_N_PBS_ATTRIBUTES
Index: trunk/pbs_drmaa/submit.c
===================================================================
--- trunk/pbs_drmaa/submit.c	(revision 99)
+++ trunk/pbs_drmaa/submit.c	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: submit.c 386 2011-01-06 18:13:33Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -24,5 +24,4 @@
 #include <unistd.h>
 #include <string.h>
-#include <stdlib.h>
 
 #include <pbs_ifl.h>
@@ -30,5 +29,4 @@
 
 #include <drmaa_utils/conf.h>
-#include <drmaa_utils/exec.h>
 #include <drmaa_utils/drmaa.h>
 #include <drmaa_utils/drmaa_util.h>
@@ -48,17 +46,20 @@
 		__attribute__ ((unused))
 #	endif
-	= "$Id$";
+	= "$Id: submit.c 386 2011-01-06 18:13:33Z mamonski $";
 #endif
 
-static void pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self );
-
-static char *pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self );
-
-static void pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self );
-
-static void pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *pbs_attr, char *value, unsigned placeholders );
-
-static struct attrl *pbsdrmaa_submit_filter(struct attrl *pbs_attr);
-
+static void
+pbsdrmaa_submit_destroy( pbsdrmaa_submit_t *self );
+
+static char *
+pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self );
+
+static void
+pbsdrmaa_submit_eval( pbsdrmaa_submit_t *self );
+
+
+static void
+pbsdrmaa_submit_set( pbsdrmaa_submit_t *self, const char *pbs_attr,
+		char *value, unsigned placeholders );
 
 static void pbsdrmaa_submit_apply_defaults( pbsdrmaa_submit_t *self );
@@ -100,5 +101,6 @@
 		self->apply_job_environment = pbsdrmaa_submit_apply_job_environment;
 		self->apply_email_notification = pbsdrmaa_submit_apply_email_notification;
-		self->apply_native_specification = pbsdrmaa_submit_apply_native_specification;
+		self->apply_native_specification =
+			pbsdrmaa_submit_apply_native_specification;
 
 		self->pbs_job_attributes = pbsdrmaa_pbs_template_new();
@@ -136,75 +138,63 @@
 pbsdrmaa_submit_submit( pbsdrmaa_submit_t *self )
 {
+	volatile bool conn_lock = false;
 	struct attrl *volatile pbs_attr = NULL;
 	char *volatile job_id = NULL;
 	TRY
 	 {
-		fsd_template_t *pbs_tmpl = self->pbs_job_attributes;
-		int i;
-
-		for( i = PBSDRMAA_N_PBS_ATTRIBUTES - 1; i >= 0; i-- ) /* down loop -> start with custom resources */
+		const fsd_template_t *pbs_tmpl = self->pbs_job_attributes;
+		unsigned i;
+
+		for( i = 0;  i < PBSDRMAA_N_PBS_ATTRIBUTES;  i++ )
 		 {
 			const char *name = pbs_tmpl->by_code( pbs_tmpl, i )->name;
-			const char *value = pbs_tmpl->get_attr( pbs_tmpl, name );
-
-			if (!value)
-				continue;
-
-			if ( i == PBSDRMAA_ATTR_CUSTOM_RESOURCES)
+			if( name  &&  name[0] != '!' && pbs_tmpl->get_attr( pbs_tmpl, name ) )
 			 {
-				char *value_copy = fsd_strdup(value);
-				char *tok_comma_ctx = NULL;
-				char *res_token = NULL;
-				/* matlab:2,simulink:1 */
-
-				for (res_token = strtok_r(value_copy, ";", &tok_comma_ctx); res_token; res_token = strtok_r(NULL, ";", &tok_comma_ctx))
+				struct attrl *p;
+				const char *resource;
+				const char *value;
+				value = pbs_tmpl->get_attr( pbs_tmpl, name );
+				fsd_malloc( p, struct attrl );
+				memset( p, 0, sizeof(struct attrl) );
+				p->next = pbs_attr;
+				pbs_attr = p;
+				resource = strchr( name, '.' );
+				if( resource )
 				 {
-					char *value_p = strstr(res_token, ":");
-
-					if (value_p)
-					 {
-						char *name_p = NULL;
-						*value_p = '\0';
-						value_p++;
-						name_p = fsd_asprintf("Resource_List.%s",res_token);
-						pbs_attr = pbsdrmaa_add_attr( pbs_attr, name_p, value_p );
-						fsd_free(name_p);
-					 }
-					else
-					 {
-						fsd_exc_raise_code( FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE );
-					 }
-				 }
-
-				fsd_free(value_copy);
-			 }
-			else if (i == PBSDRMAA_ATTR_NODE_PROPERTIES)
-			 {
-				const char *nodes_value = pbs_tmpl->get_attr( pbs_tmpl, PBSDRMAA_NODES );
-				char *final_value = NULL;
-
-				if (nodes_value)
-				 {
-					final_value = fsd_asprintf("%s:%s",nodes_value, value);
+					p->name = fsd_strndup( name, resource-name );
+					p->resource = fsd_strdup( resource+1 );
 				 }
 				else
-				 {
-					final_value = fsd_asprintf("1:%s", value);
-				 }
-
-				pbs_tmpl->set_attr( pbs_tmpl, PBSDRMAA_NODES, final_value);
-				fsd_free(final_value);
+					p->name = fsd_strdup( name );
+				fsd_log_debug(("set attr: %s = %s", name, value));
+				p->value = fsd_strdup( value );
+				p->op = SET;
+			 }
+		 }
+
+		conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex );
+retry:
+		job_id = pbs_submit( ((pbsdrmaa_session_t*)self->session)->pbs_conn,
+				(struct attropl*)pbs_attr, self->script_filename,
+				self->destination_queue, NULL );
+		if( job_id == NULL )
+		{
+			if (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED)
+			 {
+				pbsdrmaa_session_t *pbsself = (pbsdrmaa_session_t*)self->session;
+				pbs_disconnect( pbsself->pbs_conn );
+				sleep(1);
+				pbsself->pbs_conn = pbs_connect( pbsself->super.contact );
+				if( pbsself->pbs_conn < 0 )
+					pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+				else
+					goto retry;
 			 }
 			else
 			 {
-				pbs_attr = pbsdrmaa_add_attr( pbs_attr, name, value );
+				pbsdrmaa_exc_raise_pbs( "pbs_submit" );
 			 }
-		 }
-
-
-		pbs_attr = pbsdrmaa_submit_filter(pbs_attr);
-
-		job_id = ((pbsdrmaa_session_t *)self->session)->pbs_connection->submit( ((pbsdrmaa_session_t *)self->session)->pbs_connection, (struct attropl*)pbs_attr, self->script_filename, self->destination_queue);
-
+		}
+		conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
 	 }
 	EXCEPT_DEFAULT
@@ -215,4 +205,6 @@
 	FINALLY
 	 {
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
 		if( pbs_attr )
 			pbsdrmaa_free_attrl( pbs_attr );
@@ -309,6 +301,5 @@
 		if( wd != NULL )
 			script_len += strlen("cd ") + strlen(wd) + strlen("; ");
-		script_len += strlen("touch ") + strlen(((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix) + strlen("/$PBS_JOBID.started;");
-		script_len += strlen(executable);
+		script_len += strlen("exec ") + strlen(executable);
 		if( argv != NULL )
 			for( i = argv;  *i != NULL;  i++ )
@@ -316,6 +307,4 @@
 		if( input_path != NULL )
 			script_len += strlen(" <") + strlen(input_path);
-
-		script_len += strlen(";EXIT_CODE=$?; echo $EXIT_CODE >") + strlen(((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix) + strlen("/$PBS_JOBID.exitcode; exit $EXIT_CODE");
 	 }
 
@@ -327,6 +316,5 @@
 		if( wd != NULL )
 			s += sprintf( s, "cd %s; ", wd );
-		s += sprintf( s, "touch %s/$PBS_JOBID.started;", ((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix);
-		s += sprintf( s, "%s", executable );
+		s += sprintf( s, "exec %s", executable );
 		if( argv != NULL )
 			for( i = argv;  *i != NULL;  i++ )
@@ -334,7 +322,4 @@
 		if( input_path != NULL )
 			s += sprintf( s, " <%s", input_path );
-
-		s += sprintf( s, ";EXIT_CODE=$?; echo $EXIT_CODE >%s/$PBS_JOBID.exitcode; exit $EXIT_CODE", ((pbsdrmaa_session_t *)self->session)->job_exit_status_file_prefix);
-
 		fsd_assert( s == script+script_len );
 	 }
@@ -407,4 +392,5 @@
 	fsd_template_t *pbs_attr = self->pbs_job_attributes;
 	const char *join_files;
+	bool b_join_files;
 	int i;
 
@@ -436,13 +422,6 @@
 
 	join_files = jt->get_attr( jt, DRMAA_JOIN_FILES );
-	if (join_files != NULL && strcmp(join_files, "y") == 0)
-	  {
-		pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOIN_FILES, "oe" ); 
-	  }
-        else if (join_files != NULL && strcmp(join_files, "n") != 0)
-          {
-		fsd_exc_raise_fmt( FSD_ERRNO_INVALID_VALUE, "invalid value of %s attribute. Should be 'y' or 'n'.",
-					DRMAA_JOIN_FILES );
-          }
+	b_join_files = join_files != NULL  &&  !strcmp(join_files,"1");
+	pbs_attr->set_attr( pbs_attr, PBSDRMAA_JOIN_FILES, (b_join_files ? "y" : "n") ); 
 }
 
@@ -474,6 +453,4 @@
 }
 
-
-
 void
 pbsdrmaa_submit_apply_job_environment( pbsdrmaa_submit_t *self )
@@ -481,38 +458,21 @@
 	const fsd_template_t *jt = self->job_template;
 	const char *const *env_v;
-	const char *jt_wd;
-	char *wd;
-	char *env_c = NULL;
-	int ii = 0, len = 0;
 
 	env_v = jt->get_v_attr( jt, DRMAA_V_ENV);
-	jt_wd    = jt->get_attr( jt, DRMAA_WD );
-	
-	if (!jt_wd)
+
+	if (env_v)
 	{
-		wd = fsd_getcwd();
-	}
-	else
-	{
-		wd = fsd_strdup(jt_wd);
-	}
-
-	if (env_v)
-	 {
+		char *env_c = NULL;
+		int ii = 0, len = 0;
+
 		ii = 0;
-		while (env_v[ii])
-		 {
+		while (env_v[ii]) {
 			len += strlen(env_v[ii]) + 1;
 			ii++;
-		 }
-	 }
-	
-	len+= strlen("PBS_O_WORKDIR=") + strlen(wd);
-
-	fsd_calloc(env_c, len + 1, char);
-	env_c[0] = '\0';
-
-	if (env_v)
-	{
+		}
+
+		fsd_calloc(env_c, len + 1, char);
+		env_c[0] = '\0';
+
 		ii = 0;
 		while (env_v[ii]) {
@@ -522,13 +482,10 @@
 		}
 
+		env_c[strlen(env_c) -1 ] = '\0'; /*remove the last ',' */
+
+		self->pbs_job_attributes->set_attr(self->pbs_job_attributes, "Variable_List", env_c);
+
+		fsd_free(env_c);
 	}
-	
-	strcat(env_c, "PBS_O_WORKDIR=");
-	strcat(env_c, wd);
-
-	self->pbs_job_attributes->set_attr(self->pbs_job_attributes, "Variable_List", env_c);
-
-	fsd_free(env_c);
-	fsd_free(wd);
 }
 
@@ -560,24 +517,5 @@
 }
 
-static const char *get_job_env(pbsdrmaa_submit_t *self, const char *env_name)
-{
-	const fsd_template_t *jt = self->job_template;
-	const char *const *env_v = jt->get_v_attr( jt, DRMAA_V_ENV);
-	int ii = 0;
-
-	while (env_v[ii])
-	 {
-		char *eq_p = strstr(env_v[ii], "=");
-
-		if ((eq_p) && (strncmp(env_v[ii], env_name, eq_p - env_v[ii]) == 0))
-				return ++eq_p;
-
-		ii++;
-	 }
-
-	return NULL;
-}
-
-static void parse_resources(pbsdrmaa_submit_t *self, fsd_template_t *pbs_attr,const char *resources)
+static void parse_resources(fsd_template_t *pbs_attr,const char *resources)
 {
 	char * volatile name = NULL;
@@ -598,8 +536,5 @@
 				name = fsd_asprintf("Resource_List.%s", arg);
 				value = ++psep;
-				if (value[0] == '$' && get_job_env(self, value + 1))
-					pbs_attr->set_attr( pbs_attr, name , get_job_env(self, value + 1) ); /*get value from job env variable */
-				else
-					pbs_attr->set_attr( pbs_attr, name , value );
+				pbs_attr->set_attr( pbs_attr, name , value );
 				fsd_free(name);
 				name = NULL;
@@ -607,5 +542,6 @@
 			else
 			{
-				fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Invalid native specification: %s (Invalid resource specification: %s)", resources, arg);
+                                fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Invalid native specification: %s (Invalid resource specification: %s)", resources, arg);
+
 			}
 		}
@@ -629,5 +565,5 @@
 	TRY
 	  {
-		for (arg = strtok_r(add_attr_copy, ",", &ctxt); arg; arg = strtok_r(NULL, ",",&ctxt) )
+		for (arg = strtok_r(add_attr_copy, ",", &ctxt); arg; arg = strtok_r(NULL, ":",&ctxt) )
 		{
 			name = fsd_strdup(strtok_r(arg, "=", &ctxt2));
@@ -651,6 +587,4 @@
 		const char *native_specification )
 {
-	fsd_log_enter(( "({native_specification=%s})", native_specification ));
-
 	if( native_specification == NULL )
 		native_specification = self->job_template->get_attr(
@@ -660,4 +594,5 @@
 
 	{
+		fsd_iter_t * volatile args_list = fsd_iter_new(NULL, 0);
 		fsd_template_t *pbs_attr = self->pbs_job_attributes;
 		char *arg = NULL;
@@ -667,29 +602,19 @@
 
 		TRY
-		  {
-			for (arg = strtok_r((char *)native_spec_copy, " \t", &ctxt); arg; arg = strtok_r(NULL, " \t",&ctxt) ) {
-				if (!opt)
-				  {
-					if ( (arg[0] != '-') || (strlen(arg) != 2) )
+		 {
+			for (arg = strtok_r(native_spec_copy, " \t", &ctxt); arg; arg = strtok_r(NULL, " \t",&ctxt) ) {
+				if (!opt) {
+					if ( (arg[0] != '-') || ((strlen(arg) != 2) &&  arg[2] != ' ' && arg[1] !='-' ) )
 						fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE,
-							"Invalid native specification: -o(ption) expected (arg=%s native=%s).",
-							arg, native_specification);
-
-					opt = arg[1];
-
-					/* handle NO-arg options */
-
-					switch (opt) {
-						case 'h' :
-							pbs_attr->set_attr( pbs_attr, "Hold_Types" , "u" );
-							break;
-						default :
-							continue; /*no NO-ARG option */
+								"Invalid native specification: %s",
+								native_specification);
+					if(arg[1] == '-') {
+						parse_additional_attr(pbs_attr, arg+2);
 					}
-
-					opt = 0;
-				  }
-				else
-				  {
+					else {
+						opt = arg[1];
+					}
+					
+				} else {
 					switch (opt) {
 						
@@ -715,4 +640,7 @@
 							pbs_attr->set_attr( pbs_attr, "Execution_Time" , arg );
 							break;
+						case 'h' :
+							pbs_attr->set_attr( pbs_attr, "Hold_Types" , arg );
+							break;
 						case 'A' :
 							pbs_attr->set_attr( pbs_attr, "Account_Name" , arg );
@@ -728,9 +656,5 @@
 							break;
 						case 'q' :
-							if (self->destination_queue)
-								fsd_free(self->destination_queue);
-
 							self->destination_queue = fsd_strdup( arg );
-							fsd_log_debug(("self->destination_queue = %s", self->destination_queue));
 							break;
 						case 'r' :
@@ -744,4 +668,5 @@
 							break;
 						case 'v' :
+						case 'V' :
 							pbs_attr->set_attr( pbs_attr, "Variable_List" , arg );
 							break;
@@ -750,5 +675,5 @@
 							break;
 						case 'l' :
-							parse_resources( self, pbs_attr, arg);
+							parse_resources(pbs_attr, arg);
 							break;							
 						default :
@@ -758,4 +683,5 @@
 									native_specification, opt);
 					}
+
 					opt = 0;
 				}
@@ -766,4 +692,5 @@
 						"Invalid native specification: %s",
 						native_specification);
+
 		 }
 		FINALLY
@@ -772,5 +699,6 @@
 			pbs_attr->set_attr( pbs_attr, "submit_args", native_specification);
 #endif
-			fsd_free((char *)native_spec_copy);
+			args_list->destroy(args_list);
+			fsd_free(native_spec_copy);
 		 }
 		END_TRY
@@ -778,99 +706,2 @@
 }
 
-struct attrl *
-pbsdrmaa_submit_filter(struct attrl *pbs_attr)
-{
-	fsd_log_enter(( "({pbs_attr=%p})", (void*)pbs_attr));
-
-	if (getenv(PBSDRMAA_SUBMIT_FILTER_ENV) == NULL) 
-	  {
-		return pbs_attr;
-	  } 
-	else 
-	  {
-		struct attrl *ii = NULL;
-		char *empty_args[] = { NULL };
-		int exit_status = -1;
-		const char *submit_filter = getenv(PBSDRMAA_SUBMIT_FILTER_ENV);
-		char *stdin_buf = NULL;
-		int stdin_size = 0;
-		char *stdout_buf = NULL;
-		char *stderr_buf = NULL;
-		char *output_line = NULL;
-		char *ctx = NULL;
-
-		fsd_log_debug(("Executing filter script: %s", submit_filter));
-		
-		
-		for (ii = pbs_attr; ii; ii = ii->next) 
-		  {
-			stdin_size += strlen(ii->name) + strlen(ii->value) + 2 /* '=' and '\n' */;
-			if (ii->resource)
-			  {
-				stdin_size += strlen(ii->resource) +  1; /* '.' */
-			  }
-		  }
-
-		stdin_size+=1; /* '\0' */
-
-		stdin_buf = fsd_calloc(stdin_buf, stdin_size, char);
-		stdin_buf[0] = '\0';
-
-		for (ii = pbs_attr; ii; ii = ii->next) 
-		  {
-			strcat(stdin_buf, ii->name);
-			if (ii->resource)
-			  {
-				strcat(stdin_buf, ".");
-				strcat(stdin_buf, ii->resource);
-			  }
-			strcat(stdin_buf, "=");
-			strcat(stdin_buf, ii->value);
-			strcat(stdin_buf, "\n");
-		  }
-		
-		exit_status = fsd_exec_sync(submit_filter, empty_args, stdin_buf, &stdout_buf, &stderr_buf);
-    fsd_free(stdin_buf);
-
-		if (exit_status != 0)
-		  {
-			fsd_log_error(("Filter script %s exited with non-zero code: %d", submit_filter, exit_status));
-			fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_VALUE, "Submit filter script failed (code: %d, message: %s)", exit_status, stderr_buf);
-		  }
-		
-		fsd_log_debug(("Submit filter exit_status=%d, stderr=%s", exit_status, stderr_buf));
-
-		pbsdrmaa_free_attrl(pbs_attr);
-		pbs_attr = NULL;
-
-		/* exit_status == 0 */
-		for (output_line = strtok_r(stdout_buf, "\n", &ctx);  output_line ; output_line = strtok_r(NULL, "\n", &ctx))
-		  {
-			char *attr_name = NULL;
-			char *attr_value = NULL;
-
-			attr_value = strstr(output_line,"=");
-			attr_name = output_line;
-
-			if (!attr_value)
-			  {
-				fsd_exc_raise_fmt(FSD_DRMAA_ERRNO_INVALID_ATTRIBUTE_FORMAT, "Invalid output line of submit filter: %s", output_line);
-			  }
-			else
-			  {
-				*attr_value = '\0';
-				attr_value++; 
-			  }
-			
-
-			pbs_attr = pbsdrmaa_add_attr( pbs_attr, attr_name, attr_value );
-      }
-
-	  fsd_free(stdout_buf);
-    fsd_free(stderr_buf);	
-
-		return pbs_attr;
-	  }
-
-}
-
Index: trunk/pbs_drmaa/submit.h
===================================================================
--- trunk/pbs_drmaa/submit.h	(revision 72)
+++ trunk/pbs_drmaa/submit.h	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: submit.h 338 2010-09-28 14:48:45Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -28,6 +28,4 @@
 
 typedef struct pbsdrmaa_submit_s pbsdrmaa_submit_t;
-
-#define PBSDRMAA_SUBMIT_FILTER_ENV "PBSDRMAA_SUBMIT_FILTER"
 
 pbsdrmaa_submit_t *
Index: trunk/pbs_drmaa/job.c
===================================================================
--- trunk/pbs_drmaa/job.c	(revision 103)
+++ trunk/pbs_drmaa/job.c	(revision 1)
@@ -1,3 +1,3 @@
-/* $Id$ */
+/* $Id: job.c 370 2010-11-16 09:51:00Z mamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
@@ -26,5 +26,4 @@
 #include <string.h>
 #include <unistd.h>
-#include <sys/stat.h>
 
 #include <drmaa_utils/drmaa.h>
@@ -34,5 +33,4 @@
 
 #include <pbs_drmaa/job.h>
-#include <pbs_drmaa/log_reader.h>
 #include <pbs_drmaa/pbs_attrib.h>
 #include <pbs_drmaa/session.h>
@@ -44,19 +42,20 @@
 		__attribute__ ((unused))
 #	endif
-	= "$Id$";
+	= "$Id: job.c 370 2010-11-16 09:51:00Z mamonski $";
 #endif
 
 
-static void pbsdrmaa_job_control( fsd_job_t *self, int action );
-
-static void pbsdrmaa_job_update_status( fsd_job_t *self );
-
-static void pbsdrmaa_job_on_missing( fsd_job_t *self );
-
-static void pbsdrmaa_job_on_missing_standard( fsd_job_t *self );
-
-static void pbsdrmaa_job_update( fsd_job_t *self, struct batch_status* );
-
-static int pbsdrmaa_job_read_exit_status( const char *job_id, const char *job_state_dir_prefix);
+static void
+pbsdrmaa_job_control( fsd_job_t *self, int action );
+
+static void
+pbsdrmaa_job_update_status( fsd_job_t *self );
+
+static void
+pbsdrmaa_job_on_missing( fsd_job_t *self );
+
+static void
+pbsdrmaa_job_update( fsd_job_t *self, struct batch_status* );
+
 
 fsd_job_t *
@@ -68,5 +67,4 @@
 	self->super.update_status = pbsdrmaa_job_update_status;
 	self->super.on_missing = pbsdrmaa_job_on_missing;
-	self->missing_time = 0;
 	self->update = pbsdrmaa_job_update;
 	return (fsd_job_t*)self;
@@ -77,40 +75,93 @@
 pbsdrmaa_job_control( fsd_job_t *self, int action )
 {
+	volatile bool conn_lock = false;
 	pbsdrmaa_session_t *session = (pbsdrmaa_session_t*)self->session;
 	const char *job_id = self->job_id;
-
-	fsd_log_enter(( "({job_id=%s}, action=%d)", self->job_id, action ));
-
-	switch( action )
-	 {
-		/*
-		 * We cannot know whether we did suspend job
-		 * in other way than remembering this inside DRMAA session.
-		 */
-		case DRMAA_CONTROL_SUSPEND:
-			session->pbs_connection->sigjob( session->pbs_connection, (char*)job_id, "SIGSTOP");
-			self->flags |= FSD_JOB_SUSPENDED;
-			break;
-		case DRMAA_CONTROL_RESUME:
-			session->pbs_connection->sigjob( session->pbs_connection, (char*)job_id, "SIGCONT");
-			self->flags &= ~FSD_JOB_SUSPENDED;
-			break;
-		case DRMAA_CONTROL_HOLD:
-			session->pbs_connection->holdjob( session->pbs_connection, (char*)job_id );
-			self->flags |= FSD_JOB_HOLD;
-			break;
-		case DRMAA_CONTROL_RELEASE:
-			session->pbs_connection->rlsjob( session->pbs_connection, (char*)job_id );
-			self->flags &= ~FSD_JOB_HOLD;
-			break;
-		case DRMAA_CONTROL_TERMINATE:
-			session->pbs_connection->deljob( session->pbs_connection, (char*)job_id );
-			/* TODO: make deldelay configurable ???:
-			 * deldelay=N -- delay between SIGTERM and SIGKILL (default 0) */
-			self->flags &= FSD_JOB_TERMINATED_MASK;
-			if( (self->flags & FSD_JOB_TERMINATED) == 0 )
-				self->flags |= FSD_JOB_TERMINATED | FSD_JOB_ABORTED;
-			break;
-	 }
+	const char *apicall = NULL;
+	int rc = PBSE_NONE;
+
+	fsd_log_enter(( "({job_id=%s}, action=%d)",
+			self->job_id, action ));
+
+	TRY
+	 {
+		int try_count;
+		const int max_tries = 3;
+
+		conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex );
+
+		/*TODO reconnect */
+		for( try_count=0;  try_count < max_tries;  try_count++ )
+		 {
+			switch( action )
+			 {
+				/*
+				 * We cannot know whether we did suspend job
+				 * in other way than remembering this inside DRMAA session.
+				 */
+				case DRMAA_CONTROL_SUSPEND:
+					apicall = "pbs_sigjob";
+					rc = pbs_sigjob( session->pbs_conn, (char*)job_id,
+							"SIGSTOP", NULL );
+					if( rc == PBSE_NONE )
+						self->flags |= FSD_JOB_SUSPENDED;
+					break;
+				case DRMAA_CONTROL_RESUME:
+					apicall = "pbs_sigjob";
+					rc = pbs_sigjob( session->pbs_conn, (char*)job_id,
+							"SIGCONT", NULL );
+					if( rc == PBSE_NONE )
+						self->flags &= ~FSD_JOB_SUSPENDED;
+					break;
+				case DRMAA_CONTROL_HOLD:
+					apicall = "pbs_holdjob";
+					rc = pbs_holdjob( session->pbs_conn, (char*)job_id,
+							USER_HOLD, NULL );
+					if( rc == PBSE_NONE )
+						self->flags |= FSD_JOB_HOLD;
+					break;
+				case DRMAA_CONTROL_RELEASE:
+					apicall = "pbs_rlsjob";
+					rc = pbs_rlsjob( session->pbs_conn, (char*)job_id,
+							USER_HOLD, NULL );
+					if( rc == PBSE_NONE )
+						self->flags &= FSD_JOB_HOLD;
+					break;
+				case DRMAA_CONTROL_TERMINATE:
+					apicall = "pbs_deljob";
+					rc = pbs_deljob( session->pbs_conn, (char*)job_id, NULL );
+					/* Torque:
+					 * deldelay=N -- delay between SIGTERM and SIGKILL (default 0) */
+					if( rc == PBSE_NONE )
+					 {
+						self->flags &= FSD_JOB_TERMINATED_MASK;
+						if( (self->flags & FSD_JOB_TERMINATED) == 0 )
+							self->flags |= FSD_JOB_TERMINATED | FSD_JOB_ABORTED;
+					 }
+					break;
+			 }
+
+			if( rc == PBSE_NONE )
+				break;
+			else if( rc == PBSE_INTERNAL )
+			 {
+				/*
+				 * In PBS Pro pbs_sigjob raises internal server error (PBSE_INTERNAL)
+				 * when job just changed its state to running.
+				 */
+				fsd_log_debug(( "repeating request (%d of %d)",
+							try_count+2, max_tries ));
+				sleep( 1 );
+			 }
+			else
+				pbsdrmaa_exc_raise_pbs( apicall );
+		 } /* end for */
+	 }
+	FINALLY
+	 {
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
+	 }
+	END_TRY
 
 	fsd_log_return((""));
@@ -121,17 +172,53 @@
 pbsdrmaa_job_update_status( fsd_job_t *self )
 {
+	volatile bool conn_lock = false;
 	struct batch_status *volatile status = NULL;
 	pbsdrmaa_session_t *session = (pbsdrmaa_session_t*)self->session;
 
 	fsd_log_enter(( "({job_id=%s})", self->job_id ));
-	
 	TRY
 	 {
-
+		conn_lock = fsd_mutex_lock( &self->session->drm_connection_mutex );
+retry:
 #ifdef PBS_PROFESSIONAL
-		status = session->pbs_connection->statjob( session->pbs_connection, self->job_id, NULL);
+		status = pbs_statjob( session->pbs_conn, self->job_id, NULL, NULL );
 #else
-		status = session->pbs_connection->statjob( session->pbs_connection, self->job_id, session->status_attrl);
+		status = pbs_statjob( session->pbs_conn, self->job_id, session->status_attrl, NULL );
 #endif
+		fsd_log_debug(( "pbs_statjob(fd=%d, job_id=%s, attribs={...}) =%p",
+				 session->pbs_conn, self->job_id, (void*)status ));
+		if( status == NULL )
+		 {
+#ifndef PBS_PROFESSIONAL
+			fsd_log_error(("pbs_statjob error: %d, %s, %s", pbs_errno, pbse_to_txt(pbs_errno), pbs_strerror(pbs_errno)));
+#else
+			fsd_log_error(("pbs_statjob error: %d, %s", pbs_errno, pbse_to_txt(pbs_errno)));
+#endif
+			switch( pbs_errno )
+			 {
+				case PBSE_UNKJOBID:
+					break;
+				case PBSE_PROTOCOL:
+				case PBSE_EXPIRED:
+					pbs_disconnect( session->pbs_conn );
+					sleep(1);
+					session->pbs_conn = pbs_connect( session->super.contact );
+					if( session->pbs_conn < 0 )
+						pbsdrmaa_exc_raise_pbs( "pbs_connect" );
+					else 
+					 {
+						fsd_log_error(("retry:"));
+						goto retry;
+					 }
+				default:
+					pbsdrmaa_exc_raise_pbs( "pbs_statjob" );
+					break;
+				case 0:  /* ? */
+					fsd_exc_raise_code( FSD_ERRNO_INTERNAL_ERROR );
+					break;
+			 }
+		 }
+
+		conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
 
 		if( status != NULL )
@@ -139,13 +226,13 @@
 			((pbsdrmaa_job_t*)self)->update( self, status );
 		 }
-		else if( self->state < DRMAA_PS_DONE )
-		 {
+		else
 			self->on_missing( self );
-		 }
 	 }
 	FINALLY
 	 {
+		if( conn_lock )
+			conn_lock = fsd_mutex_unlock( &self->session->drm_connection_mutex );
 		if( status != NULL )
-			session->pbs_connection->statjob_free( session->pbs_connection, status );
+			pbs_statfree( status );
 	 }
 	END_TRY
@@ -161,5 +248,5 @@
 	struct attrl *i = NULL;
 	char pbs_state = 0;
-	int exit_status = -101;
+	int exit_status = -2;
 	const char *cpu_usage = NULL;
 	const char *mem_usage = NULL;
@@ -184,5 +271,5 @@
 				break;
 			case PBSDRMAA_ATTR_EXIT_STATUS:
-				exit_status = fsd_atoi( i->value );
+				exit_status = atoi( i->value );
 				break;
 			case PBSDRMAA_ATTR_RESOURCES_USED:
@@ -204,5 +291,4 @@
 					self->project = fsd_strdup(i->value);
 				break;
-#ifndef PBS_PROFESSIONAL
 			case PBSDRMAA_ATTR_EXECUTION_HOST:
 				if (!self->execution_hosts) {
@@ -211,12 +297,4 @@
 				}
 				break;
-#else
-			case PBSDRMAA_ATTR_EXECUTION_VNODE:
-				if (!self->execution_hosts) {
-					fsd_log_debug(("execution_hosts = %s", i->value));
-					self->execution_hosts = fsd_strdup(i->value);
-				}
-				break;
-#endif
 			case PBSDRMAA_ATTR_START_TIME:
 				{
@@ -236,15 +314,8 @@
 		fsd_log_debug(( "pbs_state: %c", pbs_state ));
 
-	if( exit_status != -101 )
+	if( exit_status != -2 )
 	 {
 		fsd_log_debug(( "exit_status: %d", exit_status ));
 		self->exit_status = exit_status;
-
-		if (self->exit_status < 0)
-		 {
-			self->exit_status = -1;
-			fsd_log_error(("ExitStatus = %d, probably system problem, report job %s to the local administrator", exit_status, self->job_id));
-		 }
-
 	 }
 	if(pbs_state){
@@ -252,10 +323,7 @@
 		 {
 			case 'C': /* Job is completed after having run. */
-#ifdef PBS_PROFESSIONAL
-			case 'F': /* Job is completed after having run. */
-#endif
 				self->flags &= FSD_JOB_TERMINATED_MASK;
 				self->flags |= FSD_JOB_TERMINATED;
-				if (exit_status != -101) { /* has exit code */
+				if (exit_status != -2) { /* has exit code */
 					if( self->exit_status == 0) 
 						self->state = DRMAA_PS_DONE;
@@ -266,12 +334,5 @@
 					self->exit_status = -1;
 				}
-				if (modify_time != 0)
-					self->end_time = modify_time; /* take last modify time as end time */
-				else
-					self->end_time = time(NULL);
-				
-				if (self->start_time == 0)
-					self->start_time = self->end_time;
-
+				self->end_time = modify_time; /* take last modify time as end time */
 				break;
 			case 'E': /* Job is exiting after having run. - MM: ignore exiting state (transient state) - outputs might have not been transfered yet, 
@@ -311,5 +372,6 @@
 		int hours, minutes, seconds;
 		long mem;
-		if( cpu_usage && sscanf( cpu_usage, "%d:%d:%d", &hours, &minutes, &seconds ) == 3 )
+		if( cpu_usage && sscanf( cpu_usage, "%d:%d:%d",
+				&hours, &minutes, &seconds ) == 3 )
 		 {
 			self->cpu_usage = 60*( 60*hours + minutes ) + seconds;
@@ -326,5 +388,6 @@
 			fsd_log_debug(( "vmem_usage: %s=%ldB", vmem_usage, self->vmem_usage ));
 		 }
-		if( walltime && sscanf( walltime, "%d:%d:%d", &hours, &minutes, &seconds ) == 3 )
+		if( walltime && sscanf( walltime, "%d:%d:%d",
+					&hours, &minutes, &seconds ) == 3 )
 		 {
 			self->walltime = 60*( 60*hours + minutes ) + seconds;
@@ -333,98 +396,54 @@
 	 }
 }
+
 
 void
 pbsdrmaa_job_on_missing( fsd_job_t *self )
 {
-	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*)self->session;
-	pbsdrmaa_job_t *pbsself = (pbsdrmaa_job_t *)self;
-	
-	if (!pbsself->missing_time)
-	 {
-		pbsself->missing_time = time(NULL);
-	 }
-
-	fsd_log_info(("pbsdrmaa_job_on_missing: pbs_home=%s, wait_thread_started=%d, submit_time=%d, missing_time=%d", 
-		pbssession->pbs_home, 
-		pbssession->super.wait_thread_started, 
-		(int)self->submit_time, 
-		(int)pbsself->missing_time));
-	
-	#define DRMAA_MAX_MISSING_TIME (30)
-	if( pbssession->pbs_home != NULL && pbssession->super.wait_thread_started && self->submit_time && (time(NULL) - pbsself->missing_time < DRMAA_MAX_MISSING_TIME))
-		fsd_log_info(("Job on missing but WT is running. Skipping...")); /* TODO: try to provide implementation that uses accounting/server log files */
+	fsd_drmaa_session_t *session = self->session;
+	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*)session;
+	if( !pbssession->wait_thread_log){	
+	unsigned missing_mask = 0;
+
+	fsd_log_enter(( "({job_id=%s})", self->job_id ));
+	fsd_log_warning(( "self %s missing from DRM queue", self->job_id ));
+
+	switch( session->missing_jobs )
+	 {
+		case FSD_REVEAL_MISSING_JOBS:         missing_mask = 0;     break;
+		case FSD_IGNORE_MISSING_JOBS:         missing_mask = 0x73;  break;
+		case FSD_IGNORE_QUEUED_MISSING_JOBS:  missing_mask = 0x13;  break;
+	 }
+	fsd_log_debug(( "last job_ps: %s (0x%02x); mask: 0x%02x",
+				drmaa_job_ps_to_str(self->state), self->state, missing_mask ));
+
+	if( self->state < DRMAA_PS_DONE
+			&&  (self->state & ~missing_mask) )
+		fsd_exc_raise_fmt(
+				FSD_ERRNO_INTERNAL_ERROR,
+				"self %s missing from queue", self->job_id
+				);
+
+	if( (self->flags & FSD_JOB_TERMINATED_MASK) == 0 )
+	 {
+		self->flags &= FSD_JOB_TERMINATED_MASK;
+		self->flags |= FSD_JOB_TERMINATED;
+	 }
+
+	if( (self->flags & FSD_JOB_ABORTED) == 0
+			&&  session->missing_jobs == FSD_IGNORE_MISSING_JOBS )
+	 { /* assume everthing was ok */
+		self->state = DRMAA_PS_DONE;
+		self->exit_status = 0;
+	 }
 	else
-		pbsdrmaa_job_on_missing_standard( self );	
-}
-
-void
-pbsdrmaa_job_on_missing_standard( fsd_job_t *self )
-{
-	fsd_drmaa_session_t *session = self->session;
-	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t *)session;
-	int exit_status = -1;
-	
-	fsd_log_enter(( "({job_id=%s})", self->job_id ));
-	fsd_log_warning(( "Job %s missing from DRM queue", self->job_id ));
-
-	fsd_log_info(( "job_on_missing: last job_ps: %s (0x%02x)", drmaa_job_ps_to_str(self->state), self->state));
-
-	if( (exit_status = pbsdrmaa_job_read_exit_status(self->job_id, pbssession->job_exit_status_file_prefix)) == 0 )
-	{
-		self->state = DRMAA_PS_DONE;
-		self->exit_status = exit_status;
+	 { /* job aborted */
+		self->state = DRMAA_PS_FAILED;
+		self->exit_status = -1;
+	 }
+
+	fsd_log_return(( "; job_ps=%s, exit_status=%d",
+				drmaa_job_ps_to_str(self->state), self->exit_status ));
 	}
-	else
-	{
-		self->state = DRMAA_PS_FAILED;
-		self->exit_status = exit_status;
-	}
-        fsd_log_info(("job_on_missing evaluation result: state=%d exit_status=%d", self->state, self->exit_status));
-
-	fsd_cond_broadcast( &self->status_cond);
-	fsd_cond_broadcast( &self->session->wait_condition );
-
-	fsd_log_return(( "; job_ps=%s, exit_status=%d", drmaa_job_ps_to_str(self->state), self->exit_status ));
-}
-
-int
-pbsdrmaa_job_read_exit_status( const char *job_id, const char *job_state_dir_prefix)
-{
-	char *status_file = NULL, *start_file = NULL;
-	FILE *fhandle = NULL;
-	int exit_status = -1;
-
-	fsd_log_enter(("({job_id=%s, job_state_dir_prefix=%s})", job_id, job_state_dir_prefix));
-
-	status_file = fsd_asprintf("%s/%s.exitcode", job_state_dir_prefix, job_id);
-	start_file = fsd_asprintf("%s/%s.started", job_state_dir_prefix, job_id);
-
-	if ((fhandle = fopen(status_file, "r")) == NULL)
-	 {
-		struct stat tmpstat;
-
-		fsd_log_error(("Failed to open job status file: %s", status_file));
-		if (stat(start_file, &tmpstat) == 0 && (tmpstat.st_mode & S_IFREG))
-		 {
-			exit_status = 143; /* SIGTERM */
-			fsd_log_info(("But start file exist %s. Assuming that job was killed (exit_status=%d).", start_file, exit_status));
-		 }
-		else
-		 {
-			fsd_log_error(("Start file not found: %s", start_file));
-		 }
-	
-
-	 }
-	else
-	 {
-		(void)fscanf(fhandle, "%d", &exit_status); /*on error exit_status == -1 */
-		fclose(fhandle);
-	 }
-
-	fsd_free(status_file);
-	fsd_free(start_file);
-
-	return exit_status;
-}
-
+}
+
Index: trunk/pbs_drmaa/pbs_attrib.gperf
===================================================================
--- trunk/pbs_drmaa/pbs_attrib.gperf	(revision 71)
+++ trunk/pbs_drmaa/pbs_attrib.gperf	(revision 1)
@@ -1,8 +1,8 @@
 %{
-/* $Id$ */
+/* $Id: pbs_attrib.gperf 2677 2009-09-08 14:32:22Z mmamonski $ */
 /*
  *  FedStage DRMAA for PBS Pro
  *  Copyright (C) 2006-2009  FedStage Systems
- *  Copyright (C) 2011 Poznan Supercomputing and Networking Center
+ *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -31,5 +31,5 @@
 		__attribute__ ((unused))
 #	endif
-	= "$Id$";
+	= "$Id: pbs_attrib.gperf 2677 2009-09-08 14:32:22Z mmamonski $";
 #endif
 
@@ -60,5 +60,4 @@
 Resource_List.nice, t(PBSDRMAA_ATTR_NICE)
 Resource_List.vmem, t(PBSDRMAA_ATTR_VMEM_LIMIT)
-Resource_List.mem, t(PBSDRMAA_ATTR_MEM_LIMIT)
 Resource_List.pcput, t(PBSDRMAA_ATTR_SINGLE_CPU_TIME_LIMIT)
 Resource_List.pmem, t(PBSDRMAA_ATTR_SINGLE_RSS_LIMIT)
@@ -68,9 +67,5 @@
 Resource_List.host, t(PBSDRMAA_ATTR_HOST)
 Resource_List.nodes, t(PBSDRMAA_ATTR_NODES)
-Resource_List.procs, t(PBSDRMAA_ATTR_PROCS)
-Resource_List.ncpus, t(PBSDRMAA_ATTR_NCPUS)
 Resource_List.software, t(PBSDRMAA_ATTR_SOFTWARE)
-Resource_List.place, t(PBSDRMAA_ATTR_PLACE)
-Resource_List.select, t(PBSDRMAA_ATTR_SELECT)
 Mail_Points, t(PBSDRMAA_ATTR_MAIL_POINTS)
 Output_Path, t(PBSDRMAA_ATTR_OUTPUT_PATH)
@@ -92,5 +87,4 @@
 # additional job and general attribute names
 exec_host, t(PBSDRMAA_ATTR_EXECUTION_HOST)
-exec_vnode, t(PBSDRMAA_ATTR_EXECUTION_VNODE)
 Job_Owner, t(PBSDRMAA_ATTR_JOB_OWNER)
 resources_used, t(PBSDRMAA_ATTR_RESOURCES_USED)
@@ -104,6 +98,10 @@
 submit_args, t(PBSDRMAA_ATTR_SUBMIT_ARGS)
 mtime, t(PBSDRMAA_ATTR_MTIME)
-Resource_List.node_properties, t(PBSDRMAA_ATTR_NODE_PROPERTIES)
-Resource_List.custom_resources, t(PBSDRMAA_ATTR_CUSTOM_RESOURCES)
+# reservation attributes:
+# reserve_start,       t(PBSDRMAA_ATTR_RESERVATION_START)
+# reserve_end,         t(PBSDRMAA_ATTR_RESERVATION_END)
+# reserve_duration,    t(PBSDRMAA_ATTR_RESERVATION_DURATION)
+# reserve_state,       t(PBSDRMAA_ATTR_RESERVATION_STATE)
+# reserve_substate,    t(PBSDRMAA_ATTR_RESERVATION_SUBSTATE)
 %%
 #undef t
@@ -176,5 +174,4 @@
 	{ "Resource_List.nice", PBSDRMAA_ATTR_NICE, false },
 	{ "Resource_List.vmem", PBSDRMAA_ATTR_VMEM_LIMIT, false },
-	{ "Resource_List.mem", PBSDRMAA_ATTR_MEM_LIMIT, false },
 	{ "Resource_List.pcput", PBSDRMAA_ATTR_SINGLE_CPU_TIME_LIMIT, false },
 	{ "Resource_List.pmem", PBSDRMAA_ATTR_SINGLE_RSS_LIMIT, false },
@@ -184,9 +181,5 @@
 	{ "Resource_List.host", PBSDRMAA_ATTR_HOST, false },
 	{ "Resource_List.nodes", PBSDRMAA_ATTR_NODES, false },
-	{ "Resource_List.procs", PBSDRMAA_ATTR_PROCS, false },
-	{ "Resource_List.ncpus", PBSDRMAA_ATTR_NCPUS, false },
 	{ "Resource_List.software", PBSDRMAA_ATTR_SOFTWARE, false },
-	{ "Resource_List.place", PBSDRMAA_ATTR_PLACE, false },
-	{ "Resource_List.select", PBSDRMAA_ATTR_SELECT, false },
 	{ "Mail_Points", PBSDRMAA_ATTR_MAIL_POINTS, false },
 	{ "Output_Path", PBSDRMAA_ATTR_OUTPUT_PATH, false },
@@ -207,5 +200,4 @@
 	{ "stageout", PBSDRMAA_ATTR_STAGEOUT, false },
 	{ "exec_host", PBSDRMAA_ATTR_EXECUTION_HOST, false },
-	{ "exec_vnode", PBSDRMAA_ATTR_EXECUTION_VNODE, false },
 	{ "Job_Owner", PBSDRMAA_ATTR_JOB_OWNER, false },
 	{ "resources_used", PBSDRMAA_ATTR_RESOURCES_USED, false },
@@ -219,7 +211,4 @@
 	{ "submit_args", PBSDRMAA_ATTR_SUBMIT_ARGS, false },
 	{ "mtime", PBSDRMAA_ATTR_MTIME, false },
-	{ "Resource_List.node_properties", PBSDRMAA_ATTR_NODE_PROPERTIES, false }, /* DRMAA extenstions */
-	{ "Resource_List.custom_resources", PBSDRMAA_ATTR_CUSTOM_RESOURCES, false },
-	
 };
 
Index: trunk/pbs_drmaa/pbs_conn.c
===================================================================
--- trunk/pbs_drmaa/pbs_conn.c	(revision 101)
+++ 	(revision )
@@ -1,648 +1,0 @@
-/* $Id$ */
-/*
- *  FedStage DRMAA for PBS Pro
- *  Copyright (C) 2006-2007  FedStage Systems
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef HAVE_CONFIG_H
-#	include <config.h>
-#endif
-
-#include <pbs_error.h>
-
-#include <drmaa_utils/datetime.h>
-#include <drmaa_utils/drmaa.h>
-#include <drmaa_utils/iter.h>
-#include <drmaa_utils/conf.h>
-#include <drmaa_utils/datetime.h>
-
-#include <pbs_drmaa/session.h>
-#include <pbs_drmaa/pbs_conn.h>
-#include <pbs_drmaa/util.h>
-
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-
-
-
-static char* pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination );
-
-static struct batch_status* pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self,  char *job_id, struct attrl *attrib );
-
-static void pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status );
-
-static void pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal );
-
-static void pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self,  char *job_id );
-
-static void pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id );
-
-static void pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self,  char *job_id );
-
-/* static void pbsdrmaa_pbs_connection_autoclose_thread_loop( pbsdrmaa_pbs_conn_t *self, bool reconnect); */
-
-
-static void check_reconnect( pbsdrmaa_pbs_conn_t *self, bool reconnect);
-
-/*
-static void start_autoclose_thread( pbsdrmaa_pbs_conn_t *self );
-
-static void stop_autoclose_thread( pbsdrmaa_pbs_conn_t *self );
-
-static void autoclose_thread_loop( void *data ); */
-
-
-#if defined PBS_PROFESSIONAL && defined PBSE_HISTJOBID
-	#define IS_MISSING_JOB (pbs_errno == PBSE_UNKJOBID || pbs_errno == PBSE_HISTJOBID)
-#else
-	#define IS_MISSING_JOB (pbs_errno == PBSE_UNKJOBID)
-#endif
-#define IS_TRANSIENT_ERROR (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED || pbs_errno == PBSOLDE_PROTOCOL || pbs_errno == PBSOLDE_EXPIRED || pbs_errno == PBSE_BADCRED)
-
-pbsdrmaa_pbs_conn_t * 
-pbsdrmaa_pbs_conn_new( fsd_drmaa_session_t *session, const char *server )
-{
-	pbsdrmaa_pbs_conn_t *volatile self = NULL;
-
-	fsd_log_enter((""));
-
-	TRY
-	  {
-		fsd_malloc(self, pbsdrmaa_pbs_conn_t );
-		
-		self->session = session;
-		
-		self->submit = pbsdrmaa_pbs_submit;
-		self->statjob = pbsdrmaa_pbs_statjob;
-		self->statjob_free = pbsdrmaa_pbs_statjob_free;
-		self->sigjob = pbsdrmaa_pbs_sigjob;
-		self->deljob = pbsdrmaa_pbs_deljob;
-		self->rlsjob = pbsdrmaa_pbs_rlsjob;
-		self->holdjob = pbsdrmaa_pbs_holdjob;
-
-		self->server = fsd_strdup(server);
-
-		self->connection_fd = -1;
-
-		/*ignore SIGPIPE - otherwise pbs_disconnect cause the program to exit */
-		signal(SIGPIPE, SIG_IGN);	
-
-		check_reconnect(self, false);
-	  }
-	EXCEPT_DEFAULT
-	  {
-		if( self != NULL)
-		  {
-			fsd_free(self->server);
-			fsd_free(self);
-
-			if (self->connection_fd != -1)
-			  {
-	                        fsd_log_info(( "pbs_disconnect(%d)", self->connection_fd ));
-				pbs_disconnect(self->connection_fd);
-			  }
-		  }
-			
-		fsd_exc_reraise();
-	  }
-	END_TRY
-
-	fsd_log_return((""));
-
-	return self;
-}
-
-void
-pbsdrmaa_pbs_conn_destroy ( pbsdrmaa_pbs_conn_t * self )
-{
-	fsd_log_enter((""));
-
-	TRY
-	{
-		if(self != NULL)
-		{
-			if (self->connection_fd != -1)
-			  {
-				fsd_log_info(( "pbs_disconnect(%d)", self->connection_fd ));
-				pbs_disconnect(self->connection_fd);
-
-			  }
-			fsd_free(self->server);
-			fsd_free(self);	
-		}
-	}
-	EXCEPT_DEFAULT
-	{
-		fsd_exc_reraise();
-	}
-	END_TRY
-	
-	fsd_log_return((""));
-}
-
-#ifdef HAVE_PBS_SUBMIT_HASH
-
-
-#include <torque4.h>
-
-void set_job_defaults(job_info *ji) {
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_c, CHECKPOINT_UNSPECIFIED, STATIC_DATA);
-
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_h, NO_HOLD, STATIC_DATA);
-
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_j, NO_JOIN, STATIC_DATA);
-
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_k, NO_KEEP, STATIC_DATA);
-
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_m, MAIL_AT_ABORT, STATIC_DATA);
-
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_p, DEFAULT_PRIORITY, STATIC_DATA);
-
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_r, "FALSE", STATIC_DATA);
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_f, "FALSE", STATIC_DATA);
-  
-  hash_add_or_exit_c(&ji->mm, &ji->client_attr, "pbs_dprefix", "#PBS", STATIC_DATA);
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_job_radix, "0", STATIC_DATA);
-  hash_add_or_exit_c(&ji->mm, &ji->job_attr, ATTR_v, "", ENV_DATA);
-}  
-
-
-static char *pbs_submit_4_wrapper(int connection_fd, struct attropl *attrib, char  *script, char *destination)
-{	
-	char *new_jobname = NULL;
-	char *jobname_copy = NULL;
-	char *errmsg = NULL;
-	job_info          ji;
-	int local_errno = 0;
-	struct attropl *p;
-
-	memset(&ji, 0, sizeof(job_info));
-
-	if (memmgr_init_c(&ji.mm, 8192) != PBSE_NONE) /* do not want to use g++ just for this file*/
-	  {
-		pbsdrmaa_exc_raise_pbs( "memmgr_init", connection_fd);
-	  }
-
-	set_job_defaults(&ji);
-
-	for (p = attrib; p; p = p->next) {
-		if (p->resource) {
-			hash_add_or_exit_c(&ji.mm, &ji.res_attr, p->resource, p->value, CMDLINE_DATA);
-		} else {
-			hash_add_or_exit_c(&ji.mm, &ji.job_attr, p->name, p->value, CMDLINE_DATA);
-		}
-	}
-
-
- 	pbs_errno = pbs_submit_hash(
-                  connection_fd,
-                  &ji.mm,
-                  ji.job_attr,
-                  ji.res_attr,
-                  script,
-                  destination,
-                  NULL,
-                  &new_jobname,
-                  &errmsg); 		
-
-	fsd_log_info(("pbs_submit_hash(%s,%s) = %d (jobid=%s)", script, destination, local_errno, new_jobname));
-	
-	jobname_copy = fsd_strdup(new_jobname);
-
-	memmgr_destroy_c(&ji.mm);
-
-	return jobname_copy;
-}
-#endif
-
-char* 
-pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination )
-{
-	char *volatile job_id = NULL;
-	volatile bool first_try = true;
-	volatile bool conn_lock = false;
-
-	fsd_log_enter((""));
-
-	TRY
-	 {
-		conn_lock = fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-		check_reconnect(self, false);
-
-retry:
-
-#ifdef HAVE_PBS_SUBMIT_HASH
-		job_id = pbs_submit_4_wrapper(self->connection_fd, attrib, script, destination);
-#else
-		job_id = pbs_submit(self->connection_fd, attrib, script, destination, NULL);
-#endif
-
-		fsd_log_info(("pbs_submit(%s, %s) = %s", script, destination, job_id));
-
-		if(job_id == NULL)
-		 {
-			fsd_log_error(( "pbs_submit failed, pbs_errno = %d", pbs_errno ));
-			if (IS_TRANSIENT_ERROR && first_try)
-			 {
-				check_reconnect(self, true);
-				first_try = false;
-				goto retry;
-			 }
-			else
-			 {
-				pbsdrmaa_exc_raise_pbs( "pbs_submit", self->connection_fd);
-			 }
-		 }
-	 }
-	EXCEPT_DEFAULT
-	 {
-		fsd_free(job_id);
-		fsd_exc_reraise();
-	 }
-	FINALLY
-	 {
-		if(conn_lock)
-			conn_lock = fsd_mutex_unlock(&self->session->drm_connection_mutex);
-	 }
-	END_TRY
-
-
-	fsd_log_return(("%s", job_id));
-
-	return job_id;
-}
-
-struct batch_status* 
-pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self,  char *job_id, struct attrl *attrib )
-{
-	struct batch_status *volatile status = NULL;
-	volatile bool first_try = true;
-	volatile bool conn_lock = false;
-#if defined PBS_PROFESSIONAL
-    char *stat_job_extend = "x";
-#else
-    char *stat_job_extend = NULL;
-#endif
-
-
-
-	fsd_log_enter((""));
-
-	TRY
-	 {
-		conn_lock = fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-		check_reconnect(self, false);
-
-retry:
-		status = pbs_statjob(self->connection_fd, job_id, attrib, stat_job_extend);
-
-#if defined PBS_PROFESSIONAL
-		fsd_log_info(( "pbs_statjob( fd=%d, job_id=%s, attribs={...}, \"x\" ) = %p", self->connection_fd, job_id, (void*)status));
-#else
-		fsd_log_info(( "pbs_statjob( fd=%d, job_id=%s, attribs={...} ) = %p", self->connection_fd, job_id, (void*)status));
-#endif
-
-		if(status == NULL && pbs_errno)
-		 {
-			if (IS_MISSING_JOB)
-			 {
-				fsd_log_info(( "missing job = %s (code=%d)", job_id, pbs_errno ));
-			 }
-			else if (IS_TRANSIENT_ERROR && first_try)
-			 {
-				fsd_log_info(( "pbs_statjob failed, pbs_errno = %d, retrying", pbs_errno ));
-				check_reconnect(self, true);
-				first_try = false;
-				goto retry;
-			 }
-			else
-			 {
-				pbsdrmaa_exc_raise_pbs( "pbs_statjob", self->connection_fd);
-			 }
-		 }
-	 }
-	EXCEPT_DEFAULT
-	 {
-		if( status != NULL )
-			pbs_statfree( status );
-
-		fsd_exc_reraise();
-	 }
-	FINALLY
-	 {
-		if(conn_lock)
-			conn_lock = fsd_mutex_unlock(&self->session->drm_connection_mutex);
-	 }
-	END_TRY
-
-
-	fsd_log_return((""));
-
-	return status;
-}
-
-void 
-pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status )
-{
-	fsd_log_enter((""));
-
-	pbs_statfree( job_status );
-}
-
-void 
-pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal_name )
-{
-	int rc = PBSE_NONE;
-	volatile bool first_try = true;
-	volatile bool conn_lock = false;
-
-
-	fsd_log_enter((""));
-
-	TRY
-	 {
-		conn_lock = fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-		check_reconnect(self, false);
-
-retry:
-		rc = pbs_sigjob(self->connection_fd, job_id, signal_name, NULL);
-
-		fsd_log_info(( "pbs_sigjob( fd=%d, job_id=%s, signal_name=%s) = %d", self->connection_fd, job_id, signal_name, rc));
-
-		if(rc != PBSE_NONE)
-		 {
-			fsd_log_error(( "pbs_sigjob failed, pbs_errno = %d", pbs_errno ));
-			if (IS_TRANSIENT_ERROR && first_try)
-			 {
-				check_reconnect(self, true);
-				first_try = false;
-				goto retry;
-			 }
-			else
-			 {
-				pbsdrmaa_exc_raise_pbs( "pbs_sigjob", self->connection_fd);
-			 }
-		 }
-	 }
-	EXCEPT_DEFAULT
-	 {
-		fsd_exc_reraise();
-	 }
-	FINALLY
-	 {
-		if(conn_lock)
-			conn_lock = fsd_mutex_unlock(&self->session->drm_connection_mutex);
-	 }
-	END_TRY
-
-
-	fsd_log_return((""));
-
-}
-
-void 
-pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self, char *job_id )
-{
-	int rc = PBSE_NONE;
-	volatile bool first_try = true;
-	volatile bool conn_lock = false;
-
-
-	fsd_log_enter((""));
-
-	TRY
-	 {
-		conn_lock = fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-		check_reconnect(self, false);
-
-retry:
-		rc = pbs_deljob(self->connection_fd, job_id, NULL);
-
-		fsd_log_info(( "pbs_deljob( fd=%d, job_id=%s) = %d", self->connection_fd, job_id, rc));
-
-		if(rc != PBSE_NONE)
-		 {
-			if (IS_TRANSIENT_ERROR && first_try)
-			 {
-				fsd_log_info(( "pbs_deljob failed, rc = %d, pbs_errno = %d. Retrying...", rc, pbs_errno ));
-				check_reconnect(self, true);
-				first_try = false;
-				goto retry;
-			 }
-			else
-			 {
-				pbsdrmaa_exc_raise_pbs( "pbs_deljob", self->connection_fd);
-			 }
-		 }
-	 }
-	EXCEPT_DEFAULT
-	 {
-		fsd_exc_reraise();
-	 }
-	FINALLY
-	 {
-		if(conn_lock)
-			conn_lock = fsd_mutex_unlock(&self->session->drm_connection_mutex);
-	 }
-	END_TRY
-
-
-	fsd_log_return((""));
-}
-
-void 
-pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id )
-{
-	int rc = PBSE_NONE;
-	volatile bool first_try = true;
-	volatile bool conn_lock = false;
-
-
-	fsd_log_enter((""));
-
-	TRY
-	 {
-		conn_lock = fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-		check_reconnect(self, false);
-
-retry:
-		rc = pbs_rlsjob(self->connection_fd, job_id, USER_HOLD, NULL);
-
-		fsd_log_info(( "pbs_rlsjob( fd=%d, job_id=%s) = %d", self->connection_fd, job_id, rc));
-
-		if(rc != PBSE_NONE)
-		 {
-			fsd_log_error(( "pbs_rlsjob failed, rc = %d, pbs_errno = %d", rc,  pbs_errno ));
-			if (IS_TRANSIENT_ERROR && first_try)
-			 {
-				check_reconnect(self, true);
-				first_try = false;
-				goto retry;
-			 }
-			else
-			 {
-				pbsdrmaa_exc_raise_pbs( "pbs_rlsjob", self->connection_fd);
-			 }
-		 }
-	 }
-	EXCEPT_DEFAULT
-	 {
-		fsd_exc_reraise();
-	 }
-	FINALLY
-	 {
-		if(conn_lock)
-			conn_lock = fsd_mutex_unlock(&self->session->drm_connection_mutex);
-	 }
-	END_TRY
-
-
-	fsd_log_return((""));
-}
-
-void 
-pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self,  char *job_id )
-{
-	int rc = PBSE_NONE;
-	volatile bool first_try = true;
-	volatile bool conn_lock = false;
-
-
-	fsd_log_enter((""));
-
-	TRY
-	 {
-		conn_lock = fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-		check_reconnect(self, false);
-
-retry:
-		rc = pbs_holdjob(self->connection_fd, job_id, USER_HOLD, NULL);
-
-		fsd_log_info(( "pbs_holdjob( fd=%d, job_id=%s) = %d", self->connection_fd, job_id, rc));
-
-		if(rc != PBSE_NONE)
-		 {
-			fsd_log_error(( "pbs_holdjob failed, rc = %d, pbs_errno = %d", rc, pbs_errno ));
-			if (IS_TRANSIENT_ERROR && first_try)
-			 {
-				check_reconnect(self, true);
-				first_try = false;
-				goto retry;
-			 }
-			else
-			 {
-				pbsdrmaa_exc_raise_pbs( "pbs_holdjob", self->connection_fd);
-			 }
-		 }
-	 }
-	EXCEPT_DEFAULT
-	 {
-		fsd_exc_reraise();
-	 }
-	FINALLY
-	 {
-		if(conn_lock)
-			conn_lock = fsd_mutex_unlock(&self->session->drm_connection_mutex);
-	 }
-	END_TRY
-
-
-	fsd_log_return((""));
-}
-
-void 
-check_reconnect( pbsdrmaa_pbs_conn_t *self, bool force_reconnect)
-{
-	int tries_left = ((pbsdrmaa_session_t *)self->session)->max_retries_count;
-	int sleep_time = 1;
-
-	fsd_log_enter(("(%d)", self->connection_fd));
-
-	if ( self->connection_fd != -1 ) 
-	  {
-		if (!force_reconnect)
-		  {
-			fsd_log_return(("(%d)", self->connection_fd));
-			return;
-		  }
-		else
-		 {
-			fsd_log_info(( "pbs_disconnect(%d)", self->connection_fd ));
-			pbs_disconnect(self->connection_fd);
-			self->connection_fd = -1;
-		 }
-	  }
-
-
-
-retry_connect: /* Life... */
-	self->connection_fd = pbs_connect( self->server );
-	fsd_log_info(( "pbs_connect(%s) = %d", self->server, self->connection_fd ));
-	if( self->connection_fd < 0 && tries_left-- )
-	  {
-		sleep(sleep_time);
-		sleep_time *=2;
-		goto retry_connect;
-	  }
-	
-	if( self->connection_fd < 0 )
-		pbsdrmaa_exc_raise_pbs( "pbs_connect", self->connection_fd );
-	
-	fsd_log_return(("(%d)", self->connection_fd));
-}
-
-
-/*
-void start_autoclose_thread( pbsdrmaa_pbs_conn_t *self )
-{
-
-
-}
-
-void stop_autoclose_thread( pbsdrmaa_pbs_conn_t *self )
-{
-
-
-}
-
-void autoclose_thread_loop( void *data )
-{
-	pbsdrmaa_pbs_conn_t *self = (pbsdrmaa_pbs_conn_t *)data;
-	struct timespec wait_time;
-
-	fsd_mutex_lock(&self->session->drm_connection_mutex);
-
-	if (fsd_cond_timedwait(&self->autoclose_cond, &self->session->drm_connection_mutex, wait_time);
-	 {
-		fsd_log_debug("autoclose thread signaled, waiting again");
-	 }
-	else
-	 {
-		fsd_log_info("autoclosing PBS connection: fd=%d, time_diff=%d", self->connection_fd, (int)(time(NULL) - self->last_connect_time));
-		pbs_disconnect(self->connection_fd);
-		self->connection_fd = -1;
-	 }
-
-	fsd_mutex_unlock(&self->session->drm_connection_mutex);
-}
-*/
Index: trunk/pbs_drmaa/torque4.cpp
===================================================================
--- trunk/pbs_drmaa/torque4.cpp	(revision 95)
+++ 	(revision )
@@ -1,17 +1,0 @@
-
-#include "torque4.h"
-
-void hash_add_or_exit_c(memmgr **mm, job_data **head, const char *name, const char *value, int var_type)
-{
-	hash_add_or_exit(mm, head, name, value, var_type);
-}	
-
-int memmgr_init_c(memmgr **mm, int size)
-{
-	return memmgr_init(mm,size);
-}
-
-void memmgr_destroy_c(memmgr **mm)
-{
-	memmgr_destroy(mm);
-}
Index: trunk/pbs_drmaa/log_reader.c
===================================================================
--- trunk/pbs_drmaa/log_reader.c	(revision 104)
+++ 	(revision )
@@ -1,727 +1,0 @@
-/* $Id$ */
-/*
- *  FedStage DRMAA for PBS Pro
- *  Copyright (C) 2006-2007  FedStage Systems
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
- #ifdef HAVE_CONFIG_H
-#	include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <fcntl.h>
-
-#include <pbs_ifl.h>
-#include <pbs_error.h>
-
-#include <drmaa_utils/datetime.h>
-#include <drmaa_utils/drmaa.h>
-#include <drmaa_utils/iter.h>
-#include <drmaa_utils/conf.h>
-#include <drmaa_utils/session.h>
-#include <drmaa_utils/datetime.h>
-
-#include <pbs_drmaa/job.h>
-#include <pbs_drmaa/log_reader.h>
-#include <pbs_drmaa/session.h>
-#include <pbs_drmaa/submit.h>
-#include <pbs_drmaa/util.h>
-#include <pbs_drmaa/pbs_attrib.h>
-
-#include <errno.h>
-
-enum pbsdrmaa_field_id
-{
-	PBSDRMAA_FLD_ID_DATE = 0,
-	PBSDRMAA_FLD_ID_EVENT = 1,
-	PBSDRMAA_FLD_ID_SRC = 2,
-	PBSDRMAA_FLD_ID_OBJ_TYPE = 3,
-	PBSDRMAA_FLD_ID_OBJ_ID = 4,
-	PBSDRMAA_FLD_ID_MSG = 5
-};
-
-
-#define PBSDRMAA_FLD_MSG_0008 "0008"
-#define PBSDRMAA_FLD_MSG_0010 "0010"
-
-enum pbsdrmaa_event_type
-{
-	pbsdrmaa_event_0008 = 8,
-	pbsdrmaa_event_0010 = 10
-};
-
-static void pbsdrmaa_read_log();
-
-static void pbsdrmaa_select_file( pbsdrmaa_log_reader_t * self);
-
-static void pbsdrmaa_close_log( pbsdrmaa_log_reader_t * self);
-
-static void pbsdrmaa_reopen_log( pbsdrmaa_log_reader_t * self);
-
-static time_t pbsdrmaa_parse_log_timestamp(const char *timestamp, char *unixtime_str, size_t size);
-
-static char *pbsdrmaa_get_exec_host_from_accountig(pbsdrmaa_log_reader_t * log_reader, const char *job_id);
-
-/*
- * Snippets from log files
- *
- * PBS Pro
- *
-10/11/2011 14:43:29;0008;Server@nova;Job;2127218.nova;Job Queued at request of mamonski@endor.wcss.wroc.pl, owner = mamonski@endor.wcss.wroc.pl, job name = STDIN, queue = normal
-10/11/2011 14:43:31;0008;Server@nova;Job;2127218.nova;Job Modified at request of Scheduler@nova.wcss.wroc.pl
-10/11/2011 14:43:31;0008;Server@nova;Job;2127218.nova;Job Run at request of Scheduler@nova.wcss.wroc.pl on exec_vnode (wn698:ncpus=3:mem=2048000kb)+(wn700:ncpus=3:mem=2048000kb)
-10/11/2011 14:43:31;0008;Server@nova;Job;2127218.nova;Job Modified at request of Scheduler@nova.wcss.wroc.pl
-10/11/2011 14:43:32;0010;Server@nova;Job;2127218.nova;Exit_status=0 resources_used.cpupercent=0 resources_used.cput=00:00:00 resources_used.mem=1768kb resources_used.ncpus=6 resources_used.vmem=19228kb resources_used.walltime=00:00:01
-
- *
- * Torque
- *
-10/11/2011 14:47:59;0008;PBS_Server;Job;15545337.batch.grid.cyf-kr.edu.pl;Job Queued at request of plgmamonski@ui.cyf-kr.edu.pl, owner = plgmamonski@ui.cyf-kr.edu.pl, job name = STDIN, queue = l_short
-10/11/2011 14:48:23;0008;PBS_Server;Job;15545337.batch.grid.cyf-kr.edu.pl;Job Run at request of root@batch.grid.cyf-kr.edu.pl
-10/11/2011 14:48:24;0010;PBS_Server;Job;15545337.batch.grid.cyf-kr.edu.pl;Exit_status=0 resources_used.cput=00:00:00 resources_used.mem=720kb resources_used.vmem=13308kb resources_used.walltime=00:00:00
-
-deleting job:
-I . PBS Pro
-a) in Q state
-10/16/2011 09:49:25;0008;Server@grass1;Job;2178.grass1.man.poznan.pl;Job Queued at request of mmamonski@grass1.man.poznan.pl, owner = mmamonski@grass1.man.poznan.pl, job name = STDIN, queue = workq
-10/16/2011 09:49:25;0008;Server@grass1;Job;2178.grass1.man.poznan.pl;Job Modified at request of Scheduler@grass1.man.poznan.pl
-10/16/2011 09:49:37;0008;Server@grass1;Job;2178.grass1.man.poznan.pl;Job to be deleted at request of mmamonski@grass1.man.poznan.pl
-10/16/2011 09:49:37;0100;Server@grass1;Job;2178.grass1.man.poznan.pl;dequeuing from workq, state 5
-
-
-b) in R state
-10/16/2011 09:45:12;0080;Server@grass1;Job;2177.grass1.man.poznan.pl;delete job request received
-10/16/2011 09:45:12;0008;Server@grass1;Job;2177.grass1.man.poznan.pl;Job sent signal TermJob on delete
-10/16/2011 09:45:12;0008;Server@grass1;Job;2177.grass1.man.poznan.pl;Job to be deleted at request of mmamonski@grass1.man.poznan.pl
-10/16/2011 09:45:12;0010;Server@grass1;Job;2177.grass1.man.poznan.pl;Exit_status=271 resources_used.cpupercent=0 resources_used.cput=00:00:00 resources_used.mem=2772kb resources_used.ncpus=1 resources_used.vmem=199288kb resources_used.walltime=00:00:26
-10/16/2011 09:45:12;0100;Server@grass1;Job;2177.grass1.man.poznan.pl;dequeuing from workq, state 5
-
-II. Torque
-a) in Q state
-10/15/2011 21:19:25;0008;PBS_Server;Job;113045.grass1.man.poznan.pl;Job deleted at request of mmamonski@grass1.man.poznan.pl
-10/15/2011 21:19:25;0100;PBS_Server;Job;113045.grass1.man.poznan.pl;dequeuing from batch, state EXITING
-
-b) in R state
-10/15/2011 21:19:47;0008;PBS_Server;Job;113046.grass1.man.poznan.pl;Job deleted at request of mmamonski@grass1.man.poznan.pl
-10/15/2011 21:19:47;0008;PBS_Server;Job;113046.grass1.man.poznan.pl;Job sent signal SIGTERM on delete
-10/15/2011 21:19:47;0010;PBS_Server;Job;113046.grass1.man.poznan.pl;Exit_status=271 resources_used.cput=00:00:00 resources_used.mem=0kb resources_used.vmem=0kb resources_used.walltime=00:00:10
-
-Log closed:
-10/16/2011 00:00:17;0002;PBS_Server;Svr;Log;Log closed
-
- */
-pbsdrmaa_log_reader_t * 
-pbsdrmaa_log_reader_new( fsd_drmaa_session_t *session )
-{
-	pbsdrmaa_log_reader_t *volatile self = NULL;
-
-	fsd_log_enter((""));
-
-	TRY
-	{
-		fsd_malloc(self, pbsdrmaa_log_reader_t );
-		
-		self->session = session;
-
-		self->select_file = pbsdrmaa_select_file;
-		self->read_log = pbsdrmaa_read_log;	
-		self->close = pbsdrmaa_close_log;
-		self->reopen = pbsdrmaa_reopen_log;
-		
-		self->run_flag = true;
-		self->fhandle = NULL;
-		self->date_changed = true;
-		self->first_open = true;
-		self->log_path = NULL;
-		self->current_offset = 0;
-		
-	}
-	EXCEPT_DEFAULT
-	{
-		if( self != NULL)
-			fsd_free(self);
-			
-		fsd_exc_reraise();
-	}
-	END_TRY
-
-	fsd_log_return((""));
-
-	return self;
-}
-
-
-void
-pbsdrmaa_log_reader_destroy ( pbsdrmaa_log_reader_t * self )
-{
-	fsd_log_enter((""));
-	TRY
-	{
-		if(self != NULL)
-		{
-			fsd_free(self);	
-		}
-	}
-	EXCEPT_DEFAULT
-	{
-		fsd_exc_reraise();
-	}
-	END_TRY
-	
-	fsd_log_return((""));
-}
-
-
-void
-pbsdrmaa_read_log( pbsdrmaa_log_reader_t * self )
-{
-	fsd_log_enter((""));
-	
-	fsd_mutex_lock( &self->session->mutex );
-
-	TRY
-	 {
-		while( self->run_flag )
-		 {
-			TRY
-			{
-				char *line = NULL;
-				
-				self->select_file(self);
-
-				while ((line = fsd_readline(self->fhandle)) != NULL)
-				 {
-					int field_id = PBSDRMAA_FLD_ID_DATE;
-					char *tok_ctx = NULL;
-					char *field_token = NULL;
-					char *event_timestamp = NULL;
-					int event_type = -1;
-					fsd_job_t *job = NULL;
-
-					/* at first detect if this not the end of log file */
-					if (strstr(line, "Log;Log closed")) /*TODO try to be more effective and safe */
-					 {
-						fsd_log_debug(("WT - Date changed. Closing log file"));
-						self->date_changed = true;
-						goto cleanup;
-					 }
-
-					for (field_token = strtok_r(line, ";", &tok_ctx); field_token; field_token = strtok_r(NULL, ";", &tok_ctx), field_id++)
-					 {
-						if ( field_id == PBSDRMAA_FLD_ID_DATE)
-						 {
-							event_timestamp = field_token;
-#ifdef PBS_PBS_PROFESSIONAL
-							/*additional check */
-							TRY
-							{
-							 (void)pbsdrmaa_parse_log_timestamp(event_timestamp, timestamp_unix, sizeof(timestamp_unix));
-							}
-							EXCEPT_DEFAULT
-							{
-								fsd_log_error(("Failed to parse timestamp: %s. Log corrupted?", event_timestamp));
-							}
-							END_TRY
-#endif
-						 }
-						else if ( field_id == PBSDRMAA_FLD_ID_EVENT)
-						 {
-							if (strncmp(field_token, PBSDRMAA_FLD_MSG_0008, 4) == 0)
-								event_type = pbsdrmaa_event_0008;
-							else if (strncmp(field_token, PBSDRMAA_FLD_MSG_0010, 4) == 0)
-								event_type = pbsdrmaa_event_0010;
-							else
-							 {
-								goto cleanup; /*we are interested only in the above log messages */
-							 }
-						 }
-						else if ( field_id == PBSDRMAA_FLD_ID_SRC)
-						 {
-							/* not used ignore */
-						 }
-						else if (field_id  == PBSDRMAA_FLD_ID_OBJ_TYPE)
-						 {
-							if (strncmp(field_token, "Job", 3) != 0)
-							 {
-								goto cleanup; /* we are interested only in job events */
-							 }
-						 }
-						else if (field_id == PBSDRMAA_FLD_ID_OBJ_ID)
-						 {
-							const char *event_jobid = field_token;
-							
-							if (!isdigit(event_jobid[0]))
-							 {
-								fsd_log_debug(("WT - Invalid job: %s", event_jobid)); 
-								goto cleanup;
-							 }
-
-							job = self->session->get_job( self->session, event_jobid );
-
-							if( job )
-							 {
-								fsd_log_debug(("WT - Found job event: %s", event_jobid));
-							 }
-							else
-							 {
-								fsd_log_debug(("WT - Unknown job: %s", event_jobid)); /* Not a DRMAA job */
-								goto cleanup;
-							 }
-					 	 }
-						else if (field_id == PBSDRMAA_FLD_ID_MSG)
-						 {
-							char *msg = field_token;
-							struct batch_status status;
-							struct attrl *attribs = NULL;
-							bool in_running_state = false;
-
-							if (event_type == pbsdrmaa_event_0008 && strncmp(msg, "Job Queued", 10) == 0)
-							 {
-								/* Queued
-								 * PBS Pro: 10/11/2011 14:43:29;0008;Server@nova;Job;2127218.nova;Job Queued at request of mamonski@endor.wcss.wroc.pl, owner = mamonski@endor.wcss.wroc.pl, job name = STDIN, queue = normal
-								 * Torque:  10/11/2011 14:47:59;0008;PBS_Server;Job;15545337.batch.grid.cyf-kr.edu.pl;Job Queued at request of plgmamonski@ui.cyf-kr.edu.pl, owner = plgmamonski@ui.cyf-kr.edu.pl, job name = STDIN, queue = l_short
-								 */
-								char *p_queue = NULL;
-
-								fsd_log_info(("WT - Detected queuing of job %s", job->job_id));
-
-								if ((p_queue = strstr(msg,"queue =")) == NULL)
-									fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"No queue attribute found in log line = %s", line);
-
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_JOB_STATE, "Q");
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_QUEUE, p_queue + 7);
-							 }
-							else if (event_type == pbsdrmaa_event_0008 && strncmp(msg, "Job Run", 7) == 0)
-							{
-								/*
-								 * Running
-								 * Torque: 10/11/2011 14:48:23;0008;PBS_Server;Job;15545337.batch.grid.cyf-kr.edu.pl;Job Run at request of root@batch.grid.cyf-kr.edu.pl
-								 * PBS Pro: 10/11/2011 14:43:31;0008;Server@nova;Job;2127218.nova;Job Run at request of Scheduler@nova.wcss.wroc.pl on exec_vnode (wn698:ncpus=3:mem=2048000kb)+(wn700:ncpus=3:mem=2048000kb)
-								 */
-								char timestamp_unix[64];
-
-								fsd_log_info(("WT - Detected start of job %s", job->job_id));
-
-								(void)pbsdrmaa_parse_log_timestamp(event_timestamp, timestamp_unix, sizeof(timestamp_unix));
-
-								in_running_state = true;
-
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_JOB_STATE, "R");
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_START_TIME, timestamp_unix);
-#ifdef PBS_PROFESSIONAL
-									{
-										char *p_vnode = NULL;
-										if ((p_vnode = strstr(msg, "exec_vnode")))
-										 {
-											attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_EXECUTION_VNODE, p_vnode + 11);
-										 }
-									}
-#endif
-							 }
-#ifndef PBS_PROFESSIONAL
-							else if (event_type == pbsdrmaa_event_0008 && strncmp(msg, "Job deleted", 11) == 0)
-#else
-							else if (event_type == pbsdrmaa_event_0008 && strncmp(msg, "Job to be deleted", 17) == 0)
-#endif
-							 {
-							/* Deleted
-							 * PBS Pro: 10/16/2011 09:45:12;0008;Server@grass1;Job;2177.grass1.man.poznan.pl;Job to be deleted at request of mmamonski@grass1.man.poznan.pl
-							 * Torque: 10/15/2011 21:19:25;0008;PBS_Server;Job;113045.grass1.man.poznan.pl;Job deleted at request of mmamonski@grass1.man.poznan.pl
-							 */
-								char timestamp_unix[64];
-
-								fsd_log_info(("WT - Detected deletion of job %s", job->job_id));
-
-								(void)pbsdrmaa_parse_log_timestamp(event_timestamp, timestamp_unix, sizeof(timestamp_unix));
-
-								if (job->state < DRMAA_PS_RUNNING)
-								 {
-									fsd_log_info(("WT - Job %s killed before entering running state (%d).", job->job_id, job->state));
-
-#ifdef PBS_PROFESSIONAL
-									attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_JOB_STATE, "F");
-#else
-									attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_JOB_STATE, "C");
-#endif
-
-									attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_MTIME, timestamp_unix);
-									attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_EXIT_STATUS, "-101");
-								 }
-								else
-								 {
-									fsd_log_info(("WT - Job %s killed after entering running state (%d). Waiting for Completed event...", job->job_id, job->state));
-									goto cleanup; /* job was started, ignore, wait for Exit_status message */
-								 }
-							 }
-							else if (event_type == pbsdrmaa_event_0010 && (strncmp(msg, "Exit_status=", 12) == 0))
-							 {
-							/* Completed:
-							 * PBS Pro: 10/11/2011 14:43:32;0010;Server@nova;Job;2127218.nova;Exit_status=0 resources_used.cpupercent=0 resources_used.cput=00:00:00 resources_used.mem=1768kb resources_used.ncpus=6 resources_used.vmem=19228kb resources_used.walltime=00:00:01
-							 * Torque: 10/11/2011 14:48:24;0010;PBS_Server;Job;15545337.batch.grid.cyf-kr.edu.pl;Exit_status=0 resources_used.cput=00:00:00 resources_used.mem=720kb resources_used.vmem=13308kb resources_used.walltime=00:00:00
-							 */
-								char timestamp_unix[64];
-								time_t timestamp_time_t = pbsdrmaa_parse_log_timestamp(event_timestamp, timestamp_unix, sizeof(timestamp_unix));
-								char *tok_ctx2 = NULL;
-								char *token = NULL;
-
-#ifdef PBS_PBS_PROFESSIONAL
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_JOB_STATE, "F");
-#else
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_JOB_STATE, "C");
-#endif
-								attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_MTIME, timestamp_unix);
-
-								/* tokenize !!! */
-								for (token = strtok_r(msg, " ", &tok_ctx2); token; token = strtok_r(NULL, " ", &tok_ctx2))
-								 {
-									if (strncmp(token, "Exit_status=", 12) == 0)
-									 {
-										token[11] = '\0';
-										attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_EXIT_STATUS, token + 12);
-										fsd_log_info(("WT - Completion of job %s (Exit_status=%s) detected after %d seconds", job->job_id, token+12, (int)(time(NULL) - timestamp_time_t) ));
-									 }
-									else if (strncmp(token, "resources_used.cput=", 20) == 0)
-									 {
-										token[19] = '\0';
-										attribs = pbsdrmaa_add_attr(attribs, token, token + 20);
-									 }
-									else if (strncmp(token, "resources_used.mem=", 19) == 0)
-									 {
-										token[18] = '\0';
-										attribs = pbsdrmaa_add_attr(attribs, token, token + 19);
-									 }
-									else if (strncmp(token, "resources_used.vmem=", 20) == 0)
-									 {
-										token[19] = '\0';
-										attribs = pbsdrmaa_add_attr(attribs, token, token + 20);
-									 }
-									else if (strncmp(token, "resources_used.walltime=", 24) == 0)
-									 {
-										token[23] = '\0';
-										attribs = pbsdrmaa_add_attr(attribs, token, token + 24);
-									 }
-								 }
-
-								if (!job->execution_hosts)
-								 {
-									char *exec_host = NULL;
-									fsd_log_info(("WT - No execution host information for job %s. Reading accounting logs...", job->job_id));
-									exec_host = pbsdrmaa_get_exec_host_from_accountig(self, job->job_id);
-									if (exec_host)
-									 {
-										attribs = pbsdrmaa_add_attr(attribs, PBSDRMAA_EXECUTION_HOST, exec_host);
-										fsd_free(exec_host);
-									 }
-								 }
-							 }
-							else
-							{
-								fsd_log_debug(("Ignoring msg(type=%d) = %s", event_type,  msg));
-								goto cleanup; /* ignore other job events*/
-							}
-					
-							fsd_log_debug(("WT - updating job: %s", job->job_id ));
-							status.name = job->job_id;
-							status.attribs = attribs;
-
-							((pbsdrmaa_job_t *)job)->update( job, &status );
-
-							if ( in_running_state )
-							 {
-								fsd_log_debug(("WT - forcing update of job: %s", job->job_id ));
-								TRY
-								{
-									job->update_status( job );
-								}
-								EXCEPT_DEFAULT
-								{
-									/*TODO: distinguish between invalid job and internal errors */
-									fsd_log_debug(("Job finished just after entering running state: %s", job->job_id));
-								}
-								END_TRY
-							 }
-
-
-							pbsdrmaa_free_attrl(attribs); /* TODO free on exception */
-
-							fsd_cond_broadcast( &job->status_cond);
-							fsd_cond_broadcast( &self->session->wait_condition );
-
-						 }
-						else
-						 {
-							fsd_assert(0); /*not reached */
-						 }
-					 }
-				cleanup:
-					fsd_free(line); /* TODO what about exceptions */		
-					if ( job )
-						job->release( job );
-
-
-
-				 } /* end of while getline loop */
-
-
-
-				fsd_mutex_unlock( &self->session->mutex );
-
-				/* close */
-				self->close(self);
-
-				sleep(((pbsdrmaa_session_t *)self->session)->wait_thread_sleep_time);
-
-				/* and reopen log file */
-				self->reopen(self);
-
-				fsd_mutex_lock( &self->session->mutex );
-
-				self->run_flag = self->session->wait_thread_run_flag;
-			}
-			EXCEPT_DEFAULT
-			{
-				const fsd_exc_t *e = fsd_exc_get();
-				/* Its better to exit and communicate error rather then let the application to hang */
-				fsd_log_fatal(( "Exception in wait thread: <%d:%s>. Exiting !!!", e->code(e), e->message(e) ));
-				exit(1);
-			}
-			END_TRY
-		 }
-
-		if(self->fhandle)
-			fclose(self->fhandle);
-
-		fsd_log_debug(("WT - Log file closed"));
-	}
-	FINALLY
-	{
-	 	fsd_log_debug(("WT - Terminated."));
-		fsd_mutex_unlock( &self->session->mutex ); /**/
-	}
-	END_TRY
-	
-	fsd_log_return((""));
-}
-
-void
-pbsdrmaa_select_file( pbsdrmaa_log_reader_t * self )
-{
-	pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*) self->session;
-	
-	if (self->date_changed)
-	 {
-		int num_tries = 0;
-		struct tm tm; 
-		char *old_log_path = NULL;
-		
-		fsd_log_enter((""));
-		
-		if(!self->first_open)
-			time(&self->t);	
-		else
-			self->t = pbssession->log_file_initial_time;
-			
-		localtime_r(&self->t,&tm);
-				
-		#define DRMAA_WAIT_THREAD_MAX_TRIES (12)
-		/* generate new date, close file and open new */
-		old_log_path = self->log_path;
-
-		self->log_path = fsd_asprintf("%s/server_logs/%04d%02d%02d", pbssession->pbs_home, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
-
-		if(self->fhandle)
-			fclose(self->fhandle);
-
-		fsd_log_info(("Opening log file: %s",self->log_path));
-				
-	retry:
-		if ((self->fhandle = fopen(self->log_path,"r")) == NULL && (num_tries > DRMAA_WAIT_THREAD_MAX_TRIES || self->first_open))
-		 {
-			fsd_log_error(("Can't open log file: %s. Verify pbs_home. Running standard wait_thread.", self->log_path));
-			fsd_log_error(("Remember that without keep_completed set the standard wait_thread won't provide information about job exit status"));
-			/*pbssession->super.enable_wait_thread = false;*/ /* run not wait_thread */
-			pbssession->wait_thread_log = false;
-			pbssession->super.wait_thread = pbssession->super_wait_thread;
-			pbssession->super.wait_thread(self->session);
-		 }
-		else if ( self->fhandle == NULL )
-		 { /* Torque seems not to create a new file immediately after the old one is closed */
-			fsd_log_warning(("Can't open log file: %s. Retries count: %d", self->log_path, num_tries));
-			num_tries++;
-			sleep(2 * num_tries);
-			goto retry;
-		 }
-
-		fsd_log_debug(("Log file opened"));
-
-		if(self->first_open)
-		 {
-			fsd_log_debug(("Log file lseek"));
-
-			if(fseek(self->fhandle, pbssession->log_file_initial_size, SEEK_SET) == (off_t) -1)
-			 {
-				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"fseek error");
-			 }
-			self->first_open = false;
-		 }
-		else if (old_log_path && strcmp(old_log_path, self->log_path) == 0)
-		 {
-			fsd_log_info(("PBS restarted. Seeking log file %u", (unsigned int)self->current_offset));
-			if(fseek(self->fhandle, self->current_offset, SEEK_SET) == (off_t) -1)
-			 {
-				fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"fseek error");
-			 }
-		 }
-
-		self->date_changed = false;
-		
-		fsd_free(old_log_path);
-
-		fsd_log_return((""));
-	}	
-}
-
-time_t
-pbsdrmaa_parse_log_timestamp(const char *timestamp, char *unixtime_str, size_t size)
-{
-	struct tm temp_time_tm;
-	memset(&temp_time_tm, 0, sizeof(temp_time_tm));
-	temp_time_tm.tm_isdst = -1;
-
-	if (strptime(timestamp, "%m/%d/%Y %H:%M:%S", &temp_time_tm) == NULL)
-	 {
-		fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"WT - failed to parse log timestamp: %s", timestamp);
-	 }
-	else
-	 {
-		time_t temp_time = mktime(&temp_time_tm);
-		snprintf(unixtime_str, size, "%lu", temp_time);
-		return temp_time;
-	 }
-}
-
-char *
-pbsdrmaa_get_exec_host_from_accountig(pbsdrmaa_log_reader_t * log_reader, const char *job_id)
-{
-		pbsdrmaa_session_t *pbssession = (pbsdrmaa_session_t*) log_reader->session;
-		struct tm tm;
-		time_t tm_t;
-		char *line = NULL;
-		char *exec_host = NULL;
-		char *log_path = NULL;
-		FILE *fhandle = NULL;
-
-		fsd_log_enter(("(job_id=%s)", job_id));
-
-		tm_t = time(NULL);
-		localtime_r(&tm_t, &tm);
-
-		log_path = fsd_asprintf("%s/server_priv/accounting/%04d%02d%02d", pbssession->pbs_home, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
-
-		fsd_log_info(("Opening accounting log file: %s", log_path));
-
-		if ((fhandle = fopen(log_path, "r")) == NULL)
-		 {
-			fsd_log_error(("Failed to open accounting log file: %s", log_path));
-			fsd_free(log_path);
-			return NULL;
-		 }
-
-		fsd_free(log_path);
-/*
-10/27/2011 14:09:32;E;114249.grass1.man.poznan.pl;user=drmaa group=drmaa jobname=none queue=shortq ctime=1319717371 qtime=1319717371 etime=1319717371 start=1319717372 owner=drmaa@grass1.man.poznan.pl exec_host=grass4.man.poznan.pl/0 Resource_List.neednodes=1 Resource_List.nodect=1 Resource_List.nodes=1 Resource_List.walltime=02:00:00 session=28561 end=1319717372 Exit_status=0 resources_used.cput=00:00:00 resources_used.mem=0kb resources_used.vmem=0kb resources_used.walltime=00:00:00
- */
-		while ((line = fsd_readline(fhandle)) != NULL)
-		 {
-
-			if (line[20] == 'E'  && strncmp(line + 22, job_id, strlen(job_id)) == 0 )
-			 {
-				char *p = NULL;
-
-				fsd_log_debug(("Matched accounting log record = %s", line));
-
-				if (!(exec_host = strstr(line, "exec_host")))
-				 {
-					fsd_log_error(("Invalid accounting record: %s", exec_host));
-					break;
-				 }
-
-				exec_host += 10;
-
-				p = exec_host;
-				while (*p != ' ' && *p != '\0')
-					p++;
-				*p = '\0';
-
-				break;
-			 }
-
-			fsd_free(line);
-		 }
-
-		if (exec_host)
-		 {
-			fsd_log_info(("Job %s was executing on hosts %s.", job_id, exec_host));
-			exec_host = fsd_strdup(exec_host);
-		 }
-		else
-		 {
-			fsd_log_error(("Could not find executions hosts for %s.", job_id));
-		 }
-
-		if (line)
-			fsd_free(line);
-
-		fclose(fhandle);
-
-		return exec_host;
-}
-
-void
-pbsdrmaa_close_log( pbsdrmaa_log_reader_t * self )
-{
-
-	self->current_offset = ftello(self->fhandle);
-	
-	fsd_log_debug(("Closing log  file (offset=%d)", (int)self->current_offset));
-
-	fclose(self->fhandle);
-
-	self->fhandle = NULL;
-}
-
-void
-pbsdrmaa_reopen_log( pbsdrmaa_log_reader_t * self )
-{
-	fsd_log_debug(("Reopening log file: %s (offset=%d)", self->log_path, (int)self->current_offset));
-
-	if ((self->fhandle = fopen(self->log_path,"r")) == NULL)
-	 {
-		fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"Failed to reopen log file");
-	 }
-
-	if(fseek(self->fhandle, self->current_offset, SEEK_SET) == (off_t) -1)
-	 {
-		fsd_exc_raise_fmt(FSD_ERRNO_INTERNAL_ERROR,"fseek error");
-	 }
-}
-
Index: trunk/pbs_drmaa/pbs_conn.h
===================================================================
--- trunk/pbs_drmaa/pbs_conn.h	(revision 85)
+++ 	(revision )
@@ -1,75 +1,0 @@
-/* $Id$ */
-/*
- *  PSNC DRMAA for Torque/PBS Pro
- *  Copyright (C) 2012 Poznan Supercomputing and Networking Center
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
- 
-#ifndef __PBS_DRMAA__PBS_CONN_H
-#define __PBS_DRMAA__PBS_CONN_H
-
-#ifdef HAVE_CONFIG_H
-#	include <config.h>
-#endif
-
-#include <stdio.h>
-
-#include <drmaa_utils/job.h>
-#include <drmaa_utils/session.h>
-#include <drmaa_utils/thread.h>
-
-
-#include <pbs_ifl.h>
-
-typedef struct pbsdrmaa_pbs_conn_s pbsdrmaa_pbs_conn_t;
-
-pbsdrmaa_pbs_conn_t *
-pbsdrmaa_pbs_conn_new(
-		fsd_drmaa_session_t * session,
-		const char *server);
-
-void pbsdrmaa_pbs_conn_destroy ( pbsdrmaa_pbs_conn_t * self );
-
-struct pbsdrmaa_pbs_conn_s {
-	fsd_drmaa_session_t *volatile session;
-
-	char* (*submit) ( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination );
-
-	struct batch_status* (*statjob) ( pbsdrmaa_pbs_conn_t *self,  char *job_id, struct attrl *attrib );
-
-	void (*statjob_free) ( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status );
-
-	void (*sigjob) ( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal );
-
-	void (*deljob) ( pbsdrmaa_pbs_conn_t *self, char *job_id );
-
-	void (*rlsjob) ( pbsdrmaa_pbs_conn_t *self, char *job_id );
-
-	void (*holdjob) ( pbsdrmaa_pbs_conn_t *self, char *job_id );
-	
-	/* contact string */
-	char *server;
-	/* connection descriptor */
-	int connection_fd;
-	
-	/* timestamp of last connect time */
-	time_t last_connect_time;
-
-	fsd_cond_t autoclose_cond;
-	fsd_mutex_t autoclose_mutex;
-	bool close_connection;
-};
-
-#endif /* __PBS_DRMAA__PBS_CONN_H */
Index: trunk/pbs_drmaa/torque4.h
===================================================================
--- trunk/pbs_drmaa/torque4.h	(revision 95)
+++ 	(revision )
@@ -1,24 +1,0 @@
-#ifdef __cplusplus
-
-#include "u_hash_map_structs.h"
-
-extern "C" {
-#endif
-
-typedef struct job_info
-{
-  memmgr *mm;
-  job_data *job_attr;
-  job_data *res_attr;
-  job_data *user_attr;
-  job_data *client_attr;
-} job_info;
-
-
-void hash_add_or_exit_c(memmgr **mm, job_data **head, const char *name, const char *value, int var_type);
-int memmgr_init_c(memmgr **mm, int size);
-void memmgr_destroy_c(memmgr **mm);
-
-#ifdef __cplusplus
-}
-#endif
Index: trunk/pbs_drmaa/log_reader.h
===================================================================
--- trunk/pbs_drmaa/log_reader.h	(revision 48)
+++ 	(revision )
@@ -1,72 +1,0 @@
-/* $Id$ */
-/*
- *  FedStage DRMAA for PBS Pro
- *  Copyright (C) 2006-2009  FedStage Systems
- *
- *  This program is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
- 
-#ifndef __PBS_DRMAA__LOG_READER_H
-#define __PBS_DRMAA__LOG_READER_H
-
-#ifdef HAVE_CONFIG_H
-#	include <config.h>
-#endif
-
-#include <stdio.h>
-
-#include <drmaa_utils/job.h>
-#include <drmaa_utils/session.h>
-
-typedef struct pbsdrmaa_log_reader_s pbsdrmaa_log_reader_t;
-
-pbsdrmaa_log_reader_t * 
-pbsdrmaa_log_reader_new ( fsd_drmaa_session_t * session);
-
-void
-pbsdrmaa_log_reader_destroy ( pbsdrmaa_log_reader_t * self );
-
-struct pbsdrmaa_log_reader_s {
-	fsd_drmaa_session_t *volatile session ;
-	
-	void (*read_log) ( pbsdrmaa_log_reader_t * self );
-	
-	void (*select_file) ( pbsdrmaa_log_reader_t * self );
-	
-	void (*close) ( pbsdrmaa_log_reader_t * self );
-
-	void (*reopen) ( pbsdrmaa_log_reader_t * self );
-
-
-	/* determines if function should run */
-	bool run_flag;
-	
-	/* date of current file */
-	time_t t;	
-	
-	/* log file handle */
-	FILE *fhandle;
-	
-	/* for wait_thread - day changed */
-	bool volatile date_changed;
-	
-	/* for wait_thread - log file first open */
-	bool volatile first_open;	
-
-	char *volatile log_path;
-
-	off_t volatile current_offset;
-};
-
-#endif /* __PBS_DRMAA__LOG_READER_H */
