Exemplo n.º 1
0
RETSIGTYPE
sig_tstop(int i)	/* SIGTSTP handler */

{
    /* move to the lower left */
    screen_end();
    fflush(stdout);

    /* default the signal handler action */
    set_signal(SIGTSTP, SIG_DFL);

    /* unblock the TSTP signal */
    release_signal(SIGTSTP);

    /* send ourselves a TSTP to stop the process */
    (void) kill(0, SIGTSTP);

    /* reset the signal handler */
    set_signal(SIGTSTP, sig_tstop);

    /* reinit screen */
    screen_reinit();

    /* jump back to a known place in the main loop */
    longjmp(jmp_int, JMP_RESUME);

    /* NOTREACHED */
}
Exemplo n.º 2
0
void init(int_ choice){
	server_loop_code = new loop_t;
	reserve_ids();
	console_init();
	load_previous_server_state();
	server_loop_code->array.name = "server loop code";
	//signal(SIGINT, simple_signal_handler);
	switch(choice){
	case 1:
		server_info_init();
		if(check_for_parameter("--net-disable", argc_, argv_) == false) net_init();
		if(check_for_parameter("--physics-disable", argc_, argv_) == false) physics_init();
		if(check_for_parameter("--gametype-disable", argc_, argv_) == false) gametype_init();
		if(check_for_parameter("--input-disable", argc_, argv_) == false) input_init(); // signals should still work from the console
		break;
	case 2:
		test_logic_init();
		break;
	case 3:
		set_signal(SIGTERM, true);
		break;
	default:
		printf("WARNING: This was NOT one of the options, terminating\n");
		set_signal(SIGTERM, true);
		break;
	}
	server_time = new server_time_t;
}
Exemplo n.º 3
0
void input_t::keyboard_to_signal(){
	const bool alt_key = query_key(SDL_SCANCODE_LALT) || query_key(SDL_SCANCODE_RALT);
	if(unlikely(alt_key)){
		if(query_key(SDL_SCANCODE_1)){
			set_signal(SIGNAL_QUIT_LOOP, true);
		}else{
			set_signal(SIGNAL_QUIT_LOOP, false);
		}
	}
}
Exemplo n.º 4
0
void set_signals( void )
  {
#ifdef SIGWINCH
  sigwinch_handler( SIGWINCH );
  if( isatty( 0 ) ) set_signal( SIGWINCH, sigwinch_handler );
#endif
  set_signal( SIGHUP, sighup_handler );
  set_signal( SIGQUIT, SIG_IGN );
  set_signal( SIGINT, sigint_handler );
  }
Exemplo n.º 5
0
void
set_signals()

