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


C++ sigfillset函数代码示例

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


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

示例1: main

int main(int argc, char *argv[]) {
    atexit(cleanup);
    sigset_t mask;
    sigfillset(&mask);
    sigdelset(&mask, SIGUSR1);
    sigprocmask(SIG_SETMASK, &mask, NULL);
    struct sigaction act;
    memset(&act, 0, sizeof act);
    act.sa_handler = sigint_handler;
    sigaction(SIGUSR1, &act, NULL);

    srand(time(NULL));

    shm_id = shmget(SHM_KEY, MEM_SIZE, S_IRUSR);
    sem_id = semget(SEM_KEY, 0, S_IWUSR | S_IRUSR);
    if (shm_id < 0 || sem_id < 0) {
        printf("Error while opening shared memory and/or semaphores occurred.\n");
        return 1;
    }

    shm = shmat(shm_id, NULL, 0);
    if (shm == (void *)-1) {
        printf("Error while accessing shared memory occurred.\n");
        return 1;
    }
    struct sembuf sem_op;
    sem_op.sem_flg = 0;
    int task_index;
    int tasks_num;
    struct timeval tval;
    while (1) {
        sem_op.sem_num = 0;
        sem_op.sem_op = -1;
        if (semop(sem_id, &sem_op, 1) == -1)
            on_host_closed();

        sem_op.sem_num = 2;
        if (semop(sem_id, &sem_op, 1) == -1)
            on_host_closed();
        task_index = shm->start_index;
        shm->start_index = (task_index + 1) % ARRAY_LEN;

        tasks_num = shm->end_index - shm->start_index;
        if (tasks_num < 0)
            tasks_num += ARRAY_LEN;

        gettimeofday(&tval, NULL);
        printf("%d %ld.%ld Get task from position %d. Number of waiting tasks: %d.\n", getpid(), tval.tv_sec, tval.tv_usec/1000, task_index, tasks_num);
        fflush(stdout);
        sem_op.sem_num = 2;
        sem_op.sem_op = 1;
        if (semop(sem_id, &sem_op, 1) == -1)
            on_host_closed();
        sem_op.sem_num = 1;
        sem_op.sem_op = 1;
        if (semop(sem_id, &sem_op, 1) == -1)
            on_host_closed();

        nanosleep(&delay, NULL);
    }
}
开发者ID:michalborzecki,项目名称:sysopy_project,代码行数:61,代码来源:consumer.c

示例2: mpls_send

