Ejemplo n.º 1
0
static char *getFileData(char *name)
{
	char *data;

	struct stat filestat;
	if ((stat(name, &filestat)) < 0) {
		fprintf(OUTPUTBUFF, "Error. Could not open file '%s'. Please check that it exists and is not write-protected.\n", name);
		main_cleanup(FATALERROR);
	}

	if (filestat.st_size == 0) {
		fprintf(OUTPUTBUFF, "Error. File '%s' has zero size.\n", name);
		main_cleanup(FATALERROR);
	}

	data = malloc(filestat.st_size + 1);
	if (data == NULL) {
		fprintf(OUTPUTBUFF, "Error. Could not allcoate memory for contents of file %s.\n", name);
		main_cleanup(FATALERROR);
	}
	else {
		size_t fileSize = 0;
		FILE *fp = fopen(name, "r");
		if (fp == NULL) {
			fprintf(OUTPUTBUFF, "Error. Could not open file '%s'. Please check that it exists and is not write-protected.\n", name);
			main_cleanup(FATALERROR);
		}
		fileSize = fread(data, 1, filestat.st_size, fp);
		data[fileSize] = 0;
		fclose(fp);
	}
	return data;
}
Ejemplo n.º 2
0
int main(int argc, char ** argv)
{
	bool success_all = true;
	bool unbalance_check = true;
	struct busy_data busy;
	const char * exec_name = argv[0];

	os_init(OS_INIT_NOFREQUENCY);
	printf("# %s Created by Olivier Cozette <*****@*****.**>\n# Copyright (C) 2013  ARM Limited\n", argv[0]);

	if ((argc > 1) && (strcmp(argv[1], "NO_BALANCE_CHECK") == 0))
	{
		argv++;
		argc--;
		unbalance_check = false;
	}

	if (argc < 5)
	{
		printf("#Usage %s [NO_BALANCE_CHECK] TOTAL_SEQUENTIAL_TIME RUNNING_TIME SLEEPING_TIME NICE_PID0 [NICE_PID1] ...\n", exec_name);
		printf("#\tif NO_BALANCED_CHECK is given, even unbalanced thread won't raise a FAILED\n");
		os_cleanup();
		exit(1);
	}

	if (!main_init(&busy, argc, argv))
	{
		printf("# error :%s\n", busy.error_str);
		main_cleanup(&busy);
		os_cleanup();
		exit(1);
	}

	if (!main_launch(&busy))
		success_all = false;
	if (!main_wait(&busy))
		success_all = false;
	if (success_all)
		printf("SUCCESS before checking if tasks were well balanced\n");
	if (!main_check(&busy))
	{
		if (unbalance_check)
			success_all = false;
		else
			printf("#Seen as unbalanced or not using all the cpu time, but this doesn't affect the result\n");
	}

	main_cleanup(&busy);
	os_cleanup();
	if (!success_all)
	{
		printf("FAILED\n");
		exit(1);
	}
	printf("SUCCESS\n");
	return 0;
}
Ejemplo n.º 3
0
int main_rehash ( ctx_t *ctx_p )
{
	debug ( 3, "" );
	int ret = 0;
	main_cleanup ( ctx_p );
	return ret;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[]) {
    static struct WSAData wsa_state;
    TCHAR *c, stunnel_exe_path[MAX_PATH];

    /* set current working directory and engine path */
    GetModuleFileName(0, stunnel_exe_path, MAX_PATH);
    c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash */
    if(c) /* found */
        c[1]=TEXT('\0'); /* truncate program name */
#ifndef _WIN32_WCE
    if(!SetCurrentDirectory(stunnel_exe_path)) {
        /* log to stderr, as s_log() is not initialized */
        _ftprintf(stderr, TEXT("Cannot set directory to %s"),
            stunnel_exe_path);
        return 1;
    }
#endif
    _tputenv_s(TEXT("OPENSSL_ENGINES"), stunnel_exe_path);

    str_init(); /* initialize per-thread string management */
    if(WSAStartup(MAKEWORD(1, 1), &wsa_state))
        return 1;
    resolver_init();
    main_init();
    if(!main_configure(argc>1 ? argv[1] : NULL, argc>2 ? argv[2] : NULL))
        daemon_loop();
    main_cleanup();
    return 0;
}
Ejemplo n.º 5
0
void signal_handler(int sig){ // {{{
	switch(sig) {
		case SIGHUP:  break;
		case SIGINT:
		case SIGTERM: main_cleanup(); exit(0); break;
	}
} // }}}
Ejemplo n.º 6
0
int main(int argc, char* argv[]) { /* execution begins here 8-) */
    int retval;

#ifdef M_MMAP_THRESHOLD
    mallopt(M_MMAP_THRESHOLD, 4096);
#endif
    tls_init(); /* initialize thread-local storage */
    retval=main_unix(argc, argv);
    main_cleanup();
    return retval;
}
Ejemplo n.º 7
0
	int DEFAULT_CC
