Beispiel #1
0
static int
sb2_libc_system (const char *line)
{
  if (line == NULL)
    /* Check that we have a command processor available.  It might
       not be available after a chroot(), for example.  */
    return do_system ("exit 0") == 0;

#if 0
  /* FIXME: sb2 now uses this as if the program
   * was single-threaded always. this is of course
   * false assumption.
  */
  if (SINGLE_THREAD_P)
#endif
    return do_system (line);

#if 0
  int oldtype = LIBC_CANCEL_ASYNC ();

  int result = do_system (line);

  LIBC_CANCEL_RESET (oldtype);

  return result;
#endif
}
Beispiel #2
0
int
__libc_system (const char *line)
{
  if (line == NULL)
    /* Check that we have a command processor available.  It might
       not be available after a chroot(), for example.  */
    return do_system ("exit 0") == 0;

  return do_system (line);
}
extern "C" int system (const char *line)
{
  JTRACE ( "before system(), checkpointing may not work" )
    ( line ) ( getenv ( ENV_VAR_HIJACK_LIBS ) ) ( getenv ( "LD_PRELOAD" ) );

  if (line == NULL)
    /* Check that we have a command processor available.  It might
       not be available after a chroot(), for example.  */
    return do_system ("exit 0") == 0;

  int result = do_system (line);

  JTRACE ( "after system()" );

  return result;
}
Beispiel #4
0
/*
 * objfile()
 *	Process the -r object file
 */
