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

C++ sigwaitinfo函数代码示例

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

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



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

示例1: run

/**
 * Run the daemon and handle unix signals
 */
static void run()
{
	sigset_t set;

	/* handle SIGINT and SIGTERM in this handler */
	sigemptyset(&set);
	sigaddset(&set, SIGINT);
	sigaddset(&set, SIGTERM);
	sigprocmask(SIG_BLOCK, &set, NULL);

	while (TRUE)
	{
		int sig;

		sig = sigwaitinfo(&set, NULL);
		if (sig == -1)
		{
			if (errno == EINTR)
			{	/* ignore signals we didn't wait for */
				continue;
			}
			DBG1(DBG_DMN, "waiting for signal failed: %s", strerror(errno));
			return;
		}
		switch (sig)
		{
			case SIGINT:
			{
				DBG1(DBG_DMN, "signal of type SIGINT received. Shutting down");
				charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
				return;
			}
			case SIGTERM:
			{
				DBG1(DBG_DMN, "signal of type SIGTERM received. Shutting down");
				charon->bus->alert(charon->bus, ALERT_SHUTDOWN_SIGNAL, sig);
				return;
			}
		}
	}
}
开发者ID:mikma,项目名称:strongswan,代码行数:44,代码来源:charon-nm.c


示例2: luasandbox_timer_stop_one

static void luasandbox_timer_stop_one(luasandbox_timer * lt, struct timespec * remaining)
{
	static struct timespec zero = {0, 0};
	struct itimerspec its;
	timer_gettime(lt->timer, &its);
	if (remaining) {
		*remaining = its.it_value;
	}

	its.it_value = zero;
	its.it_interval = zero;
	timer_settime(lt->timer, 0, &its, NULL);

	if (lt->cbdata.type == LUASANDBOX_TIMER_PROFILER) {
		// Invalidate the cbdata, delete the timer
		lt->cbdata.sandbox = NULL;
		timer_delete(lt->timer);
		// If the timer event handler is running, wait for it to finish
		// before returning to the caller, otherwise the timer event handler
		// may find itself with a dangling pointer in its local scope.
		while (sem_wait(&lt->cbdata.semaphore) && errno == EINTR);
		sem_destroy(&lt->cbdata.semaphore);
	} else {
		// Block the signal, delete the timer, flush pending signals, restore
		sigset_t sigset, oldset, pendset;
		siginfo_t info;
		sigemptyset(&sigset);
		sigaddset(&sigset, LUASANDBOX_SIGNAL);
		sigprocmask(SIG_BLOCK, &sigset, &oldset);
		timer_delete(lt->timer);
		while (1) {
			sigpending(&pendset);
			if (!sigismember(&pendset, LUASANDBOX_SIGNAL)) {
				break;
			}
			sigwaitinfo(&sigset, &info);
			luasandbox_timer_handle_signal(LUASANDBOX_SIGNAL, &info, NULL);
		}
		sigprocmask(SIG_SETMASK, &oldset, NULL);
	}
}
开发者ID:butch2k,项目名称:mediawiki-php-luasandbox,代码行数:41,代码来源:timer.c


示例3: trv_joystick_wait

static int trv_joystick_wait(void)
{
  sigset_t set;
  struct siginfo value;
  int ret;

  /* Wait for a signal */

  (void)sigemptyset(&set);
  (void)sigaddset(&set, CONFIG_GRAPHICS_TRAVELER_JOYSTICK_SIGNO);
  ret = sigwaitinfo(&set, &value);
  if (ret < 0)
    {
      int errcode = errno;

      fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errcode);
      return -errcode;
    }

  return OK;
}
开发者ID:nodesign,项目名称:nuttx-apps,代码行数:21,代码来源:trv_input.c


示例4: sigwait_loop

/**
 * This is a thread with priority kernel_prio that synchronously waits for
 * rtdal_pipeline signals (usign sigwaitinfo). All signals except thread-specific
 * ones (SIGSEGV,SIGILL,SIGBUS,SIGFPE) are blocked by all threads except this one.
 * Thread-specific signals are handled by ProcThreads which send a SIGRTMIN+1,
 * SIGRTMIN+2,SIGRTMIN+3,SIGRTMIN+4 (respectively) to this thread, which takes
 * actions accordingly.
 *
 * for signals SIGRTMIN to SIGRTMIN+4, cast the rtdal_pipeline object from this
 * si_value pointer and call rtdal_pipeline_recover_thread(pipeline,
 * pipeline->running_process, TRUE)
 */
