Esempio n. 1
0
void test_learner() {
  
  set_log_level(NONE);
  init_store();

  _node_count = 4;
  recv_from = &recv_from_scenario; 
  send_to = &send_to_scenario;
  sendidx = recvidx = 0;
  recv = learner_basic_recv;
  send = learner_basic_send;
  intheory_sm(LEARNER);

  sendidx = recvidx = 0;
  recv = learner_getfail_recv;
  send = learner_getfail_send;
  intheory_sm(LEARNER);

  sendidx = recvidx = 0;
  recv = learner_expand_recv;
  send = learner_expand_send;
  intheory_sm(LEARNER);

  sendidx = recvidx = 0;
  recv = learner_mixed_recv;
  send = learner_mixed_send;
  intheory_sm(LEARNER);

}
Esempio n. 2
0
stmt_ac *extension() {
   extern void init_store(Universal, size_t, Universal, size_t);
   extern void init_prog(cons<fun_ac> *prog_cTree);
   set_specialization_context(_arg1,_arg2);
   init_store(_global_sstore_start, _global_sstore_size, _local_sstore_start, _local_sstore_size);
init_prog(new cons<fun_ac>(
RES_7()));

return new Exp_reb(Call_reb("_Gdotproduct_1",cons<param>(
   param((funptr)&EV_8)
+= param((funptr)&EV_9)
+= param(Exp_id("VAR(ROOT(L(G(\"dotproduct\"),0, \"v\")),tINDR(NON_CST,NON_VOL,tINT(NON_CST,NON_VOL,SIGNED,STD)),A(D))"))
),0,"CALL(0,G(\"%s\"),CALL_SIG([VAR(tINDR(NON_CST,NON_VOL,tINT(NON_CST,NON_VOL,SIGNED,STD)),ROOT(L(G(\"dotproduct\"),0, \"v\")))],[],ALIAS_CALL_SIG(STORE([])),BTA_CALL_SIG([D],[]),ETA_RETURN_SIG(D,[],[])),[%s],[[ALIASES([],[])]],tINT(NON_CST,NON_VOL,SIGNED,STD),A(U))"), "");
}
Esempio n. 3
0
void init_fs(){
    int rc;
    write_log("init_fs: initializing file system\n");

    int root_is_empty = init_store();
    // If there is no root object, create one.
    if(root_is_empty){
        write_log("init_fs: root is empty, initialising root\n");
        uuid_t rootkey;
        uuid_parse(ROOT_KEY, rootkey);
        init_dir_fcb(rootkey, rootkey);
    } else {
        write_log("init_fs: root is not empty, nothing to be done\n");
    }
}
Esempio n. 4
0
int
main(int argc, char **argv)
{
  int server_sock = 0, client_sock = 0, 
    client_addrlen = sizeof(struct sockaddr_in);
  struct sockaddr_in client_addr;

  init_store();
  server_sock = init_listen_socket(5000);
  assert(server_sock > 0);
  
  while (1) {
    client_sock = accept(server_sock, &client_addr, 
                         &client_addrlen);
    if (client_sock < 0) {
      printf("%s\n", strerror(errno));
      abort();
    }
    handle_client(client_sock);
  }
  exit(0);
}
Esempio n. 5
0
parse_args(int argc, char **argv, arg_info *table, int entries, char **others, int other_count)
#endif
{
    boolean result;

    if (argv)
	this_program = argv[0];

/* Check the validity of the table and its parameters */

    result = arg_verify (argv, table, entries);

/* Initialize the storage values */

    init_store (table, entries);

    if (result) {
	boolean use_prefix = TRUE;
	char *argv0;

	argc--;
	argv0 = *++argv;
	while (argc) {
	    int index, length;

	    index = match_table (*argv, table, entries, use_prefix, &length);
	    if (index < 0) {

/* The argument doesn't match anything in the table */

		if (others) {

		    if (*argv > argv0)
			*--*argv = '-';	/* complain at invalid flag */

		    if (other_count > 0) {
			*others++ = *argv;
			other_count--;
		    } else {
			fprintf (stderr, "%s:  too many parameters: ",
				this_program);
			fprintf (stderr, "'%s' ignored\n", *argv);
		    } /* else */
		} /* if (others) */
		argv0 = *++argv;
		argc--;
	    } else {

/* A match was found */

		if (length >= strlen (*argv)) {
		    argc--;
		    argv0 = *++argv;
		    use_prefix = TRUE;
		} else {
		    (*argv) += length;
		    use_prefix = FALSE;
		} /* else */

/* Parse any necessary arguments */

		if (arg_count (table[index]) != P_NO_ARGS) {

/* Now   length   will be used to store the number of parsed characters */

		    length = arg_parse(*argv, &table[index]);
		    if (*argv == NULL)
			argc = 0;
		    else if (length >= strlen (*argv)) {
			argc--;
			argv0 = *++argv;
			use_prefix = TRUE;
		    } else {
			(*argv) += length;
			use_prefix = FALSE;
		    } /* else */
		} /* if (argv_count != P_NO_ARGS) */
		  else
		    *arg_result_ptr(table[index]) =
			    arg_table_size(table[index]);
	    } /* else */
	} /* while (argc) */
    } /* if (result) */

    return result;
} /* parse_args */
Esempio n. 6
0
// the exposed libscalpel API
// NOTE: This function is deprecated and will be removed. Use the
// libscalpel_* functions instead.
// TODO make the driver in scalpel_exec.c use this (minor refactoring needed)
// TODO add support for the remaining options avail from cmd-line
// returns SCALPEL_OK on no error, can throw runtime_error exception on errors
int scalpel_carveSingleInput(ScalpelInputReader * const reader, const char * const confFilePath,
    const char * const outDir, const unsigned char generateFooterDb,
    const unsigned char handleEmbedded, const unsigned char organizeSubdirs,
    const unsigned char previewMode,
    const unsigned char carveWithMissingFooters,
    const unsigned char noSearchOverlap) throw (std::runtime_error) {

    if (!reader || ! confFilePath || ! outDir) {
        //invalid args
        throw std::runtime_error("Invalid empty arguments");
    }

    if (!reader->dataSource || !reader->id) {
        throw std::runtime_error("Invalid empty input reader arguments");
    }

    //check fns
    if (!reader->open || !reader->read || !reader->seeko || !reader->tello
        || !reader->close || !reader->getError || !reader->getSize) {
            throw std::runtime_error("Reader callbacks not setup");
    }

    struct scalpelState state;

    std::string processorName ("scalpel_carveSingleInput()");
    char * args[5];
    args[0] = const_cast<char*> ( processorName.c_str());
    args[1] = reader->id;
    args[2] = const_cast<char*> (confFilePath);
    args[3] = const_cast<char*> (outDir);
    args[4] = 0;


    initializeState(args, &state);

    //setup input
    state.inReader = reader;

    //setup options
    const size_t outDirLen = strlen(outDir);
    strncpy(state.outputdirectory, outDir, outDirLen);
    state.outputdirectory[outDirLen] = 0;
    const size_t confFilePathLen = strlen(confFilePath);
    strncpy(state.conffile, confFilePath, confFilePathLen);
    state.conffile[confFilePathLen] = 0;
    state.generateHeaderFooterDatabase = generateFooterDb;
    state.handleEmbedded = handleEmbedded;
    state.organizeSubdirectories = organizeSubdirs;
    state.previewMode = previewMode;
    state.carveWithMissingFooters = carveWithMissingFooters;
    state.noSearchOverlap = noSearchOverlap;

    convertFileNames(&state);

    // read configuration file
    int err;
    if ((err = readSearchSpecFile(&state))) {
        // problem with config file
        handleError(&state, err); //can throw
        freeState(&state);
        std::stringstream ss;
        ss << "Error reading spec file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    // prepare audit file and make sure output directory is empty.
    if ((err = openAuditFile(&state))) {
        handleError(&state, err); //can throw
        freeState(&state);
        std::stringstream ss;
        ss << "Error opening audit file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    // Initialize the backing store of buffer to read-in, process image data.
    init_store();

    // Initialize threading model for cpu or gpu search.
    init_threading_model(&state);

    if ((err = digImageFile(&state))) {
        handleError(&state, err); //can throw
        closeAuditFile(state.auditFile);
        destroyStore();
        freeState(&state);
        std::stringstream ss;
        ss << "Error digging file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    if ((err = carveImageFile(&state))) {
        handleError(&state, err); //can throw
        closeAuditFile(state.auditFile);
        destroy_threading_model(&state);
        destroyStore();
        freeState(&state);
        std::stringstream ss;
        ss << "Error carving file, error code: " << err;
        throw std::runtime_error(ss.str());
    }

    closeAuditFile(state.auditFile);
    destroy_threading_model(&state);
    destroyStore();
    freeState(&state);

    return SCALPEL_OK;
}
Esempio n. 7
0
int libscalpel_initialize(scalpelState ** state, char * confFilePath, 
                          char * outDir, const scalpelState & options)
{
    std::string funcname("libscalpel_initialize");

    if (state == NULL)
        throw std::runtime_error(funcname + ": state argument must not be NULL.");

    if (*state != NULL)
        throw std::runtime_error(funcname + ": state has already been allocated.");

    if (outDir == NULL || strlen(outDir) == 0)
        throw std::runtime_error(funcname + ": no output directory provided.");

    if (confFilePath == NULL || strlen(confFilePath) == 0)
        throw std::runtime_error(funcname + ": no configuration file path provided.");

    scalpelState * pState = new scalpelState(options);

    char * argv[3];
    argv[0] = confFilePath;
    argv[1] = outDir;
    argv[2] = NULL;

    initializeState(&argv[0], pState);

    const size_t outDirLen = strlen(outDir);
    strncpy(pState->outputdirectory, outDir, outDirLen + 1);
    pState->outputdirectory[outDirLen + 1] = 0;
    const size_t confFilePathLen = strlen(confFilePath);
    strncpy(pState->conffile, confFilePath, confFilePathLen + 1);
    pState->conffile[confFilePathLen + 1] = 0;

    convertFileNames(pState);

    int err = 0;

    // prepare audit file and make sure output directory is empty.
    if ((err = openAuditFile(pState))) {
        handleError(pState, err); //can throw
        std::stringstream ss;
        ss << ": Error opening audit file, error code: " << err;
        throw std::runtime_error(funcname + ss.str());
    }

    // read configuration file
    if ((err = readSearchSpecFile(pState))) {
        // problem with config file
        handleError(pState, err); //can throw
        std::stringstream ss;
        ss << ": Error reading spec file, error code: " << err;
        throw std::runtime_error(funcname + ss.str());
    }

    // Initialize the backing store of buffer to read-in, process image data.
    init_store();

    // Initialize threading model for cpu or gpu search.
    init_threading_model(pState);

    *state = pState;

    return SCALPEL_OK;
}
Esempio n. 8
0
/* Entry point of cc1/c++.  Decode command args, then call compile_file.
   Exit code is 35 if can't open files, 34 if fatal error,
   33 if had nonfatal errors, else success.  */
int main(int argc, char **argv)
{
  register int i;
  dd_list files, preludes;
  dd_list_pos cur;
  int version_flag = 0;
  char *p;
  char *config_file = NULL;

#ifdef TIMER_USERTIME
  reset_timer(&total_time);
#endif
  start_timer(&total_time);
  region_init();
  parse_region = newregion();
  in_prelude = FALSE;
  num_hotspots = 0;
  parsed_files = dd_new_list(parse_region);

  copy_argc = 0;
  copy_argv = xmalloc((argc + 1) * sizeof(*copy_argv));
  files = dd_new_list(parse_region);
  preludes = dd_new_list(parse_region);

  p = argv[0] + strlen (argv[0]);
  while (p != argv[0] && p[-1] != '/'
#ifdef DIR_SEPARATOR
	 && p[-1] != DIR_SEPARATOR
#endif
	 )
    --p;
  progname = p;

#ifdef SIGPIPE
  signal (SIGPIPE, pipe_closed);
#endif

  copy_argv[0] = argv[0];
  copy_argc = 1;
  for (i = 1; i < argc; i++)
    {
      int j;
      bool copy_arg = TRUE;

      /* If this is a language-specific option,
	 decode it in a language-specific way.  */
      for (j = 0; lang_options[j] != 0; j++)
	if (!strncmp (argv[i], lang_options[j],
		      strlen (lang_options[j])))
	  break;
      if (lang_options[j] != 0)
	/* If the option is valid for *some* language,
	   treat it as valid even if this language doesn't understand it.  */
	c_decode_option(argv[i]);
      else if (argv[i][0] == '-' && argv[i][1] != 0)
	{
	  register char *str = argv[i] + 1;
	  if (str[0] == 'Y')
	    str++;

	  if (!strcmp (str, "dumpbase"))
	    copy_argv[copy_argc++] = argv[i++];
	  else if (str[0] == 'f')
	    {
	      register char *p = &str[1];
	      int found = 0;

	      /* Some kind of -f option.
		 P's value is the option sans `-f'.
		 Search for it in the table of options.  */

	      for (j = 0;
		   !found && j < sizeof (f_options) / sizeof (f_options[0]);
		   j++)
		{
		  if (!strcmp (p, f_options[j].string))
		    {
		      *f_options[j].variable = f_options[j].on_value;
		      /* A goto here would be cleaner,
			 but breaks the vax pcc.  */
		      found = 1;
		    }
		  if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
		      && ! strcmp (p+3, f_options[j].string))
		    {
		      *f_options[j].variable = ! f_options[j].on_value;
		      found = 1;
		    }
		}
	    }
	  else if (!strcmp (str, "pedantic"))
	    pedantic = 1;
	  else if (!strcmp (str, "pedantic-errors"))
	    flag_pedantic_errors = pedantic = 1;
	  else if (!strcmp (str, "quiet"))
	    quiet_flag = 1;
	  else if (!strcmp (str, "version"))
	    version_flag = 1;
	  else if (!strcmp (str, "w"))
	    inhibit_warnings = 1;
	  else if (!strcmp (str, "W"))
	    {
	      extra_warnings = 1;
	      /* We save the value of warn_uninitialized, since if they put
		 -Wuninitialized on the command line, we need to generate a
		 warning about not using it without also specifying -O.  */
	      if (warn_uninitialized != 1)
		warn_uninitialized = 2;
	    }
	  else if (str[0] == 'W')
	    {
	      register char *p = &str[1];
	      int found = 0;

	      /* Some kind of -W option.
		 P's value is the option sans `-W'.
		 Search for it in the table of options.  */

	      for (j = 0;
		   !found && j < sizeof (W_options) / sizeof (W_options[0]);
		   j++)
		{
		  if (!strcmp (p, W_options[j].string))
		    {
		      *W_options[j].variable = W_options[j].on_value;
		      /* A goto here would be cleaner,
			 but breaks the vax pcc.  */
		      found = 1;
		    }
		  if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
		      && ! strcmp (p+3, W_options[j].string))
		    {
		      *W_options[j].variable = ! W_options[j].on_value;
		      found = 1;
		    }
		}

	      if (found)
		;
	      else if (!strncmp (p, "id-clash-", 9))
		{
		  char *endp = p + 9;

		  while (*endp)
		    {
		      if (*endp >= '0' && *endp <= '9')
			endp++;
		      else
			{
			  error ("Invalid option `%s'", argv[i]);
			  goto id_clash_lose;
			}
		    }
		  warn_id_clash = 1;
		  id_clash_len = atoi (str + 10);
		id_clash_lose: ;
		}
	      else if (!strncmp (p, "larger-than-", 12))
		{
		  char *endp = p + 12;

		  while (*endp)
		    {
		      if (*endp >= '0' && *endp <= '9')
			endp++;
		      else
			{
			  error ("Invalid option `%s'", argv[i]);
			  goto larger_than_lose;
			}
		    }
		  warn_larger_than = 1;
		  larger_than_size = atoi (str + 13);
		larger_than_lose: ;
		}
	    }
	  else if (!strcmp (str, "o"))
	    copy_argv[copy_argc++] = argv[i++];
	  else if (str[0] == 'G')
	    {
	      if (str[1] == '\0')
		copy_argv[copy_argc++] = argv[i++];
	    }
	  else if (!strncmp (str, "aux-info", 8))
	    {
	      if (str[8] == '\0')
		copy_argv[copy_argc++] = argv[i++];
	    }
	  else if (!strcmp(str, "config"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  config_file = strdup(argv[i]);
		}
	      else
		error ("Missing -config file");
	    }
	  else if (!strcmp(str, "prelude"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  dd_add_last(parse_region, preludes,
			      rstrdup(parse_region, argv[i]));
		}
	      else
		error("Missing -prelude file");
	    }
	  else if (!strcmp(str, "hotspots"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  num_hotspots = atoi(argv[i]);
		  if (num_hotspots < 0)
		    error("Negative value for -hotspots count");
		}
	      else
		error("Missing -hotspots count");
	    }
	  else if (!strcmp( str, "program-files"))
	    {
	      if (i < argc - 1)
		{
		  i++;
		  add_program_files(argv[i], files);
		}
	      else
		error("Missing -program-files file");
	    }
	}
      else if (argv[i][0] == '+')
	;
      else
	{
	  /* Allow wildcards, because PAM won't expand files */
	  glob_t globbuf;
	  char **cur;

	  if (glob(argv[i], 0, NULL, &globbuf))
	    {
	      /* glob returned non-zero error status; abort */
	      fprintf(stderr, "%s: file not found\n", argv[i]);
	      exit(FATAL_EXIT_CODE);
	    }
	  else
	    for (cur = globbuf.gl_pathv; *cur; cur++)
	      {
		/* Assume anything called prelude.i is a prelude file */
		if ( strlen(*cur) >= 9 &&
                    !strncmp("prelude.i", *cur + strlen(*cur) - 9, 9))
		  dd_add_last(parse_region, preludes,
			      rstrdup(parse_region, *cur));
		else
		  dd_add_last(parse_region, files,
			      rstrdup(parse_region, *cur));
	      }
	  copy_arg = FALSE;
	}

      if (copy_arg)
	copy_argv[copy_argc++] = argv[i];
    }
  copy_argv[copy_argc] = NULL;

  if (flag_casts_preserve && flag_flow_sensitive) {
    fprintf(stderr, "-fcasts-preserve currently not allowed with "
	    "-fflow_sensitive");
    exit(FATAL_EXIT_CODE);
  }

  /* Now analyze *all* of the files.  First, initialize all appropriate
     data structures. */
  init_types();
  cval_init();
  init_effects();
  init_qtype();
  init_quals();
  init_qerror();

  init_store();

  if (config_file)
    load_config_file_quals(config_file);

  /* Add const so that we can do -fconst-subtyping no matter what */
  if (!const_qual)
    {
      begin_po_qual();
      const_qual = add_qual("const");
      add_level_qual(const_qual, level_ref);
      set_po_nonprop();
      end_po_qual();
    }

  /* Add volatile so we can handle noreturn functions */
  if (!volatile_qual)
    {
      begin_po_qual();
      volatile_qual = add_qual("volatile");
      add_level_qual(volatile_qual, level_ref);
      add_sign_qual(volatile_qual, sign_eq);
      set_po_nonprop();
      end_po_qual();
    }

  /* Add noreturn, for non-returning functions */
  if (!noreturn_qual)
    {
      begin_po_qual();
      noreturn_qual = add_qual("noreturn");
      add_level_qual(noreturn_qual, level_value);
      add_sign_qual(noreturn_qual, sign_eq);
      set_po_nonprop();
      end_po_qual();
    }

  end_define_pos(); /* Allow cqual to run with no qualifiers */

  init_pam();
  init_analyze();
  found_fs_qual = FALSE; /* Force reset, since init_analyze may
			    look up some quals */

  /* Now analyze the prelude files */
  in_prelude = TRUE;
  dd_scan(cur, preludes)
    {
      char *file;
      
      file = DD_GET(char *, cur);
      fprintf(stderr, "Analyzing prelude %s\n", file);
      compile_file(file);
    }
Esempio n. 9
0
int main(int argc,char *args[])
{
	int n,c;
	unsigned long long prof,start,end;

	end_of_data_ptr=sbrk(0);

	time_now=time(NULL);

	printf("\n");
	printf("   ********************************************\n");
        printf("   *     Astonia 3 - The Conflict Server      *\n");
	printf("   *             Version %d.%02d.%02d              *\n",VERSION>>16,(VERSION>>8)&255,VERSION&255);
	printf("   ********************************************\n");
        printf("   * Copyright (C) 2001-2008 Intent Software  *\n");
	printf("   * Copyright (C) 1997-2001 Daniel Brockhaus *\n");
	printf("   ********************************************\n");
	printf("\n");

        if (argc>1) {
		while (1) {
			c=getopt(argc,args,"a:m:i:dhc");
			if (c==-1) break;

			switch (c) {
				case 'a': 	if (optarg) areaID=atoi(optarg); break;
				case 'm': 	if (optarg) areaM=atoi(optarg); break;
				case 'd': 	demon=1; break;
				case 'h':	fprintf(stderr,"Usage: %s [-a <areaID>] [-m <mirror>] [-n <use this class A net>] [-d] [-c]\n\n-d Demonize\n-c Disable concurrent database access\n\n",args[0]); exit(0);
				case 'c':	multi=0; break;
				//case 'n':	if (optarg) server_net=atoi(optarg); break;
				case 'i':	if (optarg) serverID=atoi(optarg); break;
			}
		}
	}

	if (!areaID) {
		printf("No areaID given, assuming areaID=1\n");
		areaID=1;
	}
	if (!areaM) {
		printf("No mirror given, assuming areaM=1\n");
		areaM=1;
	}
	if (!serverID) {
		printf("No serverID given, assuming serverID=1\n");
		serverID=1;
	}

#ifdef STAFF
	while (!check_staff_start()) sleep(1);
#endif


        // set character number limit depending on area
	switch(areaID) {
		case 1:		maxchars=512; break;
		case 2:		maxchars=896; break;
		case 3:		maxchars=384; break;
		case 4:		maxchars=2048; break;
		case 5:		maxchars=768; break;
		case 6:		maxchars=384; break;
		case 7:		maxchars=1280; break;
		case 8:		maxchars=384; break;
		case 9:		maxchars=1280; break;
		case 10:	maxchars=512; break;
		case 11:	maxchars=384; break;
		case 12:	maxitem=1024*48; maxchars=384; break;
		case 13:	maxchars=9*50+200; break;
		case 14:	maxchars=16*50+200; break;
		case 15:	maxchars=384; break;
		case 16:	maxchars=384; break;
		case 17:	maxchars=512; break;
		case 18:	maxchars=768; break;
		case 19:	maxchars=384; break;
		case 20:	maxchars=768; break;
		case 21:	maxchars=768; break;
		case 22:	maxchars=512; break;
		case 23:	maxchars=512; break;
		case 24:	maxchars=384; break;
		case 25:	maxchars=384+8*25*2; break;
		case 26:	maxchars=256; break;
		case 27:	maxchars=2048; break;
		case 28:	maxchars=384; break;
		case 29:	maxchars=512; break;
		case 30:	maxchars=384; break;
		case 31:	maxitem=1024*40; maxchars=512; break;
		case 32:	maxchars=1280; break;
		case 33:	maxchars=1600; break;
		case 34:	maxchars=1280; break;
		case 35:	maxchars=768; break;
		case 36:	maxchars=768; break;
		case 37:	maxchars=1024; break;

		default:	maxchars=768; break;
	}
	
	// set item and effect limit
	if (!maxitem) maxitem=max(maxchars*12+10240,20480);
	if (!maxeffect) maxeffect=max(maxchars*2,1024);

	printf("serverID=%d, areaID=%d, areaM=%d, maxchars=%d, maxitem=%d, maxeffect=%d\n\n",
	       serverID,areaID,areaM,maxchars,maxitem,maxeffect);

	if (demon) {
		printf("Demonizing...\n\n");
		
		if (fork()) exit(0);
		for (n=0; n<256; n++) close(n);
		setsid();
#ifndef STAFF
		nologin=1;
#endif
	}

        // ignore the silly pipe errors:
        signal(SIGPIPE,SIG_IGN);

	// ignore sighup - just to be safe
        signal(SIGHUP,SIG_IGN);

	/*signal(SIGSEGV,sig_crash);
	signal(SIGFPE,sig_crash);
	signal(SIGBUS,sig_crash);
	signal(SIGSTKFLT,sig_crash);*/

        // shutdown gracefully if possible:
        signal(SIGQUIT,sig_leave);
        signal(SIGINT,sig_leave);
        signal(SIGTERM,sig_leave);

	// show profile info on CTRL-Z
	signal(SIGTSTP,sig_showprof);

	// init random number generator
        srand(time_now);

	if (!init_smalloc()) exit(1);
	if (!init_mem()) exit(1);
        if (!init_prof()) exit(1);
	if (!init_log()) exit(1);	
        if (!init_database()) exit(1);
	if (!init_lookup())  exit(1);
        if (!init_sector())  exit(1);
        if (!init_los()) exit(1);
	if (!init_timer()) exit(1);
        if (!init_notify()) exit(1);
	if (!init_create()) exit(1);
        if (!init_lib()) exit(1);
	if (!init_io()) exit(1);
        if (!init_path()) exit(1);	
	if (!init_effect()) exit(1);
	if (!init_container()) exit(1);
	if (!init_store()) exit(1);
	if (!init_chat()) exit(1);

	init_sound_sector();

	xlog("AreaID=%d, AreaM=%d, entering game loop...",areaID,areaM);

	dlog(0,0,"Server started");
	prof_reset();

        while (!quit) {
		sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (busy)",areaID,areaM,serverID,online,(10000-server_idle)/100);
		start=rdtsc();
		lock_server();

		time_now=time(NULL);
		prof=prof_start(26); tick_date(); prof_stop(26,prof);
		prof=prof_start(22); tick_timer(); prof_stop(22,prof);
                prof=prof_start(4); tick_char(); prof_stop(4,prof);
                prof=prof_start(24); tick_effect(); prof_stop(24,prof);
		prof=prof_start(36); tick_clan(); prof_stop(36,prof);
		prof=prof_start(39); tick_club(); prof_stop(39,prof);
		prof=prof_start(5); tick_player(); prof_stop(5,prof);
		prof=prof_start(34); tick_login(); prof_stop(34,prof);
                prof=prof_start(6); pflush(); prof_stop(6,prof);
		prof=prof_start(7); io_loop(); prof_stop(7,prof);
                prof=prof_start(3); tick_chat(); prof_stop(3,prof);

		if (showprof) {
			show_prof();
			showprof=0;
		}
		
		prof=prof_start(8); prof_update(); prof_stop(8,prof);

		end=rdtsc();
		cycles=end-start;

		if ((ticker&2047)==0) {
			prof=prof_start(27); area_alive(0); prof_stop(27,prof);
			prof=prof_start(28); backup_players(); prof_stop(28,prof);
			call_stat_update();
			read_motd();			
			reinit_log();
		}

		if ((ticker&255)==0) {
			call_check_task();
			call_area_load();
			shutdown_warn();
#ifdef STAFF
			check_staff_stop();
#endif
		}

		if ((ticker&255)==168) {
			prof=prof_start(38);
			consistency_check_items();
			consistency_check_map();
			consistency_check_chars();
			consistency_check_containers();
			prof_stop(38,prof);
		}

                unlock_server();

		sprintf(args[0],"./server -a %d -m %d -i %d # %d on %d%% load (idle)",areaID,areaM,serverID,online,(10000-server_idle)/100);

		prof=prof_start(1); tick_sleep(0); prof_stop(1,prof);
		
		ticker++;
	}

        xlog("Left game loop");
	respawn_check();

	for (n=1; n<MAXCHARS; n++) {
		if (ch[n].flags&CF_PLAYER) {
			exit_char(n);
		}
	}
	area_alive(1);

        show_prof();

	dlog(0,0,"Server stopped");

	xlog("map check");
	check_map();

        exit_lib();
	exit_database();

	xlog("Clean shutdown");
	showmem();
	exit_log();
	exit_io();

        return 0;
}