{
    (void) set_signal(SIGINT, sig_leave);
    (void) set_signal(SIGQUIT, sig_leave);
    (void) set_signal(SIGTSTP, sig_tstop);
#ifdef SIGWINCH
    (void) set_signal(SIGWINCH, sig_winch);
#endif
}
Exemplo n.º 6
0
Arquivo: init.c Projeto: kawatea/cedit
void init_window(void)
{
    load_setting();
    
    //メインウィンドウの外観の設定
    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(main_window), "cedit");
    gtk_window_set_icon(GTK_WINDOW(main_window), get_icon("icon.png"));
    gtk_window_move(GTK_WINDOW(main_window), window_x, window_y);
    gtk_window_set_default_size(GTK_WINDOW(main_window), window_width, window_height);
    
    //ウィンドウの内部の設定
    GtkWidget *main_vbox = gtk_vbox_new(FALSE, 3);
    gtk_container_add(GTK_CONTAINER(main_window), main_vbox);
    init_bar(main_vbox);
    init_editor(main_vbox);
    
    //全体の動作の設定
    init_tag();
    init_library();
    set_action("New", FALSE);
    set_action("Save", FALSE);
    set_action("Undo", FALSE);
    set_action("Redo", FALSE);
    set_action("Cut", FALSE);
    set_action("Copy", FALSE);
    set_action("Delete", FALSE);
    static GtkTargetEntry target[] = {{"text/uri-list",  0, 10}};
    gtk_drag_dest_set(view, GTK_DEST_DEFAULT_ALL, target, 1, GDK_ACTION_COPY);
    gtk_drag_dest_set(main_window, GTK_DEST_DEFAULT_ALL, target, 1, GDK_ACTION_COPY);
    set_signal();
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: vlehuger/42sh
int				main(int ac, char **av, char **env)
{
	t_sh		*sh;
	int			stop;

	create_env(env);
	env = add_builtin_pid(env);
	set_signal();
	if (ac > 1)
		(void)av;
	else
	{
		stop = 0;
		sh = get_sh(&stop);
		set_terminal(sh);
		while (!stop)
		{
			sh->ft_stdin = dup(STDIN_FILENO);
			sh->ft_stdout = dup(STDOUT_FILENO);
			start_sh(sh);
			ft_putenv("PID_EXECV", NULL);
		}
	}
	return (0);
}
Exemplo n.º 8
0
void signal_function(int signal){
	if(pull_signal(SIGTERM) && signal == SIGTERM){
		printf("Halting the program because of a hang in the loop\n");
		assert(false);
	}
	set_signal(signal, true);
}
Exemplo n.º 9
0
int main(void)
{
    tls_client_t client = {0};
    const char *gnutls_ver = NULL;
    time_t start = 0;
    time_t end = 0;
    int ret = 0;
    int i = 0;

    /* initialise signal handling */
    set_signal();

    coap_log_set_level(COAP_LOG_DEBUG);

    gnutls_ver = gnutls_check_version(NULL);
    if (gnutls_ver == NULL)
    {
        coap_log_error("Unable to determine GnuTLS version");
        return EXIT_FAILURE;
    }
    coap_log_info("GnuTLS version: %s", gnutls_ver);

    ret = tls_init();
    if (ret != SOCK_OK)
    {
        coap_log_error("%s", sock_strerror(ret));
        return EXIT_FAILURE;
    }

    ret = tls_client_create(&client, TRUST_FILE_NAME, CERT_FILE_NAME, KEY_FILE_NAME);
    if (ret != SOCK_OK)
    {
        coap_log_error("%s", sock_strerror(ret));
        tls_deinit();
        return EXIT_FAILURE;
    }

    for (i = 0; i < NUM_ITER; i++)
    {
        start = time(NULL);
        ret = client_run(&client);
        end = time(NULL);
        if (ret != SOCK_OK)
        {
            coap_log_error("%s", sock_strerror(ret));
            tls_client_destroy(&client);
            tls_deinit();
            return EXIT_FAILURE;
        }
        coap_log_info("Result: %s", sock_strerror(ret));
        coap_log_debug("Time: %d sec", (int)(end - start));
        coap_log_debug("Sleeping for %d seconds...", DELAY);
        sleep(DELAY);
    }

    tls_client_destroy(&client);
    tls_deinit();
    return EXIT_SUCCESS;
}
Exemplo n.º 10
0
pid_t gld_fork(void)
{
  pid_t pid;
  
  pid = fork();
  if (pid == (pid_t)-1)
  {
    syslog(LOG_CRIT,"fork() = %s",strerror(errno));
    return(pid);
  }
  else if (pid > (pid_t)0)	/* parent returns immediately */
    return(pid);
  
  /*---------------------------------------------------
  ; set the environment for the child process.
  ;--------------------------------------------------*/

  alarm(0);	/* turn off any pending alarms */
  
  set_signal(SIGSEGV,sighandler_critical_child);
  set_signal(SIGBUS, sighandler_critical_child);
  set_signal(SIGFPE, sighandler_critical_child);
  set_signal(SIGILL, sighandler_critical_child);
  set_signal(SIGXCPU,sighandler_critical_child);
  set_signal(SIGXFSZ,sighandler_critical_child);
  set_signal(SIGPIPE,sighandler_critical_child);

  return(pid);
}
Exemplo n.º 11
0
static void do_standalone_mode(gboolean daemonize)
{
	int ret;
	int lsock[MAXSOCK];
	struct addrinfo *ai_head;
	int n;



	ret = usbip_names_init(USBIDS_FILE);
	if (ret)
		err("open usb.ids");

	ret = usbip_stub_driver_open();
	if (ret < 0)
		g_error("driver open failed");

	if (daemonize) {
		if (daemon(0,0) < 0)
			g_error("daemonizing failed: %s", g_strerror(errno));

		usbip_use_syslog = 1;
	}

	set_signal();

	ai_head = my_getaddrinfo(NULL, PF_UNSPEC);
	if (!ai_head)
		return;

	n = listen_all_addrinfo(ai_head, lsock);
	if (n <= 0)
		g_error("no socket to listen to");

	for (int i = 0; i < n; i++) {
		GIOChannel *gio;

		gio = g_io_channel_unix_new(lsock[i]);
		g_io_add_watch(gio, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
				process_comming_request, NULL);
	}


	info("usbipd start (%s)", version);


	main_loop = g_main_loop_new(FALSE, FALSE);
	g_main_loop_run(main_loop);

	info("shutdown");

	freeaddrinfo(ai_head);
	usbip_names_free();
	usbip_stub_driver_close();

	return;
}
Exemplo n.º 12
0
void th_start()
{
	if (th_initialized) return;
	main_thread.u = &main_data;
	threads[0] = &main_thread;
	th_it = 1;
	set_signal(dispatcher);
	th_initialized = 1;
}
Exemplo n.º 13
0
FeatureExtractionSpectral::FeatureExtractionSpectral(SAMPLE* signal, int bufSize, int fs, int winSize, int hopSize){
	set_signal(signal);
	set_bufSize(bufSize);
	set_fs(fs);
	set_winSize(winSize);
	set_hopSize(hopSize);
	calculate_fBinSize();
	calculate_magSpec();
}
Exemplo n.º 14
0
static void handle_sigint(void)
{
  syslog(LOG_DEBUG,"Interrupt Signal");

  save_state();
  GlobalsDeinit();
  set_signal(SIGINT,SIG_DFL);
  raise(SIGINT);
}
Exemplo n.º 15
0
static void handle_sigquit(void)
{
  syslog(LOG_DEBUG,"Quit signal");

  save_state();
  GlobalsDeinit();
  set_signal(SIGQUIT,SIG_DFL);
  raise(SIGQUIT);
}
Exemplo n.º 16
0
static void handle_sigterm(void)
{
  syslog(LOG_DEBUG,"Terminate Signal");

  save_state();
  GlobalsDeinit();
  set_signal(SIGTERM,SIG_DFL);
  raise(SIGTERM);
}
Exemplo n.º 17
0
Arquivo: Main.c Projeto: k2b3d/tconsrc
int main(int argc, char *argv[])
{
	pid_t 		pid ;
	int 		stat ;
	pthread_t	pthread_cancel_id, pthread_sms_id, pthread_cois_id ;	
	int			ret ;

	isDup(argv[0]) ;

	if((pid = fork()) < 0)
		return  -1;
	else    if(pid != 0)
		exit(0);

	setsid() ;

	set_signal() ;

	if (argc > 1) {
		if (argc == 3) {
			if (strcmp(argv[1], "-f") == 0) {
				strcpy(config_file_path, argv[2]);
			}
			else    {
				printf("---------------------------------\n");
				printf("-%s [-f ConfigFilePath]\n", argv[0]);
				printf("---------------------------------\n");
				}
			}
		else    {
			printf("---------------------------------\n");
			printf("-%s [-f ConfigFilePath]\n", argv[0]);
			printf("---------------------------------\n");
		}
	}
	else
		sprintf(config_file_path, "../config/TCenter.Config");

	memset(&Config, 0, sizeof(CONFIG_T)) ;
	readConfig(config_file_path, &Config) ;
	Log = openLog(argv[0], Config.LOG_FILE, LOG_MODE) ;
#ifdef _FOR_STAT_
	StatLog = openLog(argv[0], Config.STAT_LOG_PATH, LOG_MODE) ;
#endif
	printLog(HEAD, "=====[Program Start]=====\n") ;

	printConfig(&Config) ;

	pthread_mutex_init(&p_lock, NULL);
	thread_count = 0;

	Worker() ;

	exit_handler() ;
	return M_TRUE ;
}
Exemplo n.º 18
0
bool skeleton_init(const char* appname, int loglvl, int maxfdcnt)
{
	set_rlimit();
	set_signal();
	init_log(appname);
	set_log_level(loglvl);
	toggle_hex_level();
	init_timer();

	return gevloop.init(maxfdcnt);
}
Exemplo n.º 19
0
StringButton::StringButton(const QString string, int height, int width, int fontsize, QWidget *parent)
{
    str = string;
    QString help = help.number(fontsize);
    help = help.append("pt");
    help = help.prepend("font-size: ");

    this->setText(string);
    this->setMaximumHeight(height);
    this->setMinimumHeight(height);
    this->setMaximumWidth(width);
    this->setMinimumWidth(width);
    this->setStyleSheet(help);
    QObject::connect(this,SIGNAL(clicked()),this,SLOT(set_signal()));
}
Exemplo n.º 20
0
/* enables or disables interrupts, and returns whether interrupts were enabled
 * or not previously. */