void sigwait_loop(void) {

	int signum;
	sigset_t set;
	siginfo_t info;

	sigfillset(&set);
	sigdelset(&set,TASK_TERMINATION_SIGNAL);
	while(!sigwait_stops) {
		do {
			signum = sigwaitinfo(&set, &info);
		} while (signum == -1 && errno == EINTR);
		if (signum == -1) {
			poserror(errno, "sigwaitinfo");
			goto out;
		}
		hdebug("detected signal %d\n",signum);
		if (signum == KERNEL_SIG_THREAD_SPECIFIC) {
			printf("[rtdal]: Caught thread-specific signal\n");
#ifdef EXIT_ON_THREADSIG
			fflush(stdout);
			goto out;
#else
			sigwait_loop_process_thread_signal(&info);
#endif
		} else if (signum == SIGINT) {
			printf("Caught SIGINT, exiting\n");
			fflush(stdout);
			goto out;
		} else if (signum != SIGWINCH && signum != SIGCHLD) {
			printf("Got signal %d, exiting\n", signum);
			fflush(stdout);
			goto out;
		}
	}

out:
	kernel_exit();
}
开发者ID:alring,项目名称:aloe,代码行数:51,代码来源:rtdal_kernel_signals.c


示例5: lio_waitall

static int lio_waitall(FAR struct aiocb *const *list, int nent)
{
	sigset_t set;
	int ret;

	/* Loop until all I/O completes */

	for (;;) {
		/* Check if all I/O has completed */

		ret = lio_checkio(list, nent);
		if (ret != -EINPROGRESS) {
			/* All I/O has completed.. We are finished.  */

			return ret;
		}

		/* Then wait for SIGPOLL -- indefinitely.
		 *
		 * NOTE: If completion of the I/O causes other signals to be generated
		 * first, then this will wake up and return EINTR instead of success.
		 */

		sigemptyset(&set);
		sigaddset(&set, SIGPOLL);

		ret = sigwaitinfo(&set, NULL);
		if (ret < 0) {
			/* The most likely reason that we would get here is because some
			 * unrelated signal has been received.
			 */

			int errcode = get_errno();
			fdbg("ERROR: sigwaitinfo failed: %d\n", errcode);
			DEBUGASSERT(errcode > 0);
			return -errcode;
		}
	}
}
开发者ID:drashti304,项目名称:TizenRT,代码行数:39,代码来源:lio_listio.c


示例6: signal_check_functions

void signal_check_functions(pthread_t tid, sigset_t *ss, union sigval sv)
{
    typedef void (*signal_cb_t)(int );

    (void)kill((pid_t)0, 0);
#if __XSI_VISIBLE
    (void)killpg((pid_t)0, 0);
#endif
#if !__APPLE__
    (void)psiginfo((const siginfo_t *)0, (const char *)0);
#endif
    (void)psignal(0, (const char*)0);
    (void)pthread_kill(tid, 0);
    (void)pthread_sigmask(0, (const sigset_t*)0, (sigset_t*)0);
    (void)raise(0);
    (void)sigaction(0, (const struct sigaction*)0, (struct sigaction*)0);
    (void)sigaddset(ss, 0);
#if __XSI_VISIBLE
    (void)sigaltstack((const stack_t*)0, (stack_t*)0);
#endif
    (void)sigdelset(ss, 0);
    (void)sigemptyset(ss);
    (void)sigfillset(ss);
    (void)sigismember(ss, 0);
    (void)signal(0, (signal_cb_t)0);
    (void)sigpending(ss);
    (void)sigprocmask(0, (const sigset_t*)0, (sigset_t*)0);
#if _POSIX_REALTIME_SIGNALS > 0
    (void)sigqueue((pid_t)0, 0, sv);
#endif
    (void)sigsuspend(ss);
#if _POSIX_REALTIME_SIGNALS > 0
    (void)sigtimedwait((const sigset_t*)0, (siginfo_t*)0, (const struct timespec*)0);
#endif
    (void)sigwait(ss, (int*)0);
#if _POSIX_REALTIME_SIGNALS > 0
    (void)sigwaitinfo(ss, (siginfo_t*)0);
#endif
}
开发者ID:Zengwn,项目名称:android-platform-ndk,代码行数:39,代码来源:signal.c


示例7: memset

