Esempio n. 1
0
File: vu.c Progetto: gvx/deja
int main(int argc, char *argv[])
{
	const struct option options[] = {
		{"help", no_argument, NULL, 'h'},
		{"debug", no_argument, NULL, 'd'},
		{"version", no_argument, NULL, 'v'},
		{"silent", no_argument, NULL, 's'},
		{"persist", no_argument, NULL, 'p'},
		{0, 0, 0, 0},
	};
	char opt;
	while ((opt = getopt_long(argc, argv, "+hdvsp", options, NULL)) != -1)
	{
		switch (opt)
		{
		case 'h':
			puts("Usage: vu [OPTIONS] [module [SCRIPT ARGUMENTS]]\n"
			     "  -h, --help     Show this help message and exit\n"
			     "  -v, --version  Show the VM version and exit\n"
			     "  -d, --debug    Enable debugging\n"
			     "  -s, --silent   Do not print the stack after running\n"
			     "  -p, --persist  Use standard input and output to persist the stack\n"
			     "                 This option is intended for internal use; implies --silent");
			return 0;
		case 'v':
			printf("vu virtual machine 0.2\nbyte code protocol %d.%d\n", VERSION >> 4, VERSION & 15);
			return 0;
		case 's':
			vm_silent = true;
			break;
		case 'd':
			vm_debug = true;
			break;
		case 'p':
			vm_persist = true;
			vm_silent = true;
			break;
		}
	}

	signal(SIGINT, handle_interrupt);
	init_module_path();
	init_errors();
	V global = new_global_scope();
	V v_eva = open_std_lib(toHashMap(toScope(global)->env));
	Stack *S = new_stack();
	init_argv(argc - optind, argv + optind, v_eva);
	run(global, S);
	clear_stack(S);
	return 0;
}
Esempio n. 2
0
void generate_three_address_code(block_node * statements) {
	// Writes basic functions to be used when generating three address code
	//prepare_cfile("out.c");
	int i = 0;
	//init_array_vars(&vars, 2);
	init_array(&lines, 2);
	init_array(&functions, 2);
	init_errors();

	scope * root_scope = new_scope(NULL);

	compile_block(statements, root_scope, &lines, 0);
	if(num_of_errors > 0) {
		print_array(&errors);
	} else {
		print_code(&lines);
		write_to_file(&lines, 0, "w+");
	}
	
}
Esempio n. 3
0
//初始化服务器端,错误列表,...
void init_server()
{
	init_errors();
	signal(SIGCHLD,sig_handler); //注册信号处理函数
	chdir("/var/lib/tftpboot");  //切换主目录
}
Esempio n. 4
0
BOOL init() {
    char whereami[PATH_MAX], *slash;
    int ret;

    ret = GetModuleFileName((HINSTANCE)&__ImageBase, whereami, sizeof(whereami) -1);
    if(!ret || ret == sizeof(whereami) -1) {
	printf("ERROR: GetModuleFileName failed\n");
	return FALSE;
    }

    whereami[sizeof(whereami)-1] = '\0';
    slash = strrchr(whereami, '\\');
    if(!slash) {
	printf("ERROR: No slash found in path %s\n", whereami);
	return FALSE;
    }

    slash++;
    *slash='\0';
    SetDllDirectory(whereami);
    __try {
	cl_set_clcb_msg(msg_callback);
	ret = cl_init(CL_INIT_DEFAULT);
    }
    __except(EXCEPTION_EXECUTE_HANDLER) { ret = -1; }

    SetDllDirectory(NULL);
    if(ret) {
	printf("ERROR: Failed cl_init() returned %d\n", ret);
	return FALSE;
    }

    strncpy(slash, "clamav_log_verbose", sizeof(whereami) - (slash - whereami));
    whereami[sizeof(whereami)-1] = '\0';
    logg_verbose = access(whereami, 0) == -1 ? 0 : 1;

    strncpy(slash, "clamav.log", sizeof(whereami) - (slash - whereami));
    whereami[sizeof(whereami)-1] = '\0';
    logg_nowarn = 0;
    logg_lock = 0;
    logg_time = 1;
    // bb #5659: force log rotation at 100 MB
    logg_size = 104857600;
    logg_rotate = 1;
    logg_file = strdup(whereami);
    if(!logg_file) {
	printf("ERROR: failed to duplicate log filename\n");
	return FALSE;
    }
    strncpy(slash, "clamav.old.log", sizeof(whereami) - (slash - whereami));
    whereami[sizeof(whereami)-1] = '\0';
    if(!MoveFileEx(logg_file, whereami, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH))
	DeleteFile(logg_file);
    logg_noflush = 1;/* only flush on errors and warnings */
    if(logg("ClamAV core initialized (version %s, flevel %d)\n", cl_retver(), cl_retflevel())<0) {
	printf("ERROR: logg failed\n");
	return FALSE;
    }

    if(init_errors()) {
	logg("!Failed to initialize errors\n");
	return FALSE;
    }
    ret = interface_setup();
    logg("ClamAV module initialization %s\n", ret == TRUE ? "succeeded" : "failed! Aborting...");
    return ret;
}
Esempio n. 5
0
int
main (int argc, char **argv)
{
    int i;
    char *p;
    edg_wll_GssStatus gss_stat;
    int ret;
    FILE *pidf;

#ifndef IL_NOTIFICATIONS
    p = strdup(argv[0]);
    program_name = basename(p);
    if (strcmp(program_name, "glite-lb-proxy-interlogd") == 0) {
        file_prefix = DEFAULT_PROXY_PREFIX;
        socket_path = DEFAULT_PROXY_SOCKET;
        pidfile = DEFAULT_PROXY_PIDFILE;
    }
    free(p);
#endif
    program_name = argv[0];

    setlinebuf(stdout);
    setlinebuf(stderr);

    if ((p = getenv("EDG_WL_INTERLOG_TIMEOUT"))) TIMEOUT = atoi(p);

    i = decode_switches (argc, argv);

    if(glite_common_log_init()) {
        fprintf(stderr, "glite_common_log_init() failed, exiting.\n");
        exit(EXIT_FAILURE);
    }

    /* parse config file, if any */
    if(conf_file != NULL) {
        config = load_conf_file(conf_file);
    }

    /* check for reasonable queue lengths */
    if((queue_size_low == 0 && queue_size_high > 0) ||
            (queue_size_low > queue_size_high)) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "max queue length -Q must be greater than low queue length -q, both or none must be specified!");
        exit(EXIT_FAILURE);
    }

    /* force -b if we do not have log server */
    if(log_server == NULL) {
        log_server = strdup(DEFAULT_LOG_SERVER);
        bs_only = 1;
    }

    /* initialize error reporting */
    if(init_errors()) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize error message subsystem. Exiting.");
        exit(EXIT_FAILURE);
    }

    if (signal(SIGPIPE, SIG_IGN) == SIG_ERR
            || signal(SIGABRT, handle_signal) == SIG_ERR
            || signal(SIGTERM, handle_signal) == SIG_ERR
            || signal(SIGINT, handle_signal) == SIG_ERR) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to setup signal handlers: %s, exiting.",
                         strerror(errno));
        exit(EXIT_FAILURE);
    }

    /* just try it before deamonizing to be able to complain aloud */
    if (!(pidf = fopen(pidfile,"w"))) {
        perror(pidfile);
        exit(EXIT_FAILURE);
    }
    fclose(pidf);

    if(!debug &&
            (daemon(0,0) < 0)) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to daemonize itself: %s, exiting.",
                         strerror(errno));
        exit(EXIT_FAILURE);
    }

    pidf = fopen(pidfile,"w");
    assert(pidf); /* XXX */
    fprintf(pidf,"%d\n",getpid());
    fclose(pidf);

    umask(S_IRWXG | S_IRWXO);