int
interrupts_set(int enabled)
{
	int ret;
	sigset_t mask, omask;

	set_signal(&mask);
	if (enabled) {
		ret = sigprocmask(SIG_UNBLOCK, &mask, &omask);
	} else {
		ret = sigprocmask(SIG_BLOCK, &mask, &omask);
	}
	assert(!ret);
	return (sigismember(&omask, SIG_TYPE) ? 0 : 1);
}
Exemplo n.º 21
0
void print_msg(int flag) {
	set_signal(SIGCHAT, print_msg);
	char buf[USER_NAME_MAX_LENGTH + 10], private;
	if (flag) {
		char buf2[STR_BUF_SIZE];
		piperead(Pdesc2[1], Pdesc[0], &private, sizeof(char));
		piperead(Pdesc2[1], Pdesc[0], buf, USER_NAME_MAX_LENGTH + 10);
		piperead(Pdesc2[1], Pdesc[0], buf2, STR_BUF_SIZE);
		if (private == PRIVATE)
			wattron(chatbox, A_BOLD);
		writestr(buf);
		writestr(buf2); 
		wattroff(chatbox, A_BOLD);
	}
	else {   
Exemplo n.º 22
0
int ItemButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QPushButton::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: sig_string((*reinterpret_cast< QPair<QString,int>(*)>(_a[1]))); break;
        case 1: set_signal(); break;
        default: ;
        }
        _id -= 2;
    }
    return _id;
}
Exemplo n.º 23
0
int main(int argc, char *argv[])
{
	int serial_fd = -1;
	struct termios old_termio;

	/* check args */
	if (argc <= 1) {
		usage();
		goto err;
	};

	/* initalize */
	if ((serial_fd = serial_init(&old_termio)) < 0) {
		logging(FATAL, "serial_init() failed\n");
		goto err;
	}

	if (spfm_reset(serial_fd) == false) {
		logging(FATAL, "spfm_reset() failed\n");
		goto err;
	}

	if (set_signal(SIGINT, sig_handler) < 0) {
		logging(FATAL, "set_signal() failed\n");
		goto err;
	}

	/* play file */
	if (play_file(serial_fd, argv[1]) == false) {
		logging(WARN, "play_file() failed\n");
		goto err;
	}

	/* end process */
	spfm_reset(serial_fd);
	serial_die(serial_fd, &old_termio);
	return EXIT_SUCCESS;

err:
	if (serial_fd != -1) {
		spfm_reset(serial_fd);
		serial_die(serial_fd, &old_termio);
	}
	return EXIT_FAILURE;
}
/**
 * Handles the compound signal.
 *
 * @param p0 the signal memory
 * @param p1 the compound signal
 * @param p2 the priority
 */
