Beispiel #1
0
int main(int argc,char **argv)
{
	edg_wll_Context		ctx;
	edg_wll_QueryRec  **conditions = NULL;
	time_t				valid = 0;
	char			   *errt, *errd;
	void		*fields = NULL;

	int	sock = -1, flags = 0;
	char	*fake_addr = NULL;
		
//	sleep(20);

	me = argv[0];
	if (edg_wll_InitContext(&ctx) != 0) {
		fprintf(stderr, "Couldn't create L&B context.\n");
		exit(1);
	}

	if ( argc < 2 ) {
		usage(NULL); goto cleanup;
	}
	if ( (argc < 2) || 
	!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || 
	!strcmp(argv[1], "-h") || !strcmp(argv[1], "-?")) 
	{
		usage(NULL); goto cleanup;
	}
	else if ( !strcmp(argv[1], "new") )
	{
		int	c;
		edg_wlc_JobId		jid;
		edg_wll_NotifId		id_out;
		int			attr = 0, i = 0, excl = 0;
		edg_wll_GssCred 	mycred;
                edg_wll_GssStatus	gss_code;
		static struct option long_options[] = {
			{"state", required_argument, 0, 'S'},
			{"jdl", no_argument, 0, 'J'},
			{"bootstrap", no_argument, 0, 'B'},
			{"terminal", no_argument, 0, 'T'},
			{"history", no_argument, 0, 'H'},
			{"anonymize", no_argument, 0, 'N'},
			{"type", no_argument, 0, 'E'},
			{0, 0, 0, 0}};
           	int option_index = 0;
		char *single, *statelist, *notif_server, *typelist, *type, *typestor;
		edg_wll_JobStatCode single_code;
		enum edg_wll_StatJobtype typecode;
		int statno, stdelims, sti;
		unsigned int notif_server_port;

#define MAX_NEW_CONDS 7
		conditions = (edg_wll_QueryRec **)calloc(MAX_NEW_CONDS + 1,sizeof(edg_wll_QueryRec *));
		conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));

		while ((c = getopt_long(argc-1,argv+1,"j:o:v:n:s:a:t:f:cOS:JBTHNE:",long_options,&option_index)) > 0) { switch (c) {
			case 'j':
				conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
				conditions[i][0].attr = EDG_WLL_QUERY_ATTR_JOBID;
				conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL;
				if (edg_wlc_JobIdParse(optarg, &jid) ) {
					fprintf(stderr,"Job ID parameter not set propperly!\n");
					usage("new");
					goto cleanup;
				}
				conditions[i][0].value.j = jid;
				i++;
				edg_wll_GetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, &notif_server);
				if (!notif_server) {
					glite_jobid_getServerParts(jid, &notif_server, &notif_server_port); 
					edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, notif_server);
					edg_wll_SetParamInt(ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, notif_server_port);
				}
				free(notif_server);
				break;
			case 'o':
				if (excl) { usage("new"); return EX_USAGE; } else excl = 1;
				conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
				conditions[i][0].attr = EDG_WLL_QUERY_ATTR_OWNER;
				conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL;
				conditions[i][0].value.c = optarg;
				i++;
				break;
			case 'v':
				conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
				conditions[i][0].attr = EDG_WLL_QUERY_ATTR_JDL_ATTR;
				conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL;
				conditions[i][0].value.c = optarg;
				asprintf(&(conditions[i][0].attr_id.tag), "VirtualOrganisation");
				i++;
				break;
			case 'n':
				conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
				conditions[i][0].attr = EDG_WLL_QUERY_ATTR_NETWORK_SERVER;
				conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL;
				conditions[i][0].value.c = optarg;
				i++;
				break;
			case 's':
				if (fake_addr) { usage("new"); return EX_USAGE; }
				sock = atoi(optarg); break;
			case 'a':
				if (sock >= 0) { usage("new"); return EX_USAGE; }
				fake_addr = optarg; break;
			case 't':
				valid = time(NULL) + atol(optarg); break;
			case 'f':
				flags |= atoi(optarg); break;
			case 'J':
				flags |= EDG_WLL_STAT_CLASSADS; break;
			case 'B':
				flags |= EDG_WLL_NOTIF_BOOTSTRAP; break;
			case 'T':
				flags |= EDG_WLL_NOTIF_TERMINAL_STATES; break;
			case 'H':
				flags |= EDG_WLL_NOTIF_TERMINAL_STATES | EDG_WLL_NOTIF_HISTORY; break;
			case 'N':
				flags |= EDG_WLL_NOTIF_ANONYMIZE; break;
			case 'c':
				conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
				conditions[i][0].attr = EDG_WLL_QUERY_ATTR_STATUS;
				conditions[i][0].op = EDG_WLL_QUERY_OP_CHANGED;
				i++;
				break;
			case 'O':
				if (excl) { usage("new"); return EX_USAGE; } else excl = 1;
				if ( !edg_wll_gss_acquire_cred(NULL, NULL, GSS_C_INITIATE, &mycred, &gss_code) )
				{
					conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
					conditions[i][0].attr = EDG_WLL_QUERY_ATTR_OWNER;
					conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL;
					conditions[i][0].value.c = strdup(mycred->name);
					edg_wll_gss_release_cred(&mycred, NULL);
					i++;
				}
				else {
					fprintf(stderr,"No credentials found! Exiting. \n");	
					goto cleanup;
				}
				break;
			case 'S':
				statelist = optarg;

				statno = 0;
				stdelims = 0;
				for (sti = 0; sti < strlen(statelist); sti++) 
					if (statelist[sti] == ',') stdelims++;
				conditions[i] = (edg_wll_QueryRec *)calloc(stdelims+2,sizeof(edg_wll_QueryRec));
				while((single = strtok(statelist, ","))) {
					single_code = edg_wll_StringToStat(single);
					if (single_code != -1) {
						conditions[i][statno].attr = EDG_WLL_QUERY_ATTR_STATUS;
						conditions[i][statno].op = EDG_WLL_QUERY_OP_EQUAL;
						conditions[i][statno].value.i = single_code;
						statelist = NULL;
						statno++;
					}
					else {
						fprintf(stderr,"'%s' is not a valid state name! Exitting.\n", single);	
						goto cleanup;
					}
				}
				i++;
				break;
			case 'E':
				typelist = optarg;
				statno = 0;
				for( type = strtok_r(typelist, ",", &typestor); type ; type = strtok_r(NULL, ",", &typestor))
					statno++;
				conditions[i] = (edg_wll_QueryRec *)calloc(statno+1,sizeof(edg_wll_QueryRec));
				statno = 0;
				for( type = strtok_r(typelist, ",", &typestor); type ; type = strtok_r(NULL, ",", &typestor)) {
					typecode=edg_wll_JobtypeStrToCode(type);
					if (((int)typecode)<0) {
						fprintf(stderr,"'%s' is not a valid job type! Exitting.\n", type);	
						goto cleanup;
					}
					else {
						conditions[i][statno].attr = EDG_WLL_QUERY_ATTR_JOB_TYPE;
						conditions[i][statno].op = EDG_WLL_QUERY_OP_EQUAL;
						conditions[i][statno].value.i = typecode;
						statelist = NULL;
						statno++;
					}
				}
				i++;
				break;
			default:
				usage("new"); return EX_USAGE;
			}
			if (i > MAX_NEW_CONDS) {
				usage("new"); return EX_USAGE;
			}
		}

		if ( !edg_wll_NotifNew(ctx,
					(edg_wll_QueryRec const* const*)conditions,
					flags, sock, fake_addr, &id_out, &valid))
			fprintf(stdout,"notification ID: %s\nvalid: %s (%ld)\n",
					edg_wll_NotifIdUnparse(id_out),
					TimeToStr(valid),
					valid);
		edg_wll_NotifIdFree(id_out);
		if (attr == EDG_WLL_QUERY_ATTR_JOBID) edg_wlc_JobIdFree(jid);
		if (edg_wll_Error(ctx,&errt,&errd)) {
			fprintf(stderr, "%s: %s (%s)\n", me, errt, errd);
			return EX_IOERR;
		}
	}
	else if ( !strcmp(argv[1], "bind") )
	{
		edg_wll_NotifId		nid;
		int			c;

		while ((c = getopt(argc-1,argv+1,"s:a:t:")) > 0) switch (c) {
			case 's':
				if (fake_addr) { usage("bind"); return EX_USAGE; }
				sock = atoi(optarg); break;
			case 'a':
				if (sock >= 0) { usage("bind"); return EX_USAGE; }
				fake_addr = optarg; break;
			case 't':
				valid = time(NULL) + atol(optarg); break;
			default:
				usage("bind"); return EX_USAGE;
		}

		if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) )
		{
			fprintf(stderr,"Notification ID parameter not set propperly!\n\n");
			usage("bind");
			return EX_USAGE;
		}
		if ( !edg_wll_NotifBind(ctx, nid, sock, fake_addr, &valid) )
			printf("valid until: %s (%ld)\n", TimeToStr(valid), valid);
		edg_wll_NotifIdFree(nid);
		if (edg_wll_Error(ctx,&errt,&errd)) {
			fprintf(stderr, "%s: %s (%s)\n", me, errt, errd);
			return EX_IOERR;
		}
	}
	else if ( !strcmp(argv[1], "receive") )
	{
		edg_wll_JobStat		stat;
		edg_wll_NotifId		nid = NULL;
		int			c;
		char	*field_arg = "owner",*err;
		time_t	client_tout = time(NULL) + 600;
	        int	refresh = 0;
		struct timeval		tout;
		time_t	opt_valid = 0,do_refresh = client_tout,now;

		while ((c = getopt(argc-1,argv+1,"s:a:i:f:t:r")) > 0) switch (c) {
			case 's':
				if (fake_addr || refresh || opt_valid) { usage("receive"); return EX_USAGE; }
				sock = atoi(optarg); break;
			case 'a':
				if (sock >= 0) { usage("receive"); return EX_USAGE; }
				fake_addr = optarg; break;
			case 'i':
				client_tout = time(NULL) + atoi(optarg); break;
			case 'f':
				field_arg = optarg; break;
			case 't':
				if (sock >= 0) { usage("receive"); return EX_USAGE; }
				opt_valid = atol(optarg); break;
			case 'r':
				if (sock >= 0) { usage("receive"); return EX_USAGE; }
				refresh = 1; break;
			default:
				usage("receive"); return EX_USAGE;
		}

		if (opt_valid == 0) opt_valid = 3600;

		if ((err = glite_lb_parse_stat_fields(field_arg,&fields))) {
			fprintf(stderr,"%s: invalid argument\n",err);
			return EX_USAGE;
		}

		memset(&stat,0,sizeof stat);

		if (sock == -1) {
			int	param = optind+1;

			if (param == argc)
			{
				fprintf(stderr, "Notification ID parameter not set propperly!\n\n");
				usage("receive");
				return EX_USAGE;
			}

			valid = time(NULL) + opt_valid;

			while (param < argc) {
				if (edg_wll_NotifIdParse(argv[param], &nid)) {
					fprintf(stderr, "Notification ID parameter not set propperly!\n\n");
					usage("receive");
					return EX_USAGE;
				}

				if (edg_wll_NotifBind(ctx, nid, -1, fake_addr, &valid) )
					goto receive_err;
				fprintf(stderr,"notification is valid until: %s (%ld)\n", TimeToStr(valid), valid);
				
				param++;
			}
			now = time(NULL);
			do_refresh = now + (valid - now)/2;
			if (refresh) fprintf(stderr,"next refresh %s (%ld)\n",
					TimeToStr(do_refresh),do_refresh);
		}

		do {
			edg_wll_NotifId		recv_nid = NULL;
			int	err;

			tout.tv_sec = (refresh && client_tout >= do_refresh ? do_refresh : client_tout)
					- time(NULL);
			if (tout.tv_sec < 0) tout.tv_sec = 0;
			tout.tv_usec = 0;

			if ( (err = edg_wll_NotifReceive(ctx, sock, &tout, &stat, &recv_nid)) ) {
				edg_wll_NotifIdFree(recv_nid);
				recv_nid = NULL; 

				if (err != ETIMEDOUT) goto receive_err;
			}
			else {
				glite_lb_print_stat_fields(fields,&stat);
				edg_wll_FreeStatus(&stat);
				stat.state = EDG_WLL_JOB_UNDEF;
			}

			if ((now = time(NULL)) >= client_tout) goto cleanup;

			if (refresh && now >= do_refresh) {
				valid = now + opt_valid;
				if (!edg_wll_NotifRefresh(ctx,nid,&valid)) {
					do_refresh = now + (valid - now)/2;
					fprintf(stderr,"notification is valid until: %s (%ld)\n",TimeToStr(valid), valid);
					fprintf(stderr,"next refresh %s (%ld)\n", TimeToStr(do_refresh),do_refresh);
				}
				else {
					char	*et,*ed;
					edg_wll_Error(ctx,&et,&ed);
					do_refresh = now + (valid - now)/2;
					fprintf(stderr,"warning: edg_wll_NotifRefresh failed (%s, %s)\n"
							"next refresh %s (%ld)\n",
							et,ed,TimeToStr(do_refresh),do_refresh);
				}
			}
/* original example */
#if 0
			printf("\nnotification ID: %s\n", edg_wll_NotifIdUnparse(recv_nid)); 
			
			if (stat.state != EDG_WLL_JOB_UNDEF) {
				char	*jobid_s;

				jobid_s = edg_wlc_JobIdUnparse(stat.jobId);
				printf("Jobid:\t%s\nStatus:\t%s\n", 
						jobid_s,
						edg_wll_StatToString(stat.state));
				edg_wll_FreeStatus(&stat);
				free(jobid_s);
				stat.state = EDG_WLL_JOB_UNDEF;
			}
#endif
			
			if (recv_nid) {
				edg_wll_NotifIdFree(recv_nid);
				recv_nid = NULL;
			}
		} while (1); // till timeout....
		return 0;

receive_err:		
		if (stat.state != EDG_WLL_JOB_UNDEF) edg_wll_FreeStatus(&stat);
		if (nid) edg_wll_NotifIdFree(nid);
		edg_wll_NotifCloseFd(ctx);
		edg_wll_NotifClosePool(ctx);

		if (edg_wll_Error(ctx,&errt,&errd))
			fprintf(stderr, "%s: %s (%s)\n", me, errt, errd);

		return EX_IOERR;
	}
	else if ( !strcmp(argv[1], "change") )
	{
		edg_wlc_JobId		jid;
		edg_wll_NotifId		nid;

		if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) )
		{
			printf("Notification ID parameter not set propperly!\n");
			usage("bind");
			return 1;
		}
		if ( (argc < 4) || edg_wlc_JobIdParse(argv[3], &jid) )
		{
			fprintf(stderr,"Job ID parameter not set propperly!\n");
			usage("change");
			goto cleanup;
		}

		conditions = (edg_wll_QueryRec **)calloc(2,sizeof(edg_wll_QueryRec *));
	
		conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
		conditions[0][0].attr = EDG_WLL_QUERY_ATTR_JOBID;
		conditions[0][0].op = EDG_WLL_QUERY_OP_EQUAL;
		conditions[0][0].value.j = jid;

		conditions[1] = NULL;

		/*conditions[1] = (edg_wll_QueryRec *)calloc(3, sizeof(edg_wll_QueryRec));
		conditions[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS;
		conditions[1][0].op = EDG_WLL_QUERY_OP_EQUAL;
		conditions[1][0].value.i = EDG_WLL_JOB_DONE;

		conditions[1][1].attr = EDG_WLL_QUERY_ATTR_STATUS;
		conditions[1][1].op = EDG_WLL_QUERY_OP_EQUAL;
		conditions[1][1].value.i = EDG_WLL_JOB_RUNNING;*/

		edg_wll_NotifChange(ctx, nid,
						(edg_wll_QueryRec const * const *) conditions,
						EDG_WLL_NOTIF_REPLACE);
		edg_wlc_JobIdFree(jid);
		edg_wll_NotifIdFree(nid);
	}
	else if ( !strcmp(argv[1], "refresh") )
	{
		edg_wll_NotifId		nid;
		int			c;

		while ((c = getopt(argc-1,argv+1,"t:")) > 0) switch (c) {
			case 't':
				valid = time(NULL) + atol(optarg); break;
			default:
				usage("refresh"); return EX_USAGE;
		}

		if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) )
		{
			fprintf(stderr,"Notification ID parameter not set propperly!\n\n");
			usage("refresh");
			return EX_USAGE;
		}

		if ( !edg_wll_NotifRefresh(ctx, nid, &valid) )
			printf("valid until: %s (%ld)\n", TimeToStr(valid), valid);
		edg_wll_NotifIdFree(nid);
	}
	else if ( !strcmp(argv[1], "drop") )
	{
		edg_wll_NotifId		nid;

		if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) )
		{
			fprintf(stderr,"Notification ID parameter not set propperly!\n");
			usage("drop");
			return EX_USAGE;
		}
		edg_wll_NotifDrop(ctx, nid);
		edg_wll_NotifIdFree(nid);
	}
	else {
		usage(NULL);
		return EX_USAGE;
	}
	