/* Helper function to support starting threads for SIGEV_THREAD.  */
static void *timer_thread_main (void *arg)
{
  /* Wait for the SIGTIMER signal */
  sem_t *sem = (sem_t *)arg;
#ifdef ANDROID
  unsigned long sigset[2];
  memset(&sigset, 0, sizeof(sigset));
#else
  sigset_t sigset;
  sigemptyset(&sigset);
#endif
  sigaddset((sigset_t*)&sigset, SIGTIMER);

  th_timer_tid = gettid();
  sem_post(sem);

  /* Endless loop for waiting for signals. The loop is only ended when
     the thread is canceled.  */
  while (1) {
    siginfo_t si;
    int result;

#ifdef ANDROID
    result = __rt_sigtimedwait((sigset_t*)&sigset, &si, NULL, sizeof(sigset));
#else
    result = sigwaitinfo(&sigset, &si);
#endif
    if (result > 0)
      {
	if (si.si_code == SI_TIMER) {
	  timer *t;
	  t = static_cast<timer*>(si.si_value.sival_ptr);
	  t->alarm.signal();
	}
      }
  }
  return NULL;
}
开发者ID:Meticulus,项目名称:vendor_st-ericsson_u8500,代码行数:39,代码来源:timer.cpp


示例8: main

int main(void)
{
	int pid, rtsig;
	union sigval value;
	struct sigaction act;
	sigset_t selectset;

	act.sa_flags = SA_SIGINFO;
	act.sa_sigaction = myhandler;
	sigemptyset(&act.sa_mask);
	sigemptyset(&selectset);

	for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
		sigaddset(&act.sa_mask, rtsig);
		sighold(rtsig);
		sigaddset(&selectset, rtsig);
	}

	pid = getpid();
	value.sival_int = 5;	/* 5 is just an arbitrary value */

	for (rtsig = SIGRTMAX; rtsig >= SIGRTMIN; rtsig--) {
		sigaction(rtsig, &act, 0);
		if (sigqueue(pid, rtsig, value) != 0) {
			printf
			    ("Test UNRESOLVED: call to sigqueue did not return success\n");
			return PTS_UNRESOLVED;
		}
	}

	if (sigwaitinfo(&selectset, NULL) != SIGRTMIN) {
		printf
		    ("Test FAILED: sigwaitinfo() did not return the lowest of the multiple pending signals between SIGRTMIN and SIGRTMAX\n");
		return PTS_FAIL;
	}

	return PTS_PASS;
}
开发者ID:1587,项目名称:ltp,代码行数:38,代码来源:2-1.c


示例9: timer_notify_thread_func

static void *
timer_notify_thread_func(void *arg)
{
  sigset_t set;
  siginfo_t info;
  my_timer_t *timer;
  pthread_barrier_t *barrier= arg;

  my_thread_init();

  sigemptyset(&set);
  sigaddset(&set, MY_TIMER_EVENT_SIGNO);
  sigaddset(&set, MY_TIMER_KILL_SIGNO);

  /* Get the thread ID of the current thread. */
  timer_notify_thread_id= (pid_t) syscall(SYS_gettid);

  /* Wake up parent thread, timer_notify_thread_id is available. */
  pthread_barrier_wait(barrier);

  while (1)
  {
    if (sigwaitinfo(&set, &info) < 0)
      continue;

    if (info.si_signo == MY_TIMER_EVENT_SIGNO)
    {
      timer= (my_timer_t*)info.si_value.sival_ptr;
      timer->notify_function(timer);
    }
    else if (info.si_signo == MY_TIMER_KILL_SIGNO)
      break;
  }

  my_thread_end();

  return NULL;
}
开发者ID:JohnOhl,项目名称:mysql-connector-c,代码行数:38,代码来源:posix_timers.c


示例10: sigmgr_thread

void* sigmgr_thread()
{
	sigset_t   waitset, oset;
	siginfo_t  info;
	int        rc;
	pthread_t  ppid = pthread_self();

	pthread_detach(ppid);

	sigemptyset(&waitset);
	sigaddset(&waitset, SIGRTMIN);
	sigaddset(&waitset, SIGUSR1);

	while (1)  {
		rc = sigwaitinfo(&waitset, &info);
		if (rc != -1) {
			printf("sigwaitinfo() fetch the signal - %d\n", rc);
			sig_handler(info.si_signo);
		} else {
			printf("sigwaitinfo() returned err: %d; %s\n", errno, strerror(errno));
		}
	}
}
开发者ID:1023xp,项目名称:training,代码行数:23,代码来源:signalsync.c


