当前位置: 首页>>代码示例>>C++>>正文


C++ signal函数代码示例

本文整理汇总了C++中signal函数的典型用法代码示例。如果您正苦于以下问题:C++ signal函数的具体用法?C++ signal怎么用?C++ signal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了signal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_write_fail

static void
test_write_fail(void)
{
  int status;
  pid_t pid;
  ThriftSocket *tsocket = NULL;
  ThriftTransport *transport = NULL;
  int port = 51198;
  guchar buf[10] = TEST_DATA; /* a buffer */

  /* SIGPIPE when send to disconnected socket */
  signal(SIGPIPE, SIG_IGN);

  pid = fork ();
  assert ( pid >= 0 );

  if ( pid == 0 )
  {
    /* child listens */
    ThriftServerTransport *transport = NULL;
    ThriftTransport *client = NULL;

    ThriftServerSocket *tsocket = g_object_new (THRIFT_TYPE_SERVER_SOCKET,
        "port", port, NULL);

    transport = THRIFT_SERVER_TRANSPORT (tsocket);
    thrift_server_transport_listen (transport, NULL);

    /* wrap the client in a BufferedTransport */
    client = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT, "transport",
        thrift_server_transport_accept (transport, NULL),
        "r_buf_size", 5, NULL);
    assert (client != NULL);

    /* just close socket */
    thrift_buffered_transport_close (client, NULL);
    g_object_unref (client);
    g_object_unref (tsocket);
    exit (0);
  } else {
    /* parent connects, wait a bit for the socket to be created */
    sleep (1);

    tsocket = g_object_new (THRIFT_TYPE_SOCKET, "hostname", "localhost",
                            "port", port, NULL);
    transport = g_object_new (THRIFT_TYPE_BUFFERED_TRANSPORT,
                              "transport", THRIFT_TRANSPORT (tsocket),
                              "w_buf_size", 4, NULL);


    assert (thrift_buffered_transport_open (transport, NULL) == TRUE);
    assert (thrift_buffered_transport_is_open (transport));

    /* recognize disconnection */
    sleep(1);
    assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == TRUE);
    assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == FALSE);

    /* write and overflow buffer */
    assert (thrift_buffered_transport_write (transport, buf, 10, NULL) == FALSE);

    /* write 1 and flush */
    assert (thrift_buffered_transport_write (transport, buf, 1, NULL) == TRUE);
    assert (thrift_buffered_transport_flush (transport, NULL) == FALSE);

    thrift_buffered_transport_close (transport, NULL);

    g_object_unref (transport);
    g_object_unref (tsocket);

    assert ( wait (&status) == pid );
    assert ( status == 0 );
  }
}
开发者ID:398907877,项目名称:thrift,代码行数:74,代码来源:testbufferedtransport.c

示例2: main