cleanup:
	
	if ( conditions )
	{
		/*
		for ( i = 0; conditions[i][0].attr; i++ )
			free(conditions[1]);
		*/
		free(conditions);
	}

	int retval;
	if (retval = edg_wll_Error(ctx,&errt,&errd)) 
		fprintf(stderr, "%s: %s (%s)\n", me, errt, errd);

	edg_wll_NotifCloseFd(ctx);
	edg_wll_FreeContext(ctx);
	edg_wll_poolFree();

	return retval;
}
Beispiel #2
0
/*
 *----------------------------------------------------------------------
 *
 * edg_wll_log_proto_server - handle incoming data
 *
 * Returns: 0 if done properly or errno
 *
 * Calls:
 *
 * Algorithm:
 *
 *----------------------------------------------------------------------
 */
int edg_wll_log_proto_server(edg_wll_GssConnection *con, struct timeval *timeout, char *name, char *prefix, int noipc, int noparse)
{
	char	*buf,*dglllid,*dguser,*jobId,*name_esc;
	char	header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1];
	char	outfilename[FILENAME_MAX];
	size_t	count;
	int	count_total,size;
	u_int8_t size_end[4];
	size_t  msg_size,dglllid_size,dguser_size;
	int	i,answer,answer_sent;
	int	msg_sock;
	char    *msg,*msg_begin;
	int	filedesc,filelock_status;
	long	filepos;
	int	priority;
	long	lllid;
	int	unique;
	int	err;
	edg_wll_Context	context;
	edg_wll_Event	*event;
	edg_wlc_JobId	j;
	edg_wll_GssStatus	gss_stat;
                
	errno = i = answer = answer_sent = size = msg_size = dglllid_size = dguser_size = count = count_total = msg_sock = filedesc = filelock_status = /* priority */ unique = err = 0;     
        buf = dglllid = dguser = jobId = name_esc = msg = msg_begin = NULL;
	event = NULL;

	/* init */
	if (edg_wll_InitContext(&context) != 0) {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_ERROR,"edg_wll_InitContex(): error.\n");
		answer = ENOMEM; 
		goto edg_wll_log_proto_server_end; 
	}
	if (edg_wll_ResetError(context) != 0) { 
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_ERROR,"edg_wll_ResetError(): error.\n");
		answer = ENOMEM; 
		goto edg_wll_log_proto_server_end;
	}

	/* look for the unique unused long local-logger id (LLLID) */
	lllid = 1000*getpid();
	for (i=0; (i<1000)&&(!unique); i++) {
		struct stat statbuf;
		lllid += i;
		snprintf(confirm_sock_name, sizeof(confirm_sock_name), "/tmp/dglogd_sock_%ld", lllid);
		if ((filedesc = stat(confirm_sock_name,&statbuf)) == 0) {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Warning: LLLID %ld already in use.\n",lllid);
		} else {
			if (errno == ENOENT) {
				unique = 1;
			} else {
				glite_common_log_SYS_ERROR("stat");
			}
		}
	}
	if (!unique) {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_ERROR,"Cannot determine the unique long local-logger id (LLLID %ld)!\n",lllid);
		return EAGAIN;
	}
	glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Long local-logger id (LLLID): %ld ... [ok]\n",lllid);

	/* receive socket header */
	memset(header, 0, EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1);
	if ((err = edg_wll_gss_read_full(con, header, EDG_WLL_LOG_SOCKET_HEADER_LENGTH, timeout, &count, &gss_stat)) < 0) {
		if (err == EDG_WLL_GSS_ERROR_EOF) {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Reading socket header - no data available.\n");
			answer = err;
			answer_sent = 1; /* i.e. do not try to send answer back */
		} else {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error reading socket header.\n");
			answer = handle_gss_failures(err,&gss_stat,"Error reading socket header");
		}
		goto edg_wll_log_proto_server_end;
	} else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Reading socket header... [ok]\n");
	}

	/* Check socket header */
	header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH] = '\0';
	if (strncmp(header,EDG_WLL_LOG_SOCKET_HEADER,EDG_WLL_LOG_SOCKET_HEADER_LENGTH)) {
		/* not the proper socket header text */
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): invalid socket header\n");
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"edg_wll_log_proto_server(): read header '%s' instead of '%s'\n",
				header,EDG_WLL_LOG_SOCKET_HEADER);
		answer = EINVAL;
		goto edg_wll_log_proto_server_end;
	} else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read socket header: \"%s\" [ok]\n",header);
	}

/* XXX: obsolete
	count = 0;
	if ((err = edg_wll_gss_read_full(con, &priority, sizeof(priority), timeout, &count, &gss_stat)) < 0) {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error reading message priority.\n");
		answer = handle_gss_failures(err,&gss_stat,"Error receiving message priority");
                goto edg_wll_log_proto_server_end;
        } else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read message priority: %d [ok]\n",priority);
	}
*/

        /* read message size */
	count = 0;
	if ((err = edg_wll_gss_read_full(con, size_end, 4, timeout, &count,&gss_stat)) < 0) {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Error reading message size.\n");
		answer = handle_gss_failures(err,&gss_stat,"Error reading message size");
                goto edg_wll_log_proto_server_end;
	} else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Reading message size... [ok]\n");
	}
	size = size_end[3]; size <<=8; 
	size |= size_end[2]; size <<=8; 
	size |= size_end[1]; size <<=8; 
	size |= size_end[0];
	if (size <= 0) {
		/* probably wrong size in the header or nothing to read */
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): invalid size read from socket header\n");
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read message size '%d' [error].\n",size);
		answer = EINVAL;
		goto edg_wll_log_proto_server_end;
	} else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Read message size: %d bytes [ok].\n",size);
	}

	/* format the DG.LLLID string */
	if (asprintf(&dglllid,"DG.LLLID=%ld ",lllid) == -1) {
		glite_common_log_SYS_ERROR("asprintf");
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): nomem for DG.LLLID\n");
		answer = ENOMEM;
		goto edg_wll_log_proto_server_end;
	}
	dglllid_size = strlen(dglllid);

	/* format the DG.USER string */
	name_esc = glite_lbu_EscapeULM(name);
	if (asprintf(&dguser,"DG.USER=\"%s\" ",name_esc) == -1) {
		glite_common_log_SYS_ERROR("asprintf");
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): nomem for DG.USER\n");
		answer = ENOMEM;
		goto edg_wll_log_proto_server_end;
	}
	dguser_size = strlen(dguser);

	/* allocate enough memory for all data */
	msg_size = dglllid_size + dguser_size + size + 1;
	if ((msg = malloc(msg_size)) == NULL) {
		glite_common_log_SYS_ERROR("malloc");
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): out of memory for allocating message\n");
		answer = ENOMEM;
		goto edg_wll_log_proto_server_end;
	}
	strncpy(msg,dglllid,dglllid_size);
	msg_begin = msg + dglllid_size; // this is the "official" beginning of the message
	strncpy(msg_begin,dguser,dguser_size);

	/* receive message */
	buf = msg_begin + dguser_size;
	count = 0;
	if ((err = edg_wll_gss_read_full(con, buf, size, timeout, &count, &gss_stat)) < 0) {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error reading message from socket.\n");
		answer = handle_gss_failures(err,&gss_stat,"Error reading message from socket.");
		goto edg_wll_log_proto_server_end;
	} else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Reading message... [ok]\n");
		// glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_TRACE,"Read message: \"%s\"\n",msg);
	}       

	buf[count] = '\0';

	/* parse message and get jobId and priority from it */
	if (!noparse && strstr(msg, "DG.TYPE=\"command\"") == NULL) {
		if (edg_wll_ParseEvent(context,msg_begin,&event) != 0) { 
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_proto_server(): edg_wll_ParseEvent error\n");
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_ParseEvent(): %s\n",context->errDesc);
			answer = edg_wll_Error(context,NULL,NULL);
			goto edg_wll_log_proto_server_end;
		} else {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Parsing message for correctness...[ok]\n");
		}
		jobId = edg_wlc_JobIdGetUnique(event->any.jobId);
		priority = event->any.priority;
		edg_wll_FreeEvent(event);
		event->any.priority = priority;
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Getting jobId from message...[ok]\n");
	} else {
		if ((event = edg_wll_InitEvent(EDG_WLL_EVENT_UNDEF)) == NULL) {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN, "edg_wll_InitEvent(): out of memory\n");
			answer = ENOMEM;
			goto edg_wll_log_proto_server_end;
		}
		jobId = edg_wll_GetJobId(msg);
		if (!jobId || edg_wlc_JobIdParse(jobId,&j)) {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error getting jobId from message.\n");
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wlc_JobIdParse(%s)\n",jobId?jobId:"NULL");
			answer = EINVAL;
			goto edg_wll_log_proto_server_end;
		} else {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Getting jobId from message...[ok]\n");
		}
		free(jobId);
		jobId = edg_wlc_JobIdGetUnique(j);
		edg_wlc_JobIdFree(j);

