void process_command ()
{ char action;
  char fname[100];
  int pid, time, ret;

  printf ("command> ");
  scanf ("%c", &action);
  while (action != 'T')
  { switch (action)
    { case 's':   // submit
        scanf ("%s", &fname);
        if (Debug) printf ("File name: %s is submitted\n", fname);
        submit_process (fname);
        break;
      case 'x':  // execute
        execute_process ();
        break;
      case 'r':  // dump register
        dump_registers ();
        break;
      case 'q':  // dump ready queue and list of processes completed IO
        dump_ready_queue ();
        dump_doneWait_list ();
        break;
      case 'p':   // dump PCB
        printf ("PCB Dump Starts: Checks from 0 to %d\n", currentPid);
        for (pid=1; pid<currentPid; pid++)
          if (PCB[pid] != NULL) dump_PCB (pid);
        break;
      case 'e':   // dump events in timer
        dump_events ();
        break;
      case 'm':   // dump Memory
        for (pid=1; pid<currentPid; pid++)
          if (PCB[pid] != NULL) dump_memory (pid);
        break;
      case 'w':   // dump Swap Space
         for (pid=1; pid<currentPid; pid++)
            if (PCB[pid] != NULL) dump_swap_memory (pid);
        break;
      case 'l':   // dump Spool
        for (pid=1; pid<currentPid; pid++)
          if (PCB[pid] != NULL) dump_spool (pid);
        break;
      case 'T':  // Terminate, do nothing, terminate in while loop
        break;
      default: 
        printf ("Incorrect command!!!\n");
    }
    printf ("\ncommand> ");
    scanf ("\n%c", &action);
    if (Debug) printf ("Next command is %c\n", action);
  }
}
Example #2
0
int check(int len, char *event_set, int exp_len, char *etalon_event_set) {

	if ((exp_len < 0) || (len < 0)){
		fail("Error in preparing event sets.");
		return -1;
	}
	if (len < exp_len) {
		fail("Events are lost. Read: %d, Expected: %d", len, exp_len);
		test_msg("expected events\n");
		dump_events(etalon_event_set, exp_len);
		test_msg("real events\n");
		dump_events(event_set, len);
		return -1;
	}
	if (errors(exp_len, len, etalon_event_set, event_set) == 0) {
		pass();
		return 0;
	}
	return -1;
}
Example #3
0
int dump_log(const char *filename)
{
    int fd = open(filename, O_RDONLY);

    if (fd < 0)
        LIBERROR("cannot open %s", filename);

    size_t len = lseek(fd, 0, SEEK_END);
    char *buffer = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);

    if (buffer == MAP_FAILED) {
        close(fd);
        LIBERROR("cannot mmap %s", filename);
    }

    int ret = dump_events(buffer, len);

    munmap(buffer, len);
    close(fd);
    return ret;
}
Example #4
0
int purge_one(edg_wll_Context ctx,edg_wll_JobStat *stat,int dump, int purge, int purge_from_proxy_only)
{
	char	*dbjob = NULL;
	char	*stmt = NULL;
	glite_lbu_Statement	q = NULL;
	int		ret,dumped = 0;
	char	*res[10];
	char	*prefix = NULL, *suffix = NULL, *root = NULL;
	char	*prefix_id = NULL, *suffix_id = NULL;
	int	sql_retval;
	glite_jobid_const_t job = stat->jobId;
	edg_wll_JobStat new_stat;

	edg_wll_ResetError(ctx);
	if ( !purge && dump < 0 ) return 0;

	do {

        	if (edg_wll_Transaction(ctx)) goto err;

		switch (edg_wll_jobMembership(ctx, job)) {
			case DB_PROXY_JOB:
				if (!ctx->isProxy) {
					/* should not happen */
					goto commit;
				}
				/* continue */
				break;
			case DB_SERVER_JOB:
				if (purge_from_proxy_only) {
					/* no action needed */
					goto commit;
				}
				if (ctx->isProxy) {
					/* should not happen */
					goto commit;
				}
				/* continue */
				break;
			case DB_PROXY_JOB+DB_SERVER_JOB:
				if (ctx->isProxy) {
					purge = 0;
					if (unset_proxy_flag(ctx, job) < 0) {
						goto rollback;
					}
				}
				else {
					purge = 0;
					/* if server&proxy DB is shared ... */
					if (is_job_local(ctx,job) && purge_from_proxy_only) {
						if (unset_proxy_flag(ctx, job) < 0) {
							goto rollback;
						}
					}
					else {
						if (unset_server_flag(ctx, job) < 0) {
							goto rollback;
						}
					}
				}
				break;
			case 0:
				// Zombie job (server=0, proxy=0)? should not happen;
				// clear it to keep DB healthy
				break;
			default:
				goto rollback;
				break;
		}

		dbjob = glite_jobid_getUnique(job);	/* XXX: strict jobid already checked */


		if ( purge )
		{
			enum edg_wll_StatJobtype jobtype = get_job_type(ctx, job);

			// get job prefix/suffix before its state is deleted
			if ( jobtype == EDG_WLL_NUMBER_OF_JOBTYPES) goto rollback;
			if (get_jobid_suffix(ctx, job, jobtype, &root, &suffix)
			 || get_jobid_prefix(ctx, job, jobtype, &prefix)) {
				glite_common_log(LOG_CATEGORY_CONTROL, 
					LOG_PRIORITY_WARN, 
					"[%d] unknown job type %d of job %s", 
					getpid(), jobtype, dbjob);
				edg_wll_ResetError(ctx);
			}

			// notifications
			memcpy(&new_stat, stat, sizeof new_stat);
			new_stat.state = EDG_WLL_JOB_PURGED;
			edg_wll_NotifMatch(ctx, stat, &new_stat);
		}

		if ( purge )
		{
			edg_wll_jobsconnection_purgeall(ctx, job);
		}

		if ( purge )
		{
			trio_asprintf(&stmt,"delete from jobs where jobid = '%|Ss'",dbjob);
			glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);
			if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback;
			free(stmt); stmt = NULL;

			trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob);
			glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);
			if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; 
			free(stmt); stmt = NULL;

			trio_asprintf(&stmt,"delete from status_tags where jobid = '%|Ss'",dbjob);
			glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);
			if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback;
			free(stmt); stmt = NULL;
		}

		if ( purge && prefix && suffix )
		{
			/* Store zombie prefix */
		
			// See if that prefix is already stored in the database	
			trio_asprintf(&stmt,"select prefix_id from zombie_prefixes where prefix = '%|Ss'", prefix);
			glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

			sql_retval = edg_wll_ExecSQL(ctx,stmt,&q);
			free(stmt); stmt = NULL;

			if (sql_retval < 0) goto rollback;

			if (sql_retval == 0) { //prefix does not exist yet
				glite_lbu_FreeStmt(&q);

				trio_asprintf(&stmt,"insert into zombie_prefixes (prefix) VALUES ('%|Ss')", prefix);
				glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

				if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback;

				free(stmt); stmt = NULL;
				glite_lbu_FreeStmt(&q);

				// The record should exist now, however we need to look up the prefix_id 
				trio_asprintf(&stmt,"select prefix_id from zombie_prefixes where prefix = '%|Ss'", prefix);
				glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

				if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback;
				free(stmt); stmt = NULL;
			}
			ret = edg_wll_FetchRow(ctx,q, 1, NULL, &prefix_id);
			glite_lbu_FreeStmt(&q);


			/* Store zombie suffix */

			// See if that suffix is already stored in the database	
			trio_asprintf(&stmt,"select suffix_id from zombie_suffixes where suffix = '%|Ss'", suffix);
			glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

			sql_retval = edg_wll_ExecSQL(ctx,stmt,&q);
			free(stmt); stmt = NULL;

			if (sql_retval < 0) goto rollback;

			if (sql_retval == 0) { //suffix does not exist yet
				glite_lbu_FreeStmt(&q);

				trio_asprintf(&stmt,"insert into zombie_suffixes (suffix) VALUES ('%|Ss')", suffix);
				glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

				if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback;

				free(stmt); stmt = NULL;
				glite_lbu_FreeStmt(&q);

				// The record should exist now, however we need to look up the suffix_id 
				trio_asprintf(&stmt,"select suffix_id from zombie_suffixes where suffix = '%|Ss'", suffix);
				glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

				if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback;
				free(stmt); stmt = NULL;
			}
			ret = edg_wll_FetchRow(ctx,q, 1, NULL, &suffix_id);
			glite_lbu_FreeStmt(&q);


			/* Store zombie job */

			trio_asprintf(&stmt,"insert into zombie_jobs (jobid, prefix_id, suffix_id)"
					" VALUES ('%|Ss', '%|Ss', '%|Ss')", root, prefix_id, suffix_id);
			glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

			if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) {
				if (edg_wll_Error(ctx, NULL, NULL) == EEXIST) {
					/* job already among zombies */
					/* print warning but continue */
					/* erasing other jobs */
					char *et, *ed, *msg, *job_s;

					edg_wll_Error(ctx, &et, &ed);
					job_s = glite_jobid_unparse(job);
					
					asprintf(&msg,"Warning: erasing job %s that already existed in this LB "
						"(reused jobid or corruped DB) (%s: %s)",job_s,et,ed);
					glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "[%d] %s", getpid(), msg);
					free(et); free(ed); free(msg); free(job_s);
					edg_wll_ResetError(ctx);
				}
				else goto rollback;
			}
			glite_lbu_FreeStmt(&q);
			free(stmt); stmt = NULL;
		}

		if (dump >= 0) 
			trio_asprintf(&stmt,
				"select event,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived,seqcode "
				"from events e,users u "
				"where e.jobid='%|Ss' "
				"and u.userid=e.userid "
				"order by event", dbjob);
		else
			trio_asprintf(&stmt,"select event from events "
				"where jobid='%|Ss' "
				"order by event", dbjob);

		glite_common_log_msg(LOG_CATEGORY_LB_SERVER_DB, LOG_PRIORITY_DEBUG, stmt);

		if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) goto rollback;
		free(stmt); stmt = NULL;

		dumped = 1;
		while ((ret = edg_wll_FetchRow(ctx,q,sizofa(res),NULL,res)) > 0) {
			int	event, ret_dump = 0, i;

			event = atoi(res[0]);

			if (dump >= 0) {
				assert(ret == 10);
				ret_dump = dump_events( ctx, job, dump, (char **) &res);
			}

			for (i=0; i<sizofa(res); i++) free(res[i]);

			if (dump >= 0 && ret_dump) goto rollback;

			if ( purge ) 
				if (edg_wll_delete_event(ctx,dbjob,event)) goto rollback;
		}
		glite_lbu_FreeStmt(&q);
		if (ret < 0) goto rollback;

commit:
rollback:;
	} while (edg_wll_TransNeedRetry(ctx));


err:
	free(root);
	free(suffix);
	free(prefix);
	free(prefix_id);
	free(suffix_id);
	free(dbjob);
	free(stmt);
	glite_lbu_FreeStmt(&q);

	return edg_wll_Error(ctx,NULL,NULL);
}
Example #5
0
/*
 * Flush the event log (dump and empty)
 */
void __noprof flush_events()
{
	dump_events(top);
	top = 0;
}