void handle_compound_signal(void* p0, const void* p1, const void* p2) {

    log_message((void*) &INFO_LOG_LEVEL, (void*) &"Handle compound signal.");

    // Initialize elements.
    int c = 0;
    void* pa = NULL_POINTER;
    void* pas = NULL_POINTER;
    void* pm = NULL_POINTER;

    // Get elements.
    get_array_element(p1, (void*) &INTEGER_ARRAY, (void*) &PARTS_COUNT_INDEX, (void*) &c);
    get_array_element(p1, (void*) &POINTER_ARRAY, (void*) &PART_ABSTRACTIONS_INDEX, (void*) &pa);
    get_array_element(p1, (void*) &POINTER_ARRAY, (void*) &PART_ABSTRACTIONS_SIZES_INDEX, (void*) &pas);
    get_array_element(p1, (void*) &POINTER_ARRAY, (void*) &PART_MODELS_INDEX, (void*) &pm);

    // The part signal model.
    int j = 0;
    void* a = NULL_POINTER;
    int as = 0;
    void* m = NULL_POINTER;

    while (1) {

        if (j >= c) {

            break;
        }

        // Get part signal.
        get_array_element((void*) &pa, (void*) &POINTER_ARRAY, (void*) &j, (void*) &a);
        get_array_element((void*) &pas, (void*) &INTEGER_ARRAY, (void*) &j, (void*) &as);
        get_array_element((void*) &pm, (void*) &POINTER_ARRAY, (void*) &j, (void*) &m);

        // Add part signal to memory, using the whole signal's priority.
        // (Each signal has a priority. A signal may consist of part
        // signals. The part signals cannot have higher/lower priority
        // than their original whole signal.)
        set_signal(p0, (void*) &m, p2, (void*) &a, (void*) &as);

        j++;
    }
}
Exemplo n.º 25
0
/*
 * Flush pending signals for a given signal type
 */