/* TODO: get the priority from message some better way */
		if (strstr(msg, "DG.PRIORITY=1") != NULL)
			event->any.priority = 1;
		else event->any.priority = 0;
	}

	if (event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) {
		if(init_confirmation() < 0) { 
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error initializing 2nd UNIX socket (%s) for priority messages confirmation.\n",confirm_sock_name); 
			answer = errno; 
			goto edg_wll_log_proto_server_end; 
		} else {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Initializing 2nd UNIX socket (%s) for priority messages confirmation...[ok]\n",confirm_sock_name);
		}
	}

	/* if not command, save message to file */
	if(strstr(msg, "DG.TYPE=\"command\"") == NULL) {
		/* compose the name of the log file */
		count = strlen(prefix);
		strncpy(outfilename,prefix,count); count_total=count;
		strncpy(outfilename+count_total,".",1); count_total+=1; count=strlen(jobId);
		strncpy(outfilename+count_total,jobId,count); count_total+=count;
		outfilename[count_total]='\0';
//		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Composing filename from prefix \"%s\" and unique jobId \"%s\"...[ok]",prefix,jobId);

		/* fopen and properly handle the filelock */
#ifdef LOGD_NOFILE
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"NOT writing message to \"%s\".\n",outfilename);
		filepos = 0;
#else
		if ( edg_wll_log_event_write(context, outfilename, msg, FCNTL_ATTEMPTS, FCNTL_TIMEOUT, &filepos) ) {
			char *errd;
			// FIXME: there is probably not a correct errno
			glite_common_log_SYS_ERROR("edg_wll_log_event_write");
			answer = edg_wll_Error(context, NULL, &errd);
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_event_write error: %s\n",errd);
			free(errd);
			goto edg_wll_log_proto_server_end;
		} else glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Writing message to \"%s\"... [ok]",outfilename);
#endif
	} else {
		filepos = 0;
	}

#ifdef LB_PERF
	glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Calling perftest\n");
	glite_wll_perftest_consumeEventString(msg);
	glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Calling perftest... [done]\n");
#endif

	/* if not priority send now the answer back to client */
	if (!(event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT))) {
		if (!send_answer_back(con,answer,timeout)) { 
			answer_sent = 1;
		}
	} 

	/* send message via IPC (UNIX socket) */
	if (!noipc) {

		if ( edg_wll_log_event_send(context, socket_path, filepos, msg, msg_size, CONNECT_ATTEMPTS, timeout) ) {
			char *errd;
			// XXX: probably not a SYSTEM ERROR
			// glite_common_log_SYS_ERROR("edg_wll_log_event_send");
			answer = edg_wll_Error(context, NULL, &errd);
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"edg_wll_log_event_send error: %s\n",errd);
			free(errd);
			goto edg_wll_log_proto_server_end_1;
		} else glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,
			"Sending via IPC (UNIX socket \"%s\")\n\t"
			"the message position %ld (%ld bytes)... [ok]",
			socket_path, filepos, sizeof(filepos));

	} else {
		glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"NOT sending via IPC.\n");
	}

	if (event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) {
		if ((count = wait_for_confirmation(timeout, &answer)) < 0) {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_WARN,"Error waiting for confirmation.\n");
			answer = errno;
		} else {
			glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Waiting for confirmation... [ok].\n");
			if (count == 0) {
				glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Waking up, timeout expired.\n");
				answer = EAGAIN;
			} else {
				glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_DEBUG,"Confirmation received, waking up.\n");
			}
		}
	}

edg_wll_log_proto_server_end:
	/* if not sent already, send the answer back to client */
	if (!answer_sent) {
		answer = send_answer_back(con,answer,timeout);
	} 
	/* clean */
	edg_wll_FreeContext(context);
	if (name_esc) free(name_esc);
	if (dglllid) free(dglllid);
	if (dguser) free(dguser);
	if (jobId) free(jobId);
	if (msg) free(msg);
	if (event) free(event);

//	glite_common_log(LOG_CATEGORY_ACCESS,LOG_PRIORITY_INFO,"Done.\n");

	return answer;

edg_wll_log_proto_server_end_1:
	if (event->any.priority) {
		close(confirm_sock);
		unlink(confirm_sock_name);
	}	
	goto edg_wll_log_proto_server_end;
}
Beispiel #3
0
int main(int argc,char **argv)
{
	edg_wll_Context	ctx;
	char		*errt,*errd;
	edg_wll_Event	*events = NULL;
	edg_wlc_JobId	job;
	int		i,opt,delay = 1,count = 0, proxy = 0;

	if (argc < 2)
	    help(argv[0]);

	if (edg_wll_InitContext(&ctx) != 0) {
		fprintf(stderr, "Couldn't create L&B context.\n");
		return 1;
	}

	while ((opt=getopt(argc,argv,"r:d:xX:")) != -1)
	    switch (opt) {
	    case 'd': delay = atoi(optarg); break;
	    case 'r': count = atoi(optarg); break;
	    case 'x': proxy = 1; break;
	    case 'X': proxy = 1; 
		      edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, optarg);
		      break;
	    default:
                help(argv[0]);
	    }

	if (edg_wlc_JobIdParse(argv[optind],&job)) {
		fprintf(stderr,"%s: can't parse job ID\n",argv[1]);
		return 1;
	}

#ifdef USE_CALLBACKS
	edg_wll_RegisterTestQueryEvents(query_events_cb);
#endif

	if ( proxy ? edg_wll_JobLogProxy(ctx,job,&events) : edg_wll_JobLog(ctx,job,&events) )
	{
		edg_wll_Error(ctx,&errt,&errd);
		fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd);
	}

	for ( i = 0; events && events[i].type != EDG_WLL_EVENT_UNDEF; i++ )
	{
		char	*e = edg_wll_UnparseEvent(ctx,events+i);
		fputs(e,stdout);
		fputs("\n",stdout);
		free(e);
	}

	free_events(events);
	printf("\nFound %d events\n",i);

	while (count--) {
		puts("Sleeping ...");
		sleep(delay);
		if (proxy ? edg_wll_JobLogProxy(ctx,job,&events) : edg_wll_JobLog(ctx,job,&events)) {
			edg_wll_Error(ctx,&errt,&errd);
			fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd);
			free(errt); free(errd); errt = errd = NULL;
			free_events(events);
		}
		else puts("OK");
	}

	edg_wlc_JobIdFree(job);
	edg_wll_FreeContext(ctx); 

#ifdef USE_CALLBACKS
	edg_wll_UnregisterTestQueryEvents();
#endif
	
	return 0;

#ifdef USE_CALLBACKS
	edg_wll_UnregisterTestQueryEvents();
