• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ signalfd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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 the signal fd");
		return -1;
	}

	if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
		SYSERROR("failed to set sigfd to close-on-exec");
		close(fd);
		return -1;
	}

	DEBUG("sigchild handler set");

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


示例17: signal_fd_init

static int signal_fd_init(int epoll_fd)
{
	struct epoll_event ev;
	sigset_t mask;
	int ret;
	int fd;

	sigemptyset(&mask);
	sigaddset(&mask, SIGINT);
	sigaddset(&mask, SIGTERM);
	ret = sigprocmask(SIG_BLOCK, &mask, NULL);
	if (ret == -1) {
		perror("sigprocmask");
		return -1;
	}

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

	signal_cb.fd = fd;
	ev.events = EPOLLIN;
	ev.data.ptr = &signal_cb;

	return epoll_ctl(epoll_fd, EPOLL_CTL_ADD, fd, &ev);
}
开发者ID:osandov,项目名称:verbar,代码行数:28,代码来源:main.c


示例18: XOpenDisplay

// Ping X in @pingInterval miliseconds.
XServerPinger::XServerPinger(int pingInterval)
{
    Display *dpy;
    sigset_t sigs;

    // Open a separate connection to X.
    dpy = XOpenDisplay(NULL);
    xcb = XGetXCBConnection(dpy);
    connect(new QSocketNotifier(ConnectionNumber(dpy), QSocketNotifier::Read),
            SIGNAL(activated(int)), SLOT(xInput(int)));

    // XGetInputFocus() is our ping request.
    request = xcb_get_input_focus(xcb);
    xcb_flush(xcb);

    timer = new QTimer();
    connect(timer, SIGNAL(timeout()), SLOT(tick()));
    timer->start(pingInterval);

    // die() if we get SIGINT or SIGTERM.
    sigemptyset(&sigs);
    sigaddset(&sigs, SIGINT);
    sigaddset(&sigs, SIGTERM);
    connect(new QSocketNotifier(signalfd(-1, &sigs, 0),
                                QSocketNotifier::Read),
            SIGNAL(activated(int)), SLOT(die(int)));
    sigprocmask(SIG_BLOCK, &sigs, NULL);
}
开发者ID:siraj,项目名称:mcompositor,代码行数:29,代码来源:xserverpinger.cpp


示例19: setup_signal_handler

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

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

    ret = sigprocmask(SIG_BLOCK, &mask, NULL);
    if (ret) {
        perror("Failed to setup signal mask");
        return -errno;
    }

    ret = signalfd(-1, &mask, 0);
    if (ret < 0) {
        perror("Failed to create signalfd");
        return -errno;
    }

    return ret;
}
开发者ID:analogdevicesinc,项目名称:MathWorks_tools,代码行数:25,代码来源:test_dma.c


示例20: rb_epoll_init_event

void
rb_epoll_init_event(void)
{

	sigset_t ss;
	rb_fde_t *F;
	int sfd;
	rb_epoll_supports_event();
	if(!can_do_timerfd)
	{
		sigemptyset(&ss);
		sigaddset(&ss, RTSIGNAL);
		sigprocmask(SIG_BLOCK, &ss, 0);
		sigemptyset(&ss);
		sigaddset(&ss, RTSIGNAL);
		sfd = signalfd(-1, &ss, 0);
		if(sfd == -1)
		{
			can_do_event = -1;
			return;
		}
		F = rb_open(sfd, RB_FD_UNKNOWN, "signalfd");
		rb_set_nb(F);
		signalfd_handler(F, NULL);
	}
}
开发者ID:AbstractBeliefs,项目名称:charybdis,代码行数:26,代码来源:epoll.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ signalfd_cleanup函数代码示例发布时间:2022-05-30
下一篇:
C++ signal_stop函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap