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


C++ signalfd函数代码示例

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


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

示例1: rtsig_install_receiver

/*
 * to create and obtain a new NONBLOCKING socket file descriptor
 *
 * (!) this will block SIGRTMIN for this thread only
 *
 * returns -1 on error
 */
int rtsig_install_receiver(int listen_on_rtsig, int nonblock_on)
{
	//make thread "immune" to realtime signals
	sigset_t immune_set;
	sigemptyset(&immune_set);
	sigaddset(&immune_set, (SIGRTMIN+listen_on_rtsig));
	pthread_sigmask(SIG_BLOCK, &immune_set, NULL);

#if(USS_LIBRARY_DEBUG == 1)
	//printf("SIGRTMIN=%i\n", (int)SIGRTMIN);
	//printf("immune to %i\n", (int)SIGRTMIN+listen_on_rtsig);
#endif

	//prepare parameters
	int fd;	
	sigset_t mask;
	sigemptyset(&mask);
	sigaddset(&mask, SIGRTMIN+listen_on_rtsig);

	if(nonblock_on != 0)
	{
		//create new NONBLOCKING fd for realtime signal SIGRTMIN
		fd = signalfd(-1, &mask, SFD_NONBLOCK);
		if(fd == -1) {derr("problem with signal file descriptor"); return USS_ERROR_GENERAL;}	
	}
	else
	{
		//create new NONBLOCKING fd for realtime signal SIGRTMIN
		fd = signalfd(-1, &mask, 0);
		if(fd == -1) {derr("problem with signal file descriptor"); return USS_ERROR_GENERAL;}	
	}
	return fd;
}
开发者ID:tobib,项目名称:hetsched,代码行数:40,代码来源:uss_rtsig.cpp

示例2: main

int main (void)
{
#if defined(HAVE_SIGNALFD) && defined(HAVE_EVENTFD) \
    && defined(HAVE_EVENTFD_READ) && defined(HAVE_PPOLL)
  {
    sigset_t mask;
    int fd, fd2;
    eventfd_t ev;
    struct timespec ts = { .tv_sec = 1, .tv_nsec = 0 };
    struct pollfd pfd[2];

    sigemptyset (&mask);
    sigaddset (&mask, SIGUSR1);
    fd = signalfd (-1, &mask, 0);
    sigaddset (&mask, SIGUSR2);
    fd = signalfd (fd, &mask, 0);
    fd2 = eventfd (5, 0);
    eventfd_read (fd2, &ev);
    pfd[0].fd = fd;
    pfd[0].events = POLLIN|POLLOUT;
    pfd[1].fd = fd2;
    pfd[1].events = POLLIN|POLLOUT;
    ppoll (pfd, 2, &ts, &mask);
  }
#endif

#if defined(HAVE_UTIMENSAT)
  unlink("/tmp/valgrind-utimensat-test");
  close (creat ("/tmp/valgrind-utimensat-test", S_IRUSR | S_IWUSR));
  {
    struct timespec ts2[2] = { [0].tv_sec = 10000000, [1].tv_sec = 20000000 };
    utimensat (AT_FDCWD, "/tmp/valgrind-utimensat-test", ts2, 0);
  }
  unlink("/tmp/valgrind-utimensat-test");
#endif

#if defined(HAVE_EPOLL_CREATE) && defined(HAVE_EPOLL_PWAIT)
  {
    int fd3;
    struct epoll_event evs[10];
    sigset_t mask;

    sigemptyset (&mask);
    sigaddset (&mask, SIGUSR1);
    sigaddset (&mask, SIGUSR2);
    fd3 = epoll_create (10);
    epoll_pwait (fd3, evs, 10, 0, &mask);
  }
#endif

  return 0;
}
开发者ID:520SRig,项目名称:valgrind,代码行数:52,代码来源:syscalls-2007.c

示例3: setup_signal_fd