int main(int argc, char **argv)
{
    signal(SIGCHLD, SIG_IGN);
    signal(SIGSEGV, terminationHandler);
    fl_init_locale_support("eworkpanel", PREFIX"/share/locale");
    fl_init_images_lib();

    int X=0,Y=0,W=Fl::w(),H=Fl::h();
    int substract;

    // Get current workarea
    Fl_WM::get_workarea(X,Y,W,H);

    //printf("Free area: %d %d %d %d\n", X,Y,W,H);

    // We expect that other docks are moving away from panel :)
    mPanelWindow = new Fl_Update_Window(X, Y+H-30, W, 30, "Workpanel");
    mPanelWindow->layout_spacing(0);
    // Panel is type DOCK
    mPanelWindow->window_type(Fl_WM::DOCK);
    mPanelWindow->setAutoHide(0);

    // Read config
    bool doShowDesktop;
    pGlobalConfig.get("Panel", "ShowDesktop", doShowDesktop, false);
    bool doWorkspaces;
    pGlobalConfig.get("Panel", "Workspaces", doWorkspaces, true);
    bool doRunBrowser;
    pGlobalConfig.get("Panel", "RunBrowser", doRunBrowser, true);    
    bool doSoundMixer;
    pGlobalConfig.get("Panel", "SoundMixer", doSoundMixer, true);
    bool doCpuMonitor;
    pGlobalConfig.get("Panel", "CPUMonitor", doCpuMonitor, true);
    
    // Group that holds everything..
    Fl_Group *g = new Fl_Group(0,0,0,0);
    g->box(FL_DIV_UP_BOX);
    g->layout_spacing(2);
    g->layout_align(FL_ALIGN_CLIENT);
    g->begin();

    mSystemMenu = new MainMenu();

    Fl_VertDivider *v = new Fl_VertDivider(0, 0, 5, 18, "");
    v->layout_align(FL_ALIGN_LEFT);
    substract = 5;

    if ((doShowDesktop) || (doWorkspaces)) {
	//this is ugly:
	int size;
	if ((doShowDesktop) && (doWorkspaces)) { size=48; } else { size=24; }
	Fl_Group *g2 = new Fl_Group(0,0,size,22);
	g2->box(FL_FLAT_BOX);
	g2->layout_spacing(0);
	g2->layout_align(FL_ALIGN_LEFT);

	// Show desktop button
	if (doShowDesktop) {
		PanelButton *mShowDesktop;
		mShowDesktop = new PanelButton(0, 0, 24, 22, FL_NO_BOX, FL_DOWN_BOX, "ShowDesktop");
		mShowDesktop->layout_align(FL_ALIGN_LEFT);
		mShowDesktop->label_type(FL_NO_LABEL);
		mShowDesktop->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
		mShowDesktop->image(showdesktop_pix);
		mShowDesktop->tooltip(_("Show desktop"));
		mShowDesktop->callback( (Fl_Callback*)cb_showdesktop);
		mShowDesktop->show();
		
		substract += 26;
	}
    
	// Workspaces panel
	if (doWorkspaces) {
		mWorkspace = new PanelMenu(0, 0, 24, 22, FL_NO_BOX, FL_DOWN_BOX, "WSMenu");
		mWorkspace->layout_align(FL_ALIGN_LEFT);
		mWorkspace->label_type(FL_NO_LABEL);
		mWorkspace->align(FL_ALIGN_INSIDE|FL_ALIGN_CENTER);
		mWorkspace->image(desktop_pix);
		mWorkspace->tooltip(_("Workspaces"));
		mWorkspace->end();
		
		substract += 26;
	}
	
	g2->end();
	g2->show();
	g2->resizable();

	v = new Fl_VertDivider(0, 0, 5, 18, "");
        v->layout_align(FL_ALIGN_LEFT);
	substract += 5;
    }
    
    // Run browser
    if (doRunBrowser) {
        runBrowser = new Fl_Input_Browser("",100,FL_ALIGN_LEFT,30);
        //runBrowser->image(run_pix);
        //runBrowser->box(FL_THIN_DOWN_BOX);

        // Added _ALWAYS so callback is in case:
//.........这里部分代码省略.........
开发者ID:edeproject,项目名称:svn,代码行数:101,代码来源:workpanel.cpp

示例3: lurk

int lurk()
{
    wav_file in, out;
    int quit;
    int16_t *buffer;
    int buffer_length, buffer_bytes, read_length;
    uint64_t total_length, cut_length, peak_length;
    int recording;
    char *output_path, *output_temp_path;
    double rms;
    const char progress[] = {'|', '/', '-', '\\'};
    uint64_t progress_temp, progress_position;

    quit = 0;
    terminate_signal = 0;
    output_path = NULL;
    output_temp_path = NULL;
    progress_position = 0;
    
    printf("Reading header from %s\n", (input == NULL ? "stdin" : input));

    if(wav_open_read(input, &in) == -1)
    {
        fprintf(stderr, "Failed to open %s for input\n", input);

        return -1;
    }
    
    if(!(in.format.audio_format == 1 && /* 1 = PCM */
         in.format.bits_per_sample == 16 &&
         in.format.num_channels == 1))
    {
        fprintf(stderr, "Wrong audio format, i want 16 bit mono PCM audio\n");

        return -1;
    }
    
    printf("Output: %s\n", output);
    printf("Recording append: %s\n", recording_append);
    printf("Threshold: %g\n", threshold);
    printf("Runlength: %g seconds\n", runlength);
    if(short_filter != 0)
        printf("Short filter: %g seconds\n", short_filter);
   
    buffer_length = in.format.sample_rate / slice_divisor;
    buffer_bytes = buffer_length * in.format.block_align;
    buffer = malloc(buffer_bytes);
    if(buffer == NULL)
    {
        fprintf(stderr, "lurk: malloc audio buffer failed\n");

        return -1;
    }
    total_length = 0;
    cut_length = 0;
    peak_length = 0;
    recording = 0;

    if(time_start != 0)
    {
        char s[256];
        
        strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", localtime(&time_start));
        printf("Start time: %s\n", s);
    }
    printf("Sample rate: %d Hz\n", in.format.sample_rate);
    printf("Slice divisor: %g\n", slice_divisor);
    printf("\n");
    printf("Starting to lurk...\n");
    
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);
    
    while(quit == 0)
    {
        read_length = riff_read_wave_16(in.stream, buffer, buffer_length);
        if(read_length < 1)
        {
            if(read_length == 0)
            {
                if(recording == 1)
                    quit = 1; /* run loop one last time */
                else
                    break;
            }
            else
            {
                fprintf(stderr, "Error reading input file\n");

                if(recording == 1)
                {
                    message("Trying to close output file nicely\n");
                    wav_close_write(&out);
                    rename(output_temp_path, output_path);
                }

                break;
            }
        }

//.........这里部分代码省略.........
开发者ID:wader,项目名称:lurker,代码行数:101,代码来源:lurker.c

示例4: main

int main(int argc, char **argv) {
  struct pk_manager *m;
  unsigned int tmp_uint;
  int gotargs = 0;
  int verbosity = 0;
  int use_ipv4 = 1;
#ifdef HAVE_IPV6
  int use_ipv6 = 1;
#endif
  int use_evil = 0;
  int use_watchdog = 0;
  int max_conns = 25;
  int lport;
  int ac;
  SSL_CTX* ssl_ctx;

  /* FIXME: Is this too lame? */
  srand(time(0) ^ getpid());
  pks_global_init(PK_LOG_NORMAL);

  while (-1 != (ac = getopt(argc, argv, "46a:c:B:E:qvWZ"))) {
    switch (ac) {
      case '4':
        use_ipv4 = 0;
        break;
      case '6':
#ifdef HAVE_IPV6
        use_ipv6 = 0;
#endif
        break;
      case 'v':
        verbosity++;
        break;
      case 'q':
        verbosity--;
        break;
      case 'W':
        use_watchdog = 1;
        break;
      case 'Z':
        use_evil = 1;
        break;
      case 'B':
        gotargs++;
        if (1 == sscanf(optarg, "%u", &pk_state.bail_on_errors)) break;
        usage(EXIT_ERR_USAGE);
      case 'c':
        gotargs++;
        if (1 == sscanf(optarg, "%d", &max_conns)) break;
        usage(EXIT_ERR_USAGE);
      case 'E':
        gotargs++;
        if (1 == sscanf(optarg, "%u", &tmp_uint)) {
          pk_state.conn_eviction_idle_s = tmp_uint;
          break;
        }
        usage(EXIT_ERR_USAGE);
      default:
        usage(EXIT_ERR_USAGE);
    }
    gotargs++;
  }

  if ((argc-1-gotargs) < 5 || ((argc-1-gotargs) % 5) != 0) {
    usage(EXIT_ERR_USAGE);
  }

  signal(SIGUSR1, &raise_log_level);

  pk_state.log_mask = ((verbosity < 0) ? PK_LOG_ERRORS :
                      ((verbosity < 1) ? PK_LOG_NORMAL :
                      ((verbosity < 2) ? PK_LOG_DEBUG : PK_LOG_ALL)));

  PKS_SSL_INIT(ssl_ctx);

  if (NULL == (m = pkm_manager_init(NULL, 0, NULL, 0,
                                    PAGEKITE_NET_CLIENT_MAX,
                                    max_conns, NULL, ssl_ctx))) {
    pk_perror(argv[0]);
    exit(EXIT_ERR_MANAGER_INIT);
  }
  if (use_evil) {
    m->housekeeping_interval_min = 5;
    m->housekeeping_interval_max = 20;
    m->check_world_interval = 30;
  }
  if (use_watchdog)
    m->enable_watchdog = 1;

  for (ac = gotargs; ac < argc; ac += 1) {
    if (1 == sscanf(argv[ac+1], "%d", &lport)) {
      if (use_ipv4)
        if (NULL == (pkr_add_listener(m, lport))) {
          pk_perror(argv[0]);
          exit(EXIT_ERR_ADD_LPORT);
        }
#ifdef HAVE_IPV6
      if (use_ipv6)
        if (NULL == (pkr_add_listener_v6(m, lport))) {
          pk_perror(argv[0]);
//.........这里部分代码省略.........
开发者ID:altoplano,项目名称:libpagekite,代码行数:101,代码来源:pagekiter.c

示例5: main

int
main(int argc, char *argv[])
{
	int ch;
	time_t secs = 0, t;
	char *cp;
	long nsecs = 0;
	struct timespec rqtp;
	int i;

	if (pledge("stdio", NULL) == -1)
		err(1, "pledge");

	signal(SIGALRM, alarmh);

	while ((ch = getopt(argc, argv, "")) != -1)
		switch(ch) {
		default:
			usage();
		}
	argc -= optind;
	argv += optind;

	if (argc != 1)
		usage();

	cp = *argv;
	while ((*cp != '\0') && (*cp != '.')) {
		if (!isdigit((unsigned char)*cp))
			usage();
		t = (secs * 10) + (*cp++ - '0');
		if (t / 10 != secs)	/* oflow */
			return (EINVAL);
		secs = t;
	}

	/* Handle fractions of a second */
	if (*cp == '.') {
		cp++;
		for (i = 100000000; i > 0; i /= 10) {
			if (*cp == '\0')
				break;
			if (!isdigit((unsigned char)*cp))
				usage();
			nsecs += (*cp++ - '0') * i;
		}

		/*
		 * We parse all the way down to nanoseconds
		 * in the above for loop. Be pedantic about
		 * checking the rest of the argument.
		 */
		while (*cp != '\0') {
			if (!isdigit((unsigned char)*cp++))
				usage();
		}
	}

	rqtp.tv_sec = secs;
	rqtp.tv_nsec = nsecs;

	if ((secs > 0) || (nsecs > 0))
		if (nanosleep(&rqtp, NULL))
			err(1, NULL);
	return (0);
}
开发者ID:radixo,项目名称:openbsd-src,代码行数:66,代码来源:sleep.c

示例6: main


//.........这里部分代码省略.........
        fatal("unable to create socket: %s", strerror(errno));

    memset(&addr, 0, sizeof(struct sockaddr_in));
    addr.sin_family = AF_INET;

    if (bind(sock_answer, (struct sockaddr *)&addr, sizeof(addr)) != 0)
        fatal("unable to bind socket: %s", strerror(errno));

    /* Fill sockaddr_in structs for both servers */
    memset(&authoritative_addr, 0, sizeof(struct sockaddr_in));
    authoritative_addr.sin_addr.s_addr = inet_addr(authoritative);
    authoritative_addr.sin_port = htons(authoritative_port);
    authoritative_addr.sin_family = AF_INET;

    memset(&recursive_addr, 0, sizeof(struct sockaddr_in));
    recursive_addr.sin_addr.s_addr = inet_addr(recursive);
    recursive_addr.sin_port = htons(recursive_port);
    recursive_addr.sin_family = AF_INET;

    /* Daemonize if requested and switch to syslog */
    if (daemonize) {
        if (daemon(0, 0) == -1)
            fatal("unable to daemonize");
        log_syslog("dnsproxy");
    }

    /* Find less privileged user */
    if (user) {
        pw = getpwnam(user);
        if (!pw)
            fatal("unable to find user %s", user);
    }

    /* Do a chroot if requested */
    if (chrootdir) {
        if (chdir(chrootdir) || chroot(chrootdir))
            fatal("unable to chroot to %s", chrootdir);
        chdir("/");
    }

    /* Drop privileges */
    if (user) {
        if (setgroups(1, &pw->pw_gid) < 0)
            fatal("setgroups: %s", strerror(errno));
#if defined(HAVE_SETRESGID)
        if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) < 0)
            fatal("setresgid: %s", strerror(errno));
#elif defined(HAVE_SETREGID)
        if (setregid(pw->pw_gid, pw->pw_gid) < 0)
            fatal("setregid: %s", strerror(errno));
#else
        if (setegid(pw->pw_gid) < 0)
            fatal("setegid: %s", strerror(errno));
        if (setgid(pw->pw_gid) < 0)
            fatal("setgid: %s", strerror(errno));
#endif
#if defined(HAVE_SETRESUID)
        if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) < 0)
            fatal("setresuid: %s", strerror(errno));
#elif defined(HAVE_SETREUID)
        if (setreuid(pw->pw_uid, pw->pw_uid) < 0)
            fatal("setreuid: %s", strerror(errno));
#else
        if (seteuid(pw->pw_uid) < 0)
            fatal("seteuid: %s", strerror(errno));
        if (setuid(pw->pw_uid) < 0)
            fatal("setuid: %s", strerror(errno));
#endif
    }

    /* Init event handling */
    event_init();

    event_set(&evq, sock_query, EV_READ, do_query, &evq);
    event_add(&evq, NULL);

    event_set(&eva, sock_answer, EV_READ, do_answer, &eva);
    event_add(&eva, NULL);

    /* Zero counters and start statistics timer */
    statistics_start();

    /* Take care of signals */
    if (signal(SIGINT, signal_handler) == SIG_ERR)
        fatal("unable to mask signal SIGINT: %s", strerror(errno));

    if (signal(SIGTERM, signal_handler) == SIG_ERR)
        fatal("unable to mask signal SIGTERM: %s", strerror(errno));

    if (signal(SIGHUP, SIG_IGN) == SIG_ERR)
        fatal("unable to mask signal SIGHUP: %s", strerror(errno));

    event_sigcb = signal_event;

    /* Start libevent main loop */
    event_dispatch();

    return 0;

}
开发者ID:jeppeter,项目名称:vbox,代码行数:101,代码来源:dnsproxy.c

示例7: main

int
main(int argc, char **argv)
{
	int c;
	char *scan;
	/* the + on the front tells GNU getopt not to rearrange argv */
	const char *optlist = "+F:f:v:W;m:D";
	int stopped_early = FALSE;
	int old_optind;
	extern int optind;
	extern int opterr;
	extern char *optarg;
	int i;
	int stdio_problem = FALSE;

	/* do these checks early */
	if (getenv("TIDYMEM") != NULL)
		do_tidy_mem = TRUE;

	if (getenv("WHINY_USERS") != NULL)
		whiny_users = TRUE;

#ifdef HAVE_MCHECK_H
	if (do_tidy_mem)
		mtrace();
#endif /* HAVE_MCHECK_H */
	
#if defined(LC_CTYPE)
	setlocale(LC_CTYPE, "");
#endif
#if defined(LC_COLLATE)
	setlocale(LC_COLLATE, "");
#endif
#if defined(LC_MESSAGES)
	setlocale(LC_MESSAGES, "");
#endif
#if defined(LC_NUMERIC)
	/*
	 * Force the issue here.  According to POSIX 2001, decimal
	 * point is used for parsing source code and for command-line
	 * assignments and the locale value for processing input,
	 * number to string conversion, and printing output.
	 */
	setlocale(LC_NUMERIC, "C");
#endif
#if defined(LC_TIME)
	setlocale(LC_TIME, "");
#endif

#ifdef MBS_SUPPORT
	/*
	 * In glibc, MB_CUR_MAX is actually a function.  This value is
	 * tested *a lot* in many speed-critical places in gawk. Caching
	 * this value once makes a speed difference.
	 */
	gawk_mb_cur_max = MB_CUR_MAX;
	/* Without MBS_SUPPORT, gawk_mb_cur_max is 1. */
#endif

	(void) bindtextdomain(PACKAGE, LOCALEDIR);
	(void) textdomain(PACKAGE);

	(void) signal(SIGFPE, catchsig);
	(void) signal(SIGSEGV, catchsig);
#ifdef SIGBUS
	(void) signal(SIGBUS, catchsig);
#endif

	myname = gawk_name(argv[0]);
        argv[0] = (char *) myname;
	os_arg_fixup(&argc, &argv); /* emulate redirection, expand wildcards */

	/* remove sccs gunk */
	if (strncmp(version_string, "@(#)", 4) == 0)
		version_string += 4;

	if (argc < 2)
		usage(1, stderr);

	/* Robustness: check that file descriptors 0, 1, 2 are open */
	init_fds();

	/* init array handling. */
	array_init();

	/* we do error messages ourselves on invalid options */
	opterr = FALSE;

	/* option processing. ready, set, go! */
	for (optopt = 0, old_optind = 1;
	     (c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF;
	     optopt = 0, old_optind = optind) {
		if (do_posix)
			opterr = TRUE;

		switch (c) {
		case 'F':
			preassigns_add(PRE_ASSIGN_FS, optarg);
			break;

//.........这里部分代码省略.........
开发者ID:WndSks,项目名称:msys,代码行数:101,代码来源:main.c

示例8: main

/***********************************************************************
 *  Procedure:
 *	main - start of afterstep
 ************************************************************************/
int
main (int argc, char **argv, char **envp)
{
    register int i ;
	
	int start_viewport_x = 0 ;
	int start_viewport_y = 0 ;
	int start_desk = 0 ;

#ifdef LOCAL_DEBUG
#if 0
	LOCAL_DEBUG_OUT( "calibrating sleep_a_millisec : %s","" );
	for( i = 0 ; i < 500 ; ++i )
		sleep_a_millisec( 10 );
	LOCAL_DEBUG_OUT( "500 sliip_a_millisec(10) completed%s","" );
	for( i = 0 ; i < 50 ; ++i )
		sleep_a_millisec( 100 );
	LOCAL_DEBUG_OUT( "50 sliip_a_millisec(100) completed%s","" );
	for( i = 0 ; i < 10 ; ++i )
		sleep_a_millisec( 300 );
	LOCAL_DEBUG_OUT( "10 sliip_a_millisec(300) completed%s","" );
#endif
#endif

	_as_grab_screen_func = GrabEm;
	_as_ungrab_screen_func = UngrabEm;

	original_DISPLAY_string = getenv("DISPLAY");
	if (original_DISPLAY_string)
		original_DISPLAY_string = mystrdup(original_DISPLAY_string);

#ifdef DEBUG_TRACE_X
	trace_window_id2name_hook = &window_id2name;
#endif
	set_DeadPipe_handler(DeadPipe);

#if !HAVE_DECL_ENVIRON
	override_environ( envp );
#endif
    InitMyApp( CLASS_AFTERSTEP, argc, argv, NULL, AfterStep_usage, 0);

	LinkAfterStepConfig();

    AfterStepState = MyArgs.flags ;
    clear_flags( AfterStepState, ASS_NormalOperation );
	set_flags( AfterStepState, ASS_SuppressDeskBack );

#ifdef __CYGWIN__
    CloseOnExec = ASCloseOnExec ;
#endif

#if defined(LOG_FONT_CALLS)
	fprintf (stderr, "logging font calls now\n");
#endif

    /* These signals are mandatory : */
    signal (SIGUSR1, Restart);
    /* These signals we would like to handle only if those are not handled already (by debugger): */
    IgnoreSignal(SIGINT);
    IgnoreSignal(SIGHUP);
    IgnoreSignal(SIGQUIT);
    IgnoreSignal(SIGTERM);

    if( ConnectX( ASDefaultScr, AS_ROOT_EVENT_MASK ) < 0  )
	{
		show_error( "Hostile X server encountered - unable to proceed :-(");
		return 1;/* failed to accure window management selection - other wm is running */
	}


	ASDBus_fd = asdbus_init();

	XSetWindowBackground( dpy, Scr.Root, Scr.asv->black_pixel );
	Scr.Look.desktop_animation_tint = get_random_tint_color();

    cover_desktop();
	if( get_flags( AfterStepState, ASS_Restarting ))
	{	
		show_progress( "AfterStep v.%s is restarting ...", VERSION );
		display_progress( True, "AfterStep v.%s is restarting ...", VERSION );
	}else
	{	
    	show_progress( "AfterStep v.%s is starting up ...", VERSION );
		display_progress( True, "AfterStep v.%s is starting up ...", VERSION );
	}

	if (ASDBus_fd>=0)
	{
    	show_progress ("Successfuly accured System DBus connection.");	
		asdbus_RegisterSMClient(SMClientID_string);
	}
	
SHOW_CHECKPOINT;
	InitSession();
SHOW_CHECKPOINT;
	XSync (dpy, 0);
//.........这里部分代码省略.........
开发者ID:cooljeanius,项目名称:AfterStep,代码行数:101,代码来源:afterstep.c

示例9: IgnoreSignal

/***********************************************************************
 * our signal handlers :
 ************************************************************************/
void
IgnoreSignal (int sig)
{
	if (signal (sig, SIG_IGN) != SIG_IGN)
		signal (sig, SigDone);
}
开发者ID:cooljeanius,项目名称:AfterStep,代码行数:9,代码来源:afterstep.c

示例10: main


//.........这里部分代码省略.........
	} else {
		lsock = socket(PF_INET6, SOCK_STREAM, 0);
		
		memset(&laddr6, 0, (sa_len = sizeof(laddr6)));
		laddr6.sin6_family = AF_INET6;
		laddr6.sin6_port = htons(local_port);
		
		if (sa) {
			memcpy(&laddr6.sin6_addr, &((struct sockaddr_in6*) sa)->sin6_addr, sizeof(struct in6_addr));
			free(sa);
		}

		sa = (struct sockaddr*) &laddr6;
	}

	if (setsockopt(lsock, SOL_SOCKET, SO_REUSEADDR, &jeden, sizeof(jeden)) == -1) {
		perror("setsockopt");
		exit(1);
	}
  
	if (bind(lsock, sa, sa_len)) {
		perror("bind");
		exit(1);
	}    
  
	if (listen(lsock, 100)) {
		perror("listen");
		exit(1);
	}

	if (detach) {
		int i, ret;

		signal(SIGHUP, sighup);
		
		for (i = 0; i < 3; i++)
			close(i);

		ret = fork();
		
		if (ret == -1) {
			perror("fork");
			exit(1);
		}

		if (ret)
			exit(0);
	}

	if (pid_file) {
		FILE *f = fopen(pid_file, "w");

		if (!f)
			debug("warning: cannot write to pidfile (%s)\n", strerror(errno));
		else {
			fprintf(f, "%d", getpid());
			fclose(f);
		}
	}

	if (username && ((setgid(pw->pw_gid) == -1) || (setuid(pw->pw_uid) == -1))) {
		perror("setuid/setgid");
		exit(1);
	}

	setsid();
开发者ID:robszewczyk,项目名称:6tunnel,代码行数:67,代码来源:6tunnel.c

示例11: main


//.........这里部分代码省略.........
	}

	interactive = (argc == optind) && (action_file == NULL);

	if (interactive)
		printf("%s\n\n%s\n\n", wpa_cli_version, wpa_cli_license);

	if (global) {
		ctrl_conn = wpa_ctrl_open(global);
		if (ctrl_conn == NULL) {
			perror("Failed to connect to wpa_supplicant - "
			       "wpa_ctrl_open");
			return -1;
		}
	}

	for (; !global;) {
#ifndef CONFIG_CTRL_IFACE_UDP
		if (ctrl_ifname == NULL) {
			struct dirent *dent;
			DIR *dir = opendir(ctrl_iface_dir);
			if (dir) {
				while ((dent = readdir(dir))) {
#ifdef _DIRENT_HAVE_D_TYPE
					/* Skip the file if it is not a socket.
					 * Also accept DT_UNKNOWN (0) in case
					 * the C library or underlying file
					 * system does not support d_type. */
					if (dent->d_type != DT_SOCK &&
					    dent->d_type != DT_UNKNOWN)
						continue;
#endif /* _DIRENT_HAVE_D_TYPE */
					if (strcmp(dent->d_name, ".") == 0 ||
					    strcmp(dent->d_name, "..") == 0)
						continue;
					printf("Selected interface '%s'\n",
					       dent->d_name);
					ctrl_ifname = strdup(dent->d_name);
					break;
				}
				closedir(dir);
			}
		}
#endif /* CONFIG_CTRL_IFACE_UDP */
		ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
		if (ctrl_conn) {
			if (warning_displayed)
				printf("Connection established.\n");
			break;
		}

		if (!interactive) {
			perror("Failed to connect to wpa_supplicant - "
			       "wpa_ctrl_open");
			return -1;
		}

		if (!warning_displayed) {
			printf("Could not connect to wpa_supplicant - "
			       "re-trying\n");
			warning_displayed = 1;
		}
		os_sleep(1, 0);
		continue;
	}

#ifndef _WIN32_WCE
	signal(SIGINT, wpa_cli_terminate);
	signal(SIGTERM, wpa_cli_terminate);
#endif /* _WIN32_WCE */
#ifndef CONFIG_NATIVE_WINDOWS
	signal(SIGALRM, wpa_cli_alarm);
#endif /* CONFIG_NATIVE_WINDOWS */

	if (interactive || action_file) {
		if (wpa_ctrl_attach(ctrl_conn) == 0) {
			wpa_cli_attached = 1;
		} else {
			printf("Warning: Failed to attach to "
			       "wpa_supplicant.\n");
			if (!interactive)
				return -1;
		}
	}

	if (daemonize && os_daemonize(pid_file))
		return -1;

	if (interactive)
		wpa_cli_interactive();
	else if (action_file)
		wpa_cli_action(ctrl_conn);
	else
		wpa_request(ctrl_conn, argc - optind, &argv[optind]);

	free(ctrl_ifname);
	wpa_cli_cleanup();

	return 0;
}
开发者ID:vutukurikishore,项目名称:wpa_supplicant,代码行数:101,代码来源:wpa_cli.c

示例12: xmalloc_large_ext

void *
xmalloc_large_ext (size_t sz)
{
#if !defined(__MTA__)&&defined(USE_MMAP_LARGE_EXT)
	char extname[4096+1];
	char *tmppath;
	void *out;
	int fd, which;
	
	if (getenv ("TMPDIR"))
		tmppath = getenv ("TMPDIR");
	else if (getenv ("TEMPDIR"))
		tmppath = getenv ("TEMPDIR");
	else
		tmppath = "/tmp";
	
	sprintf (extname, "%s/graph500-ext-XXXXXX", tmppath);
	
	which = n_large_alloc++;
	if (n_large_alloc > MAX_LARGE) {
		fprintf (stderr, "Out of large allocations.\n");
		abort ();
	}
	large_alloc[which].p = 0;
	large_alloc[which].fd = -1;
	
	fd = mkstemp (extname);
	if (fd < 0) {
		perror ("xmalloc_large_ext failed to make a file");
		abort ();
	}
	if (unlink (extname)) {
		perror ("UNLINK FAILED!");
		goto errout;
	}
	
#if _XOPEN_SOURCE >= 500
	if (pwrite (fd, &fd, sizeof (fd), sz - sizeof(fd)) != sizeof (fd)) {
		perror ("resizing pwrite failed");
		goto errout;
	}
#else
	if (lseek (fd, sz - sizeof(fd), SEEK_SET) < 0) {
		perror ("lseek failed");
		goto errout;
	}
	if (write (fd, &fd, sizeof(fd)) != sizeof (fd)) {
		perror ("resizing write failed");
		goto errout;
	}
#endif
	fcntl (fd, F_SETFD, O_ASYNC);
	
	out = mmap (NULL, sz, PROT_READ|PROT_WRITE,
				MAP_SHARED|MAP_POPULATE|MAP_NOSYNC, fd, 0);
	if (MAP_FAILED == out || !out) {
		perror ("mmap ext failed");
		goto errout;
	}
	
	if (!installed_handler) {
		installed_handler = 1;
		if (atexit (exit_handler)) {
			perror ("failed to install exit handler");
			goto errout;
		}
		
		old_abort_handler = signal (SIGABRT, abort_handler);
		if (SIG_ERR == old_abort_handler) {
			perror ("failed to install cleanup handler");
			goto errout;
		}
	}
	
	large_alloc[which].p = out;
	large_alloc[which].sz = sz;
	large_alloc[which].fd = fd;
	
	return out;
	
errout:
	if (fd >= 0) close (fd);
	abort ();
#else
	return xmalloc_large (sz);
#endif
}
开发者ID:HPCProjectsTry,项目名称:grappa,代码行数:87,代码来源:xalloc.c

示例13: main


//.........这里部分代码省略.........
			i++;
		}else{
			fprintf(stderr, "Error: Unknown option '%s'.\n",argv[i]);
			mqtt_print_usage();
			return 1;
		}
	}

	/* verify necessary variable */
	if(clean_session == false && ((strlen(id_prefix) != 0) || (strlen(id) == 0))){
		if(!ud->quiet) fprintf(stderr, "Error: You must provide a client id if you are using the -c option.\n");
		return 1;
	}
	if(ud->topic_count == 0){
		fprintf(stderr, "Error: You must specify a topic to subscribe to.\n");
		mqtt_print_usage();
		return 1;
	}
	if(will_payload && !will_topic){
		fprintf(stderr, "Error: Will payload given, but no will topic given.\n");
		mqtt_print_usage();
		return 1;
	}
	if(will_retain && !will_topic){
		fprintf(stderr, "Error: Will retain given, but no will topic given.\n");
		mqtt_print_usage();
		return 1;
	}
	if(ud->password && !ud->username){
		if(!ud->quiet) fprintf(stderr, "Warning: Not using password since username not set.\n");
	}

	/* setup signal handler */
	signal(SIGINT, mqtt_signal_handler);
	signal(SIGTERM, mqtt_signal_handler);

	/* init mosquitto library */
	mosquitto_lib_init();

	/* setup client id */
	if(strlen(id_prefix) != 0){
		snprintf(id, sizeof(id), "%s%d", id_prefix, getpid());
	}else if(strlen(id) == 0){
		memset(hostname, '\0', sizeof(hostname));
		gethostname(hostname, sizeof(hostname));
		snprintf(id, sizeof(id), "mosqsub/%d-%s", getpid(), hostname);
	}
	if(strlen(id) > MOSQ_MQTT_ID_MAX_LENGTH){
		/* Enforce maximum client id length of 23 characters */
		id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
	}

	/* start mosquitto */
	mosq = mosquitto_new(id, clean_session, ud);
	if(!mosq){
		if(!ud->quiet) fprintf(stderr, "Error: %s\n", strerror(errno));
		mosquitto_lib_cleanup();
		return 1;
	}

	/* setup mosquitto */
	if(debug){
		mosquitto_log_callback_set(mosq, mqtt_log_callback);
	}
	if(will_topic && mosquitto_will_set(mosq, will_topic, will_payloadlen, will_payload, will_qos, will_retain)){
		if(!ud->quiet) fprintf(stderr, "Error: Problem setting will.\n");
开发者ID:Sanji-IO,项目名称:sanji-controller,代码行数:67,代码来源:sub_example_thread.c

示例14: posix_death_signal

void posix_death_signal(int signum)
{
    memento();
    signal(signum, SIG_DFL);
    exit(3);
}
开发者ID:MakSim345,项目名称:MS-VC08,代码行数:6,代码来源:main.cpp

示例15: main

int main(int argc, char *argv[])
{

    /* Make sure we received two arguments,
       a hostname and a port number. */
    if (argc < 2) {
	printf("Simple TCP/IP uptime server.\n");
	printf("Usage: %s <port>\n", argv[0]);
	return 1;
    }

    port = atoi(argv[1]);

    /* Create the listener socket. This socket will queue
       incoming connections. */
    listener = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
    if (listener < 0) {
	printf("Unable to create a listener socket: %s\n",
	       strerror(errno));
	return 1;
    }

    /* Now bind the listener to a local address. This uses
       the same sockaddr_in structure as connect. */
    sa_len = sizeof(sa);
    memset(&sa, 0, sa_len);
    sa.sin_family = AF_INET;
    sa.sin_port = htons(port);
    sa.sin_addr.s_addr = htonl(INADDR_ANY); /* Listen on all interfaces. */

    if (bind(listener, &sa, sa_len) < 0) {
	printf("Unable to bind to port %i: %s\n",
	       port,
	       strerror(errno));
	return 1;
    }

    /* Let the networking system know we're accepting
       connections on this socket. Ask for a connection
       queue of five clients. (If more than five clients
       try to connect before we call accept, some will
       be denied.) */
    if (listen(listener, 5) < 0) {
	printf("Unable to listen: %s\n",
	       strerror(errno));
	return 1;
    }

    /* Ready! Now accept connections until the user presses
       Control-C. */
    signal(SIGINT, signal_handler);

    for (;;) {
	char sendbuf[1024];
	int sent, length;
	FILE *uptime;

	client = accept(listener, &sa, &sa_len);
	if (client < 0) {
	    printf("Unable to accept: %s\n",
		   strerror(errno));
	    close(listener);
	    return 1;
	}

	/* We now have a live client. Print information
	   about it and then send something over the wire. */
	inet_ntop(AF_INET, &sa.sin_addr, dotted_ip, 15);
	printf("Received connection from %s.\n", dotted_ip);

	/* Use popen to retrieve the output of the
	   uptime command. This is a bit of a hack, but
	   it's portable and it works fairly well.
	   popen opens a pipe to a program (that is, it
	   executes the program and redirects its I/O
	   to a file handle). */
	uptime = popen("/usr/bin/uptime", "r");
	if (uptime == NULL) {
	    strcpy(sendbuf, "Unable to read system's uptime.\n");
	} else {
	    sendbuf[0] = '\0';
	    fgets(sendbuf, 1023, uptime);
	    pclose(uptime);
	}
		
	/* Figure out how much data we need to send. */
	length = strlen(sendbuf);
	sent = 0;

	/* Repeatedly call write until the entire
	   buffer is sent. */
	while (sent < length) {
	    int amt;

	    amt = write(client, sendbuf+sent, length-sent);

	    if (amt <= 0) {
				/* Zero-byte writes are OK if they
				   are caused by signals (EINTR).
				   Otherwise they mean the socket
//.........这里部分代码省略.........
开发者ID:jackmanlabs,项目名称:sdl-sparks,代码行数:101,代码来源:tcpserver.c


注:本文中的signal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。