static void
objfile(char *p)
{
	char tmpf[32], buf[128];
	FILE *fp;

	/*
	 * Use nm(1) and grep(1) to get all the text symbols.
	 */
	sprintf(tmpf, "/tmp/shl%d", getpid());
	sprintf(buf, "nm %s | grep ' T ' > %s", p, tmpf);
	do_system(buf);

	/*
	 * Consume the symbol names.  The format of each line is:
	 * <addr> T <name>.  We tally them into obj_syms.
	 */
	fp = fopen(tmpf, "r");
	if (fp == NULL) {
		perror(tmpf);
		exit(1);
	}
	while (fscanf(fp, "%*08lx T %s\n", buf) == 1) {
		obj_sym(buf);
	}
	fclose(fp);
	unlink(tmpf);
}
int
__libc_system (const char *line)
{
  if (line == NULL)
    /* Check that we have a command processor available.  It might
       not be available after a chroot(), for example.  */
    return do_system ("exit 0") == 0;

  if (SINGLE_THREAD_P)
    return do_system (line);

  int oldtype = LIBC_CANCEL_ASYNC ();

  int result = do_system (line);

  LIBC_CANCEL_RESET (oldtype);

  return result;
}
Beispiel #6
0
static int do_execute_dos(int argc, char **argv)
{
  const char *cmd;

  if (!argc)
    return 1;
  cmd = getenv(argv[0]);
  if (!cmd)
    return (1);
  return do_system(cmd, 0);
}
Beispiel #7
0
static int do_execute_cmdline(int argc, char **argv, int parent)
{
  char *vars, drv;
  int ret;

  ret = do_prepare_exec(argc, argv, &drv);
  vars = misc_e6_options();
  if (vars) {
    mresize_env(strlen(vars));
    do_parse_vars(vars, drv, 0);
    if (parent)
      do_parse_vars(vars, drv, 1);
    e_drv = drv;	// store for later -p
  }
  if (ret == 2)
    ret = do_system(config.dos_cmd, config.exit_on_cmd);
  return ret;
}
Beispiel #8
0
int do_line()
{
    /* Line continuation has already been handled
     * by read_line() */
    char *inlptr = input_line;

    /* Skip leading whitespace */
    while (isspace((int)*inlptr))
	inlptr++;

    if (inlptr != input_line) {
	/* If there was leading whitespace, copy the actual
	 * command string to the front. use memmove() because
	 * source and target overlap */
	memmove(input_line,inlptr,strlen(inlptr));
	/* Terminate resulting string */
	input_line[strlen(inlptr)] = NUL;
    }

    FPRINTF((stderr, "Input line: \"%s\"\n",input_line));

    /* also used in load_file */
    if (is_system(input_line[0])) {
	do_system();
	if (interactive)	/* 3.5 did it unconditionally */
	    (void) fputs("!\n", stderr);	/* why do we need this ? */
	return (0);
    }
    num_tokens = scanner(&input_line, &input_line_len);
    c_token = 0;
    while (c_token < num_tokens) {
	if (command())
	    return (1);
	if (c_token < num_tokens) {	/* something after command */
	    if (equals(c_token, ";"))
		c_token++;
	    else
		int_error("';' expected", c_token);
	}
    }
    return (0);
}
Beispiel #9
0
static int do_execute_linux(int argc, char **argv)
{
  const char *cmd;
  char buf[PATH_MAX];
  char *p;

  if (!argc)
    return 1;
  cmd = getenv(argv[0]);
  if (!cmd)
    return (1);
  strlcpy(buf, cmd, sizeof(buf));
  p = strrchr(buf, '/');
  if (!p)
    return 1;
  *p = 0;
  p++;
  if (setupDOSCommand(buf, 0, NULL))
    return 1;
  return do_system(p, 0);
}
static int dpkg_doconfigure(package_t *pkg)
{
	int r;
	char postinst[1024];
	char buf[1024];

	DPRINTF("Configuring %s\n", pkg->package);
	pkg->status &= status_statusmask;
	snprintf(postinst, sizeof(postinst), "%s%s.postinst", infodir, pkg->package);

	if (is_file(postinst)) {
		snprintf(buf, sizeof(buf), "%s configure", postinst);
		if ((r = do_system(buf)) != 0) {
			fprintf(stderr, "postinst exited with status %d\n", r);
			pkg->status |= status_statushalfconfigured;
			return 1;
		}
	}
	pkg->status |= status_statusinstalled;
	
	return 0;
}
Beispiel #11
0
static void do_service(config_t *cpe, config_t *config, struct rs_config *rs_config)
{
	struct rs_start *rs_start = &rs_config->rs_start;
	config_t *cp;

	/* At this point we expect one sublist that contains the varios
	 * resource allocations
	 */
	if (!(cpe->flags & CFG_SUBLIST))
	{
		fatal("do_service: expected list at %s:%d",
			cpe->file, cpe->line);
	}
	if (cpe->next != NULL)
	{
		cpe= cpe->next;
		fatal("do_service: expected end of list at %s:%d",
			cpe->file, cpe->line);
	}
	cpe= cpe->list;

	/* Process the list */
	for (cp= cpe; cp; cp= cp->next)
	{
		if (!(cp->flags & CFG_SUBLIST))
		{
			fatal("do_service: expected list at %s:%d",
				cp->file, cp->line);
		}
		cpe= cp->list;
		if ((cpe->flags & CFG_STRING) || (cpe->flags & CFG_SUBLIST))
		{
			fatal("do_service: expected word at %s:%d",
				cpe->file, cpe->line);
		}

		if (strcmp(cpe->word, KW_CLASS) == 0)
		{
			do_class(cpe->next, config, rs_config);
			continue;
		}
		if (strcmp(cpe->word, KW_UID) == 0)
		{
			do_uid(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_SIGMGR) == 0)
		{
			do_sigmgr(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_TYPE) == 0)
		{
			do_type(cpe->next, rs_config);
			continue;
		}
		if (strcmp(cpe->word, KW_DESCR) == 0)
		{
			do_descr(cpe->next, rs_config);
			continue;
		}
		if (strcmp(cpe->word, KW_SCHEDULER) == 0)
		{
			do_scheduler(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_PRIORITY) == 0)
		{
			do_priority(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_QUANTUM) == 0)
		{
			do_quantum(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_CPU) == 0)
		{
			do_cpu(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_IRQ) == 0)
		{
			do_irq(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_IO) == 0)
		{
			do_io(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_PCI) == 0)
		{
			do_pci(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_SYSTEM) == 0)
		{
			do_system(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_IPC) == 0)
		{
			do_ipc(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_VM) == 0)
		{
			do_vm(cpe->next, rs_start);
			continue;
		}
		if (strcmp(cpe->word, KW_CONTROL) == 0)
		{
			do_control(cpe->next, rs_start);
			continue;
		}
	}
}
Beispiel #12
0
/*
 * generate_shlib()
 *	Take relocatable input image of library, generate mappable one
 *
 * Updates library base after generation so successive libraries
 * are allocated upwards in address.
 * We place data immediately following text.
 */