#ifdef LB_PERF
    /* this must be called after installing signal handlers */
    glite_wll_perftest_init(NULL, /* host */
                            NULL, /* user */
                            NULL, /* test name */
                            event_source,
                            njobs);
#endif

    if(input_queue_attach() < 0) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize input queue: %s",
                         error_get_msg());
        exit(EXIT_FAILURE);
    }
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initialized input queue.");

    /* initialize output queues */
    if(queue_list_init(log_server) < 0) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize output event queues: %s",
                         error_get_msg());
        exit(EXIT_FAILURE);
    }
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initialized event queues.");
    if(lazy_close)
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "  using lazy mode when closing connections, timeout %d",
                         default_close_timeout);

    /* get credentials */
    if (CAcert_dir)
        setenv("X509_CERT_DIR", CAcert_dir, 1);
    if(edg_wll_gss_initialize()) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize GSS.");
        exit(EXIT_FAILURE);
    }
    ret = edg_wll_gss_watch_creds(cert_file,&cert_mtime);
    if (ret < 0)
        glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"edg_wll_gss_watch_creds failed, unable to access credentials\n");
    cred_handle = malloc(sizeof(*cred_handle));
    if(cred_handle == NULL) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to allocate structure for credentials.");
        exit(EXIT_FAILURE);
    }
    cred_handle->creds = NULL;
    cred_handle->counter = 0;
    ret = edg_wll_gss_acquire_cred(cert_file, key_file, GSS_C_INITIATE, &cred_handle->creds, &gss_stat);
    if (ret) {
        char *gss_err = NULL;

        if (ret == EDG_WLL_GSS_ERROR_GSS)
            edg_wll_gss_get_error(&gss_stat, "edg_wll_gss_acquire_cred_gsi()", &gss_err);
        glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_FATAL, "Failed to load GSI credential: %s",
                         (gss_err) ? gss_err : "edg_wll_gss_acquire_cred_gsi() failed");
        if (gss_err)
            free(gss_err);
        if(gss_stat.minor_status != 0) {
            exit(EXIT_FAILURE);
        } else {
            glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_WARN, "Continuing unauthenticated (yet).");
        }
    }
    if(cred_handle && cred_handle->creds) {
        glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_INFO, "Using certificate %s", cred_handle->creds->name);
    }

    /* parse config, initialize plugins */
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initializing plugins:\n");
    if(config) {
        char *s = strstr(config, "[interlogd]");
        char *p;
        char name[MAXPATHLEN+1];

        if(s) {
            /* next line */
            s = strchr(s, '\n');
            if(s) s++;
            while(s) {
                if(*s == 0 || *s == '[')
                    break;
                /* parse line */
                p = strchr(s, '\n');
                if(p) {
                    *p = 0;
                }
                /* XXX possible overflow by long line in config file */
                ret = sscanf(s, " plugin =%s", name);
                if(p) *p = '\n';
                if(ret > 0) {
                    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "  loading plugin %s\n", name);
                    if(plugin_mgr_init(name, config) < 0) {
                        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Failed to load plugin %s: %s\n", name, error_get_msg());
                    }
                }
                s = p + 1;
            }
        }
    }