static int setup_signal_fd(sigset_t *oldmask)
{
	sigset_t mask;
	int fd;

	/* Block everything except serious error signals. */
	if (sigfillset(&mask) ||
	    sigdelset(&mask, SIGILL) ||
	    sigdelset(&mask, SIGSEGV) ||
	    sigdelset(&mask, SIGBUS) ||
	    sigdelset(&mask, SIGWINCH) ||
	    sigprocmask(SIG_BLOCK, &mask, oldmask)) {
		SYSERROR("Failed to set signal mask.");
		return -1;
	}

	fd = signalfd(-1, &mask, 0);
	if (fd < 0) {
		SYSERROR("Failed to create signal file descriptor.");
		return -1;
	}

	if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
		SYSERROR("Failed to set FD_CLOEXEC on the signal file descriptor: %d.", fd);
		close(fd);
		return -1;
	}

	DEBUG("Set SIGCHLD handler with file descriptor: %d.", fd);

	return fd;
}
开发者ID:hfuCN,项目名称:lxc,代码行数:32,代码来源:start.c

示例4: signalfd_open

static int signalfd_open(struct file_desc *d, int *new_fd)
{
	struct signalfd_info *info;
	int tmp;
	sigset_t mask;

	info = container_of(d, struct signalfd_info, d);
	pr_info("Restoring signalfd %#x\n", info->sfe->id);

	sigset_fill(&mask, info->sfe->sigmask);
	tmp = signalfd(-1, &mask, 0);
	if (tmp < 0) {
		pr_perror("Can't create signalfd %#08x", info->sfe->id);
		return -1;
	}

	if (rst_file_params(tmp, info->sfe->fown, info->sfe->flags)) {
		pr_perror("Can't restore params on signalfd %#08x",
			  info->sfe->id);
		goto err_close;
	}

	*new_fd = tmp;
	return 0;

err_close:
	close(tmp);
	return -1;
}
开发者ID:cyrillos,项目名称:criu,代码行数:29,代码来源:signalfd.c

示例5: main

int main(int argc, char *argv[])
{
   sigset_t mask;
   int sfd;
   struct signalfd_siginfo fdsi;
   ssize_t s;

   sigemptyset(&mask);
   sigaddset(&mask, SIGINT);
   sigaddset(&mask, SIGQUIT);

   if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
       handle_error("sigprocmask");

   sfd = signalfd(-1, &mask, 0);
   if (sfd == -1)
       handle_error("signalfd");

   for (;;) {
       s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
       if (s != sizeof(struct signalfd_siginfo))
           handle_error("read");

       if (fdsi.ssi_signo == SIGINT) {
           printf("Got SIGINT\n");
       } else if (fdsi.ssi_signo == SIGQUIT) {
           printf("Got SIGQUIT\n");
           exit(EXIT_SUCCESS);
       } else {
           printf("Read unexpected signal\n");
       }
   }
}
开发者ID:deniyes,项目名称:test_code,代码行数:33,代码来源:signalfd.c

示例6: swSignalfd_setup

int swSignalfd_setup(swReactor *reactor)
{
    if (signal_fd == 0)
    {
        signal_fd = signalfd(-1, &signalfd_mask, SFD_NONBLOCK | SFD_CLOEXEC);
        if (signal_fd < 0)
        {
            swWarn("signalfd() failed. Error: %s[%d]", strerror(errno), errno);
            return SW_ERR;
        }
        SwooleG.signal_fd = signal_fd;
        if (sigprocmask(SIG_BLOCK, &signalfd_mask, NULL) == -1)
        {
            swWarn("sigprocmask() failed. Error: %s[%d]", strerror(errno), errno);
            return SW_ERR;
        }
        reactor->setHandle(reactor, SW_FD_SIGNAL, swSignalfd_onSignal);
        reactor->add(reactor, signal_fd, SW_FD_SIGNAL);
        return SW_OK;
    }
    else
    {
        swWarn("signalfd has been created");
        return SW_ERR;
    }
}
开发者ID:190235047,项目名称:swoole-src,代码行数:26,代码来源:signal.c

示例7: main

int main(int argc, char *argv[])
{
    sigset_t mask;
    int sfd, epollfd;
    struct epoll_event ev;

    sigemptyset(&mask);
    sigaddset(&mask, SIGINT);
    sigaddset(&mask, SIGTERM);
    sigaddset(&mask, SIGQUIT);
    sigaddset(&mask, SIGCHLD);

    /* Block signals so that they aren't handled
       according to their default dispositions */

    if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1)
        handle_error("sigprocmask");

    sfd = signalfd(-1, &mask, SFD_CLOEXEC | SFD_NONBLOCK);
    if (sfd == -1)
        handle_error("signalfd");

    // forking after epoll created leades to world of pain
    do_forks(MAX_CHILDREN, sfd);

    run_epoll(sfd, 1);

    return EXIT_SUCCESS;
}
开发者ID:yanburman,项目名称:forker,代码行数:29,代码来源:forker.c