static void
generate_shlib(void)
{
	char buf[128], tmpf[32], tabf[32];
	FILE *fp;
	int x, cmdlen;
	ulong txtsize, datasize, bsssize;

	/*
	 * Build a jump table to prepend to the .shl output
	 */
	sprintf(tabf, "/tmp/sht%d.s", getpid());
	fp = fopen(tabf, "w");
	if (fp == NULL) {
		perror(tabf);
		exit(1);
	}
	fprintf(fp, "\t.text\n");
	fprintf(fp, "tbl_%s:\n", curlib);
	for (x = 0; db_syms[x]; ++x) {
		fprintf(fp, "\t.long\t%s\n", db_syms[x]);
	}
	fclose(fp);
	sprintf(buf, "cd /tmp; gcc -c %s", tabf);
	do_system(buf);
	unlink(tabf);

	/*
	 * Convert jump table filename to a .o
	 */
	tabf[strlen(tabf)-1] = 'o';

	/*
	 * Get shared library text size using size(1)
	 */
	sprintf(tmpf, "/tmp/shll%d", getpid());
	sprintf(buf, "size %s > %s", curinput, tmpf);
	do_system(buf);
	fp = fopen(tmpf, "r");
	(void)fgets(buf, sizeof(buf), fp);
	if (fscanf(fp, "%ld", &txtsize) != 1) {
		fprintf(stderr, "Error: corrupt size(1) output in %s\n",
			tmpf);
		exit(1);
	}
	fclose(fp);
	unlink(tmpf);

	/*
	 * Generate the library at its assigned address
	 */
	txtsize += (sizeof(struct aout) + (sizeof(ulong) * (ndb_syms-1)));
	txtsize = roundup(txtsize, page_size);
	sprintf(buf, "ld -o %s -Ttext %lx -Tdata %lx %s %s",
		curoutput,
		lib_base + sizeof(struct aout),
		lib_base + txtsize,
		tabf, curinput);

	/*
	 * Run the command to get our object
	 */
	unlink(curoutput);
	do_system(buf);

	/*
	 * Dig up data size so we can bump lib_base forward
	 * the right amount.  We couldn't calculate this until
	 * now, because BSS/common has an undecided size until
	 * finally linked.
	 */
	sprintf(tmpf, "/tmp/xsh%d", getpid());
	sprintf(buf, "size %s > %s", curoutput, tmpf);
	do_system(buf);
	fp = fopen(tmpf, "r");
	if (fp == NULL) {
		perror(tmpf);
		exit(1);
	}

	/*
	 * Skip header line, get data and BSS size
	 */
	(void)fgets(buf, sizeof(buf), fp);
	if (fscanf(fp, "%ld\t%ld\t%ld", &txtsize, &datasize, &bsssize) != 3) {
		fprintf(stderr, "Error: corrupt size(1) output in %s\n",
			tmpf);
		exit(1);
	}
	fclose(fp);

	/*
	 * Advance library base.  Make sure everything still flies
	 * as a shared library--can't map partial pages!
	 */
	txtsize += sizeof(struct aout);
	lib_base += (txtsize + datasize + roundup(bsssize, page_size));
	if (lib_base & (page_size - 1)) {
		fprintf(stderr, "Error: lib_base no longer page aligned\n");
		fprintf(stderr, " txt 0x%lx data 0x%lx BSS 0x%lx base 0x%x\n",
			txtsize, datasize, bsssize, lib_base);
		exit(1);
	}
	unlink(tmpf);
	unlink(tabf);
}
/*
 * signal thread
 *
 */