示例11: TEST

TEST(signal, sigwaitinfo) {
  // Block SIGALRM.
  sigset_t just_SIGALRM;
  sigemptyset(&just_SIGALRM);
  sigaddset(&just_SIGALRM, SIGALRM);
  sigset_t original_set;
  ASSERT_EQ(0, sigprocmask(SIG_BLOCK, &just_SIGALRM, &original_set));

  // Raise SIGALRM.
  sigval_t sigval;
  sigval.sival_int = 1;
  ASSERT_EQ(0, sigqueue(getpid(), SIGALRM, sigval));

  // Get pending SIGALRM.
  siginfo_t info;
  errno = 0;
  ASSERT_EQ(SIGALRM, sigwaitinfo(&just_SIGALRM, &info));
  ASSERT_EQ(0, errno);
  ASSERT_EQ(SIGALRM, info.si_signo);
  ASSERT_EQ(1, info.si_value.sival_int);

  ASSERT_EQ(0, sigprocmask(SIG_SETMASK, &original_set, NULL));
}
开发者ID:RUIXUEZHAOFENGNIAN,项目名称:platform_bionic,代码行数:23,代码来源:signal_test.cpp


示例12: ping_via_slots

int ping_via_slots(const char *name, struct servants_list_item *servants)
{
	int sig = 0;
	pid_t pid = 0;
	int status = 0;
	int servants_finished = 0;
	sigset_t procmask;
	siginfo_t sinfo;
	struct servants_list_item *s;

	sigemptyset(&procmask);
	sigaddset(&procmask, SIGCHLD);
	sigprocmask(SIG_BLOCK, &procmask, NULL);

	for (s = servants; s; s = s->next) {
            if(sbd_is_disk(s)) {
                s->pid = assign_servant(s->devname, &slot_ping_wrapper, 0, (const void*)name);
            }
        }

	while (servants_finished < disk_count) {
		sig = sigwaitinfo(&procmask, &sinfo);
		if (sig == SIGCHLD) {
			while ((pid = wait(&status))) {
				if (pid == -1 && errno == ECHILD) {
					break;
				} else {
					s = lookup_servant_by_pid(pid);
					if (s && sbd_is_disk(s)) {
						servants_finished++;
					}
				}
			}
		}
	}
	return 0;
}
开发者ID:credativ,项目名称:sbd,代码行数:37,代码来源:sbd-md.c


示例13: sigwaitinfo

/*[sig_thread]*/
static void *sig_thread(void *arg)
{
	int signum;
	siginfo_t info;

	do {
		signum = sigwaitinfo((sigset_t *)arg, &info);
		if (signum == MYSIG_COUNT)
			printf("Got MYSIG_COUNT; value: %s\n",
			  (char *)info.si_value.sival_ptr);
		else if (signum == MYSIG_STOP) {
			printf("Got MYSIG_STOP; terminating thread\n");
			return (void *)true;
		}
		else
			printf("Got %d\n", signum);
	} while (signum != -1 || errno == EINTR);
	EC_FAIL

EC_CLEANUP_BGN
	EC_FLUSH("sig_thread")
	return (void *)false;
EC_CLEANUP_END
}
开发者ID:4get,项目名称:aup2ex,代码行数:25,代码来源:thrq.c


示例14: msd_signal_thread_cycle

/**
 * 功能: 专职信号处理线程
 * 说明: 
 *      1.将别的线程阻塞起来的信号,全部加入到自己的监听掩码中来
 *      2.无限循环,阻塞起来,等待自己监听的信号到来
 * 注意:
 *      1. 对于共有信号的这种处理,是"同步"方式
 * 返回:成功:0; 失败:-x
 **/
static void* msd_signal_thread_cycle(void *arg)
{    
    sigset_t   waitset;    
    siginfo_t  info;    
    int        rc;
    msd_thread_signal_t *sig_worker = (msd_thread_signal_t *)arg;
    
    MSD_INFO_LOG("Worker[Signal] begin to work");
    
    /* 将别的线程阻塞的信号,全部加入自己的监听范围 */
    sigemptyset(&waitset);
    sigaddset(&waitset, SIGTERM);    
    sigaddset(&waitset, SIGQUIT);
    sigaddset(&waitset, SIGCHLD);
    sigaddset(&waitset, SIGPIPE);
    sigaddset(&waitset, SIGINT);
    sigaddset(&waitset, SIGHUP);

    /* 无线循环阻塞,等待信号到来 */
    while (1)  
    {       
        rc = sigwaitinfo(&waitset, &info);        
        if (rc != MSD_ERR) 
        {   
            /* 同步处理信号 */
            msd_public_signal_handler(info.si_signo, sig_worker);
        } 
        else 
        {            
            MSD_ERROR_LOG("Sigwaitinfo() returned err: %d; %s", errno, strerror(errno));       
        }    

     }
    //free(sig_worker);//msd_destroy_instance中会统一释放资源
    return (void *)NULL;
}
开发者ID:hq-cml,项目名称:mossad,代码行数:45,代码来源:msd_signal.c