#endif
	switch (edg_wll_Error(ctx,&errt,&errd)) {
		case 0: break;
		case ENOENT:
			puts("No events found");
			break;
		default:
			fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd);
			return 1;
	}

	edg_wlc_JobIdFree(job);
	edg_wll_FreeContext(ctx); 

	return 0;
}
Beispiel #4
0
int
plugin_confirm_authorization(lcas_request_t request, lcas_cred_id_t lcas_cred)
{
    char *user_dn;
    int ret;
    edg_wll_Context ctx;
    struct _edg_wll_GssPrincipal_data princ;
    X509 *cert = NULL;
    STACK_OF(X509) * chain = NULL;
    void *cred = NULL;
    struct vomsdata *voms_info = NULL;
    int err;
    authz_action action;

    memset(&princ, 0, sizeof(princ));

    lcas_log_debug(1,"\t%s-plugin: checking LB access policy\n",
                   modname);

    if (edg_wll_InitContext(&ctx) != 0) {
        lcas_log(0, "Couldn't create L&B context\n");
        ret = LCAS_MOD_FAIL;
        goto end;
    }

    if ((action = find_authz_action(request)) == ACTION_UNDEF) {
        lcas_log(0, "lcas.mod-lb() error: unsupported action\n");
        ret = LCAS_MOD_FAIL;
        goto end;
    }

    user_dn = lcas_get_dn(lcas_cred);
    if (user_dn == NULL) {
        lcas_log(0, "lcas.mod-lb() error: user DN empty\n");
        ret = LCAS_MOD_FAIL;
        goto end;
    }
    princ.name = user_dn;

    cred = lcas_get_gss_cred(lcas_cred);
    if (cred == NULL) {
        lcas_log(0, "lcas.mod-lb() warning: user gss credential empty\n");
#if 0
        ret = LCAS_MOD_FAIL;
        goto end;
#endif
    }

#ifndef NO_GLOBUS_GSSAPI
    if (cred) {
        voms_info = VOMS_Init(NULL, NULL);
        if (voms_info == NULL) {
            lcas_log(0, "lcas.mod-lb() failed to initialize VOMS\n");
            ret = LCAS_MOD_FAIL;
            goto end;
        }

        ret = VOMS_RetrieveFromCred(cred, RECURSE_CHAIN, voms_info, &err);
        if (ret == 1)
            edg_wll_get_fqans(ctx, voms_info, &princ.fqans);
    }
#endif

    ret = check_authz_policy(edg_wll_get_server_policy(), &princ, action);
    ret = (ret == 1) ? LCAS_MOD_SUCCESS : LCAS_MOD_FAIL;

end:
    edg_wll_FreeContext(ctx);
#ifndef NO_GLOBUS_GSSAPI
    if (voms_info)
        VOMS_Destroy(voms_info);
#endif
    if (cert)
        X509_free(cert);
    if (chain)
        sk_X509_pop_free(chain, X509_free);

    return ret;
}
Beispiel #5
0
int main(int argc,char **argv)
{
	edg_wll_Context	ctx;
	char		*errt,*errd,*e,a;
	edg_wll_Event	*events;
	int		i;
	edg_wll_QueryRec	jq[2],eq[2];
	edg_wlc_JobId	job;
	edg_wll_Source	src;

	if (argc != 3) help(argv[0]);

	puts(
"*\n"
"* USE WITH CARE, AT YOUR OWN RISK, UNDER ABNORMAL CONDITIONS ONLY,\n"
"* AND BE ALWAYS SURE WHAT YOU ARE DOING.\n"
"* \n"
"* THIS PROGRAM IS A PERFECT EXAMPLE HOW L&B SEQENCE CODES SHOULD NOT BE USED\n"
"* IN NORMAL OPERATION.\n"
"\n"
"Do you want to proceed?"
	);

	scanf("%c",&a);
	if (a != 'y' && a != 'Y') return 1;

	if (edg_wll_InitContext(&ctx) != 0) {
		fprintf(stderr, "Couldn't create L&B context.\n");
		return 1;
	}

	if (edg_wlc_JobIdParse(argv[1],&job)) {
		fprintf(stderr,"%s: can't parse job ID\n",argv[1]);
		return 1;
	}

	if (( src = edg_wll_StringToSource(argv[2])) == EDG_WLL_SOURCE_NONE) {
		fprintf(stderr,"%s: unknown event source\n",argv[2]);
		return 1;
	}

	jq[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
	jq[0].op = EDG_WLL_QUERY_OP_EQUAL;
	jq[0].value.j = job;
	jq[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;

	eq[0].attr = EDG_WLL_QUERY_ATTR_SOURCE;
	eq[0].op = EDG_WLL_QUERY_OP_EQUAL;
	eq[0].value.i = src;
	eq[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;

	if ( edg_wll_QueryEvents(ctx,jq,eq,&events) )
	{
		if ( edg_wll_Error(ctx, &errt, &errd) != E2BIG )
			goto err;

		fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd);
	}

	for ( i = 0; events[i].type != EDG_WLL_EVENT_UNDEF; i++ );

	e = edg_wll_UnparseEvent(ctx,events+i-1);

	fputs(e,stdout);
	fputs("\n",stdout);

	if (edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,src) || 
		edg_wll_SetLoggingJob(ctx,job,events[i-1].any.seqcode,EDG_WLL_SEQ_NORMAL) ||
		edg_wll_IncSequenceCode(ctx) || /* necessary to simulate this
						* call in last event logging 
						* _after_ current seq. was used */
		edg_wll_LogAbort(ctx,"manual abort")) goto err;


	free(e);
	free_events(events);

	edg_wll_FreeContext(ctx); 

	return 0;

err:
	switch (edg_wll_Error(ctx,&errt,&errd)) {
		case 0: break;
		case ENOENT:
			puts("No events found");
			break;
		default:
			fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd);
			return 1;
	}

	edg_wll_FreeContext(ctx); 

	return 0;
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    char 	*job = NULL,*server = NULL,*seq = NULL,*filename = NULL;
    char 	buf[MAXMSGSIZE];
    int 	lbproxy = 0, num_subjobs = 0, lbdirect = 0;
    int 	done = 0, njobs = 1,i,j;
    edg_wll_Context	ctx;
    edg_wlc_JobId	jobid,*subjobs;
    FILE	*f;

    if (edg_wll_InitContext(&ctx) != 0) {
        fprintf(stderr, "Couldn't create L&B context.\n");
        return 1;
    }

    opterr = 0;

    me = strdup(argv[0]);

    do {
        switch (getopt(argc,argv,"m:xyN:n:f:")) {
        case 'm':
            server = strdup(optarg);
            break;
        case 'x':
            lbproxy = 1;
            break;
        case 'y':
            lbdirect = 1;
            break;
        case 'N':
            njobs = atoi(optarg);
            break;
        case 'n':
            num_subjobs = atoi(optarg);
            break;
        case 'f':
            filename = (char *) strdup(optarg);
            break;
        case '?':
            usage();
            exit(EINVAL);
        case -1:
            done = 1;
            break;
        }
    } while (!done);

    if (lbproxy && lbdirect) {
        fprintf(stderr,"%s: only one of -x or -y options may be specified \n",me);
        usage();
        exit(1);
    }

    if (!server) {
        fprintf(stderr,"%s: -m required\n",me);
        usage();
        exit(1);
    }

    if ((njobs <= 0) || (num_subjobs < 0)) {
        fprintf(stderr,"%s: wrong number of jobs\n",me);
        usage();
        exit(1);
    }

    if (!filename) {
        fprintf(stderr,"%s: -f required\n",me);
        usage();
        exit(1);
    }

    if ( (f = fopen(filename,"r")) == NULL) {
        perror(filename);
        exit(1);
    }

    /* MAIN LOOP */
    for (i = 0; i<njobs; i++) {
        /* create jobid */
        if (!job) {
            char *p = strchr(server,':');
            if (p) *p=0;
            edg_wlc_JobIdCreate(server,p?atoi(p+1):0,&jobid);
            *p=':';
            job = edg_wlc_JobIdUnparse(jobid);
            fprintf(stdout,"new jobid: %s\n",job);
        }
        else if ((errno = edg_wlc_JobIdParse(job,&jobid))) {
            perror(job);
            exit(1);
        }

        /* register */
        edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,EDG_WLL_SOURCE_USER_INTERFACE);
        // edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,edg_wll_StringToSource(src));

        if (lbproxy) {
            if (edg_wll_RegisterJobProxy(ctx,jobid,
                                         num_subjobs?EDG_WLL_REGJOB_COLLECTION:EDG_WLL_REGJOB_SIMPLE,
                                         "JDL: blabla", "NNNSSSS",
                                         num_subjobs,NULL,&subjobs))
            {
                char 	*et,*ed;
                edg_wll_Error(ctx,&et,&ed);
                fprintf(stderr,"edg_wll_RegisterJobProxy(%s): %s (%s)\n",job,et,ed);
                exit(1);
            }
        } else {
            if (edg_wll_RegisterJobSync(ctx,jobid,
                                        num_subjobs?EDG_WLL_REGJOB_COLLECTION:EDG_WLL_REGJOB_SIMPLE,
                                        "JDL: blabla", "NNNSSSS",
                                        num_subjobs,NULL,&subjobs))
            {
                char 	*et,*ed;
                edg_wll_Error(ctx,&et,&ed);
                fprintf(stderr,"edg_wll_RegisterJobSync(%s): %s (%s)\n",job,et,ed);
                exit(1);
            }
        }

        /* log events */
        while (!feof(f)) {
            edg_wll_LogLine logline;

            if (!fgets(buf,sizeof(buf),f)) break;
            if (strcmp(buf,"\n")) {
                // fprintf(stdout,"%d: %s\n",i,buf);
                asprintf(&logline,"DG.JOBID=\"%s\" %s",job,buf);
                if (lbproxy) {
                    if (edg_wll_DoLogEventServer(ctx,EDG_WLL_LOGFLAG_PROXY,logline)) {
                        char    *et,*ed;
                        edg_wll_Error(ctx,&et,&ed);
                        fprintf(stderr,"edg_wll_DoLogEventServer(): %s (%s)\n",et,ed);
                        exit(1);
                    }
                } else if (lbdirect) {
                    if (edg_wll_DoLogEventServer(ctx,EDG_WLL_LOGFLAG_DIRECT,logline)) {
                        char    *et,*ed;
                        edg_wll_Error(ctx,&et,&ed);
                        fprintf(stderr,"edg_wll_DoLogEventServer(): %s (%s)\n",et,ed);
                        exit(1);
                    }
                } else {
                    if (edg_wll_DoLogEvent(ctx,logline)) {
                        char    *et,*ed;
                        edg_wll_Error(ctx,&et,&ed);
                        fprintf(stderr,"edg_wll_DoLogEvent(): %s (%s)\n",et,ed);
                        exit(1);
                    }
                }

                if (logline) free(logline);
            }
        }
        rewind(f);
        if (job) free(job);
        job = NULL;

        /* seq. code */
        seq = edg_wll_GetSequenceCode(ctx);
        fprintf(stdout,"\n%s=\"%s\"\n",num_subjobs?"EDG_WL_COLLECTION_JOBID":"EDG_JOBID",job);
        fprintf(stdout,"EDG_WL_SEQUENCE=\"%s\"\n",seq);
        free(seq);

        if (num_subjobs) for (j=0; subjobs[j]; j++) {
                char	*job_s = edg_wlc_JobIdUnparse(subjobs[j]);
                fprintf(stdout,"EDG_WL_SUB_JOBID[%d]=\"%s\"\n",j,job_s);
                free(job_s);
            }

    } /* MAIN LOOP */

    fclose(f);
    edg_wll_FreeContext(ctx);

    return 0;
}
Beispiel #7
0
int main(int argc,char **argv) {

        /* VARIABLES DECLARATION */ 
	edg_wll_Context	ctx;
	struct tm	tm;
	time_t	from,to;
	int	i, err = 0;

        /* VARIABLES INITIALIZATION */ 
	edg_wll_QueryRec	cond[3];	/* [2] is terminator */
	edg_wll_Event	*events = NULL;

	edg_wll_InitContext(&ctx);

	if (argc != 3) usage(argv[0]);
	memset(&tm,0,sizeof tm);
	if (sscanf(argv[1],"%d-%d-%d:%d:%d:%d",
		&tm.tm_year,
		&tm.tm_mon,
		&tm.tm_mday,
		&tm.tm_hour,
		&tm.tm_min,
                &tm.tm_sec)!= 6) usage(argv[0]);

	tm.tm_mon--;
	tm.tm_year -= 1900;
	from = timegm(&tm);

	memset(&tm,0,sizeof tm);
	if (sscanf(argv[2],"%d-%d-%d:%d:%d:%d",
		&tm.tm_year,
		&tm.tm_mon,
		&tm.tm_mday,
		&tm.tm_hour,
		&tm.tm_min,
                &tm.tm_sec) != 6) usage(argv[0]);

	tm.tm_mon--;
	tm.tm_year -= 1900;
	to = timegm(&tm);
	memset(cond,0,sizeof cond);

        /* QUERY CONDITIONS INITIALIZATION: ALL JOBS DONE WITHIN TIME INTERVAL */
	cond[0].attr = EDG_WLL_QUERY_ATTR_TIME;
	cond[0].op = EDG_WLL_QUERY_OP_WITHIN;
	cond[0].value.t.tv_sec = from;
	cond[0].value2.t.tv_sec = to;

	cond[1].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE;
	cond[1].value.i = EDG_WLL_EVENT_DONE;
	
	if (edg_wll_QueryEventsProxy(ctx,NULL,cond,&events)) {
		char	*et,*ed;
        	et = ed = NULL;

		edg_wll_Error(ctx,&et,&ed);
		fprintf(stderr,"edg_wll_QueryEventsProxy: %s, %s\n",
			et,ed ? ed : "");

		free(et); free(ed);
		err = 1;
		goto cleanup;
	}

        /* SELECTION OF DONE FAILED-OR-OK JOBS */
//   printf("SELECTION OF DONE JOBS\n");
//   printf("OWNER\tJOBID\tEXITCODE\tTIMESTAMP\tFAILUREREASON\n");     
	for (i=0; events[i].type; i++) {
		edg_wll_Event	*e = events+i;
                if(e->done.status_code == EDG_WLL_DONE_OK) {
                        char    *job = glite_jobid_unparse(e->any.jobId);

                        printf("%s\t%s\t%s",
                                e->any.user,
                                job,
                                ctime(&e->done.timestamp.tv_sec)
                                //asctime(gmtime(&e->done.timestamp.tv_sec))
                                );
                        free(job);
                }

/*		if (e->done.status_code == EDG_WLL_DONE_FAILED) {
			char	*job = glite_jobid_unparse(e->any.jobId);                        
                        printf("%s\t%s\t%d\t%s\t%s\n",
                                e->any.user,
                                job,
                                e->done.status_code,
                                ctime(&e->done.timestamp.tv_sec),
                                e->done.reason
                                );
			free(job);
		} else if(e->done.status_code == EDG_WLL_DONE_OK) {
			char	*job = glite_jobid_unparse(e->any.jobId);

                        printf("%s\t%s\t%d\t%s\tNULL\n",
                                e->any.user,
                                job,
                                e->done.status_code,
                                ctime(&e->done.timestamp.tv_sec)                               
                                );
			free(job);}*/
	}
				
cleanup:
	if (events) {
		for (i=0; events[i].type; i++) edg_wll_FreeEvent(events+i);
		free(events); events = NULL;
	}

	edg_wll_FreeContext(ctx);

	return err;
}
Beispiel #8
0
int main(int argc, char *argv[])
{
	char			   *server, *jobid_s, *user;
	edg_wlc_JobId                   jobid = NULL;
	int					opt, err = 0;
	long 				i;
	int port = 0; 

	server = jobid_s = user = NULL;
	while ( (opt = getopt_long(argc, argv, "hs:p:j:u:c:n:v:", opts, NULL)) != EOF)
		switch (opt) {
		case 'h': usage(argv[0]); return 0;
		case 's': server = strdup(optarg); break;
		case 'p': port = atoi(optarg); break;
		case 'j': jobid_s = strdup(optarg); break;
		case 'u': user = strdup(optarg); break;
		case '?': usage(argv[0]); return 1;
		}

	if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; }

	/*variables*/
	edg_wll_Context		ctx;
	edg_wll_QueryRec	*jc[4];
	edg_wll_JobStat		*statesOut = NULL;
	edg_wlc_JobId		*jobsOut = NULL;
	/*end variables*/

	if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; }

	/*context*/
	edg_wll_InitContext(&ctx);
	
	edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server);
	if (port) edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, port);
	/*end context*/

	/*queryrec*/
	jc[0] = (edg_wll_QueryRec *) malloc(2*sizeof(edg_wll_QueryRec));
	jc[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER;
	jc[0][0].op = EDG_WLL_QUERY_OP_EQUAL;
	jc[0][0].value.c = NULL;
	jc[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF;

	jc[1] = (edg_wll_QueryRec *) malloc(2*sizeof(edg_wll_QueryRec));
	jc[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS;
	jc[1][0].op = EDG_WLL_QUERY_OP_EQUAL;
	jc[1][0].value.i = EDG_WLL_JOB_RUNNING;
	jc[1][1].attr = EDG_WLL_QUERY_ATTR_UNDEF;

	jc[2] = (edg_wll_QueryRec *) malloc(3*sizeof(edg_wll_QueryRec));
	jc[2][0].attr = EDG_WLL_QUERY_ATTR_DESTINATION;
	jc[2][0].op = EDG_WLL_QUERY_OP_EQUAL;
	jc[2][0].value.c = "XXX";
	jc[2][1].attr = EDG_WLL_QUERY_ATTR_DESTINATION;
	jc[2][1].op = EDG_WLL_QUERY_OP_EQUAL;
	jc[2][1].value.c = "YYY";
	jc[2][2].attr = EDG_WLL_QUERY_ATTR_UNDEF;

	jc[3] = NULL;
	/*end queryrec*/

	/*query*/
	err = edg_wll_QueryJobsExt(ctx, (const edg_wll_QueryRec **)jc, 
				   0, &jobsOut, &statesOut); 
	/*end query*/

	if ( err == E2BIG ) {
		fprintf(stderr,"Warning: only limited result returned!\n");
		return 0;
	} else if (err) {
		char	*et,*ed;
		
		edg_wll_Error(ctx,&et,&ed);
		fprintf(stderr,"%s: edg_wll_QueryJobs(): %s (%s)\n",argv[0],et,ed);

		free(et); free(ed);
	}

	/*printstates*/
	for (i = 0; statesOut[i].state; i++ ) {
		printf("jobId : %s\n", edg_wlc_JobIdUnparse(statesOut[i].jobId));
		printf("state : %s\n\n", edg_wll_StatToString(statesOut[i].state));
	}
	/*end printstates*/

	if ( jobsOut ) {
		for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]);
		free(jobsOut);
	}
	if ( statesOut ) {
		for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]);
		free(statesOut);
	}
	free(jc[0]); free(jc[1]); free(jc[2]);

	edg_wll_FreeContext(ctx);

	return err;
}
int
event_queue_send(struct event_queue *eq, struct queue_thread *me)
{
	OutputPlugin *output = (OutputPlugin*)eq->plugin_data;
	edg_wll_Context context;
	edg_wll_Event *notif_event;
	edg_wll_JobStat state_out;
	il_octet_string_t event;
	char *jobstat_char;
	int ret;

	assert(output != NULL);

	edg_wll_InitContext(&context);

	while(!event_queue_empty(eq)) {
	    struct server_msg *msg;
	    cms::Message *cms_msg = NULL;

	    if(event_queue_get(eq, me, &msg) == 0) {
		    break;
	    }

	    if(0 == msg->len) {
		    glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG,
				     "    not sending empty message at offset %ld for job %s",
				     msg->offset, msg->job_id_s);
		    if(event_store_commit(msg->es, msg->ev_len, 0, msg->generation) < 0) {
			    /* failure committing message, this is bad */
			    goto err;
		    }
		    event_queue_remove(eq, me);
		    continue;
	    }

	    glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
			     "    trying to deliver event at offset %ld for job %s",
			     msg->offset, msg->job_id_s);
	    
	    if(decode_il_msg(&event, msg->msg + 17) < 0) {
		    set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing notification event data");
		    goto err;
	    }
	    ret=edg_wll_ParseNotifEvent(context, event.data, &notif_event);
	    if(ret) {
		    set_error(IL_LBAPI, ret, "event_queue_send: error parsing notification event");
		    goto err;
	    }
	    jobstat_char = glite_lbu_UnescapeXML((const char *) notif_event->notification.jobstat);
	    if (jobstat_char == NULL) {
		    set_error(IL_LBAPI, EINVAL, "event_queue_send: error unescaping job status");
		    goto err;
	    }
	    if ( edg_wll_ParseJobStat(context, jobstat_char, strlen(jobstat_char), &state_out)) {
		    set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing job status");
		    fprintf(stderr, "Status string: %s\n", jobstat_char);
		    goto err;
	    }
	    
	    try {
		    cms_msg = output->createMessage(state_out);
		    
		    free(event.data); event.data = NULL;
		    edg_wll_FreeEvent(notif_event);
		    free(notif_event); notif_event = NULL;
		    edg_wll_FreeStatus(&state_out);
		    free(jobstat_char); jobstat_char = NULL;
		    
		    output->send(cms_msg); 
		    delete cms_msg;
		    if(event_store_commit(msg->es, msg->ev_len, 0, msg->generation) < 0) {
			    /* failure committing message, this is bad */
			    goto err;
		    }
		    glite_common_log(IL_LOG_CATEGORY, LOG_PRIORITY_DEBUG, 
				     "    event sent to %s", eq->dest_name);
		    
	    } catch(cms::CMSException &e) {
		    if(cms_msg) {
			    delete cms_msg;
		    }
		    me->timeout = TIMEOUT;
		    edg_wll_FreeContext(context);
		    set_error(IL_DL, 0, e.what());
		    return 0;
	    }
	    event_queue_remove(eq, me);
	    me->first_event_sent = 1;
	    eq->last_sent = time(NULL);
	}
	edg_wll_FreeContext(context);
	return 1;