void
cli_signal_flush(clicon_handle h)
{
    /* XXX A bit rough. Use sigpending() and more clever logic ?? */

    sigfn_t   h1, h2, h3, h4;

    set_signal (SIGTSTP, SIG_IGN, &h1);
    set_signal (SIGQUIT, SIG_IGN, &h2);
    set_signal (SIGCHLD, SIG_IGN, &h3);
    set_signal (SIGINT, SIG_IGN, &h4);

    cli_signal_unblock (h);

    set_signal (SIGTSTP, h1, NULL);
    set_signal (SIGQUIT, h2, NULL);
    set_signal (SIGCHLD, h3, NULL);
    set_signal (SIGINT, h4, NULL);

    cli_signal_block (h);
}
Exemplo n.º 26
0
void input_engine(){
	try{
		input_t *input = (input_t*)find_pointer(all_ids_of_type("input_t")[0]);
		throw_if_nullptr(input);
		input->array.data_lock.lock(); // no throws are allowed beyond this point
		client_t *self = (client_t*)find_pointer(self_id);
		if(self != nullptr && self->keyboard_map_id != DEFAULT_INT_VALUE){
			input->array.data_lock.unlock();
			input->set_keyboard_map_id(self->keyboard_map_id);
			input->array.data_lock.lock();
		}
		input->loop();
		if(input->query_key(SDL_SCANCODE_ESCAPE)){
			set_signal(SIGTERM, true);
		}
		input->array.data_lock.unlock();
	}catch(std::logic_error &e){
		printf_("WARNING: input_t: cannot use the input library yet\n", PRINTF_UNLIKELY_WARN);
	}
}
Exemplo n.º 27
0
Arquivo: awk25.cpp Projeto: apense/qse
static int awk_main (int argc, qse_char_t* argv[])
{
	//QSE::HeapMmgr hm (1000000);
	//MyAwk awk (&hm);
	MyAwk awk;

	if (awk.open() <= -1)
	{
		print_error (awk);
		return -1;
	}
	app_awk = &awk;

	set_signal ();
	int n = awk_main_2 (awk, argc, argv);
	unset_signal ();

	app_awk = QSE_NULL;
	awk.close ();
	return n;
}
Exemplo n.º 28
0
int main(int argc, char *argv[])
{
	int rtc = 0, file_arg = 0, do_what = 0, no_db = 1, allowopt = 1;
	char *config_file = NULL, *tmp_dir = NULL;
	char *domain = NULL, *sender = NULL;

	set_parm_logfun(&stderrlog);

	for (int i = 1; i < argc; ++i)
	{
		char *arg = argv[i];

		if (allowopt && arg[0] == '-')
		{
			if (arg[1] != '-')
			{
				char **target;
				switch (arg[1])
				{
					case 'f':
						target = &config_file;
						break;
					case 't':
						target = &tmp_dir;
						break;
					default:
						fprintf(stderr,
							"dkimsign: invalid option: %s\n", arg);
						return 1;
				}

				if (arg[2])
					*target = &arg[2];
				else
					*target = ++i < argc ? argv[i] : NULL;
			}
			else if (arg[2] == 0)
			{
				allowopt = 0;
			}
			else if (strcmp(arg, "--syslog") == 0)
			{
				do_what |= do_syslog;
			}
			else if (strcmp(arg, "--domain") == 0)
			{
				domain = ++i < argc ? argv[i] : NULL;
			}
			else if (strcmp(arg, "--sender") == 0)
			{
				sender = ++i < argc ? argv[i] : NULL;
			}
			else if (strcmp(arg, "--config") == 0)
			{
				do_what |= do_config;
			}
			else if (strcmp(arg, "--version") == 0)
			{
				do_what |= do_version;
			}
			else if (strcmp(arg, "--filter") == 0)
			{
				do_what |= do_filter;
				do_what |= do_syslog;
			}
			else if (strcmp(arg, "--db-filter") == 0)
			{
				do_what |= do_filter;
				do_what |= do_syslog;
				no_db = 0;
			}
			else if (strcmp(arg, "--help") == 0)
			{
				printf("This is a wrapper around the zdkimfilter executable.\n"
					"Usage:\n"
					"           dkimsign [opts] message-file...\n"
					"with opts:\n"
					"  -f config-filename  override %s\n"
					"  -t temp-dir         override the temporary directory\n"
					"  --syslog            use syslog (MAIL) rather than stderr\n"
					"  --filter            use stdin and ignore any message-file\n"
					"  --db-filter         same as filter, but enable db logging\n"
					"  --domain domain     signing domain, can be full address\n"
					"  --sender sender     envelope sender if different from domain\n"
					"  --config            have the exec check and print config\n"
					"  --help              print this stuff and exit\n"
					"  --version           have the exec print version and exit\n",
						default_config_file);
				return 0;
			}
			else
			{
				fprintf(stderr,
					"dkimsign: invalid option: %s\n", arg);
				return 1;
			}
		}
		else // message files
		{
			file_arg = i;
			break;
		}
	}

	if (file_arg == 0 && (do_what & ~do_syslog) == 0)
		return 1;

	// hack to ease auto tests
	if (strcmp(argv[argc-1], "--batch-test") == 0)
	{
		do_what &= ~do_syslog;
		no_needless_logging = 1;
	}

	if (do_what & do_syslog)
	{
		openlog("dkimsign", LOG_PID, LOG_MAIL);
		set_parm_logfun(do_report = &syslog);
	}

	char *xargv[argc - file_arg + 10];
	size_t xargc = 0;

	char *ctlfile = NULL;
	char *msgfile = NULL;
	char *execfile = get_executable(argv[0]);
	if (execfile == NULL)
	{
		(*do_report)(LOG_CRIT, "Cannot find the zdkimfilter executable");
		rtc = 1;
	}
	else
		xargv[xargc++] = execfile;

	if (config_file)
	{
		xargv[xargc++] = "-f";
		xargv[xargc++] = config_file;
	}

	if (do_what & do_version)
	{
		do_what &= ~do_config;
		xargv[xargc++] = "--version";
	}
	else if (do_what & do_config)
	{
		xargv[xargc++] = "--batch-test";
	}
	else if ((file_arg || (do_what & do_filter)) && rtc == 0)
	{
		do_what |= do_mail;
		rtc = create_tmpfiles(config_file, domain, sender, tmp_dir, &ctlfile,
			(do_what & do_filter)? &msgfile: NULL, no_db == 0);

		if (rtc == 0)
		{
			if (no_db)
				xargv[xargc++] = "--no-db";
			if ((do_what & do_filter) != 0)
				xargv[xargc++] = "--no-fork";
			xargv[xargc++] = "-t1,dkimsign";
			xargv[xargc++] = ctlfile;
			if (file_arg)
				for (int i = file_arg; i < argc; ++i)
					xargv[xargc++] = argv[i];
		}
	}

	if (rtc == 0)
	{
		xargv[xargc] = NULL;
		set_signal();

		rtc = run_zdkimfilter(xargv, do_what);
	}

	if (do_what & do_syslog)
		closelog();

	if (ctlfile)
	{
		if (!no_needless_logging)
			unlink(ctlfile);
		free(ctlfile);
	}

	if (msgfile)
	{
		unlink(msgfile);
		free(msgfile);
	}

	if (execfile && execfile != zdkimfilter_executable)
		free(execfile);

	return rtc;
}
Exemplo n.º 29
0
int ad_mv(int argc, char *argv[], AFPObj *obj)
{
    size_t baselen, len;
    int rval;
    char *p, *endp;
    struct stat sb;
    int ch;
    char path[MAXPATHLEN];


    pdid = htonl(1);
    did = htonl(2);

    argc--;
    argv++;

    while ((ch = getopt(argc, argv, "finv")) != -1)
        switch (ch) {
        case 'i':
            iflg = 1;
            fflg = nflg = 0;
            break;
        case 'f':
            fflg = 1;
            iflg = nflg = 0;
            break;
        case 'n':
            nflg = 1;
            fflg = iflg = 0;
            break;
        case 'v':
            vflg = 1;
            break;
        default:
            usage_mv();
        }

    argc -= optind;
    argv += optind;

    if (argc < 2)
        usage_mv();

    set_signal();
    cnid_init();
    if (openvol(obj, argv[argc - 1], &dvolume) != 0) {
        SLOG("Error opening CNID database for source \"%s\": ", argv[argc - 1]);
        return 1;
    }

    /*
     * If the stat on the target fails or the target isn't a directory,
     * try the move.  More than 2 arguments is an error in this case.
     */
    if (stat(argv[argc - 1], &sb) || !S_ISDIR(sb.st_mode)) {
        if (argc > 2)
            usage_mv();
        if (openvol(obj, argv[0], &svolume) != 0) {
            SLOG("Error opening CNID database for destination \"%s\": ", argv[0]);
            return 1;
        }
        rval = do_move(argv[0], argv[1]);
        closevol(&svolume);
        closevol(&dvolume);
        return 1;
    }

    /* It's a directory, move each file into it. */
    if (strlen(argv[argc - 1]) > sizeof(path) - 1)
        ERROR("%s: destination pathname too long", *argv);

    (void)strcpy(path, argv[argc - 1]);
    baselen = strlen(path);
    endp = &path[baselen];
    if (!baselen || *(endp - 1) != '/') {
        *endp++ = '/';
        ++baselen;
    }

    for (rval = 0; --argc; ++argv) {
        /*
         * Find the last component of the source pathname.  It
         * may have trailing slashes.
         */
        p = *argv + strlen(*argv);
        while (p != *argv && p[-1] == '/')
            --p;
        while (p != *argv && p[-1] != '/')
            --p;

        if ((baselen + (len = strlen(p))) >= PATH_MAX) {
            SLOG("%s: destination pathname too long", *argv);
            rval = 1;
        } else {
            memmove(endp, p, (size_t)len + 1);
            openvol(obj, *argv, &svolume);

            if (do_move(*argv, path))
                rval = 1;
            closevol(&svolume);
        }
    }

    closevol(&dvolume);
    return rval;
}
Exemplo n.º 30
0
/**
 * The main entry function.
 *
 * Command line arguments have to be in order:
 * - command (cyboi)
 * - abstraction (compound|operation)
 * - location (inline|file|ftp|http)
 * - model (a compound model or primitive operation, for example: exit or model.submodel)
 *
 * Usage:
 * cyboi compound|operation inline|file|ftp|http model.submodel
 *
 * Example 1 (starts up and right away shuts down the system):
 * cyboi operation inline exit
 *
 * Example 2 (calls the startup routine of some application):
 * cyboi compound file /application/logic/startup.cybol
 *
 * The main function follows a system lifecycle to start up,
 * run and shut down the CYBOI system, in the following order:
 * 1 initialize global variables
 * 2 create statics (state/ logic knowledge container etc.)
 * 3 create startup signal and add to signal memory
 * 4 run dynamics (signal waiting loop)
 * 5 destroy startup signal
 * 6 destroy statics (state/ logic knowledge container etc.)
 *
 * @param p0 the argument count (argc)
 * @param p1 the argument vector (argv)
 * @return the return value
 */