示例15: my_sigwaitinfo

static int my_sigwaitinfo(const sigset_t* set, siginfo_t* info, struct timespec* timeout)
{
	return sigwaitinfo(set, info);
}
开发者ID:ystk,项目名称:debian-ltp,代码行数:4,代码来源:sigwaitinfo01.c


示例16: main

int
main(void)
{
	int status;
	struct mq_attr attr;
	struct sigaction sa;
	sigset_t set;
	siginfo_t info;
	mqd_t mq;
	pid_t pid;

	PLAIN_REQUIRE_KERNEL_MODULE("mqueuefs", 0);

	mq_unlink(MQNAME);

	sigemptyset(&set);
	sigaddset(&set, SIGRTMIN);
	sigprocmask(SIG_BLOCK, &set, NULL);
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_SIGINFO;
	sa.sa_sigaction = (void *) SIG_DFL;
	sigaction(SIGRTMIN, &sa, NULL);

	attr.mq_maxmsg  = 5;
	attr.mq_msgsize = 128;
	mq = mq_open(MQNAME, O_CREAT | O_RDWR | O_EXCL, 0666, &attr);
	if (mq == (mqd_t)-1)
		err(1, "mq_open()");
	status = mq_getattr(mq, &attr);
	if (status)
		err(1, "mq_getattr()");
	pid = fork();
	if (pid == 0) { /* child */
		int prio, j, i;
		char *buf;
		struct sigevent sigev;

		signal(SIGALRM, sighandler);

		sigev.sigev_notify = SIGEV_SIGNAL;
		sigev.sigev_signo = SIGRTMIN;
		sigev.sigev_value.sival_int = 2;

		mq_close(mq);
		mq = mq_open(MQNAME, O_RDWR | O_NONBLOCK);
		if (mq == (mqd_t)-1)
			err(1, "child: mq_open");
		buf = malloc(attr.mq_msgsize);
		for (j = 0; j < LOOPS; ++j) {
			alarm(3);
			status = mq_notify(mq, &sigev);
			if (status)
				err(1, "child: mq_notify");
			status = sigwaitinfo(&set, &info);
			if (status == -1)
				err(1, "child: sigwaitinfo");
			if (info.si_value.sival_int != 2)
				err(1, "child: sival_int");
			status = mq_receive(mq, buf, attr.mq_msgsize, &prio);
			if (status == -1)
				err(2, "child: mq_receive");
			for (i = 0; i < attr.mq_msgsize; ++i)
				if (buf[i] != i)
					err(3, "child: message data corrupted");
			if (prio != PRIO)
				err(4, "child: priority is incorrect: %d",
					 prio);
		}
		alarm(0);
		free(buf);
		mq_close(mq);
		return (0);
	} else if (pid == -1) {
		err(1, "fork()");
	} else {
		char *buf;
		int i, j;

		signal(SIGALRM, sighandler);
		buf = malloc(attr.mq_msgsize);
		for (j = 0; j < LOOPS; ++j) {
			for (i = 0; i < attr.mq_msgsize; ++i) {
				buf[i] = i;
			}
			alarm(3);
			status = mq_send(mq, buf, attr.mq_msgsize, PRIO);
			if (status) {
				kill(pid, SIGKILL);
				err(2, "mq_send()");
			}
		}
		alarm(3);
		wait(&status);
		alarm(0);
	}
	status = mq_close(mq);
	if (status)
		err(1, "mq_close");
	mq_unlink(MQNAME);
	return (0);
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,代码来源:mqtest5.c


示例17: pcntl_sigwaitinfo

static void pcntl_sigwaitinfo(INTERNAL_FUNCTION_PARAMETERS, int timedwait) /* {{{ */
{
    zval            *user_set, **user_signo, *user_siginfo = NULL;
    long             tv_sec = 0, tv_nsec = 0;
    sigset_t         set;
    HashPosition     pos;
    int              signo;
    siginfo_t        siginfo;
    struct timespec  timeout;

    if (timedwait) {
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|zll", &user_set, &user_siginfo, &tv_sec, &tv_nsec) == FAILURE) {
            return;
        }
    } else {
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &user_set, &user_siginfo) == FAILURE) {
            return;
        }
    }

    if (sigemptyset(&set) != 0) {
        PCNTL_G(last_error) = errno;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
        RETURN_FALSE;
    }

    zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(user_set), &pos);
    while (zend_hash_get_current_data_ex(Z_ARRVAL_P(user_set), (void **)&user_signo, &pos) == SUCCESS)
    {
        if (Z_TYPE_PP(user_signo) != IS_LONG) {
            SEPARATE_ZVAL(user_signo);
            convert_to_long_ex(user_signo);
        }
        signo = Z_LVAL_PP(user_signo);
        if (sigaddset(&set, signo) != 0) {
            PCNTL_G(last_error) = errno;
            php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
            RETURN_FALSE;
        }
        zend_hash_move_forward_ex(Z_ARRVAL_P(user_set), &pos);
    }

    if (timedwait) {
        timeout.tv_sec  = (time_t) tv_sec;
        timeout.tv_nsec = tv_nsec;
        signo = sigtimedwait(&set, &siginfo, &timeout);
    } else {
        signo = sigwaitinfo(&set, &siginfo);
    }
    if (signo == -1 && errno != EAGAIN) {
        PCNTL_G(last_error) = errno;
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
    }

    /*
     * sigtimedwait and sigwaitinfo can return 0 on success on some
     * platforms, e.g. NetBSD
     */
    if (!signo && siginfo.si_signo) {
        signo = siginfo.si_signo;
    }

    if (signo > 0 && user_siginfo) {
        if (Z_TYPE_P(user_siginfo) != IS_ARRAY) {
            zval_dtor(user_siginfo);
            array_init(user_siginfo);
        } else {
            zend_hash_clean(Z_ARRVAL_P(user_siginfo));
        }
        add_assoc_long_ex(user_siginfo, "signo", sizeof("signo"), siginfo.si_signo);
        add_assoc_long_ex(user_siginfo, "errno", sizeof("errno"), siginfo.si_errno);
        add_assoc_long_ex(user_siginfo, "code",  sizeof("code"),  siginfo.si_code);
        switch(signo) {
#ifdef SIGCHLD
        case SIGCHLD:
            add_assoc_long_ex(user_siginfo,   "status", sizeof("status"), siginfo.si_status);
# ifdef si_utime
            add_assoc_double_ex(user_siginfo, "utime",  sizeof("utime"),  siginfo.si_utime);
# endif
# ifdef si_stime
            add_assoc_double_ex(user_siginfo, "stime",  sizeof("stime"),  siginfo.si_stime);
# endif
            add_assoc_long_ex(user_siginfo,   "pid",    sizeof("pid"),    siginfo.si_pid);
            add_assoc_long_ex(user_siginfo,   "uid",    sizeof("uid"),    siginfo.si_uid);
            break;
#endif
        case SIGILL:
        case SIGFPE:
        case SIGSEGV:
        case SIGBUS:
            add_assoc_double_ex(user_siginfo, "addr", sizeof("addr"), (long)siginfo.si_addr);
            break;
#ifdef SIGPOLL
        case SIGPOLL:
            add_assoc_long_ex(user_siginfo, "band", sizeof("band"), siginfo.si_band);
# ifdef si_fd
            add_assoc_long_ex(user_siginfo, "fd",   sizeof("fd"),   siginfo.si_fd);
# endif
            break;
#endif
//.........这里部分代码省略.........
开发者ID:oasynnoum,项目名称:ore-php,代码行数:101,代码来源:pcntl.c


示例18: main

int
main(int argc, char **argv)
{
	(void)argc;
	(void)argv;
	int fd = hcall_init();

	uval laddr = mem_hold(4096);
	char *ptr = mmap(NULL, 4096,
			 PROT_READ | PROT_WRITE, MAP_SHARED,
			 fd, laddr);

	args.opcode = H_CREATE_MSGQ;
	args.args[0] = laddr;
	args.args[1] = 4096;
	args.args[2] = 0;

	hcall(&args);

	uval xirr = args.args[0];

	printf(UVAL_CHOOSE("hcall: %x (%lx) %x %x\n",
			   "hcall: %lx (%lx) %lx %lx\n"),
	       args.retval, xirr, args.args[1], args.args[2]);

	sigfillset(&msg_sig.sa_mask);
	sigaction(SIGRTMIN, &msg_sig, NULL);

	ora.oh_interrupt = xirr;
	ora.oh_signal = SIGRTMIN;
	ioctl(fd, OH_IRQ_REFLECT, &ora);

	struct msg_queue *mq = (struct msg_queue *)ptr;

	printf(UVAL_CHOOSE("msgq: %lx %lx %lx\n",
			   "msgq: %lx %lx %lx\n"),
	       mq->bufSize, mq->head, mq->tail);

	uval lpid;

	args.opcode = H_GET_LPID;
	hcall(&args);
	lpid = args.args[0];
	printf(UVAL_CHOOSE("self lpid: %lx\n", "self lpid: %lx\n"), lpid);

	while (1) {
		sigset_t set;

		sigemptyset(&set);
		sigaddset(&set, SIGRTMIN);

		siginfo_t info;
		int ret = sigwaitinfo(&set, &info);

		printf("sigwaitinfo: %d\n", ret);
		printf(UVAL_CHOOSE("msgq: %lx %lx %lx\n",
				   "msgq: %lx %lx %lx\n"),
		       mq->bufSize, mq->head, mq->tail);

		int tail = mq->tail % mq->bufSize;
		struct async_msg_s *msg = &mq->buffer[tail];

		printf(UVAL_CHOOSE("msg from: %lx\n", "msg from: %lx\n"),
		       msg->am_source);
		printf(UVAL_CHOOSE("msg raw data: %lx %lx %lx %lx\n",
				   "msg raw data: %lx %lx %lx %lx\n"),
		       msg->am_data.amu_data[0], msg->am_data.amu_data[1],
		       msg->am_data.amu_data[2], msg->am_data.amu_data[3]);

		++mq->tail;
	}

	close(fd);
	return 0;
}
开发者ID:jiamacs,项目名称:rhype,代码行数:75,代码来源:hmsg.c


示例19: main

/**
 * int main()
 *
 * Invokes the backend, waits until it has successfully detached from the I/O ports,
 * and then quits. 
 */
int main() {
  /** Block SIGUSR1, SIGCHLD until we can handle them. */
  sigset_t waitset;
  sigemptyset(&waitset);
  sigaddset(&waitset, SIGUSR1);
  sigaddset(&waitset, SIGCHLD);
  sigprocmask(SIG_BLOCK, &waitset, NULL);
  
  /** Install signal handlers for those signals. */
  struct sigaction actions;
  sigemptyset(&actions.sa_mask);
  actions.sa_flags = SA_SIGINFO;
  actions.sa_sigaction = dummy_signal_action;
  sigaction(SIGUSR1, &actions, NULL);
  sigaction(SIGCHLD, &actions, NULL);
  
  /** Fork the child */
  pid_t childpid = fork();
  if(childpid < 0) {
    perror("Could not fork() child:");
    return 1;
  }

  if(childpid == 0) {
    /* Detach session, setup file descriptors, spawn Racket process. */
    if(setsid() < 0) {
      perror("Could not detach session:");
      return 1;
    }

#ifndef NDEBUG
    putenv("PLTSTDERR=debug");
#endif

    // Prefer build directory if debug build.
    if(!IS_INSTALLED() && access(SEASHELL_DEBUG_MAIN, F_OK) != -1) {
      char * argv2[] = {SEASHELL_DEBUG_MAIN, "-s", NULL};
      execv(SEASHELL_DEBUG_MAIN, argv2);
      perror("Could not execv() the Seashell backend:");
      return 1;
    }
    // Main case if not in debug mode (fall through if)
    char * argv[] = {SEASHELL_MAIN, "-s", NULL};
    execv(SEASHELL_MAIN, argv);

    perror("Could not execv() the Seashell backend:");
    return 1;
  } else {
    /* Setup file descriptors, pass key and port, exit. */
    while (true) {
      siginfo_t info;
      int result = sigwaitinfo(&waitset, &info);

      if (result < 0) {
        if (errno == EINTR) {
          continue;
        } else {
          perror("sigwaitinfo failed with:");
          return 1;
        }
      } else {
        /** Wait for the process to quit (successfully) or detach. */
        if (info.si_signo == SIGCHLD) {
          int status = 0;
          result = waitpid(childpid, &status, WCONTINUED | WUNTRACED);

          if (result < 0) {
            perror("wait failed with:");
            return 1;
          } else if (WIFEXITED(status)) {
            return WEXITSTATUS(status);
          }
        } else if (info.si_signo == SIGUSR1) {
          return 0;
        }
      }
    }
  }
}
开发者ID:Gibstick,项目名称:seashell,代码行数:85,代码来源:user.c


示例20: nto_wait

static ptid_t
nto_wait (ptid_t ptid,
	  struct target_waitstatus *ourstatus, int target_options)
{
  sigset_t set;
  siginfo_t info;
  procfs_status status;
  const int trace_mask = (_DEBUG_FLAG_TRACE_EXEC | _DEBUG_FLAG_TRACE_RD
			  | _DEBUG_FLAG_TRACE_WR | _DEBUG_FLAG_TRACE_MODIFY);

  TRACE ("%s\n", __func__);

  ourstatus->kind = TARGET_WAITKIND_SPURIOUS;

  sigemptyset (&set);
  sigaddset (&set, SIGUSR1);

  devctl (nto_inferior.ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0);
  while (!(status.flags & _DEBUG_FLAG_ISTOP))
    {
      sigwaitinfo (&set, &info);
      devctl (nto_inferior.ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status),
	      0);
    }
  nto_find_new_threads (&nto_inferior);

  if (status.flags & _DEBUG_FLAG_SSTEP)
    {
      TRACE ("SSTEP\n");
      ourstatus->kind = TARGET_WAITKIND_STOPPED;
      ourstatus->value.sig = TARGET_SIGNAL_TRAP;
    }
  /* Was it a breakpoint?  */
  else if (status.flags & trace_mask)
    {
      TRACE ("STOPPED\n");
      ourstatus->kind = TARGET_WAITKIND_STOPPED;
      ourstatus->value.sig = TARGET_SIGNAL_TRAP;
    }
  else if (status.flags & _DEBUG_FLAG_ISTOP)
    {
      TRACE ("ISTOP\n");
      switch (status.why)
	{
	case _DEBUG_WHY_SIGNALLED:
	  TRACE ("  SIGNALLED\n");
	  ourstatus->kind = TARGET_WAITKIND_STOPPED;
	  ourstatus->value.sig =
	    target_signal_from_host (status.info.si_signo);
	  nto_inferior.exit_signo = ourstatus->value.sig;
	  break;
	case _DEBUG_WHY_FAULTED:
	  TRACE ("  FAULTED\n");
	  ourstatus->kind = TARGET_WAITKIND_STOPPED;
	  if (status.info.si_signo == SIGTRAP)
	    {
	      ourstatus->value.sig = 0;
	      nto_inferior.exit_signo = 0;
	    }
	  else
	    {
	      ourstatus->value.sig =
		target_signal_from_host (status.info.si_signo);
	      nto_inferior.exit_signo = ourstatus->value.sig;
	    }
	  break;

	case _DEBUG_WHY_TERMINATED:
	  {
	    int waitval = 0;

	    TRACE ("  TERMINATED\n");
	    waitpid (ptid_get_pid (ptid), &waitval, WNOHANG);
	    if (nto_inferior.exit_signo)
	      {
		/* Abnormal death.  */
		ourstatus->kind = TARGET_WAITKIND_SIGNALLED;
		ourstatus->value.sig = nto_inferior.exit_signo;
	      }
	    else
	      {
		/* Normal death.  */
		ourstatus->kind = TARGET_WAITKIND_EXITED;
		ourstatus->value.integer = WEXITSTATUS (waitval);
	      }
	    nto_inferior.exit_signo = 0;
	    break;
	  }

	case _DEBUG_WHY_REQUESTED:
	  TRACE ("REQUESTED\n");
	  /* We are assuming a requested stop is due to a SIGINT.  */
	  ourstatus->kind = TARGET_WAITKIND_STOPPED;
	  ourstatus->value.sig = TARGET_SIGNAL_INT;
	  nto_inferior.exit_signo = 0;
	  break;
	}
    }

  return ptid_build (status.pid, status.tid, 0);
//.........这里部分代码省略.........
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.toolchain,代码行数:101,代码来源:nto-low.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ sil_wrw_mem函数代码示例发布时间:2022-05-30
下一篇:
C++ sigwait函数代码示例发布时间: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