void 
mpls_send(struct attacks *attacks)
{
    sigset_t mask;
    struct mpls_data *mpls_data;
    libnet_ptag_t t;
    libnet_t *lhandler;
    int32_t sent;
    int32_t payload_size=0, packet_size=0;
    u_int8_t *payload=NULL;
    dlist_t *p;
    struct interface_data *iface_data;
    struct interface_data *iface_data2;
    
    pthread_mutex_lock(&attacks->attack_th.finished);

    pthread_detach(pthread_self());

    mpls_data = attacks->data;
    
    sigfillset(&mask);

    if (pthread_sigmask(SIG_BLOCK, &mask, NULL))
    {
       thread_error("mpls_send pthread_sigmask()",errno);
       return;
    }
    
    if (mpls_data->ip_payload && mpls_data->ip_payload[0])
    {
       payload_size = strlen((const char *)mpls_data->ip_payload);
       payload = mpls_data->ip_payload;
    }
       
    
    for (p = attacks->used_ints->list; p; p = dlist_next(attacks->used_ints->list, p)) 
    {
        iface_data = (struct interface_data *) dlist_data(p);
        lhandler = iface_data->libnet_handler;

        switch(mpls_data->proto)
        {
        case IPPROTO_TCP:
            packet_size = LIBNET_TCP_H + payload_size;
            t = libnet_build_tcp(
                mpls_data->src_port,       /* source port */
                mpls_data->dst_port,       /* destination port */
                0x666,                     /* sequence number */
                0x00000000,                /* acknowledgement num */
                TH_SYN,                    /* control flags */
                32767,                     /* window size */
                0,                         /* checksum */
                0,                         /* urgent pointer */
                packet_size,  /* TCP packet size */
                payload,     /* payload */
                payload_size,              /* payload size */
                lhandler,                  /* libnet handle */
                0);                        /* libnet id */
        break;
        
        case IPPROTO_UDP:
            packet_size = LIBNET_UDP_H + payload_size;
            t = libnet_build_udp(
                mpls_data->src_port,       /* source port */
                mpls_data->dst_port,       /* destination port */
                packet_size,  /* UDP packet size */
                0,                         /* checksum */
                payload,     /* payload */
                payload_size,              /* payload size */
                lhandler,                  /* libnet handle */
                0);                        /* libnet id */
        break;
        
        case IPPROTO_ICMP:
            packet_size = LIBNET_ICMPV4_ECHO_H + payload_size;
            t = libnet_build_icmpv4_echo(
                ICMP_ECHO,                     /* type */
                0,                             /* code */
                0,                             /* checksum */
                0x42,                          /* id */
                0x42,                          /* sequence number */
                payload, /* payload */
                payload_size, /* payload size */
                lhandler,                      /* libnet handle */
                0);
        break;
        }
        
        if (t == -1)
        {
            thread_libnet_error("Can't build tcp/udp/icmp header",lhandler);
            libnet_clear_packet(lhandler);
            return;
        }

        t = libnet_build_ipv4(
            LIBNET_IPV4_H + packet_size,  /* length */
            0,                                         /* TOS */
            242,                                       /* IP ID */
            0,                                         /* IP Frag */
//.........这里部分代码省略.........
开发者ID:BuddhaLabs,项目名称:yersinia-OSX,代码行数:101,代码来源:mpls.c

示例3: th_uptime

/*
 * Uptime thread...
 */
void *
th_uptime(void *arg)
{
   int ret,n;
   struct timeval timeout;
   sigset_t mask;

write_log(0,"\n th_uptime thread = %d\n",(int)pthread_self());

   sigfillset(&mask);

   if (pthread_sigmask(SIG_BLOCK, &mask, NULL))
   {
      thread_error("th_uptime pthread_sigmask()",errno);
      th_uptime_exit();
   }

   if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL))
   {
      thread_error("th_uptime pthread_setcancelstate()",errno);
      th_uptime_exit();
   }

   pthread_cleanup_push( &th_uptime_clean, (void *)NULL );
   
   if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL))
   {
      thread_error("th_uptime pthread_setcancelstate()",errno);
      th_uptime_exit();
   }

   if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL))
   {
      n=errno;
      pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
      thread_error("th_uptime pthread_setcanceltype()",n);
      th_uptime_exit();
   }

   while(1)
   {
      timeout.tv_sec  = 1;
      timeout.tv_usec = 0;

      if ( (ret=select( 0, NULL, NULL, NULL, &timeout ) ) == -1 )
      {
         n=errno;
         thread_error("th_uptime select()",n);
         continue;
      }

      if ( !ret )  /* Timeout, update uptime... */
         uptime++; 
   }

   pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);         

   pthread_cleanup_pop(0);

   return (NULL);
}
开发者ID:ATouhou,项目名称:security-courses,代码行数:64,代码来源:yersinia.c

示例4: main