main(int argc, char** argv)
{
	int pid;
	char text[256];
	if (argc != 2)
	{
		g_printf("Usage : xrdp-chansrv 'username'\n");
		g_exit(1);
	}
	username = argv[1];
	g_init(); /* os_calls */
	read_ini();
	read_logging_conf();
	chan_init();
	log_start(&log_conf);
	pid = g_getpid();
	log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[main]: "
			"app started pid %d(0x%8.8x)", pid, pid);
	g_signal_kill(term_signal_handler); /* SIGKILL */
	g_signal_terminate(term_signal_handler); /* SIGTERM */
	g_signal_user_interrupt(term_signal_handler); /* SIGINT */
	g_signal_pipe(nil_signal_handler); /* SIGPIPE */
	g_signal_child_stop(stop_signal_handler);
	g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
	g_term_event = g_create_wait_obj(text);
	g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
	g_thread_done_event = g_create_wait_obj(text);
	tc_thread_create(channel_thread_loop, 0);
	while (!g_is_wait_obj_set(g_term_event))
	{
		if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0)
		{
			log_message(&log_conf, LOG_LEVEL_WARNING, "chansrv[main]: "
					"main: error, g_obj_wait failed");
			break;
		}
	}
	while (!g_is_wait_obj_set(g_thread_done_event))
	{
		/* wait for thread to exit */
		if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
		{
			log_message(&log_conf, LOG_LEVEL_WARNING, "chansrv[main]: "
					"main: error, g_obj_wait failed");
			break;
		}
	}
	/* cleanup */
	main_cleanup();
	log_message(&log_conf, LOG_LEVEL_INFO, "chansrv[main]: "
			"main: app exiting pid %d(0x%8.8x)", pid, pid);
	return 0;
}
Ejemplo n.º 8
0
void main_child(int pid, void * data)
{
	struct busy_data * busy =
		(struct busy_data *)data;

	os_sleep(1); /* allows the other fork to happen ASAP */
	os_nice_set(pid, busy->nice);

	busy_run((int)(busy->total_sequential_time / (busy->running_time + busy->sleeping_time)),
			busy->sleeping_time,
			busy->busy_loop);
	main_cleanup(busy);
}
Ejemplo n.º 9
0
int main() {

        SSL_library_init();
        SSL_load_error_strings();

        // Initializing the group once up front cut execution time in half! However the code should function without a reusable group.
        ecies_group_init();

        // Comment this line out if you want the program to execute consistently each time.
        srand(time(NULL));

        for (uint64_t i = 0; i < 100; i++) {
                if (processor(i)) {
                        main_cleanup();
                        return 1;
                }
        }

        printf("Finished.\n");
        main_cleanup();

        return 0;
}
Ejemplo n.º 10
0
int  main (int argc, char **argv){ // {{{
	int c;
	int option_index;
	opt_func func;
	
	opts_init();
	
	option_index = -1;
	while( (c = getopt_long (argc, argv, short_options, long_options, &option_index)) != -1){
		struct cmdline_option *mopt;
		
		if(option_index == -1){
			mopt = map_opts[c - 32];
		}else{
			mopt = &option_data[ long_options[option_index].val ];
		}
		if(mopt == NULL)
			exit(255);
		
		switch(mopt->type){
			case OPT_VALUE_INT:
				*(unsigned int *)(mopt->opt_ptr) = atoi(optarg);
				break;
			case OPT_VALUE_STR:
				*(char **)       (mopt->opt_ptr) = strdup(optarg);
				break;
			case OPT_VALUE_BOOL:
				*(unsigned int *)(mopt->opt_ptr) = 1;
				break;
			case OPT_GROUP:
				break;
			case OPT_FUNC:
				func = (opt_func)(mopt->opt_ptr);
				func();
				exit(0);
		}
		
		option_index = -1;
	}
	
	main_rest();
	main_cleanup();	
	
	return 0;
} // }}}
Ejemplo n.º 11
0
NOEXPORT void daemon_thread(void *arg) {
    (void)arg; /* skip warning about unused parameter */

    main_initialize();
    /* get a valid configuration */
    while(main_configure(cmdline.config_file, NULL)) {
        unbind_ports(); /* in case initialization failed after bind_ports() */
        log_flush(LOG_MODE_ERROR); /* otherwise logs are buffered */
        PostMessage(hwnd, WM_INVALID_CONFIG, 0, 0); /* display error */
        WaitForSingleObject(config_ready, INFINITE);
        log_close(); /* prevent main_configure() from logging in error mode */
    }
    error_mode=0; /* a valid configuration was loaded */

    /* start the main loop */
    daemon_loop();
    main_cleanup();
    _endthread(); /* SIGNAL_TERMINATE received */
}
Ejemplo n.º 12
0
NOEXPORT void daemon_thread(void *arg) {
    (void)arg; /* squash the unused parameter warning */

    tls_alloc(NULL, NULL, "main"); /* new thread-local storage */
    main_init();
    SetEvent(main_initialized); /* unlock the GUI thread */
    /* get a valid configuration */
    while(main_configure(cmdline.config_file, NULL)) {
        if(cmdline.config_file && *cmdline.config_file=='-')
            cmdline.config_file=NULL; /* don't retry commandline switches */
        unbind_ports(); /* in case initialization failed after bind_ports() */
        log_flush(LOG_MODE_ERROR); /* otherwise logs are buffered */
        PostMessage(hwnd, WM_INVALID_CONFIG, 0, 0); /* display error */
        WaitForSingleObject(config_ready, INFINITE);
        log_close(); /* prevent main_configure() from logging in error mode */
    }
    PostMessage(hwnd, WM_VALID_CONFIG, 0, 0);

    /* start the main loop */
    daemon_loop();
    main_cleanup();
    _endthread(); /* SIGNAL_TERMINATE received */
}
Ejemplo n.º 13
0
int main ( int _argc, char *_argv[] )
{
	struct ctx *ctx_p = xcalloc ( 1, sizeof ( *ctx_p ) );
	argv = _argv;
	argc = _argc;
	int ret = 0, nret;
	//SAFE ( posixhacks_init(), errno = ret = _SAFE_rc );
	ctx_p->config_group			 = DEFAULT_CONFIG_GROUP;
	ctx_p->vms_min				 = DEFAULT_VMS_MIN;
	ctx_p->vms_max				 = DEFAULT_VMS_MAX;
	ctx_p->vms_spare_min			 = DEFAULT_VMS_SPARE_MIN;
	ctx_p->vms_spare_max			 = DEFAULT_VMS_SPARE_MAX;
	strncpy ( ctx_p->listen_addr, strdup ( DEFAULT_LISTEN ), 256 );
	ctx_p->flags[KILL_ON_DISCONNECT]	 = DEFAULT_KILL_ON_DISCONNECT;
	ncpus					 = sysconf ( _SC_NPROCESSORS_ONLN ); // Get number of available logical CPUs
	memory_init();
	ctx_p->pid				 = getpid();
	int quiet = 0, verbose = 3;
	error_init ( &ctx_p->flags[OUTPUT_METHOD], &quiet, &verbose, &ctx_p->flags[DEBUG] );
	nret = arguments_parse ( argc, argv, ctx_p );

	if ( nret ) ret = nret;

	if ( !ret ) {
		nret = configs_parse ( ctx_p, PS_CONFIG );

		if ( nret ) ret = nret;
	}

	if ( !ctx_p->kvm_args[SHARGS_PRIMARY].c ) {
		char *args_line = strdup ( DEFAULT_KVM_ARGS );
		parse_parameter ( ctx_p, KVM_ARGS, args_line, PS_DEFAULTS );
	}

	debug ( 4, "ncpus == %u", ncpus );
	debug ( 4, "debugging flags: %u 0 3 %u", ctx_p->flags[OUTPUT_METHOD], ctx_p->flags[DEBUG] );
	{
		int n = 0;

		while ( n < SHARGS_MAX ) {
			kvm_args_t *args_p = &ctx_p->kvm_args[n++];
			debug ( 9, "Custom arguments %u count: %u", n - 1, args_p->c );
			int i = 0;

			while ( i < args_p->c ) {
				int macros_count = -1, expanded = -1;
				args_p->v[i] = parameter_expand ( ctx_p, args_p->v[i], 4, &macros_count, &expanded, parameter_get, ctx_p );
				debug ( 12, "args_p->v[%u] == \"%s\" (t: %u; e: %u)", i, args_p->v[i], macros_count, expanded );

				if ( macros_count == expanded )
					args_p->isexpanded[i]++;

				i++;
			}
		}
	}
	ctx_p->state = STATE_STARTING;
	nret = main_rehash ( ctx_p );

	if ( nret )
		ret = nret;

	{
		int rc = ctx_check ( ctx_p );

		if ( !ret ) ret = rc;
	}
	debug ( 3, "Current errno is %i.", ret );

	// == RUNNING ==
	if ( ret == 0 )
		ret = kvmpool ( ctx_p );

	// == /RUNNING ==
	main_cleanup ( ctx_p );
	error_deinit();
	ctx_cleanup ( ctx_p );
	debug ( 1, "finished, exitcode: %i: %s.", ret, strerror ( ret ) );
	free ( ctx_p );
#ifndef __FreeBSD__	// Hanging up with 100%CPU eating, https://github.com/xaionaro/clsync/issues/97
	//SAFE ( posixhacks_deinit(), errno = ret = _SAFE_rc );
#endif
	return ret;
}
Ejemplo n.º 14
0
int main(int argc, char *argv[])
{
	int allowEdit, allowHintSub, fixStems, debug, badParam;
	char *fontInfoFileName=NULL; /* font info file name, or suffix of environment variable holding the fontfino string. */
	char *fontinfo = NULL; /* the string of fontinfo data */
	int firstFileNameIndex = -1; /* arg index for first bez file name, or  suffix of environment variable holding the bez string. */
	register char *current_arg;
	short total_files = 0; 
	int result, argi;
  
	badParam = fixStems = debug = doAligns = doStems = allstems = FALSE;
	allowEdit = allowHintSub = TRUE;
	fileSuffix = (char*)dfltExt;

	/* read in options */
	argi = 0;
	while (++argi < argc)
		{
	   current_arg = argv[argi];
	   
		if (current_arg[0] == '\0')
			continue;
		else if (current_arg[0] != '-')
			{
			if (firstFileNameIndex == -1)
				firstFileNameIndex = argi;
			total_files++;
			continue;
			}
		else if (firstFileNameIndex != -1)
			{
			fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-\" option found after first file name.\n");
			exit(1);
 			}

		switch (current_arg[1])
			{
			case '\0':
				badParam = TRUE;
				break;
			case 'u':
				printUsage();
				#ifdef EXECUTABLE
				  exit(0);
				#else
					longjmp(aclibmark, 1);
				#endif
				break;
			case 'h':
				printHelp();
				#ifdef EXECUTABLE
				  exit(0);
				#else
					longjmp(aclibmark, 1);
				#endif
				break;
			 case 'e':
				allowEdit = FALSE;
				break;
			 case 'f':
				fontInfoFileName = argv[++argi];
				if  ((fontInfoFileName[0] == '\0') || (fontInfoFileName[0] == '-'))
					{
					fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-f\" option must be followed by a file name.\n");
					exit(1);
					}
				break;
			 case 's':
				fileSuffix = argv[++argi];
				if  ((fileSuffix[0] == '\0') || (fileSuffix[0] == '-'))
					{
					fprintf(OUTPUTBUFF, "Error. Illegal command line. \"-s\" option must be followed by a string, and the string must not begin with '-'.\n");
					exit(1);
					}
				break;
			case 'n':
				allowHintSub = FALSE;
				break;
			case 'q':
				verbose = FALSE;
				break;
			 case 'D':
				debug = TRUE;
				break;
			case 'F':
				fixStems = TRUE;
			  break;
			case 'a':
				allstems = 1;
				break;
				
			case 'r':
				allowEdit = allowHintSub = FALSE;
				fileSuffix = (char *)reportExt;
				switch (current_arg[2])
					{
					case 'a':
						reportRetryCB = reportRetry;
						addCharExtremesCB = charZoneCB;
						addStemExtremesCB = stemZoneCB;
						doAligns = 1;

						addHStemCB = NULL;
						addVStemCB = NULL;
						doStems = 0;
						break;
					case 's':
						reportRetryCB = reportRetry;
						addHStemCB = hstemCB;
						addVStemCB = vstemCB;
						doStems = 1;

						addCharExtremesCB = NULL;
						addStemExtremesCB = NULL;
						doAligns = 0;
						break;
					default:
						fprintf(OUTPUTBUFF, "Error. %s is an invalid parameter.\n", current_arg);
						badParam = TRUE;
						break;
					}
					break;
			case 'v':
				printVersions();
				exit(0);
				break;
			  break;
#if ALLOWCSOUTPUT
			case 'C':
				charstringoutput = TRUE;
				break;
#endif
			default:
				fprintf(OUTPUTBUFF, "Error. %s is an invalid parameter.\n", current_arg);
				badParam = TRUE;
				break;
			}
		}

	if (firstFileNameIndex == -1)
		{
		fprintf(OUTPUTBUFF, "Error. Illegal command line. Must provide bez file name.\n");
		badParam = TRUE;
		}
	if (fontInfoFileName == NULL)
		{
		fprintf(OUTPUTBUFF, "Error. Illegal command line. Must provide font info file name.\n");
		badParam = TRUE;
		}
		
	if (badParam) 