void *signalthread(void *param)
{
	struct thread_param *par = param;
	struct sched_param schedp;
	sigset_t sigset;
	struct timespec before, after;
	struct thread_stat *stat = par->stats;
	int policy = par->prio ? SCHED_FIFO : SCHED_OTHER;
	int stopped = 0;
	int first = 1;

	if (tracelimit) {
		do_system("echo 1 > /proc/sys/kernel/trace_all_cpus");
		do_system("echo 1 > /proc/sys/kernel/trace_freerunning");
		do_system("echo 0 > /proc/sys/kernel/trace_print_at_crash");
		do_system("echo 1 > /proc/sys/kernel/trace_user_triggered");
		do_system("echo -1 > /proc/sys/kernel/trace_user_trigger_irq");
		do_system("echo 0 > /proc/sys/kernel/trace_verbose");
		do_system("echo 0 > /proc/sys/kernel/preempt_thresh");
		do_system("echo 0 > /proc/sys/kernel/wakeup_timing");
		do_system("echo 0 > /proc/sys/kernel/preempt_max_latency");
		if (ftrace)
			do_system("echo 1 > /proc/sys/kernel/mcount_enabled");

		do_system("echo 1 > /proc/sys/kernel/trace_enabled");
	}

	stat->tid = gettid();

	sigemptyset(&sigset);
	sigaddset(&sigset, par->signal);
	sigprocmask(SIG_BLOCK, &sigset, NULL);

	memset(&schedp, 0, sizeof(schedp));
	schedp.sched_priority = par->prio;
	sched_setscheduler(0, policy, &schedp);

	stat->threadstarted++;

	if (tracelimit) {
		if (oldtrace)
			gettimeofday(NULL, (struct timezone *)1);
		else
			prctl(0, 1);
	}

	clock_gettime(CLOCK_MONOTONIC, &before);

	while (!shutdown) {
		struct timespec now;
		long diff;
		int sigs;

		if (sigwait(&sigset, &sigs) < 0)
			goto out;

		clock_gettime(CLOCK_MONOTONIC, &after);

		/*
		 * If it is the first thread, sleep after every 16
		 * round trips.
		 */
		if (!par->id && !(stat->cycles & 0x0F))
			usleep(10000);

		/* Get current time */
		clock_gettime(CLOCK_MONOTONIC, &now);
		pthread_kill(stat->tothread, SIGUSR1);

		/* Skip the first cycle */
		if (first) {
			first = 0;
			before = now;
			continue;
		}

		diff = calcdiff(after, before);
		before = now;
		if (diff < stat->min)
			stat->min = diff;
		if (diff > stat->max)
			stat->max = diff;
		stat->avg += (double) diff;

		if (!stopped && tracelimit && (diff > tracelimit)) {
			stopped++;
			if (oldtrace)
				gettimeofday(NULL, NULL);
			else
				prctl(0, 0);
			shutdown++;
		}
		stat->act = diff;
		stat->cycles++;

		if (par->bufmsk)
			stat->values[stat->cycles & par->bufmsk] = diff;

		if (par->max_cycles && par->max_cycles == stat->cycles)
			break;
	}

out:
	/* switch to normal */
	schedp.sched_priority = 0;
	sched_setscheduler(0, SCHED_OTHER, &schedp);

	stat->threadstarted = -1;

	return NULL;
}
Beispiel #14
0
/*
 * generate_stubs()
 *	Create the libc.a containing only stubs
 *
 * Actually, libc.a contains all the stubs, plus a module with the
 * minimal code needed to map in the real library.
 */