err:
	if(event.data) {
		free(event.data);
	}
	if(notif_event) {
		edg_wll_FreeEvent(notif_event);
		free(notif_event);
	}
	if(jobstat_char) {
		free(jobstat_char);
	}
	edg_wll_FreeStatus(&state_out);

	return -1;
}
Beispiel #10
0
int main(int argc,char **argv) {
	edg_wll_Context	ctx;
	struct tm	tm;
	time_t	from,to;
	int	i, err = 0;

	edg_wll_QueryRec	cond[3],jcond[2];	/* [2] is terminator */
	edg_wll_Event	*events = NULL;

	if (edg_wll_InitContext(&ctx) != 0) {
		fprintf(stderr, "Couldn't create L&B context.\n");
		return 1;
	}

	if (argc != 3) usage(argv[0]);

	
	memset(&tm,0,sizeof tm);

	if (sscanf(argv[1],"%d-%d-%d:%d:%d",
		&tm.tm_year,
		&tm.tm_mon,
		&tm.tm_mday,
		&tm.tm_hour,
		&tm.tm_min) != 5) usage(argv[0]);

	tm.tm_mon--;
	tm.tm_year -= 1900;

	from = mktime(&tm);
	
	if (sscanf(argv[2],"%d-%d-%d:%d:%d",
		&tm.tm_year,
		&tm.tm_mon,
		&tm.tm_mday,
		&tm.tm_hour,
		&tm.tm_min) != 5) usage(argv[0]);

	tm.tm_mon--;
	tm.tm_year -= 1900;

	to = mktime(&tm);

	memset(jcond,0,sizeof jcond);

	jcond[0].attr = EDG_WLL_QUERY_ATTR_OWNER;
	jcond[0].op = EDG_WLL_QUERY_OP_UNEQUAL;
	jcond[0].value.c = "nonexistent";

	memset(cond,0,sizeof cond);
	cond[0].attr = EDG_WLL_QUERY_ATTR_TIME;
	cond[0].op = EDG_WLL_QUERY_OP_WITHIN;
	cond[0].value.t.tv_sec = from;
	cond[0].value2.t.tv_sec = to;

	cond[1].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE;
	cond[1].value.i = EDG_WLL_EVENT_DONE;
	
	if (edg_wll_QueryEvents(ctx,jcond,cond,&events)) {
		char	*et,*ed;
		et = ed = NULL;

		edg_wll_Error(ctx,&et,&ed);
		fprintf(stderr,"edg_wll_QueryEventsProxy: %s, %s\n",
			et,ed ? ed : "");

		free(et); free(ed);
		err = 1;
		goto cleanup;
	}

	for (i=0; events[i].type; i++) {
		edg_wll_Event	*e = events+i;

		if (e->done.status_code == EDG_WLL_DONE_FAILED) {
			char	*job = glite_jobid_unparse(e->any.jobId);

			printf("%s\t%s\t%s\t%s\n",
				job,
				ctime(&e->done.timestamp.tv_sec),
				e->done.host,
				e->done.reason
				);

			free(job);
		}
	}
				
cleanup:
	if (events) {
		for (i=0; events[i].type; i++) edg_wll_FreeEvent(events+i);
		free(events); events = NULL;
	}

	edg_wll_FreeContext(ctx);

	return err;
}
Beispiel #11
0
int
main(int argc, char *argv[])
{

	char 	*destname= NULL,*hostname=NULL,*testname = NULL,*filename = NULL;
	char	*event;
	int 	num_jobs = 1;
	int 	opt;
	int     skip = -1;
	edg_wll_Context ctx;
	enum {
		DEST_UNDEF = 0,
		DEST_LL,
		DEST_IL,
		DEST_PROXY,
		DEST_BKSERVER,
		DEST_DUMP,
	} dest = 0;
	struct timeval log_timeout = { tv_sec: 2, tv_usec: 0 };


	if (edg_wll_InitContext(&ctx) != 0) {
		fprintf(stderr, "Couldn't create L&B context.\n");
		return 1;
	}

	opterr = 0;

	while ((opt = getopt_long(argc,argv,"hd:t:f:m:n:Ns:P::p:",
		long_options, (int *) 0)) != EOF) {

		switch (opt) {
		case 'd': destname = (char *) strdup(optarg); break;
		case 't': testname = (char *) strdup(optarg); break;
		case 'f': filename = (char *) strdup(optarg); break;
		case 'm': hostname = (char *) strdup(optarg); break;
		case 'p': logfile_prefix = (char*) strdup(optarg); break;
		case 's': il_socket = (char*) strdup(optarg); break;
		case 'n': num_jobs = atoi(optarg); break;
		case 'P': skip = optarg ? atoi(optarg) : 0; break;
		case 'h': 
		default:
			usage(argv[0]); exit(0);
		}
	} 

	if(destname) {
		if(!strncasecmp(destname, "pr", 2)) 
			dest=DEST_PROXY;
		else if(!strncasecmp(destname, "lo", 2) || !strncasecmp(destname, "ll", 2))
			dest=DEST_LL;
		else if(!strncasecmp(destname, "in", 2) || !strncasecmp(destname, "il", 2))
			dest=DEST_IL;
		else if(!strncasecmp(destname, "bk", 2) || !strncasecmp(destname, "se", 2))
			dest=DEST_BKSERVER;
		else if(!strncasecmp(destname, "du", 2)) 
			dest=DEST_DUMP;
		else {
			fprintf(stderr,"%s: wrong destination\n",argv[0]);
			usage(argv[0]);
			exit(1);
		}
	} 

	if((dest == DEST_IL) && (il_socket == NULL)) 
		il_socket = DEFAULT_SOCKET;
	if((dest == DEST_PROXY) && il_socket) {
		char store_sock[256], serve_sock[256];
		sprintf(store_sock, "%s%s", il_socket, "store.sock");
		sprintf(serve_sock, "%s%s", il_socket, "serve.sock");
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, store_sock);
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, serve_sock);
	}

	if (num_jobs <= 0) {
		fprintf(stderr,"%s: wrong number of jobs\n",argv[0]);
		usage(argv[0]);
		exit(1);
	}

	if (!filename && destname) {
		fprintf(stderr,"%s: -f required\n",argv[0]);
		usage(argv[0]);
		exit(1);
	}

	if (glite_wll_perftest_init(hostname, NULL, testname, filename, num_jobs) < 0) {
		fprintf(stderr,"%s: glite_wll_perftest_init failed\n",argv[0]);
		exit(1);
	}

	if(dest) {
		char *jobid;
		int len;
		while ((len=glite_wll_perftest_produceEventString(&event, &jobid)) > 0) {
			switch(dest) {
			case DEST_PROXY:
				ctx->p_tmp_timeout = ctx->p_sync_timeout;
				if (edg_wll_DoLogEventServer(ctx,EDG_WLL_LOGFLAG_PROXY,event)) {
					char    *et,*ed;
					edg_wll_Error(ctx,&et,&ed);
					fprintf(stderr,"edg_wll_DoLogEventServer(): %s (%s)\n",et,ed);
					fprintf(stderr,"Event:\n%s\n", event);
					exit(1);
				}
				break;
				
			case DEST_LL:
#if defined(EVENTS_USER_PRESENT)
				/* erase DG.USER, will be added by LL */
				do {
					char *p = strstr(event, "DG.USER");

					if(p != NULL) {
						char *s = strchr(p+9, '"');
						if(s == NULL) {
							s = strstr(p+7, "DG.");
							if(s == NULL) {
								s = event + len - 1;
							}
						} else {
							while(*++s == ' ') ;
						}
						memmove(p, s, event + len + 1 - s);
					}
				} while(0);
#endif
				ctx->p_tmp_timeout = ctx->p_log_timeout;
				if (edg_wll_DoLogEvent(ctx,event)) {
					char    *et,*ed;
					edg_wll_Error(ctx,&et,&ed);
					fprintf(stderr,"edg_wll_DoLogEvent(): %s (%s)\n",et,ed);
					fprintf(stderr,"Event:\n%s\n", event);
					exit(1);
				}
				break;

			case DEST_BKSERVER:
				ctx->p_tmp_timeout = ctx->p_log_timeout;
				edg_wlc_JobIdParse(jobid, &ctx->p_jobid);
				if (edg_wll_DoLogEventServer(ctx,EDG_WLL_LOGFLAG_DIRECT,event)) {
					char    *et,*ed;
					edg_wll_Error(ctx,&et,&ed);
					fprintf(stderr,"edg_wll_DoLogEventServer(): %s (%s)\n",et,ed);
					fprintf(stderr,"Event:\n%s\n", event);
					exit(1);
				}
				break;

			case DEST_IL:
				ctx->p_tmp_timeout = log_timeout; /* ctx->p_log_timeout */;
				if (edg_wll_DoLogEventIl(ctx, event, jobid, len, skip)) {
					char    *et,*ed;
					edg_wll_Error(ctx,&et,&ed);
					fprintf(stderr,"edg_wll_DoLogEventIl(): %s (%s)\n",et,ed);
					fprintf(stderr,"Event:\n%s\n", event);
					exit(1);
				}
				break;

			case DEST_DUMP:
				printf("%s", event);
				break;

			default:
				break;
			}
			free(event);
		}
	} else {
		/* no destination - only print jobid's that would be used */
		char *jobid;

		while(jobid = glite_wll_perftest_produceJobId()) {
			fprintf(stdout, "%s\n", jobid);
		}
	}
	edg_wll_FreeContext(ctx);
	return 0;

}
Beispiel #12
0
int 
glite_wll_perftest_init(const char *host,
			const char *user,
			const char *testname,
			const char *filename, 
			int n)
{
	edg_wll_Context ctx;

	if (edg_wll_InitContext(&ctx) != 0) {
		fprintf(stderr, "edg_wll_InitContext() failed\n");
		return(-1);
	}

	if(trio_asprintf(&termination_string, EDG_WLL_FORMAT_USERTAG,
		    PERFTEST_END_TAG_NAME, PERFTEST_END_TAG_VALUE) < 0)
		return(-1);

	/* set parameters */
	if(user) 
		test_user = strdup(user);
	else {
		test_user = getenv("PERFTEST_USER");
		if(test_user == NULL) 
			test_user = "******";
	}
	if(testname)
		test_name = strdup(testname);
	else {
		test_name = getenv("PERFTEST_NAME");
		if(test_name == NULL)
			test_name = "unspecified";
	}
	if(host == NULL) {
		host = getenv("PERFTEST_HOST");
		if(host == NULL)
			host = "localhost";
	}
	{
		char *p;

		p = strrchr(host, ':');
  		if(p) 
			*p = 0;
		dest_host = strdup(host);
		if(p) {
			*p++ = ':';
			dest_port = atoi(p);
		} else 
			dest_port = GLITE_JOBID_DEFAULT_PORT;
	}

	/* reset event source */
	cur_event = cur_job = 0;
	njobs = n;

	/* if we are asked to read events in, read them */
	if(filename) {
		int fd;
		
		if((fd=open(filename, O_RDONLY)) < 0) {
			fprintf(stderr, "glite_wll_perftest_init: Could not open event file %s: %s",
				filename, strerror(errno));
			return(-1);
		}
		
		if((nevents=read_events(fd)) < 0)
			return(-1);

		close(fd);

		fprintf(stderr, "PERFTEST_JOB_SIZE=%d\n", nevents);
		fprintf(stderr, "PERFTEST_NUM_JOBS=%d\n", njobs);
		fprintf(stderr, "PERFTEST_NUM_SUBJOBS=%d\n", nsubjobs);
	}

	/* we suppose nsubjobs was filled in by read_events() */


	/* generate final_jobid */
	do {
		glite_jobid_t jobid;

		if(glite_wll_perftest_createJobId(dest_host,
						  dest_port,
						  test_user,
						  test_name,
						  n,
						  &jobid) != 0) {
			fprintf(stderr, "produceJobId: error creating jobid\n");
			return(-1);
		}
		if((final_jobid=edg_wlc_JobIdUnparse(jobid)) == NULL) {
			fprintf(stderr, "produceJobId: error unparsing jobid\n");
			return(-1);
		}
		glite_jobid_free(jobid);
	} while(0);

	/* generate jobids[0..njobs-1, 0..nsubjobs] */
	jobids = calloc(njobs*(nsubjobs + 1), sizeof(char*));
	if(jobids == NULL) {
		fprintf(stderr, "glite_wll_perftest_init: not enough memory for job id's\n");
		return(-1);
	}
        while (--n >= 0) {
		glite_jobid_t jobid;
		glite_jobid_t *subjobid;
		int i;

		if(glite_wll_perftest_createJobId(dest_host,
						  dest_port,
						  test_user,
						  test_name,
						  n,
						  &jobid) != 0) {
			fprintf(stderr, "produceJobId: error creating jobid\n");
			return(-1);
		}
		if((jobids[n*(nsubjobs+1)]=edg_wlc_JobIdUnparse(jobid)) == NULL) {
			fprintf(stderr, "produceJobId: error unparsing jobid\n");
			return(-1);
		}

		/* generate subjob ids */
		if(nsubjobs > 0) {
			if(edg_wll_GenerateSubjobIds(ctx, jobid, nsubjobs, test_name,
						     &subjobid) < 0) {
				fprintf(stderr, "produceJobId: error generating subjob ids\n");
				return -1;
			}
		}
		for(i = 1; i <= nsubjobs; i++) {
			if((jobids[n*(nsubjobs+1) + i] = edg_wlc_JobIdUnparse(subjobid[i-1])) == NULL) {
				fprintf(stderr, "produceJobId: error unparsing jobid\n");
				return(-1);
			}
			glite_jobid_free(subjobid[i-1]);
		}
		glite_jobid_free(jobid);
	}

			
	return(0);
}
Beispiel #13
0
int main() {
	int round, retval, i, j;
	char *query;
	edg_wll_QueryRec **conds;
	edg_wll_Context ctx;

	if (edg_wll_InitContext(&ctx) != 0) {
                fprintf(stderr, "Couldn't create L&B context.\n");
                return 1;
        }


	for (round = 0; 1 ;round++) {
		switch(round) {
			case 0:
				// Simple query
				asprintf(&query,"status=running");
				break;
			case 1:
				// ANDed query
				asprintf(&query,"status=running&owner=testowner");
				break;
			case 2:
				// ANDed and ORed query
				asprintf(&query,"status=running|=submitted&jobtype<>simple");
				break;
			case 3:
				// Bad attribute name
				asprintf(&query,"sXatus=running");
				break;
			case 4:
				// Bad attribute value
				asprintf(&query,"status=ruXning");
				break;
			case 5:
				// Query Empty
				query = strdup("");
				break;
			case 6:
				// No Operator
				query = strdup("status=running&owner");
				break;
			case 7:
				// No Operator in ORed condition
				query = strdup("status=running&owner=I|You");
				break;
			case 8:
				// No rval
				query = strdup("status=running&owner=");
				break;
			case 9:
				// Multiple operators
				query = strdup("status=running=submitted");
				break;
			case 10:
				// Empty AND section
				query = strdup("status=running&");
				break;
			case 11:
				// Empty AND section inbetween
				asprintf(&query,"status=running&&owner=testowner");
				break;
			case 12:
				// Empty OR section inbetween
				asprintf(&query,"status=running|||=submitted&jobtype<>simple");
				break;
			case 13:
				// Confused operator
				asprintf(&query,"status==running");
				break;

			default:
				goto done;
		}

		retval = edg_wll_ParseQueryConditions(ctx, query, &conds);

		//fprintf(stderr, "%s\n", ctx->errDesc);

		switch(round) {
			case 0:
			case 10:
				assert(conds[0] != NULL);
				assert(conds[0][0].attr == EDG_WLL_QUERY_ATTR_STATUS);
				assert(conds[0][0].op == EDG_WLL_QUERY_OP_EQUAL);
				assert(conds[0][0].value.i == EDG_WLL_JOB_RUNNING);
				assert(conds[0][1].attr == EDG_WLL_QUERY_ATTR_UNDEF);
				assert(conds[1] == NULL);
				assert(retval == 0);
				assert(ctx->errDesc == NULL);
				break;
			case 1:
			case 11:
				assert(retval == 0);
				assert(conds[0] != NULL);
				assert(conds[0][0].attr == EDG_WLL_QUERY_ATTR_STATUS);
				assert(conds[0][0].op == EDG_WLL_QUERY_OP_EQUAL);
				assert(conds[0][0].value.i == EDG_WLL_JOB_RUNNING);
				assert(conds[0][1].attr == EDG_WLL_QUERY_ATTR_UNDEF);
				assert(conds[1] != NULL);
				assert(conds[1][0].attr == EDG_WLL_QUERY_ATTR_OWNER);
				assert(conds[1][0].op == EDG_WLL_QUERY_OP_EQUAL);
				assert(!strcmp(conds[1][0].value.c, "testowner"));
				assert(conds[1][1].attr == EDG_WLL_QUERY_ATTR_UNDEF);
				assert(conds[2] == NULL);
				assert(retval == 0);
				assert(ctx->errDesc == NULL);
				break;
			case 2:
			case 12:
				assert(retval == 0);
				assert(conds[0] != NULL);
				assert(conds[0][0].attr == EDG_WLL_QUERY_ATTR_STATUS);
				assert(conds[0][0].op == EDG_WLL_QUERY_OP_EQUAL);
				assert(conds[0][0].value.i == EDG_WLL_JOB_RUNNING);
				assert(conds[0][1].attr == EDG_WLL_QUERY_ATTR_STATUS);
				assert(conds[0][1].op == EDG_WLL_QUERY_OP_EQUAL);
				assert(conds[0][1].value.i == EDG_WLL_JOB_SUBMITTED);
				assert(conds[0][2].attr == EDG_WLL_QUERY_ATTR_UNDEF);
				assert(conds[1] != NULL);
				assert(conds[1][0].attr == EDG_WLL_QUERY_ATTR_JOB_TYPE);
				assert(conds[1][0].op == EDG_WLL_QUERY_OP_UNEQUAL);
				assert(conds[1][0].value.i == EDG_WLL_STAT_SIMPLE);
				assert(conds[1][1].attr == EDG_WLL_QUERY_ATTR_UNDEF);
				assert(conds[2] == NULL);
				assert(retval == 0);
				assert(ctx->errDesc == NULL);
				break;
			case 3:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "Unknown argument"));
				break;
			case 4:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "Unknown job state"));
				break;
			case 5:
				assert(retval == 0);
				assert(conds == NULL);
				break;
			case 6:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "Missing operator in condition"));
				break;
			case 7:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "Missing operator before"));
				break;
			case 8:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "No value given for attribute"));
				break;
			case 9:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "Unknown job state"));
				break;
			case 13:
				assert(retval == EINVAL);
				assert(strstr(ctx->errDesc, "Unknown operator"));
				break;
		}

		edg_wll_ResetError(ctx);
		free(query); query=NULL;
                if (conds) {
                        for (j = 0; conds[j]; j++) {
                                for (i = 0 ; (conds[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
                                        edg_wll_QueryRecFree(&conds[j][i]);
                                free(conds[j]);
                        }
                        free(conds); conds = NULL;
                }
	}
	


done:
	edg_wll_FreeContext(ctx);
	return 0;
}
double lb_statistics(std::string const& queue_id, stats_t mode, int seconds)
{
  std::string lbserver_fqdn(
    glite::wms::common::configuration::Configuration::instance()->wp()
      ->lbserver().front()
  );
  std::string lbserver_host;
  int lbserver_port = 9000;
  static boost::regex const regex("(.*):([[:digit:]]*).*");
  boost::smatch pieces;
  if (boost::regex_match(lbserver_fqdn, pieces, regex)) {
    lbserver_host.assign(pieces[1].first, pieces[1].second);
    lbserver_port = boost::lexical_cast<int>(
      std::string().assign(pieces[2].first, pieces[2].second)
    );
  }
  std::string lbserver;
  if (lbserver_host.empty()) {
    lbserver = lbserver_fqdn;
  } else {
    lbserver = lbserver_host;
  }

  edg_wll_Context ctx;
  edg_wll_InitContext(&ctx);
  edg_wll_SetParam(
    ctx,
    EDG_WLL_PARAM_QUERY_SERVER,
    lbserver.c_str()
  );
  edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, lbserver_port);

  edg_wll_QueryRec group[2];
  group[0].attr = EDG_WLL_QUERY_ATTR_DESTINATION;
  group[0].op = EDG_WLL_QUERY_OP_EQUAL;
  group[0].value.c = const_cast<char*>(queue_id.c_str());
    
  group[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
    
  time_t now(::time(0));
  time_t to(now);
  time_t from(now - seconds);
  float* durations = 0;
  float* dispersions = 0;
  char** groups = 0;
  int from_res, to_res;
  if (!edg_wll_StateDurationsFromTo(
      ctx,
      group,
      EDG_WLL_JOB_SUBMITTED, // TODO transition SCHEDULED -> RUNNING not implemented yet, lb server side
      EDG_WLL_JOB_RUNNING,
      0,
      &from,
      &to,
      &durations,
      &dispersions,
      &groups,
      &from_res,
      &to_res)
  ) {
    if (mode == avg) {
      return durations[0];
    } else {
      return dispersions[0];
    }
  }
  return 0.0;
}
int main(int argc,char **argv) {

        /* VARIABLES DECLARATION */ 
	edg_wll_Context	ctx;
	struct tm	tm;
	time_t	from,to;
	int	i, err = 0;

        /* VARIABLES INITIALIZATION */ 
	edg_wll_QueryRec	cond[4];	/* [3] is terminator */
	edg_wll_Event	*events = NULL;

	edg_wll_InitContext(&ctx);

	if (argc != 3) usage(argv[0]);

	
	memset(&tm,0,sizeof tm);

	if (sscanf(argv[1],"%d-%d-%d:%d:%d:%d",
		&tm.tm_year,
		&tm.tm_mon,
		&tm.tm_mday,
		&tm.tm_hour,
		&tm.tm_min,
                &tm.tm_sec)!= 6) usage(argv[0]);

	tm.tm_mon--;
	tm.tm_year -= 1900;

	from = timegm(&tm);
        memset(&tm,0,sizeof tm);
	
	if (sscanf(argv[2],"%d-%d-%d:%d:%d:%d",
		&tm.tm_year,
		&tm.tm_mon,
		&tm.tm_mday,
		&tm.tm_hour,
		&tm.tm_min,
                &tm.tm_sec) != 6) usage(argv[0]);

	tm.tm_mon--;
	tm.tm_year -= 1900;

	to = timegm(&tm);

	memset(cond,0,sizeof cond);

        /* QUERY CONDITIONS INITIALIZATION: ALL JOBS DONE WITHIN TIME INTERVAL */
	cond[0].attr = EDG_WLL_QUERY_ATTR_TIME;
	cond[0].op = EDG_WLL_QUERY_OP_WITHIN;
	cond[0].value.t.tv_sec = from;
	cond[0].value2.t.tv_sec = to;

	cond[1].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE;
	cond[1].value.i = EDG_WLL_EVENT_TRANSFER;

        cond[2].attr =  EDG_WLL_QUERY_ATTR_SOURCE;
        cond[2].value.i = EDG_WLL_SOURCE_JOB_SUBMISSION;
	
	if (edg_wll_QueryEventsProxy(ctx,NULL,cond,&events)) {
		char	*et,*ed;
        	et = ed = NULL;

		edg_wll_Error(ctx,&et,&ed);
		fprintf(stderr,"edg_wll_QueryEventsProxy: %s, %s\n",
			et,ed ? ed : "");

		free(et); free(ed);
		err = 1;
		goto cleanup;
	}
//   printf("JOBS TRANSFERED TO CONDOR\n");
//   printf("OWNER\tJOBID\tSOURCE\tQUEUE\tTIMESTAMP\tRESULT\n");
	for (i=0; events[i].type; i++) {
		edg_wll_Event	*e = events+i;

		if (e->transfer.result == 2) {
			char	*job = glite_jobid_unparse(e->any.jobId);
                        printf("%s\t%s\t%s",
                                e->any.user,
                                job,
                                ctime(&e->transfer.timestamp.tv_sec)
                                );

			free(job);
		}
	}
				
cleanup:
	if (events) {
		for (i=0; events[i].type; i++) edg_wll_FreeEvent(events+i);
		free(events); events = NULL;
	}

	edg_wll_FreeContext(ctx);

	return err;
}
Beispiel #16
0
int
event_queue_send(struct event_queue *eq)
{
	OutputPlugin *output = (OutputPlugin*)eq->plugin_data;
	edg_wll_Context context;
	edg_wll_Event *notif_event;
    edg_wll_JobStat *state_out;
    il_octet_string_t event;
    char *jobstat_char;
	int ret;

	assert(output != NULL);

	edg_wll_InitContext(&context);

	while(!event_queue_empty(eq)) {
	    struct server_msg *msg;
	    cms::TextMessage *cms_msg;
	    char *s;
	    unsigned int i;
	    std::string val;

	    if(event_queue_get(eq, &msg) < 0) {
	    	goto err;
	    }

	    try {
	    	if(decode_il_msg(&event, msg->msg) < 0) {
	    		set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing notification event data");
	    		goto err;
	    	}
	    	ret=edg_wll_ParseNotifEvent(context, event.data, &notif_event);
	    	if(ret) {
	    		set_error(IL_LBAPI, ret, "event_queue_send: error parsing notification event");
	    		goto err;
	    	}
	        jobstat_char = glite_lbu_UnescapeXML((const char *) notif_event->notification.jobstat);
	        if (jobstat_char == NULL) {
	            set_error(IL_LBAPI, EINVAL, "event_queue_send: error unescaping job status");
	            goto err;
	        }
	        if ( edg_wll_ParseJobStat(context, jobstat_char, strlen(jobstat_char), state_out)) {
	        	set_error(IL_LBAPI, EINVAL, "event_queue_send: error parsing job status");
	        	goto err;
	        }


	    	cms_msg = output->session->createTextMessage();
	    	/* ownerDn */
	    	val.assign(state_out->owner);
	    	cms_msg->setStringProperty("ownerDn", val);
	    	/* voname */
	    	s = edg_wll_JDLField(state_out,"VirtualOrganisation");
	    	val.assign(s);
	    	free(s);
	    	cms_msg->setStringProperty("voname", val);
	    	/* bkHost */
	    	glite_jobid_getServerParts(state_out->jobId, &s, &i);
	    	val.assign(s);
	    	free(s);
	    	cms_msg->setStringProperty("bkHost", val);
	    	/* networkServer */
	    	/* TODO: XXX cut out hostname */
	    	val.assign(state_out->network_server);
	    	cms_msg->setStringProperty("networkHost", val);
	    	timeval2str(&state_out->lastUpdateTime, &s);
	    	val.assign(s);
	    	if(s) free(s);
	    	cms_msg->setStringProperty("lastUpdateTime", val);
	    	/* stateName */
	    	s = edg_wll_StatToString(state_out->state);
	    	val.assign(s);
	    	if(s) free(s);
	    	cms_msg->setStringProperty("stateName", val);
	    	timeval2str(&state_out->stateEnterTime, &s);
	    	val.assign(s);
	    	if(s) free(s);
	    	cms_msg->setStringProperty("stateStartTime", val);
	    	/* condorId */
	    	val.assign(state_out->condorId);
	    	cms_msg->setStringProperty("condorId", val);
	    	/* destSite */
	    	val.assign(state_out->destination);
	    	cms_msg->setStringProperty("destSite", val);
	    	/* exitCode */
	    	cms_msg->setIntProperty("exitCode", state_out->exit_code);
	    	/* doneCode */
	    	cms_msg->setIntProperty("doneCode", state_out->done_code);
	    	/* statusReason */
	    	val.assign(state_out->reason);
	    	cms_msg->setStringProperty("statusReason", val);

	    	free(event.data);
	    	edg_wll_FreeEvent(notif_event);
	    	free(notif_event);
	    	edg_wll_FreeStatus(state_out);
	    	free(state_out);
	    	free(jobstat_char);
	    } catch(cms::CMSException &e) {
	    	goto err;
	    }

	    try {
	    	output->send(cms_msg);
		    delete cms_msg;
	    	if(event_store_commit(msg->es, msg->ev_len, queue_list_is_log(eq), msg->generation) < 0) {
	    		/* failure committing message, this is bad */
	    		goto err;
	    	}
	        event_queue_remove(eq);
	        eq->first_event_sent = 1;
	    } catch(cms::CMSException &e) {
		    delete cms_msg;
	    	output->cleanup();
	    	eq->timeout = TIMEOUT;
	    	edg_wll_FreeContext(context);
	    	return 0;
	    }
	}
	edg_wll_FreeContext(context);
	return 1;

err:
	if(event.data) {
		free(event.data);
	}
	if(notif_event) {
    	edg_wll_FreeEvent(notif_event);
    	free(notif_event);
	}
	if(jobstat_char) {
		free(jobstat_char);
	}
	if(state_out) {
		edg_wll_FreeStatus(state_out);
		free(state_out);
	}
	return -1;
}
Beispiel #17
0
int main(int argc, char *argv[])
{
	char			   *server, *jobid_s, *user;
	int					opt, err = 0;
	edg_wlc_JobId                   jobid = NULL;
	long 				i;
	int port = 0;


	server = jobid_s = NULL;
	while ( (opt = getopt_long(argc, argv, "hs:p:j:u:c:n:v:", opts, NULL)) != EOF)
		switch (opt) {
		case 'h': usage(argv[0]); return 0;
		case 's': server = strdup(optarg); break;
		case 'p': port = atoi(optarg); break;
		case 'j': jobid_s = strdup(optarg); break;
		case 'u': user = strdup(optarg); break;
		case '?': usage(argv[0]); return 1;
		}

	if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; }

	/*variables*/
	edg_wll_Context     ctx;
	edg_wll_Event      *eventsOut;
	edg_wll_QueryRec    jc[2];
	edg_wll_QueryRec    ec[2];
	/*end variables*/

	if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; }

	/*context*/
	edg_wll_InitContext(&ctx);
	
	edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server);
	if (port) edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, port);
	/*end context*/

	/*queryrec*/
	jc[0].attr = EDG_WLL_QUERY_ATTR_USERTAG;
	jc[0].op = EDG_WLL_QUERY_OP_EQUAL;
	jc[0].attr_id.tag = "color";
	jc[0].value.c = "red";
	jc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
	ec[0].attr = EDG_WLL_QUERY_ATTR_USERTAG;
	ec[0].op = EDG_WLL_QUERY_OP_EQUAL;
	ec[0].attr_id.tag = "color";
	ec[0].value.c = "green";
	ec[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
	/*end queryrec*/

	/*query*/
	err = edg_wll_QueryEvents(ctx, jc, ec, &eventsOut); 
	/*end query*/

	if ( err == E2BIG ) {
		fprintf(stderr,"Warning: only limited result returned!\n");
		return 0;
	} else if (err) {
		char	*et,*ed;
		
		edg_wll_Error(ctx,&et,&ed);
		fprintf(stderr,"%s: edg_wll_QueryEvents(): %s (%s)\n",argv[0],et,ed);

		free(et); free(ed);
	}

	if ( err == ENOENT ) return err;

	/*printevents*/
	for (i = 0; eventsOut && (eventsOut[i].type); i++ ) {
		//printf("jobId : %s\n", edg_wlc_JobIdUnparse(eventsOut[i].jobId));
		printf("event : %s\n\n", edg_wll_EventToString(eventsOut[i].type));
	}
	/*end printevents*/

	if ( eventsOut ) {
		for (i=0; &(eventsOut[i]); i++) edg_wll_FreeEvent(&(eventsOut[i]));
		free(eventsOut);
	}

	edg_wll_FreeContext(ctx);

	return err;
}
Beispiel #18
0
int main(int argc,char *argv[])
{
	edg_wll_Context			ctx;
	edg_wll_QueryResults	rslts		= EDG_WLL_QUERYRES_UNDEF;
	edg_wll_QueryRec	  **jc			= NULL,
						  **ec			= NULL;
	edg_wll_JobStat		   *statesOut	= NULL;
	edg_wlc_JobId		   *jobsOut		= NULL;
	edg_wll_Event		   *eventsOut	= NULL;
	char				   *fname		= NULL,
						   *server		= NULL,
						   *proxy_sock	= NULL,
						   *s;
	int						result		= 0,
							jobsLimit	= 0,
							stdisp		= 0,
							eventsLimit	= 0,
							resultsLimit	= 0,
							i, j, ret,
							errCode,
							flags		= 0;

	myname	= argv[0];
	ret		= 0;
	do {
		switch ( getopt(argc,argv,"hvsePp:i:m:r:J:E:CSNR:") ) {
		case 'h': usage();  exit(0);
		case '?': usage(); exit(EINVAL);
		case 'v': verbose = 1; break;
		case 'i': fname = strdup(optarg); break;
		case 'm': server = strdup(optarg); break;
		case 's': stdisp = 1; break;
		case 'e': query_jobs = 0; break;
		case 'P': query_lbproxy = 1; break;
		case 'p': proxy_sock = strdup(optarg); break;
		case 'r':
			if ( !strcasecmp(optarg, "limited") ) rslts = EDG_WLL_QUERYRES_LIMITED;
			else if ( !strcasecmp(optarg, "none") ) rslts = EDG_WLL_QUERYRES_NONE;
			else if ( !strcasecmp(optarg, "all") ) rslts = EDG_WLL_QUERYRES_ALL;
			else { usage(); exit(EINVAL); }
			break;
		case 'J': jobsLimit = atoi(optarg); break;
		case 'E': eventsLimit = atoi(optarg); break;
		case 'R': resultsLimit = atoi(optarg); break;
		case 'S': flags = flags | EDG_WLL_STAT_CHILDSTAT; break;
		case 'C': flags = flags | EDG_WLL_STAT_CLASSADS; break;
		case 'N': flags = flags | 1024; break; //crude, I know
		case -1: ret = 1; break;
		}
	} while ( !ret );

	if ( edg_wll_InitContext(&ctx) ) {
		if ( verbose ) fprintf(stderr,"%s: cannot initialize edg_wll_Context\n",myname);
		exit(1);
	}

	if ( jobsLimit > 0 ) {
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_JOBS_LIMIT, jobsLimit);
		if ( verbose ) printf("Soft query limit for jobs: %d\n", jobsLimit);
	}
	else if ( verbose ) printf("Soft query limit for jobs not set\n");

	if ( resultsLimit > 0 ) {
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, resultsLimit);
		if ( verbose ) printf("Results limit for jobs: %d\n", resultsLimit);
	}
	else if ( verbose ) printf("Results limit for jobs not set\n");

	if ( query_events ) {
		if ( eventsLimit > 0 ) {
			edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_EVENTS_LIMIT, eventsLimit);
			if ( verbose ) printf("Soft query limit for events: %d\n", eventsLimit);
		}
		else if ( verbose ) printf("Soft query limit for events not set\n");
	}

	if ( rslts != EDG_WLL_QUERYRES_UNDEF )
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, rslts);
	else
		edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &rslts);

	if ( verbose ) printf("When any limit overflows, the returned result set is: %s\n",
							rslts==EDG_WLL_QUERYRES_LIMITED? "limited":
							(rslts==EDG_WLL_QUERYRES_ALL? "unlimited": "empty"));
	
	if ( server ) {
		char *p = strchr(server, ':');
		if ( p ) {
			edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, atoi(p+1));
			*p = 0;
		}
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server);
		free(server);
	}

	if ( proxy_sock ) {
		edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, proxy_sock);
		free(proxy_sock);
	}

	if ( fname ) {
		fin = fopen(fname, "r");
		if ( !fin ) {
			if ( verbose ) fprintf(stderr, "Can't open given input file %s. Using stdin.\n", fname);
			fin = stdin;
		}
		free(fname);
	} else {
		if ( verbose ) fprintf(stderr, "No input file given. Using stdin.\n");
		fin = stdin;
	}

	jobsOut		= NULL;
	statesOut	= NULL;
	eventsOut	= NULL;


	do
	{
		if ( verbose && (fin == stdin) ) printf("Enter job conditions:\n");
		
		ret = cond_parse(&jc, 1);
		if ( ret == PQRV_ERR ) { result = 1; goto cleanup; }
		if ( query_events && (ret != PQRV_EOF) ) {
			if ( verbose && (fin == stdin) ) printf("Enter event conditions:\n");
			ret = cond_parse(&ec, 0);
			if ( ret == PQRV_ERR ) { result = 1; goto cleanup; }
		}

		if ( (ret == PQRV_EOF) && !jc && (query_jobs || (query_events && !ec)) ) break;

		if ( verbose ) {
			printf("job conditions list: ");
			printconds(jc);
			if ( query_events ) { printf("event condition list: "); printconds(ec); }
		}

		if ( query_jobs ) {
			if ( query_bkserver ) 
				errCode = edg_wll_QueryJobsExt(ctx,
								(const edg_wll_QueryRec **) jc,
								flags, &jobsOut, stdisp? &statesOut: NULL);
			else
				errCode = edg_wll_QueryJobsExtProxy(ctx,
								(const edg_wll_QueryRec **) jc,
								flags, &jobsOut, stdisp? &statesOut: NULL);
		} else {
			if ( query_bkserver )
				errCode = edg_wll_QueryEventsExt(ctx,
								(const edg_wll_QueryRec **) jc,
								(const edg_wll_QueryRec **) ec,
								&eventsOut);
			else
				errCode = edg_wll_QueryEventsExtProxy(ctx,
								(const edg_wll_QueryRec **) jc,
								(const edg_wll_QueryRec **) ec,
								&eventsOut);
		}

		if ( errCode ) {
			dgerr(ctx, NULL);
			if ( (errCode != EPERM) && (errCode != E2BIG) ) goto cycle_cleanup;
        } else if ( verbose ) {
			if ( query_jobs ) printf("Matched jobs: ");
			else printf("Matched events: ");
		}

		if ( verbose ) {
			if ( (query_jobs && jobsOut && jobsOut[0]) ||
				 (query_events && eventsOut && eventsOut[0].type) )
				putchar('\n');
			else printf("No one matches\n");
		}

		if ( query_jobs && jobsOut && !stdisp ) {
			for ( i = 0; jobsOut[i]; i++ ) {
				s = edg_wlc_JobIdUnparse(jobsOut[i]);
				printf("jobId: %s\n", edg_wlc_JobIdUnparse(jobsOut[i]));
				free(s);
				edg_wlc_JobIdFree(jobsOut[i]);
			}
			free(jobsOut);
			jobsOut = NULL;
		}
		if ( query_jobs && statesOut ) {
			if ( stdisp ) for ( i = 0; statesOut[i].state; i++ ) printstat(statesOut[i]);
			for ( i = 0; statesOut[i].state; i++ ) edg_wll_FreeStatus(&statesOut[i]);
			free(statesOut);
			statesOut = NULL;
		}
		if ( query_events && eventsOut ) {
			for ( i = 0; eventsOut[i].type; i++ ) {
				s = edg_wlc_JobIdUnparse(eventsOut[i].any.jobId);
				printf("event: %-11s (jobid %s)\n", edg_wll_EventToString(eventsOut[i].type), s);
				free(s);
			}
			free(eventsOut);
			eventsOut = NULL;
		}

cycle_cleanup:
		if ( jc ) {
			for ( i = 0; jc[i]; i++ ) {
				for ( j = 0; jc[i][j].attr; j++ ) free_QueryRec(&jc[i][j]);
				free(jc[i]);
			}
			free(jc);
		}

		if ( ec ) {
			for ( i = 0; ec[i]; i++ ) {
				for ( j = 0; ec[i][j].attr; j++ ) free_QueryRec(&ec[i][j]);
				free(ec[i]);
			}
			free(ec);
		}
	} while ( ret != PQRV_EOF );

cleanup:
	if ( fin != stdin ) fclose(fin);
	edg_wll_FreeContext(ctx);

	return result;
}