示例8: _g_posix_signal_source_new

GSource *
_g_posix_signal_source_new (gint signum)
{
  sigset_t sigset;
  gint fd;
  GSource *_source;
  _GPosixSignalSource *source;

  _source = NULL;

  sigemptyset (&sigset);
  sigaddset (&sigset, signum);

  if (sigprocmask (SIG_BLOCK, &sigset, NULL) == -1)
    g_assert_not_reached ();

  fd = signalfd (-1, &sigset, SFD_NONBLOCK | SFD_CLOEXEC);

  _source = g_source_new (&_g_posix_signal_source_funcs, sizeof (_GPosixSignalSource));
  source = (_GPosixSignalSource *) _source;

  source->pollfd.fd = fd;
  source->pollfd.events = G_IO_IN;
  g_source_add_poll (_source, &source->pollfd);

  source->signum = signum;
  return _source;
}
开发者ID:Spacy,项目名称:gnome-online-accounts,代码行数:28,代码来源:gposixsignal.c

示例9: create_signal_io

static int create_signal_io(void)
{
	sigset_t mask;
	GIOChannel *signal_io;
	int signal_fd, signal_source;

	sigemptyset(&mask);
	sigaddset(&mask, SIGTERM);
	sigaddset(&mask, SIGINT);

	if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) {
		g_error("Can't set signal mask");
		return 1;
	}

	signal_fd = signalfd(-1, &mask, 0);
	if (signal_fd < 0) {
		g_error("Can't create signal filedescriptor");
		return 1;
	}

	signal_io = g_io_channel_unix_new(signal_fd);

	g_io_channel_set_close_on_unref(signal_io, TRUE);

	signal_source = g_io_add_watch(signal_io,
			G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
			signal_cb, GINT_TO_POINTER(signal_fd));

	g_io_channel_unref(signal_io);

	return signal_source;
}
开发者ID:Conjuror,项目名称:ofono,代码行数:33,代码来源:test-server.c

示例10: local_init

static int local_init(const char *option)
{
	sigset_t mask;
	int ret;
	static struct timer t = {
		.callback = check_pids,
		.data = &t,
	};

	if (option)
		shmfile = option;

	shm_queue_init();

	sigemptyset(&mask);
	sigaddset(&mask, SIGUSR1);
	sigprocmask(SIG_BLOCK, &mask, NULL);

	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
	if (sigfd < 0) {
		eprintf("failed to create a signal fd: %m\n");
		return -1;
	}

	add_timer(&t, 1);

	ret = register_event(sigfd, local_handler, NULL);
	if (ret) {
		eprintf("failed to register local event handler (%d)\n", ret);
		return -1;
	}

	return 0;
}
开发者ID:Nexenta,项目名称:sheepdog,代码行数:34,代码来源:local.c

示例11: setup_signals

static int
setup_signals(struct weston_launch *wl)
{
	int ret;
	sigset_t mask;
	struct sigaction sa;

	memset(&sa, 0, sizeof sa);
	sa.sa_handler = SIG_DFL;
	sa.sa_flags = SA_NOCLDSTOP | SA_RESTART;
	ret = sigaction(SIGCHLD, &sa, NULL);
	assert(ret == 0);

	sa.sa_handler = SIG_IGN;
	sa.sa_flags = 0;
	sigaction(SIGHUP, &sa, NULL);

	ret = sigemptyset(&mask);
	assert(ret == 0);
	sigaddset(&mask, SIGCHLD);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGTERM);
	sigaddset(&mask, SIGUSR1);
	sigaddset(&mask, SIGUSR2);
	ret = sigprocmask(SIG_BLOCK, &mask, NULL);
	assert(ret == 0);

	wl->signalfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
	if (wl->signalfd < 0)
		return -errno;

	return 0;
}
开发者ID:kendling,项目名称:weston,代码行数:33,代码来源:weston-launch.c

示例12: init_signal

static int init_signal(void)
{
	sigset_t mask;
	int ret;

	sigemptyset(&mask);
	sigaddset(&mask, SIGTERM);
	sigprocmask(SIG_BLOCK, &mask, NULL);

	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
	if (sigfd < 0) {
		sd_err("failed to create a signal fd: %m");
		return -1;
	}

	ret = register_event(sigfd, signal_handler, NULL);
	if (ret) {
		sd_err("failed to register signal handler (%d)", ret);
		return -1;
	}

	sd_debug("register signal_handler for %d", sigfd);

	return 0;
}
开发者ID:gitter-badger,项目名称:sheepdog,代码行数:25,代码来源:sheep.c