#ifndef PERF_EMPTY
    /* find all unsent events waiting in files */
#ifdef LB_PERF
    if(norecover) {
        if(event_store_init(file_prefix) < 0) {
            glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize event stores: %s",
                             error_get_msg());
            exit(EXIT_FAILURE);
        }
    } else
#endif
    {
        pthread_t rid;

        if(pthread_create(&rid, NULL, recover_thread, NULL) < 0) {
            glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to start recovery thread: %s", strerror(errno));
            exit(EXIT_FAILURE);
        }
        pthread_detach(rid);
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Started recovery thread.");
    }
#endif

    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Using %d threads for parallel delivery.", parallel);
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Entering main loop.");

    /* do the work */
    if(loop() < 0) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Fatal error: %s", error_get_msg());
        if (killflg) {
            input_queue_detach();
            unlink(pidfile);
            exit(EXIT_FAILURE);
        }
    }
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Done!");
    input_queue_detach();
    unlink(pidfile);

    exit (0);
}
Esempio n. 6
0
int main(int argc, char* argv[])
{
  char* path_to_config;
  char* path_to_errors;
  int   is_batch_mode;
  int key = 0;
  int list_scr = 0;
  struct process_list* proc_list;
  screen_t* screen = NULL;
  int screen_num = 0;
  int q;
  int paranoia_level;

  /* Check OS to make sure we can run. */
  paranoia_level = check();

  init_options(&options);
  options.paranoia_level = paranoia_level;

  path_to_config = get_path_to_config(argc, argv);
  path_to_errors = get_path_to_error(argc, argv);
  is_batch_mode = get_batch_mode(argc, argv);

  init_errors(is_batch_mode, path_to_errors);

  q = read_config(path_to_config, &options);
  if (q == 0) {
    debug_printf("Config file successfully parsed.\n");
    options.config_file = 1;
  }
  else
    debug_printf("Could not parse config file.\n");

  /* Parse command line arguments. */
  parse_command_line(argc, argv, &options, &list_scr, &screen_num);


  /* Add default screens */
  if (options.default_screen == 1)
    init_screen();

  /* Remove unused but declared counters */
  tamp_counters();

  if (list_scr) {
    list_screens();
    delete_screens();
    exit(0);
  }

  if (options.spawn_pos) {
    /* monitor only spawned process */
    int child = spawn(argv + options.spawn_pos);
    options.only_pid = child;
    options.idle = 1;
  }

  do {
    if (screen_num >= 0)
      screen = get_screen(screen_num);
    else
      screen = get_screen_by_name(argv[-screen_num]);

    if (!screen) {
      fprintf(stderr, "No such screen.\n");
      exit(EXIT_FAILURE);
    }

    /* initialize the list of processes, and then run */
    proc_list = init_proc_list();

    if (options.spawn_pos) {
      options.spawn_pos = 0;  /* do this only once */
      new_processes(proc_list, screen, &options);
      start_child();
    }

    if (options.batch) {
      batch_mode(proc_list, screen);
      key = 'q';
    }
#ifdef HAVE_LIBCURSES
    else {
      key = live_mode(proc_list, screen);
      if ((key == '+')  || (key == KEY_RIGHT)) {
        screen_num = (screen_num + 1) % get_num_screens();
        active_col = 0;
        done_proc_list(proc_list);
        free(header);
      }
      if ((key == '-') || (key == KEY_LEFT)) {
        int n = get_num_screens();
        screen_num = (screen_num + n - 1) % n;
        active_col = 0;
        done_proc_list(proc_list);
        free(header);
      }
      if ((key == 'u') || (key == 'K') || (key == 'p')) {
        done_proc_list(proc_list);
      }
    }
#endif
  } while (key != 'q');

  /* done, free memory (makes valgrind happy) */
  close_error();
  delete_screens();
  done_proc_list(proc_list);
  free_options(&options);
  return 0;
}