/**
 * @brief Program entry point.
 * @param argc The argument count
 * @param argv The argument vector
 * @return EXIT_SUCCESS, EXIT_PARITY_ERROR, EXIT_MULTIPLE_ERRORS
**/
int main(int argc, char *argv[])  
{
    uint8_t client_count = 0;
    int shmfd;
    
    
    /* setup signal handlers */
    const int signals[] = {SIGINT, SIGTERM};
    struct sigaction s;

    s.sa_handler = signal_handler;
    s.sa_flags   = 0;
    if(sigfillset(&s.sa_mask) < 0) {
        bail_out(EXIT_FAILURE, "sigfillset");
    }
    for(int i = 0; i < COUNT_OF(signals); i++) {
        if (sigaction(signals[i], &s, NULL) < 0) {
            bail_out(EXIT_FAILURE, "sigaction");
        }
    }
    
    /* Handle arguments */
    if (argc > 0) {
       progname = argv[0]; 
    }
    
    if (argc > 2) {
        fprintf(stderr, "USAGE: %s [input_file]", progname);
        exit(EXIT_FAILURE);
    }

    switch (argc) {
    /* Handle dict input from stdin */
    case 1: 
        printf("Please input your dictionary: \n");
        in_stream = stdin;
        read_dict();
    break;
    /* Handle dict input from file */
    case 2: 
		if ((in_stream = fopen(argv[1], "r")) == NULL)
		{
            bail_out(EXIT_FAILURE, "Invalid File");
		}
        read_dict();
    break;
    default:
        fprintf(stderr, "USAGE: %s [input_file]", progname);
        exit(EXIT_FAILURE);
        break; 
    }

    /* Create a new Shared Memory Segment (shm_open) */
    shmfd = shm_open(SHM_NAME, O_RDWR | O_CREAT | O_EXCL, PERMISSION);

    if (shmfd == (-1)) {
        bail_out(EXIT_FAILURE, "shm_open failed");
    }
    
    /*  Truncate a file to a specified length 
        extend (set size) */ 
    if (ftruncate(shmfd, sizeof *shared) == -1) {
        (void) close(shmfd);
        bail_out(EXIT_FAILURE, "ftruncate failed");
    }

    /* Map shared memory object */
    shared = mmap(NULL, sizeof *shared,
                    PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0);

    if (shared == MAP_FAILED) {
        (void) close(shmfd);
        bail_out(EXIT_FAILURE, "MMAP failed");
    }

    if (close(shmfd) == -1) {
        bail_out(EXIT_FAILURE, "close(shmfd) failed");
    }
    
    shared->sc_terminate = -1;

    /* Create new named semaphores */
    s_server = sem_open(S_SERVER, O_CREAT | O_EXCL, PERMISSION, 0);
    s_client = sem_open(S_CLIENT, O_CREAT | O_EXCL, PERMISSION, 1);
    s_return = sem_open(S_RETURN, O_CREAT | O_EXCL, PERMISSION, 0);
    
    if(s_server == SEM_FAILED || 
        s_client == SEM_FAILED || 
        s_return == SEM_FAILED) {
        bail_out(EXIT_FAILURE, "sem_open(3) failed"); 
    }

    sem_set = 1;

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

示例5: my_waitpid

int
my_waitpid (int pid, int *status, int flags)
{
  int ret, out_errno;

  linux_debug ("my_waitpid (%d, 0x%x)\n", pid, flags);

  if (flags & __WALL)
    {
      sigset_t block_mask, org_mask, wake_mask;
      int wnohang;

      wnohang = (flags & WNOHANG) != 0;
      flags &= ~(__WALL | __WCLONE);

      if (!wnohang)
	{
	  flags |= WNOHANG;

	  /* Block all signals while here.  This avoids knowing about
	     LinuxThread's signals.  */
	  sigfillset (&block_mask);
	  sigprocmask (SIG_BLOCK, &block_mask, &org_mask);

	  /* ... except during the sigsuspend below.  */
	  sigemptyset (&wake_mask);
	}

      while (1)
	{
	  /* Since all signals are blocked, there's no need to check
	     for EINTR here.  */
	  ret = waitpid (pid, status, flags);
	  out_errno = errno;

	  if (ret == -1 && out_errno != ECHILD)
	    break;
	  else if (ret > 0)
	    break;

	  if (flags & __WCLONE)
	    {
	      /* We've tried both flavors now.  If WNOHANG is set,
		 there's nothing else to do, just bail out.  */
	      if (wnohang)
		break;

	      linux_debug ("blocking\n");

	      /* Block waiting for signals.  */
	      sigsuspend (&wake_mask);
	    }
	  flags ^= __WCLONE;
	}

      if (!wnohang)
	sigprocmask (SIG_SETMASK, &org_mask, NULL);
    }
  else
    {
      do
	ret = waitpid (pid, status, flags);
      while (ret == -1 && errno == EINTR);
      out_errno = errno;
    }

  linux_debug ("my_waitpid (%d, 0x%x): status(%x), %d\n",
	       pid, flags, status ? *status : -1, ret);

  errno = out_errno;
  return ret;
}
开发者ID:bitthunder-toolchain,项目名称:binutils,代码行数:72,代码来源:linux-waitpid.c

示例6: stub_pid1

int stub_pid1(sd_id128_t uuid) {
        enum {
                STATE_RUNNING,
                STATE_REBOOT,
                STATE_POWEROFF,
        } state = STATE_RUNNING;

        sigset_t fullmask, oldmask, waitmask;
        usec_t quit_usec = USEC_INFINITY;
        pid_t pid;
        int r;

        /* The new environment we set up, on the stack. */
        char new_environment[] =
                "container=systemd-nspawn\0"
                "container_uuid=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

        /* Implements a stub PID 1, that reaps all processes and processes a couple of standard signals. This is useful
         * for allowing arbitrary processes run in a container, and still have all zombies reaped. */

        assert_se(sigfillset(&fullmask) >= 0);
        assert_se(sigprocmask(SIG_BLOCK, &fullmask, &oldmask) >= 0);

        pid = fork();
        if (pid < 0)
                return log_error_errno(errno, "Failed to fork child pid: %m");

        if (pid == 0) {
                /* Return in the child */
                assert_se(sigprocmask(SIG_SETMASK, &oldmask, NULL) >= 0);
                setsid();
                return 0;
        }

        reset_all_signal_handlers();

        log_close();
        close_all_fds(NULL, 0);
        log_open();

        /* Flush out /proc/self/environ, so that we don't leak the environment from the host into the container. Also,
         * set $container= and $container_uuid= so that clients in the container that query it from /proc/1/environ
         * find them set. */
        sd_id128_to_string(uuid, new_environment + sizeof(new_environment) - SD_ID128_STRING_MAX);
        reset_environ(new_environment, sizeof(new_environment));

        rename_process("STUBINIT");

        assert_se(sigemptyset(&waitmask) >= 0);
        assert_se(sigset_add_many(&waitmask,
                                  SIGCHLD,          /* posix: process died */
                                  SIGINT,           /* sysv: ctrl-alt-del */
                                  SIGRTMIN+3,       /* systemd: halt */
                                  SIGRTMIN+4,       /* systemd: poweroff */
                                  SIGRTMIN+5,       /* systemd: reboot */
                                  SIGRTMIN+6,       /* systemd: kexec */
                                  SIGRTMIN+13,      /* systemd: halt */
                                  SIGRTMIN+14,      /* systemd: poweroff */
                                  SIGRTMIN+15,      /* systemd: reboot */
                                  SIGRTMIN+16,      /* systemd: kexec */
                                  -1) >= 0);

        /* Note that we ignore SIGTERM (sysv's reexec), SIGHUP (reload), and all other signals here, since we don't
         * support reexec/reloading in this stub process. */

        for (;;) {
                siginfo_t si;
                usec_t current_usec;

                si.si_pid = 0;
                r = waitid(P_ALL, 0, &si, WEXITED|WNOHANG);
                if (r < 0) {
                        r = log_error_errno(errno, "Failed to reap children: %m");
                        goto finish;
                }

                current_usec = now(CLOCK_MONOTONIC);

                if (si.si_pid == pid || current_usec >= quit_usec) {

                        /* The child we started ourselves died or we reached a timeout. */

                        if (state == STATE_REBOOT) { /* dispatch a queued reboot */
                                (void) reboot(RB_AUTOBOOT);
                                r = log_error_errno(errno, "Failed to reboot: %m");
                                goto finish;

                        } else if (state == STATE_POWEROFF)
                                (void) reboot(RB_POWER_OFF); /* if this fails, fall back to normal exit. */

                        if (si.si_pid == pid && si.si_code == CLD_EXITED)
                                r = si.si_status; /* pass on exit code */
                        else
                                r = 255; /* signal, coredump, timeout, … */

                        goto finish;
                }
                if (si.si_pid != 0)
                        /* We reaped something. Retry until there's nothing more to reap. */
                        continue;
//.........这里部分代码省略.........
开发者ID:OpenDZ,项目名称:systemd,代码行数:101,代码来源:nspawn-stub-pid1.c

示例7: daemonize

/**
 * Set up log file and run in the backgroud
 */
void daemonize()
{
#ifdef WINDOWS
    if (!debug) {
        int fd;
        FILE *pidfh;

        if ((fd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1) {
            perror("Can't open log file");
            exit(1);
        }
        if (strcmp(pidfile, "")) {
            // Write out the pid file, before we redirect STDERR to the log.
            if ((pidfh = fopen(pidfile, "w")) == NULL) {
                perror("Can't open pid file for writing");
                exit(1);
            }
            fprintf(pidfh, "%d\n", GetCurrentProcessId());
            fclose(pidfh);
        }
        dup2(fd, 2);
        close(fd);
        applog = stderr;
    }
#else  // WINDOWS
    if (!debug) {
        int pid, fd;
        FILE *pidfh;

        if ((fd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1) {
            perror("Can't open log file");
            exit(1);
        }
        if ((pid = fork()) == -1) {
            perror("Couldn't fork");
            exit(1);
        } else if (pid > 0) {
            parent = 1;
            exit(0);
        }
        if (strcmp(pidfile, "")) {
            // Write out the pid file, before we redirect STDERR to the log.
            if ((pidfh = fopen(pidfile, "w")) == NULL) {
                perror("Can't open pid file for writing");
                exit(1);
            }
            fprintf(pidfh, "%d\n", getpid());
            fclose(pidfh);
        }
        setsid();
        dup2(fd, 2);
        close(fd);
        for (fd = 0; fd < 30; fd++) {
            if ((fd != 2) && (fd != listener)) {
                close(fd);
            }
        }
#ifdef VMS
        chdir("SYS$LOGIN");
#else
        chdir("/");
#endif
        umask(0);
        applog = stderr;
    }

    nice(-20);
    {
        struct sigaction act;

        sigfillset(&act.sa_mask);
        act.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT | SA_RESTART;

        act.sa_handler = gotsig;
        sigaction(SIGINT, &act, NULL);
        sigaction(SIGTERM, &act, NULL);
        act.sa_handler = gotpipe;
        sigaction(SIGPIPE, &act, NULL);
        act.sa_handler = SIG_IGN;
        sigaction(SIGCHLD, &act, NULL);
    }
#endif  // WINDOWS
}
开发者ID:shoki,项目名称:uftp,代码行数:86,代码来源:proxy_init.c

示例8: schedule_unload

int schedule_unload(pid_t pid, FAR struct binary_s *bin)
{
  struct sigaction act;
  struct sigaction oact;
  sigset_t sigset;
  irqstate_t flags;
  int errorcode;
  int ret;

  /* Make sure that SIGCHLD is unmasked */

  (void)sigemptyset(&sigset);
  (void)sigaddset(&sigset, SIGCHLD);
  ret = sigprocmask(SIG_UNBLOCK, &sigset, NULL);
  if (ret != OK)
    {
      /* The errno value will get trashed by the following debug output */

      errorcode = get_errno();
      bvdbg("ERROR: sigprocmask failed: %d\n", ret);
      goto errout;
    }

  /* Add the structure to the list.  We want to do this *before* connecting
   * the signal handler.  This does, however, make error recovery more
   * complex if sigaction() fails below because then we have to remove the
   * unload structure for the list in an unexpected context.
   */

  unload_list_add(pid, bin);

  /* Register the SIGCHLD handler */

  act.sa_sigaction = unload_callback;
  act.sa_flags     = SA_SIGINFO;

  (void)sigfillset(&act.sa_mask);
  (void)sigdelset(&act.sa_mask, SIGCHLD);

  ret = sigaction(SIGCHLD, &act, &oact);
  if (ret != OK)
    {
      /* The errno value will get trashed by the following debug output */

      errorcode = get_errno();
      bvdbg("ERROR: sigaction failed: %d\n" , ret);

      /* Emergency removal from the list */

      flags = irqsave();
      if (unload_list_remove(pid) != bin)
        {
          blldbg("ERROR: Failed to remove structure\n");
        }
      
      goto errout;
    }

  return OK;

errout:
  set_errno(errorcode);
  return ERROR;
}
开发者ID:1015472,项目名称:PX4NuttX,代码行数:64,代码来源:binfmt_schedunload.c

示例9: CnxtAdslLEDTask

void CnxtAdslLEDTask(void *sem)
{
	BOOL HandShakeLED;
	BOOL ShowtimeLED;

	struct task_struct *tsk = current ;
	tsk->session = 1 ;
	tsk->pgrp = 1 ;
#if defined (CONFIG_CNXT_GSHDSL) || defined (CONFIG_CNXT_GSHDSL_MODULE)
	strcpy ( tsk->comm, "CnxtGshdslLEDTask" ) ;
#else
	strcpy ( tsk->comm, "CnxtAdslLEDTask" ) ;
#endif

	/* sigstop and sigcont will stop and wakeup kupdate */
	spin_lock_irq(&tsk->sigmask_lock);
	sigfillset(&tsk->blocked);
	siginitsetinv(&current->blocked, sigmask(SIGCONT) | sigmask(SIGSTOP));
	recalc_sigpending(tsk);
	spin_unlock_irq(&tsk->sigmask_lock);

	up((struct semaphore *)sem);

	TaskDelayConnect ( GP_TIMER_DMT_LED ) ;
	
	while(1)
	{
		/* Condensed Showtime State to two Booleans - In Showtime and In Training */
		ShowtimeLED= FALSE;
		HandShakeLED= FALSE;

		switch (HWSTATE.dwLineStatus)
		{
			case HW_IO_MODEM_STATUS_ACTIVATED:
				ShowtimeLED= TRUE;
				break;

			case HW_IO_MODEM_STATUS_CHANNEL_ANALYSIS:
			case HW_IO_MODEM_STATUS_TRANSCEIVER_TRAINING:
			case HW_IO_MODEM_STATUS_EXCHANGE:
			case HW_IO_MODEM_STATUS_ACTIVATION:
				HandShakeLED= TRUE;
				break;
		}

		/* Blink Showtime LED if in Training */
		if (ShowtimeLED || HandShakeLED)
		{
			WriteGPIOData( GPOUT_SHOWTIME_LED,LED_ON );
		}

		/* This logic is for a blinking Showtime LED */
		if (!ShowtimeLED)
		{
			WriteGPIOData( GPOUT_SHOWTIME_LED,LED_OFF );
		}

		TaskDelayMsec(LED_DELAY_PERIOD);

	}
}
开发者ID:ProjectZeroSlackr,项目名称:linux-2.4.32-ipod,代码行数:61,代码来源:cnxtadsl.c

示例10: main

int main(int argc, char *argv[]) {
	static struct sigaction act;

	act.sa_handler = get_signal;
	sigfillset(&(act.sa_mask));
	sigaction(SIGSEGV, &act, NULL);

	int no_curses = 0;

	extern char *optarg;
	extern int optind, optopt;
	int c, refresh_tmp_time = 0;
	char *endptr;
	while ((c = getopt(argc, argv, ":r:ch")) != -1) {
		switch (c) {
		case 'r':
			refresh_tmp_time = (int) strtol(optarg, &endptr, 10);
			if ((refresh_tmp_time) && (refresh_tmp_time < 30)) {
				refresh_time = refresh_tmp_time * 1000;
			}
			break;
		case 'c':
			no_curses = 1;
			break;
		case 'h':
			printf("Usage: dbtop [parameters]\n");
			printf("no parameters - standart ncurses mode\n\n");
			printf("parameters:\n");
			printf("-r interval - refresh interval for ncurses mode(in seconds)\n");
			printf("-c - show one time users list (no ncurses)\n");
			exit(0);
			break;
		}
	}
	_socket = connect_to_server_dbtop();
	in = fdopen(_socket, "r+");
	out = fdopen(_socket, "w");
	if (!in || !out) {
		printf("Can't connect to socket. Maybe governor is not started\n");
		exit(-1);
	}
	if (no_curses) {
		client_type_t ctt = DBTOPCL;
		fwrite(&ctt, sizeof(client_type_t), 1, out);
		fflush(out);
		accounts = NULL;
		recv_accounts = NULL;
		read_info();
		printOneScreenNoCurses();
		exit(0);
	}
	
///    
    /*client_type_t ctt = DBTOP;
	fwrite(&ctt, sizeof(client_type_t), 1, out);
	fflush(out);*/
	accounts = NULL;
	recv_accounts = NULL;
	initscr();
	
	signal(SIGALRM, end_pgm);
	signal(SIGHUP, end_pgm);
	signal(SIGPIPE, end_pgm);
	signal(SIGQUIT, end_pgm);
	signal(SIGTERM, end_pgm);
	signal(SIGINT, end_pgm);
	
	noecho();
	nonl();
	intrflush(stdscr, false);
	keypad(stdscr, true);
	curs_set(0);
	if (has_colors()) {
		start_color();
		use_default_colors();
		init_pair(1, COLOR_GREEN, COLOR_BLUE);
		init_pair(2, COLOR_BLUE, -1);
		init_pair(3, COLOR_RED, -1);
	}
	raw();
	halfdelay(5);
    
    read_keys();
	closesock();
}
开发者ID:damolp,项目名称:mysql-governor,代码行数:85,代码来源:dbtop.c

示例11: spawn_ras

static pid_t spawn_ras(struct ast_channel *chan, char *args)
{
	pid_t pid;
	int x;	
	char *c;

	char *argv[PPP_MAX_ARGS];
	int argc = 0;
	char *stringp=NULL;
	sigset_t fullset, oldset;

	sigfillset(&fullset);
	pthread_sigmask(SIG_BLOCK, &fullset, &oldset);

	/* Start by forking */
	pid = fork();
	if (pid) {
		pthread_sigmask(SIG_SETMASK, &oldset, NULL);
		return pid;
	}

	/* Restore original signal handlers */
	for (x=0;x<NSIG;x++)
		signal(x, SIG_DFL);

	pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);

	/* Execute RAS on File handles */
	dup2(chan->fds[0], STDIN_FILENO);

	/* Drop high priority */
	if (ast_opt_high_priority)
		ast_set_priority(0);

	/* Close other file descriptors */
	for (x=STDERR_FILENO + 1;x<1024;x++) 
		close(x);

	/* Reset all arguments */
	memset(argv, 0, sizeof(argv));

	/* First argument is executable, followed by standard
	   arguments for dahdi PPP */
	argv[argc++] = PPP_EXEC;
	argv[argc++] = "nodetach";

	/* And all the other arguments */
	stringp=args;
	c = strsep(&stringp, ",");
	while(c && strlen(c) && (argc < (PPP_MAX_ARGS - 4))) {
		argv[argc++] = c;
		c = strsep(&stringp, ",");
	}

	argv[argc++] = "plugin";
	argv[argc++] = "dahdi.so";
	argv[argc++] = "stdin";

	/* Finally launch PPP */
	execv(PPP_EXEC, argv);
	fprintf(stderr, "Failed to exec PPPD!\n");
	exit(1);
}
开发者ID:nicwolff,项目名称:asterisk-agi-mp3,代码行数:63,代码来源:app_dahdiras.c

示例12: _SMERP_posixMain


//.........这里部分代码省略.........
					std::cerr << "Pidfile is locked, another daemon running?" << std::endl;
					return _SMERP::ErrorCodes::FAILURE;
				}
			}

			// daemonize, lose process group, terminal output, etc.
			if( daemon( 0, 0 ) ) {
				std::cerr << "Daemonizing server failed" << std::endl;
				return _SMERP::ErrorCodes::FAILURE;
			}

			// now here we lost constrol over the console, we should
			// create a temporary logger which at least tells what's
			// going on in the syslog
			_SMERP::LogBackend::instance().setSyslogLevel( config.syslogLogLevel );
			_SMERP::LogBackend::instance().setSyslogFacility( config.syslogFacility );
			_SMERP::LogBackend::instance().setSyslogIdent( config.syslogIdent );

			// if we are root we can drop privileges now
			struct group *groupent;
			struct passwd *passwdent;

			groupent = getgrnam( config.group.c_str( ) );
			passwdent = getpwnam( config.user.c_str( ) );
			if( groupent == NULL || passwdent == NULL ) {
				LOG_CRITICAL << "Illegal group '" << config.group << "' or user '" << config.user << "'";
				return _SMERP::ErrorCodes::FAILURE;
			}

			if( setgid( groupent->gr_gid ) < 0 ) {
				LOG_CRITICAL << "setgid for group '" << config.group << "' failed!";
				return _SMERP::ErrorCodes::FAILURE;
			}

			if( setuid( passwdent->pw_uid ) < 0 ) {
				LOG_CRITICAL << "setgid for user '" << config.user << "' failed!";
				return _SMERP::ErrorCodes::FAILURE;
			}

			// create a pid file and lock id
			std::ofstream pidFile( config.pidFile.c_str( ), std::ios_base::trunc );
			if( !pidFile.good( ) ) {
				LOG_CRITICAL << "Unable to create PID file '" << config.pidFile << "'!";
				return _SMERP::ErrorCodes::FAILURE;
			}
			pidFile << getpid( ) << std::endl;
			pidFile.close( );

			// Create the final logger based on the configuration
			// file logger only here to get the right permissions
			_SMERP::LogBackend::instance().setLogfileLevel( config.logFileLogLevel );
			_SMERP::LogBackend::instance().setLogfileName( config.logFile );
		}

		// Block all signals for background thread.
		sigset_t new_mask;
		sigfillset( &new_mask );
		sigset_t old_mask;
		pthread_sigmask( SIG_BLOCK, &new_mask, &old_mask );

		LOG_NOTICE << "Starting server";

		// Run server in background thread(s).
		_SMERP::ServerHandler	handler( handlerConfig );
		_SMERP::Network::server s( config.address, config.SSLaddress, handler,
					   config.threads, config.maxConnections );
		boost::thread t( boost::bind( &_SMERP::Network::server::run, &s ));

		// Restore previous signals.
		pthread_sigmask( SIG_SETMASK, &old_mask, 0 );

		// Wait for signal indicating time to shut down.
		sigset_t wait_mask;
		sigemptyset( &wait_mask );
		sigaddset( &wait_mask, SIGINT );
		sigaddset( &wait_mask, SIGQUIT );
		sigaddset( &wait_mask, SIGTERM );
		pthread_sigmask( SIG_BLOCK, &wait_mask, 0 );
		int sig = 0;
		sigwait( &wait_mask, &sig );

		// Stop the server.
		LOG_INFO << "Stopping server";
		s.stop();
		t.join();
		LOG_NOTICE << "Server stopped";

		// Daemon stuff
		if( !config.foreground ) {
			(void)remove( config.pidFile.c_str( ) );
		}
	}
	catch (std::exception& e)	{
		// Aba: how to delete the pid file here?
		LOG_ERROR << "posixMain: exception: " << e.what() << "\n";
		return _SMERP::ErrorCodes::FAILURE;
	}

	return _SMERP::ErrorCodes::OK;
}
开发者ID:Wolframe,项目名称:SMERP,代码行数:101,代码来源:posixMain.cpp