示例13: signal_task_run

static void signal_task_run(void *arg)
{
	int fd;
	sigset_t mask;
	wire_fd_state_t fd_state;

	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGQUIT);
	sigaddset(&mask, SIGTERM);
	sigaddset(&mask, SIGHUP);

	/* Block signals so that they aren't handled
	   according to their default dispositions */

	if (sigprocmask(SIG_BLOCK, &mask, NULL) == -1) {
		perror("sigprocmask failed");
		return;
	}

	fd = signalfd(-1, &mask, 0);
	if (fd == -1) {
		perror("signalfd failed");
		return;
	}

	wire_fd_mode_init(&fd_state, fd);

	while (1) {
		struct signalfd_siginfo fdsi;
		ssize_t s;

		wire_fd_mode_read(&fd_state);
		wire_fd_wait(&fd_state);

		s = read(fd, &fdsi, sizeof(struct signalfd_siginfo));
		if (s != sizeof(struct signalfd_siginfo)) {
			wire_log(WLOG_ERR, "failed to read from signalfd %d: ret=%d errno=%d: %m\n", fd, (int)s, errno);
			wio_close(fd);
			break;
		}

		if (fdsi.ssi_signo == SIGINT || fdsi.ssi_signo == SIGTERM || fdsi.ssi_signo == SIGQUIT) {
			wire_log(WLOG_NOTICE, "Got signal %d", fdsi.ssi_signo);
			handle_shutdown_signal();
			break;
		} else if (fdsi.ssi_signo == SIGHUP) {
			wire_log(WLOG_INFO, "Got sighup, saving state");
			disk_manager_save_state();
		} else {
			wire_log(WLOG_WARNING, "Read unexpected signal %d", fdsi.ssi_signo);
		}
	}

	sigprocmask(SIG_UNBLOCK, &mask, NULL);

	wire_fd_mode_none(&fd_state);
	wio_close(fd);
	wire_log(WLOG_INFO, "signal thread exiting");
}
开发者ID:baruch,项目名称:disksurvey,代码行数:60,代码来源:main.c

示例14: wl_event_loop_add_signal

WL_EXPORT struct wl_event_source *
wl_event_loop_add_signal(struct wl_event_loop *loop,
			int signal_number,
			wl_event_loop_signal_func_t func,
			void *data)
{
	struct wl_event_source_signal *source;
	sigset_t mask;

	source = malloc(sizeof *source);
	if (source == NULL)
		return NULL;

	source->base.interface = &signal_source_interface;
	source->signal_number = signal_number;

	sigemptyset(&mask);
	sigaddset(&mask, signal_number);
	source->base.fd = signalfd(-1, &mask, SFD_CLOEXEC);
	sigprocmask(SIG_BLOCK, &mask, NULL);

	source->func = func;

	return add_source(loop, &source->base, WL_EVENT_READABLE, data);
}
开发者ID:magcius,项目名称:wayland,代码行数:25,代码来源:event-loop.c

示例15: sigemptyset

int32_t IOLoop::addSignalHandler(int signum, HandlerCallback&& handler)
{
    sigset_t mask;
    sigemptyset(&mask);
    sigaddset(&mask, signum);
    // block watched signals: otherwise the default handler is called
    if(sigprocmask(SIG_BLOCK, &mask, 0)) 
    {
        TORNADO_LOG_ERROR("sigprocmask faild err=%s", STR_ERRNO);  
        return -1;
    }

    int32_t sfd = signalfd(-1, &mask, SFD_NONBLOCK | SFD_CLOEXEC);
    if(sfd < 0)
    {
        TORNADO_LOG_ERROR("signalfd faild err=%s", STR_ERRNO);  
        return sfd;
    }

    if( addHandler(sfd, std::move(handler), IOLoop::READ) )
    {
        TORNADO_LOG_ERROR("addHandler faild sfd=%d", sfd);  
        removeHandler(sfd);
        ::close(sfd);
        return -1;
    }
    return sfd;
}
开发者ID:zhengyinglin,项目名称:simplesvr,代码行数:28,代码来源:IOLoop.cpp


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