#ifdef EXECUTABLE
		exit(NONFATALERROR);
#else
		longjmp(aclibmark, -1);
#endif

#if ALLOWCSOUTPUT
	if (charstringoutput)
		read_char_widths();
#endif

	AC_SetReportCB(reportCB, verbose);
	fontinfo = getFileData(fontInfoFileName);
	argi = firstFileNameIndex-1;
	while (++argi < argc)
		{
		char *bezdata;
		char *output;
		size_t outputsize = 0;
		bezName = argv[argi];
		bezdata = getFileData(bezName);
		outputsize = 4*strlen(bezdata);
		output = malloc(outputsize); 

		if (doAligns || doStems)
			openReportFile(bezName, fileSuffix);
			
		result = AutoColorString(bezdata, fontinfo, output, (int*)&outputsize, allowEdit, allowHintSub, debug);
		if (result == AC_DestBuffOfloError)
			{
			free(output);
			if (reportFile != NULL)
				closeReportFile();
			if (doAligns || doStems)
				openReportFile(bezName, fileSuffix);
			output = malloc(outputsize); 
			/* printf("NOTE: trying again. Input size %d output size %d.\n", strlen(bezdata), outputsize); */
			AC_SetReportCB(reportCB, FALSE);
			result = AutoColorString(bezdata, fontinfo, output, (int*)&outputsize, allowEdit, allowHintSub, debug);
			AC_SetReportCB(reportCB, verbose);
			}
		if (reportFile != NULL)
			closeReportFile();
		else
			{
			if ((outputsize != 0) && (result == AC_Success))
				writeFileData(bezName, output, fileSuffix);
			}
		free(output);
		main_cleanup( (result == AC_Success) ? OK : FATALERROR);
		}
		

  return 0;
  }