示例13: Sigfillset

void Sigfillset(sigset_t *set)
{ 
    if (sigfillset(set) < 0)
	unix_error("Sigfillset error");
    return;
}
开发者ID:bitchbitch,项目名称:ACM-ICPC,代码行数:6,代码来源:echoclient.c

示例14: _sigaction

int
_sigaction(int sig, const struct sigaction * act, struct sigaction * oact)
{
	int ret = 0;
	struct sigaction gact;

	/* Check if the signal number is out of range: */
	if (sig < 1 || sig > NSIG) {
		/* Return an invalid argument: */
		errno = EINVAL;
		ret = -1;
	} else {
		if (_thread_initial == NULL)
			_thread_init();

		/*
		 * Check if the existing signal action structure contents are
		 * to be returned: 
		 */
		if (oact != NULL) {
			/* Return the existing signal action contents: */
			oact->sa_handler = _thread_sigact[sig - 1].sa_handler;
			oact->sa_mask = _thread_sigact[sig - 1].sa_mask;
			oact->sa_flags = _thread_sigact[sig - 1].sa_flags;
		}

		/* Check if a signal action was supplied: */
		if (act != NULL) {
			/* Set the new signal handler: */
			_thread_sigact[sig - 1].sa_mask = act->sa_mask;
			_thread_sigact[sig - 1].sa_flags = act->sa_flags;
			_thread_sigact[sig - 1].sa_handler = act->sa_handler;
		}

		/*
		 * Check if the kernel needs to be advised of a change
		 * in signal action:
		 */
		if (act != NULL && sig != _SCHED_SIGNAL && sig != SIGCHLD &&
		    sig != SIGINFO) {
			/*
			 * Ensure the signal handler cannot be interrupted
			 * by other signals.  Always request the POSIX signal
			 * handler arguments.
			 */
			sigfillset(&gact.sa_mask);
			gact.sa_flags = SA_SIGINFO | SA_RESTART;

			/*
			 * Check if the signal handler is being set to
			 * the default or ignore handlers:
			 */
			if (act->sa_handler == SIG_DFL ||
			    act->sa_handler == SIG_IGN)
				/* Specify the built in handler: */
				gact.sa_handler = act->sa_handler;
			else
				/*
				 * Specify the thread kernel signal
				 * handler:
				 */
				gact.sa_handler = (void (*) ()) _thread_sig_handler;

			/* Change the signal action in the kernel: */
		    	if (__sys_sigaction(sig,&gact,NULL) != 0)
				ret = -1;
		}
	}

	/* Return the completion status: */
	return (ret);
}
开发者ID:AhmadTux,项目名称:DragonFlyBSD,代码行数:72,代码来源:uthread_sigaction.c