static void
generate_stubs(void)
{
	int x;
	FILE *fp;
	char *sym, buf[128];

	/*
	 * Clean up any old files
	 */
	do_system("rm -f /tmp/sho*.[cso]");

	/*
	 * Generate the loader stub
	 */
	fp = fopen("/tmp/sho.c", "w");
	if (fp == NULL) {
		perror("/tmp/sho.c");
		exit(1);
	}
	fprintf(fp,
"void *_addr_%s;\n"
"_load_%s() {\n"
"	extern void *_load();\n"
"	_addr_%s = _load(\"%s\");\n"
"	if (_addr_%s == 0) _notify(0, 0, \"kill\", 4); }\n",
	libname, libname, libname, curoutput, libname);
	fclose(fp);

	/*
	 * Generate a stub for each entry needed
	 */
	for (x = 0; sym = db_syms[x]; ++x) {
		sprintf(buf, "/tmp/sho%d.s", x);
		fp = fopen(buf, "w");
		if (fp == NULL) {
			perror(buf);
			exit(1);
		}
#ifdef i386
	/*
	 * Yes, this is pretty gross.  I should have an abstraction
	 * layer, with a nice, complicated way to communicate strings
	 * with arguments back and forth.
	 */
		fprintf(fp,
"	.globl	%s\n"
"%s:	movl	__addr_%s,%%eax\n"
"	testl	%%eax,%%eax\n"
"	je	1f\n"
"	jmp	%d(%%eax)\n"
"1:	call	__load_%s\n"
"	jmp	%s\n",
				sym, sym, libname, x * sizeof(ulong),
				libname, sym);
#endif
		fclose(fp);
	}

	/*
	 * Create a library with all stubs, as well as our library
	 * loader.
	 */
	do_system("cd /tmp; gcc -c sho*.[sc]");
	unlink(curlib);
	sprintf(buf, "ar -crs %s /tmp/sho*.o shlib.o shcalls.o", curlib);
	do_system(buf);

	/*
	 * Clean up
	 */
	do_system("rm -f /tmp/sho*.[cso]");
}
Beispiel #15
0
static void phylogenetic_tree_menu(void)
{
        int catchint;

        catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
        if (catchint) {
                if (setjmp(jmpbuf) != 0)
                        fprintf(stdout,"\n.. Interrupt\n");
#ifdef UNIX
                if (signal(SIGINT,jumper) == BADSIG)
                        fprintf(stdout,"Error: signal\n");
#else
                if (signal(SIGINT,SIG_DFL) == (void*)BADSIG)
                        fprintf(stdout,"Error: signal\n");
#endif
        }


    while(TRUE)
    {
        fprintf(stdout,"\n\n\n");
        fprintf(stdout,"****** PHYLOGENETIC TREE MENU ******\n");
        fprintf(stdout,"\n\n");

        fprintf(stdout,"    1.  Input an alignment\n");
        fprintf(stdout,"    2.  Exclude positions with gaps?        ");
	if(tossgaps)
		fprintf(stdout,"= ON\n");
	else
		fprintf(stdout,"= OFF\n");
        fprintf(stdout,"    3.  Correct for multiple substitutions? ");
	if(kimura)
		fprintf(stdout,"= ON\n");
	else
		fprintf(stdout,"= OFF\n");
        fprintf(stdout,"    4.  Draw tree now\n");
        fprintf(stdout,"    5.  Bootstrap tree\n");
	fprintf(stdout,"    6.  Output format options\n");
        fprintf(stdout,"\n");
        fprintf(stdout,"    S.  Execute a system command\n");
        fprintf(stdout,"    H.  HELP\n");
        fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");

        getstr("Your choice",lin1);
        if(*lin1 == EOS) return;

        switch(toupper(*lin1))
        {
       	 	case '1': seq_input(FALSE);
				phylip_name[0]=EOS;
				clustal_name[0]=EOS;
				dist_name[0]=EOS;
				nexus_name[0]=EOS;
         	   	break;
        	case '2': tossgaps ^= TRUE;
          	  	break;
      		case '3': kimura ^= TRUE;;
            		break;
        	case '4': phylogenetic_tree(phylip_name,clustal_name,dist_name,nexus_name,"amenu.pim");
            		break;
        	case '5': bootstrap_tree(phylip_name,clustal_name,nexus_name);
            		break;
		case '6': tree_format_options_menu();
			break;
        	case 'S': do_system();
            		break;
            	case '?':
        	case 'H': get_help('7');
            		break;
            	case 'Q':
        	case 'X': return;

        	default: fprintf(stdout,"\n\nUnrecognised Command\n\n");
            	break;
        }
    }
}
Beispiel #16
0
static void profile_align_menu(void)
{
        int catchint;

        catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
        if (catchint) {
                if (setjmp(jmpbuf) != 0)
                        fprintf(stdout,"\n.. Interrupt\n");
#ifdef UNIX
                if (signal(SIGINT,jumper) == BADSIG)
                        fprintf(stdout,"Error: signal\n");
#else
                if (signal(SIGINT,SIG_DFL) == (void*)BADSIG)
                        fprintf(stdout,"Error: signal\n");
#endif
        }


    while(TRUE)
    {
	fprintf(stdout,"\n\n\n");
        fprintf(stdout,"****** PROFILE AND STRUCTURE ALIGNMENT MENU ******\n");
        fprintf(stdout,"\n\n");

        fprintf(stdout,"    1.  Input 1st. profile             ");
        if (!profile1_empty) fprintf(stdout,"(loaded)");
        fprintf(stdout,"\n");
        fprintf(stdout,"    2.  Input 2nd. profile/sequences   ");
        if (!profile2_empty) fprintf(stdout,"(loaded)");
        fprintf(stdout,"\n\n");
        fprintf(stdout,"    3.  Align 2nd. profile to 1st. profile\n");
        fprintf(stdout,"    4.  Align sequences to 1st. profile (%s)\n\n",
                        (!quick_pairalign) ? "Slow/Accurate" : "Fast/Approximate");
        fprintf(stdout,"    5.  Toggle Slow/Fast pairwise alignments = %s\n\n",
                                        (!quick_pairalign) ? "SLOW" : "FAST");
        fprintf(stdout,"    6.  Pairwise alignment parameters\n");
        fprintf(stdout,"    7.  Multiple alignment parameters\n\n");
        fprintf(stdout,"    8.  Toggle screen display                = %s\n",
                                        (!showaln) ? "OFF" : "ON");
        fprintf(stdout,"    9.  Output format options\n");
        fprintf(stdout,"    0.  Secondary structure options\n");
        fprintf(stdout,"\n");
        fprintf(stdout,"    S.  Execute a system command\n");
        fprintf(stdout,"    H.  HELP\n");
        fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");

        getstr("Your choice",lin1);
        if(*lin1 == EOS) return;

        switch(toupper(*lin1))
        {
        case '1': profile_no = 1;      /* 1 => 1st profile */ 
          profile_input();
		  strcpy(profile1_name, seqname);
            break;
        case '2': profile_no = 2;      /* 2 => 2nd profile */
          profile_input();
		  strcpy(profile2_name, seqname);
            break;
        case '3': profile_align(p1_tree_name,p2_tree_name);       /* align the 2 alignments now */
            break;
        case '4': new_sequence_align(phylip_name);  /* align new sequences to profile 1 */
            break;
        case '5': quick_pairalign ^= TRUE;
	    break;
        case '6': pair_menu();
            break;
        case '7': multi_menu();
            break;
        case '8': showaln ^= TRUE;
	    break;
        case '9': format_options_menu();
            break;
        case '0': ss_options_menu();
            break;
        case 'S': do_system();
            break;
        case '?':
        case 'H': get_help('6');
            break;
        case 'Q':
        case 'X': return;

        default: fprintf(stdout,"\n\nUnrecognised Command\n\n");
            break;
        }
    }
}
Beispiel #17
0
static void multiple_align_menu(void)
{
        int catchint;

        catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
        if (catchint) {
                if (setjmp(jmpbuf) != 0)
                        fprintf(stdout,"\n.. Interrupt\n");
#ifdef UNIX
                if (signal(SIGINT,jumper) == BADSIG)
                        fprintf(stdout,"Error: signal\n");
#else
                if (signal(SIGINT,SIG_DFL) == (void*)BADSIG)
                        fprintf(stdout,"Error: signal\n");
#endif
        }


    while(TRUE)
    {
        fprintf(stdout,"\n\n\n");
        fprintf(stdout,"****** MULTIPLE ALIGNMENT MENU ******\n");
        fprintf(stdout,"\n\n");


        fprintf(stdout,"    1.  Do complete multiple alignment now (%s)\n",
                        (!quick_pairalign) ? "Slow/Accurate" : "Fast/Approximate");
        fprintf(stdout,"    2.  Produce guide tree file only\n");
        fprintf(stdout,"    3.  Do alignment using old guide tree file\n\n");
        fprintf(stdout,"    4.  Toggle Slow/Fast pairwise alignments = %s\n\n",
                                        (!quick_pairalign) ? "SLOW" : "FAST");
        fprintf(stdout,"    5.  Pairwise alignment parameters\n");
        fprintf(stdout,"    6.  Multiple alignment parameters\n\n");
	fprintf(stdout,"    7.  Reset gaps before alignment?");
	if(reset_alignments_new)
		fprintf(stdout," = ON\n");
	else
		fprintf(stdout," = OFF\n");
        fprintf(stdout,"    8.  Toggle screen display          = %s\n",
                                        (!showaln) ? "OFF" : "ON");
        fprintf(stdout,"    9.  Output format options\n");
        fprintf(stdout,"\n");

        fprintf(stdout,"    S.  Execute a system command\n");
        fprintf(stdout,"    H.  HELP\n");
        fprintf(stdout,"    or press [RETURN] to go back to main menu\n\n\n");

        getstr("Your choice",lin1);
        if(*lin1 == EOS) return;

        switch(toupper(*lin1))
        {
        case '1': align(phylip_name);
            break;
        case '2': make_tree(phylip_name);
            break;
        case '3': get_tree(phylip_name);
            break;
        case '4': quick_pairalign ^= TRUE;
            break;
        case '5': pair_menu();
            break;
        case '6': multi_menu();
            break;
	case '7': reset_alignments_new ^= TRUE;
	    if(reset_alignments_new==TRUE)
		reset_alignments_all=FALSE;
            break;
        case '8': showaln ^= TRUE;
	    break;
        case '9': format_options_menu();
            break;
        case 'S': do_system();
            break;
        case '?':
        case 'H': get_help('2');
            break;
        case 'Q':
        case 'X': return;

        default: fprintf(stdout,"\n\nUnrecognised Command\n\n");
            break;
        }
    }
}
Beispiel #18
0
void main_menu(void)
{
        int catchint;

        catchint = signal(SIGINT, SIG_IGN) != SIG_IGN;
        if (catchint) {
                if (setjmp(jmpbuf) != 0)
                        fprintf(stdout,"\n.. Interrupt\n");
#ifdef UNIX
                if (signal(SIGINT,jumper) == BADSIG)
                        fprintf(stdout,"Error: signal\n");
#else
                if (signal(SIGINT,SIG_DFL) == (void*)BADSIG)
                        fprintf(stdout,"Error: signal\n");
#endif
        }

	while(TRUE) {
		fprintf(stdout,"\n\n\n");
		fprintf(stdout," **************************************************************\n");
		fprintf(stdout," ******** CLUSTAL %s Multiple Sequence Alignments  ********\n",revision_level);
		fprintf(stdout," **************************************************************\n");
		fprintf(stdout,"\n\n");
		
		fprintf(stdout,"     1. Sequence Input From Disc\n");
		fprintf(stdout,"     2. Multiple Alignments\n");
		fprintf(stdout,"     3. Profile / Structure Alignments\n");
		fprintf(stdout,"     4. Phylogenetic trees\n");
		fprintf(stdout,"\n");
		fprintf(stdout,"     S. Execute a system command\n");
		fprintf(stdout,"     H. HELP\n");
		fprintf(stdout,"     X. EXIT (leave program)\n\n\n");
		
		getstr("Your choice",lin1);

		switch(toupper(*lin1)) {
			case '1': seq_input(FALSE);
				phylip_name[0]=EOS;
				clustal_name[0]=EOS;
				dist_name[0]=EOS;
				nexus_name[0]=EOS;
				break;
			case '2': multiple_align_menu();
				break;
			case '3': profile_align_menu();
				break;
			case '4': phylogenetic_tree_menu();
				break;
			case 'S': do_system();
				break;
			case '?':
			case 'H': get_help('1');
				break;
			case 'Q':
			case 'X': exit(0);
				break;
			default: fprintf(stdout,"\n\nUnrecognised Command\n\n");
				break;
		}
	}
}
static void do_server(int port)
{
    fd_set readfds;
    int server;
    struct sockaddr_in saserver;
    command* cp;
    int maxd, n;
    int flg;
    btcli child;
    char buf[2048];

    /* Create a socket, and start listening. */

    server = socket (AF_INET, SOCK_STREAM, 0);
    if (server == -1)
    {
	printf("socket creation failed!\n");
	perror (progname);
	exit (EXIT_FAILURE);
    }

    memset (&saserver, 0, sizeof (saserver));
    saserver.sin_family = AF_INET;
    saserver.sin_addr.s_addr = INADDR_ANY;
    saserver.sin_port = htons (port);

    if (bind (server, (struct sockaddr *) &saserver, sizeof (saserver)))
    {
	printf("socket bind failed!\n");
	perror (progname);
	exit (EXIT_FAILURE);
    }

    if (listen (server, 1))
    {
	printf("listen failed!\n");
	perror (progname);
	exit (EXIT_FAILURE);
    }

    /*
     * This loop below is controlled by ''mode''.  It takes on a
     * number of different values, at different times to mean
     * different things.
     *  RUN	- We might have a BTCLI running, but should
     *            keep pumping data anyway.
     *  DIE	- We should exit as soon as possible.
     *            We should kill btcli, and btclid.
     *            All connected users are dropped
     *  START   - We should start a copy of btcli
     *  STOP    - We should kill the current copy of BTCLI.
     *  RESTART - We should kill btcli, and then start it again
     *  SHELL   - We should stop btcli, run a command and restart btcli
     *  DEVINFO - Output the parameters to btcli
     * 
     */
    mode = MODE_RUN;

    /*
    Change to having one big loop (not two nested)
    Select on the following things:
    ''accept'' on the socket server, so that new people can telnet in.
    ''read'' from each of the sockets for commands.
    ''read'' from stdin, to check that no one is typing on the screen.
    ''read'' from the btcli (if it exists), and buffer the data
    */

    child.pid = 0;
    child.read = child.write = -1;
    start_btcli(&child);

    if((print_output & 2) != 0)
	printf("Starting 'do_server' loop\n");

    set_non_block(server);

    set_non_block(STDIN_FILENO);

    setbuf(stdin, NULL);

    flg = fcntl(STDIN_FILENO, F_GETFL);
/*  if((print_output & 2) != 0)
	printf("STDIN Flags = 0x%x\n", flg);*/

    fcntl(STDIN_FILENO, F_SETFL, flg|O_NDELAY);

    flg = fcntl(STDIN_FILENO, F_GETFL);
/*  if((print_output & 2) != 0)
	printf("STDIN Flags = 0x%x\n", flg);*/

    cmd_stdin.ptr = 0;
    cmd_stdin.handle = STDIN_FILENO;
    cmd_stdin.next = NULL;
    cmd_head = &cmd_stdin;

    do
    {
	FD_ZERO (&readfds);

	FD_SET (server, &readfds);
	maxd = server;

	/* Read from btcli */
	if(child.read != -1)
	{
	    FD_SET (child.read, &readfds);
	    if(child.read > maxd)
		maxd = child.read;
	}

	/* Read from the ''command'' list (stdin and socket connections) */
	for(cp = cmd_head; cp != NULL; cp = cp->next)
	{
	    if (cp->handle >= 0)
	    {
		FD_SET (cp->handle, &readfds);
		if(cp->handle > maxd)
		    maxd = cp->handle;
	    }
	}

	/* Perform the select */
	/* printf ("[%d\n", count_clients()); */
  	n = select (maxd + 1, &readfds, NULL, NULL, NULL);
	/* printf ("]\n"); */

	if (n == -1)
	{
	    printf("select -> got -1\n");
	    perror (progname);
	    continue;
	}

	/* Someone want to connect to the socket */
	if (FD_ISSET (server, &readfds))
	{
	    /* Add to list of clients */
	    add_client(server);
	}

	/* read the output from btcli */
	if (child.read != -1 && FD_ISSET (child.read, &readfds))
	{
	    n = read (child.read, buf, sizeof (buf) - 1);
	    if(n > 0)
	    {
		 /*
		  * (Has anyone noticed this is C, not C++?)
		  * If there isn't a newline at the end, add one.
		  * This is bad if we got a partial line; we
		  * could do tricks with select to help here.
		  */
		 if (n < sizeof(buf) - 1 && buf[n-1] != '\n')
		      buf[n++] = '\n';
		 buf[n] = '\0';

		/* Output the data from btcli to the screen */
		if ((print_output & 1) != 0)
		{
		    printf ("%s\0", buf);
		}

		/* output the data to the sockets */
		write_to_clients(buf, n);
	    }
	    else
	    {
		/* we failed to read anything from btcli (but select said that we could) */
		if (n < 0)
		{
		    printf("read (from child) -> got -1\n");
		    perror (progname);
		}
/*		mode = MODE_RESTART;*/
		/* Wait for explicit instruction to restart */
		mode = MODE_STOP;
	    }
	}

	/* This is where we handle data coming in from the socket
	   connection. */
	for (cp = cmd_head; cp != NULL; cp = cp->next)
	{
	    if (cp->handle >= 0 && FD_ISSET (cp->handle, &readfds))
	    {
#ifdef SIGALRM
		if(cp->handle == STDIN_FILENO)
		    alarm (1);
#endif
		n = read (cp->handle, buf, sizeof (buf) - 1);
#ifdef SIGALRM
		if(cp->handle == STDIN_FILENO)
		    alarm (0);
#endif
		if (n > 0)
		{
		    buf[n] = 0;
		    command_add_frag(cp, child.write, buf, n);
		}
		else
		{
		    if(n < 0)
		    {
			if(errno != EINTR)
			{
			    printf("read (from client) -> got -1\n");
			    perror (progname);
			}
		    }
		    else
		    {
			if((print_output & 2) != 0)
			    printf ("EOF on client\n");
		    }
		    if(cp->handle != STDIN_FILENO)
		    {
			close(cp->handle);	/* Close the socket handle (needed!?) */
			cp->handle = -1;	/* Mark the client for removal */
		    }
		}
	    }
	}
	remove_clients();

	/* Now we do different thing if we have been given a special btclid command */

	switch (mode)
	{
	case MODE_RESTART:

	    if((print_output & 2) != 0)
		printf("ReStarting\n");

	    close_btcli(&child);
	    start_btcli(&child);

	    mode = MODE_RUN;

	    break;

	case MODE_SHELL:

	    close_btcli(&child);

	    if((print_output & 2) != 0)
		printf("Running shell command ''%s''\n", shell);

	    do_system(shell);

	    memset(shell, 0, sizeof(shell));

	    start_btcli(&child);

	    mode = MODE_RUN;

	    break;

	case MODE_DEVINFO:

	    strcpy(buf, "ARGS:");
	    for(n=1; (n<64)&&(args[n]!=NULL); n++)
	    {
		strcat(buf, " ");
		strcat(buf, args[n]);
	    }
	    strcat(buf, "\r\n");

	    write_to_clients(buf, strlen(buf));

	    if((print_output & 1) != 0)
		printf ("%s", buf);

	    mode = MODE_RUN;

	    break;

	case MODE_STOP:

	    if(child.pid != 0)
		close_btcli(&child);

	    mode = MODE_RUN;

	    break;

	case MODE_START:

	    if(child.pid == 0)
		start_btcli(&child);

	    mode = MODE_RUN;

	    break;
	}
    }
    while (mode != MODE_DIE);

    close_btcli(&child);

    close (server);
}