Ejemplo n.º 15
0
int DEFAULT_CC
main(int argc, char **argv)
{
    tbus waiters[4];
    int pid = 0;
    char text[256];
    char *home_text;
    char *display_text;
    char log_file[256];
    enum logReturns error;
    struct log_config logconfig;

    g_init("xrdp-chansrv"); /* os_calls */

    home_text = g_getenv("HOME");

    if (home_text == 0)
    {
        g_writeln("error reading HOME environment variable");
        g_deinit();
        return 1;
    }

    read_ini();
    pid = g_getpid();

    /* starting logging subsystem */
    g_memset(&logconfig, 0, sizeof(struct log_config));
    logconfig.program_name = "XRDP-Chansrv";
    g_snprintf(log_file, 255, "%s/xrdp-chansrv.log", home_text);
    g_writeln("chansrv::main: using log file [%s]", log_file);

    if (g_file_exist(log_file))
    {
        g_file_delete(log_file);
    }

    logconfig.log_file = log_file;
    logconfig.fd = -1;
    logconfig.log_level = LOG_LEVEL_ERROR;
    logconfig.enable_syslog = 0;
    logconfig.syslog_level = 0;
    error = log_start_from_param(&logconfig);

    if (error != LOG_STARTUP_OK)
    {
        switch (error)
        {
            case LOG_ERROR_MALLOC:
                g_writeln("error on malloc. cannot start logging. quitting.");
                break;
            case LOG_ERROR_FILE_OPEN:
                g_writeln("error opening log file [%s]. quitting.",
                          getLogFile(text, 255));
                break;
            default:
                g_writeln("log_start error");
                break;
        }

        g_deinit();
        return 1;
    }

    LOGM((LOG_LEVEL_ALWAYS, "main: app started pid %d(0x%8.8x)", pid, pid));
    /*  set up signal handler  */
    g_signal_kill(term_signal_handler); /* SIGKILL */
    g_signal_terminate(term_signal_handler); /* SIGTERM */
    g_signal_user_interrupt(term_signal_handler); /* SIGINT */
    g_signal_pipe(nil_signal_handler); /* SIGPIPE */
    g_signal_child_stop(child_signal_handler); /* SIGCHLD */
    display_text = g_getenv("DISPLAY");
    LOGM((LOG_LEVEL_INFO, "main: DISPLAY env var set to %s", display_text));
    get_display_num_from_display(display_text);

    if (g_display_num == 0)
    {
        LOGM((LOG_LEVEL_ERROR, "main: error, display is zero"));
        g_deinit();
        return 1;
    }

    LOGM((LOG_LEVEL_INFO, "main: using DISPLAY %d", g_display_num));
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_main_term", pid);
    g_term_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_thread_done", pid);
    g_thread_done_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_chansrv_%8.8x_exec", pid);
    g_exec_event = g_create_wait_obj(text);
    g_exec_mutex = tc_mutex_create();
    g_exec_sem = tc_sem_create(0);
    tc_thread_create(channel_thread_loop, 0);

    while (g_term_event > 0 && !g_is_wait_obj_set(g_term_event))
    {
        waiters[0] = g_term_event;
        waiters[1] = g_exec_event;

        if (g_obj_wait(waiters, 2, 0, 0, 0) != 0)
        {
            LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
            break;
        }

        if (g_is_wait_obj_set(g_term_event))
        {
            break;
        }

        if (g_is_wait_obj_set(g_exec_event))
        {
            g_reset_wait_obj(g_exec_event);
            run_exec();
        }
    }

    while (g_thread_done_event > 0 && !g_is_wait_obj_set(g_thread_done_event))
    {
        /* wait for thread to exit */
        if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
        {
            LOGM((LOG_LEVEL_ERROR, "main: error, g_obj_wait failed"));
            break;
        }
    }

    /* cleanup */
    main_cleanup();
    LOGM((LOG_LEVEL_INFO, "main: app exiting pid %d(0x%8.8x)", pid, pid));
    g_deinit();
    return 0;
}