示例15: main

int main(int argc, char *argv[]) {
        _cleanup_udev_unref_ struct udev *udev = NULL;
        _cleanup_udev_event_unref_ struct udev_event *event = NULL;
        _cleanup_udev_device_unref_ struct udev_device *dev = NULL;
        _cleanup_udev_rules_unref_ struct udev_rules *rules = NULL;
        char syspath[UTIL_PATH_SIZE];
        const char *devpath;
        const char *action;
        sigset_t mask, sigmask_orig;
        int err;

        err = fake_filesystems();
        if (err < 0)
                return EXIT_FAILURE;

        udev = udev_new();
        if (udev == NULL)
                return EXIT_FAILURE;

        log_debug("version %s", VERSION);
        mac_selinux_init("/dev");

        sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);

        action = argv[1];
        if (action == NULL) {
                log_error("action missing");
                goto out;
        }

        devpath = argv[2];
        if (devpath == NULL) {
                log_error("devpath missing");
                goto out;
        }

        rules = udev_rules_new(udev, 1);

        strscpyl(syspath, sizeof(syspath), "/sys", devpath, NULL);
        dev = udev_device_new_from_syspath(udev, syspath);
        if (dev == NULL) {
                log_debug("unknown device '%s'", devpath);
                goto out;
        }

        udev_device_set_action(dev, action);
        event = udev_event_new(dev);

        sigfillset(&mask);
        sigprocmask(SIG_SETMASK, &mask, &sigmask_orig);
        event->fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
        if (event->fd_signal < 0) {
                fprintf(stderr, "error creating signalfd\n");
                goto out;
        }

        /* do what devtmpfs usually provides us */
        if (udev_device_get_devnode(dev) != NULL) {
                mode_t mode = 0600;

                if (streq(udev_device_get_subsystem(dev), "block"))
                        mode |= S_IFBLK;
                else
                        mode |= S_IFCHR;

                if (!streq(action, "remove")) {
                        mkdir_parents_label(udev_device_get_devnode(dev), 0755);
                        mknod(udev_device_get_devnode(dev), mode, udev_device_get_devnum(dev));
                } else {
                        unlink(udev_device_get_devnode(dev));
                        rmdir_parents(udev_device_get_devnode(dev), "/");
                }
        }

        udev_event_execute_rules(event,
                                 3 * USEC_PER_SEC, USEC_PER_SEC,
                                 NULL,
                                 rules,
                                 &sigmask_orig);
        udev_event_execute_run(event,
                               3 * USEC_PER_SEC, USEC_PER_SEC,
                               NULL);
out:
        if (event != NULL && event->fd_signal >= 0)
                close(event->fd_signal);
        mac_selinux_finish();

        return err ? EXIT_FAILURE : EXIT_SUCCESS;
}
开发者ID:275288698,项目名称:systemd-ubuntu-with-dbus,代码行数:89,代码来源:test-udev.c


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