int main(int p0, char** p1) {

    // Return 1 to indicate an error, by default.
    int r = 1;

    //
    // Global variables.
    //

    // Initialize global variables.
    // CAUTION!
    // They have to be initialized before the command line parameter check below!
    // Otherwise, the logger may not be able to log possible error messages.
    initialize_global_variables();

    //
    // Testing.
    //

    // Call testing procedures.
    // Comment/ uncomment this as needed.
    // CAUTION!
    // This has to stand AFTER the initialization of the
    // global variables because these are used by the testing code.
//    test();
//    return 0;

    if (p1 != NULL_POINTER) {

        if (p0 == STARTUP_PARAMETERS_COUNT) {

            //
            // Knowledge container.
            //

            // The knowledge container and its count and size.
            void* k = NULL_POINTER;
            int kc = 0;
            int ks = 0;

            // Create knowledge container.
            create_compound((void*) &k, (void*) &ks);

            //
            // Internals container.
            //

            // The internals container and its count and size.
            void* i = NULL_POINTER;
            int ic = 0;
            int is = 0;

            // Create internals container.
//??            create_internals((void*) &i, (void*) &ic, (void*) &is);

            //
            // Signal container.
            //

            // The signal container and its count and size.
            void* s = NULL_POINTER;
            int sc = 0;
            int ss = 0;

            // Create signal container.
            create_signal_memory((void*) &s, (void*) &ss);

            //
            // Startup model.
            //

            // Initialize persistent part abstraction, location, model
            // and their counts and sizes.
            void* ppa = (void*) p1[ABSTRACTION_STARTUP_PARAMETER_INDEX];
            int ppac = strlen(p1[ABSTRACTION_STARTUP_PARAMETER_INDEX]);
            int ppas = ppac;
            void* ppl = (void*) p1[LOCATION_STARTUP_PARAMETER_INDEX];
            int pplc = strlen(p1[LOCATION_STARTUP_PARAMETER_INDEX]);
            int ppls = pplc;
            void* ppm = (void*) p1[MODEL_STARTUP_PARAMETER_INDEX];
            int ppmc = strlen(p1[MODEL_STARTUP_PARAMETER_INDEX]);
            int ppms = ppmc;

            // Initialize transient part abstraction, model
            // and their counts and sizes.
            // CAUTION! A transient location is not stored,
            // since that is only needed temporarily
            // for model loading.
            void* tpa = NULL_POINTER;
            int tpac = 0;
            int tpas = 0;
            void* tpm = NULL_POINTER;
            int tpmc = 0;
            int tpms = 0;

            // Create transient part abstraction, model
            // and their counts and sizes.
            interpret_model((void*) &tpa, (void*) &tpac, (void*) &tpas,
                (void*) &ppa, (void*) &ppac,
                (void*) &STRING_ABSTRACTION, (void*) &STRING_ABSTRACTION_COUNT);
            interpret_located_model((void*) &tpm, (void*) &tpmc, (void*) &tpms,
                (void*) &ppa, (void*) &ppac,
                (void*) &ppl, (void*) &pplc,
                (void*) &ppm, (void*) &ppmc);

            //
            // Startup signal.
            //

            // Add startup signal to signal memory.
            set_signal((void*) &s, (void*) &sc, (void*) &ss,
                (void*) &tpm, (void*) &tpmc,
                (void*) &NORMAL_PRIORITY,
                (void*) &tpa, (void*) &tpac);

            //
            // Waiting loop.
            //

            // The system is now started up and complete so that a loop
            // can be entered, waiting for signals (events/ interrupts)
            // which are stored/ found in the signal memory.
            // The loop is left as soon as its shutdown flag is set.
            wait((void*) &s, (void*) &sc, (void*) &ss,
                (void*) &k, (void*) &kc, (void*) &ks,
                (void*) &i, (void*) &ic, (void*) &is);

            //
            // Destruction.
            //

            //?? Do not forget to destroy startup abstraction etc. HERE!

            // Destroy startup model.
            destroy_model((void*) &tpm, (void*) &tpmc, (void*) &tpms,
                (void*) &NULL_POINTER, (void*) &NULL_POINTER, (void*) &NULL_POINTER,
                (void*) &tpa, (void*) &tpac,
                (void*) &tpa, (void*) &tpac,
                (void*) &tpm, (void*) &tpmc,
                (void*) &NULL_POINTER, (void*) &NULL_POINTER,
                (void*) &NULL_POINTER, (void*) &NULL_POINTER,
                (void*) &NULL_POINTER, (void*) &NULL_POINTER);

            // Destroy signal container.
            destroy_signal_memory((void*) &s, (void*) &ss);

            // Destroy internals container.
//??            destroy_internals((void*) &i, (void*) &ic, (void*) &is);

            // Destroy knowledge container.
            destroy_compound((void*) &k, (void*) &ks);

            log_message((void*) &INFO_LOG_LEVEL, (void*) &EXIT_CYBOI_NORMALLY_MESSAGE, (void*) &EXIT_CYBOI_NORMALLY_MESSAGE_COUNT);

            // Return 0 to indicate proper shutdown.
            r = 0;

        } else {

            log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_NUMBER_IS_INCORRECT_MESSAGE, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_NUMBER_IS_INCORRECT_MESSAGE_COUNT);
            log_message((void*) &INFO_LOG_LEVEL, (void*) &USAGE_MESSAGE, (void*) &USAGE_MESSAGE_COUNT);
        }

    } else {

        log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_VECTOR_IS_NULL_MESSAGE, (void*) &COULD_NOT_EXECUTE_CYBOI_THE_COMMAND_LINE_ARGUMENT_VECTOR_IS_NULL_MESSAGE_COUNT);
    }

    return r;
}