Ejemplo n.º 1
0
static void zerocross_interrupt(FAR const struct zc_lowerhalf_s *lower,
                                FAR void *arg)
{
  FAR struct zc_upperhalf_s *priv = (FAR struct zc_upperhalf_s *)arg;
  FAR struct zc_open_s *opriv;
  irqstate_t flags;

  /* This routine is called both task level and interrupt level, so
   * interrupts must be disabled.
   */

  flags = enter_critical_section();

  /* Update sample value */

  sample++;

  /* Visit each opened reference and notify a zero cross event */

  for (opriv = priv->zu_open; opriv; opriv = opriv->do_flink)
    {
      /* Signal the waiter */

#ifdef CONFIG_CAN_PASS_STRUCTS
      union sigval value;
      value.sival_int = (int)sample;
      (void)sigqueue(opriv->do_pid, opriv->do_notify.zc_signo, value);
#else
      (void)sigqueue(opriv->do_pid, opriv->do_notify.zc_signo,
                     (FAR void *)sample);
#endif
    }

  leave_critical_section(flags);
}
Ejemplo n.º 2
0
static void rtc_alarm_callback(FAR void *priv, int alarmid)
{
	FAR struct rtc_upperhalf_s *upper = (FAR struct rtc_upperhalf_s *)priv;
	FAR struct rtc_alarminfo_s *alarminfo;

	DEBUGASSERT(upper != NULL && alarmid >= 0 &&
					alarmid < CONFIG_RTC_NALARMS);
	alarminfo = &upper->alarminfo[alarmid];

	/*
	 * Do we think that the alaram is active?  It might be due to some
	 * race condition between a cancellation event and the alarm
	 * expiration.
	 */

	if (alarminfo->active) {
		/* Yes.. signal the alarm expriration */

#ifdef CONFIG_CAN_PASS_STRUCTS
		(void)sigqueue(alarminfo->pid, alarminfo->signo,
				alarminfo->sigvalue);
#else
		(void)sigqueue(alarminfo->pid, alarminfo->signo,
				alarminfo->sigvalue->sival_ptr);
#endif
	}

	/* The alarm is no longer active */

	alarminfo->active = false;
}
Ejemplo n.º 3
0
/*
 *  stress_sigq
 *	stress by heavy sigqueue message sending
 */
static int stress_sigq(const args_t *args)
{
	pid_t pid;

	if (stress_sighandler(args->name, SIGUSR1, stress_sigqhandler, NULL) < 0)
		return EXIT_FAILURE;

again:
	pid = fork();
	if (pid < 0) {
		if (g_keep_stressing_flag && (errno == EAGAIN))
			goto again;
		pr_fail_dbg("fork");
		return EXIT_FAILURE;
	} else if (pid == 0) {
		sigset_t mask;

		(void)setpgid(0, g_pgrp);
		stress_parent_died_alarm();

		(void)sigemptyset(&mask);
		(void)sigaddset(&mask, SIGUSR1);

		while (g_keep_stressing_flag) {
			siginfo_t info;
			if (sigwaitinfo(&mask, &info) < 0)
				break;
			if (info.si_value.sival_int)
				break;
		}
		pr_dbg("%s: child got termination notice\n", args->name);
		pr_dbg("%s: exited on pid [%d] (instance %" PRIu32 ")\n",
			args->name, (int)getpid(), args->instance);
		_exit(0);
	} else {
		/* Parent */
		union sigval s;
		int status;

		do {
			(void)memset(&s, 0, sizeof(s));
			s.sival_int = 0;
			(void)sigqueue(pid, SIGUSR1, s);
			inc_counter(args);
		} while (keep_stressing());

		pr_dbg("%s: parent sent termination notice\n", args->name);
		(void)memset(&s, 0, sizeof(s));
		s.sival_int = 1;
		(void)sigqueue(pid, SIGUSR1, s);
		(void)shim_usleep(250);
		/* And ensure child is really dead */
		(void)kill(pid, SIGKILL);
		(void)shim_waitpid(pid, &status, 0);
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 4
0
static void pthread_condtimedout(int argc, uint32_t pid, uint32_t signo)
{
#ifdef HAVE_GROUP_MEMBERS

  FAR struct tcb_s *tcb;
  siginfo_t info;

  /* The logic below if equivalent to sigqueue(), but uses sig_tcbdispatch()
   * instead of sig_dispatch().  This avoids the group signal deliver logic
   * and assures, instead, that the signal is delivered specifically to this
   * thread that is known to be waiting on the signal.
   */

  /* Get the waiting TCB.  sched_gettcb() might return NULL if the task has
   * exited for some reason.
   */

  tcb = sched_gettcb((pid_t)pid);
  if (tcb)
    {
      /* Create the siginfo structure */

      info.si_signo           = signo;
      info.si_code            = SI_QUEUE;
      info.si_errno           = ETIMEDOUT;
      info.si_value.sival_ptr = NULL;
#ifdef CONFIG_SCHED_HAVE_PARENT
      info.si_pid             = (pid_t)pid;
      info.si_status          = OK;
#endif

      /* Process the receipt of the signal.  The scheduler is not locked as
       * is normally the case when this function is called because we are in
       * a watchdog timer interrupt handler.
       */

      (void)sig_tcbdispatch(tcb, &info);
    }

#else /* HAVE_GROUP_MEMBERS */

  /* Things are a little easier if there are not group members.  We can just
   * use sigqueue().
   */

#ifdef CONFIG_CAN_PASS_STRUCTS
  union sigval value;

  /* Send the specified signal to the specified task. */

  value.sival_ptr = NULL;
  (void)sigqueue((int)pid, (int)signo, value);
#else
  (void)sigqueue((int)pid, (int)signo, NULL);
#endif

#endif /* HAVE_GROUP_MEMBERS */
}
Ejemplo n.º 5
0
void* control_thread(void *thid_arr)
{
	int thid = 0, i;
	union sigval data;
	sigset_t set, set1, set2;
	struct timeval tp;

	sigemptyset(&set);
	for(i = SIGRTMIN; i <= SIGRTMAX; i++)
		sigaddset(&set, SIGRTMIN);

	pthread_sigmask(SIG_BLOCK, &set, NULL);
	printf("Inside control thread\n");
	sleep(10);
	//cpu_bind(0);	

	while(1)
	{
		if(!Scheduler_Data.polling_thread_count)
			continue;

		pid_t process_id = Scheduler_Data.process_list[thid];
		unsigned long share_unit = Scheduler_Data.share_unit[thid];
		int signum = Scheduler_Data.signal_num[thid];

		sigset_t polling_thread_set;
		sigemptyset(&polling_thread_set);
		sigaddset(&polling_thread_set, signum);

		if(process_id != INVALID_PROCEESS)
		{
			gettimeofday(&tp, NULL); 
			fprintf(stderr, "control thread starting process id: %d, signum: %d, share_unit:%lu time:%d sec %d usec\n", process_id, signum, share_unit, tp.tv_sec, tp.tv_usec);
	 
			//data.sival_ptr = (void *)(&polling_thread_set);
			data.sival_int = signum;
			sigqueue(process_id, signum, data);
		}
		thid++;
		if(thid > Scheduler_Data.polling_thread_count-1)
			thid = 0;

		if(process_id != INVALID_PROCEESS)
		{
			sleep(share_unit/10);
			//data.sival_ptr = (void *)(&polling_thread_set);
			gettimeofday(&tp, NULL); 
			fprintf(stderr, "control thread sleeping process id: %d, signum: %d, share_unit:%lu time:%d sec %d usec\n", process_id, signum, share_unit, tp.tv_sec, tp.tv_usec);
	 
			data.sival_int = signum;
			sigqueue(process_id, signum, data);   
		}
	}
	return NULL;
}
Ejemplo n.º 6
0
static void lio_sighandler(int signo, siginfo_t *info, void *ucontext)
{
	FAR struct aiocb *aiocbp;
	FAR struct lio_sighand_s *sighand;
	int ret;

	DEBUGASSERT(signo == SIGPOLL && info);

	/* The info structure should contain a pointer to the AIO control block */

	aiocbp = (FAR struct aiocb *)info->si_value.sival_ptr;
	DEBUGASSERT(aiocbp && aiocbp->aio_result != -EINPROGRESS);

	/* Recover our private data from the AIO control block */

	sighand = (FAR struct lio_sighand_s *)aiocbp->aio_priv;
	DEBUGASSERT(sighand && sighand->list);
	aiocbp->aio_priv = NULL;

	/* Prevent any asynchronous I/O completions while the signal handler runs */

	sched_lock();

	/* Check if all of the pending I/O has completed */

	ret = lio_checkio(sighand->list, sighand->nent);
	if (ret != -EINPROGRESS) {
		/* All pending I/O has completed */
		/* Restore the signal handler */

		(void)sigaction(SIGPOLL, &sighand->oact, NULL);

		/* Restore the sigprocmask */

		(void)sigprocmask(SIG_SETMASK, &sighand->oprocmask, NULL);

		/* Signal the client */

		if (sighand->sig->sigev_notify == SIGEV_SIGNAL) {
#ifdef CONFIG_CAN_PASS_STRUCTS
			(void)sigqueue(sighand->pid, sighand->sig->sigev_signo, sighand->sig->sigev_value);
#else
			(void)sigqueue(sighand->pid, sighand->sig->sigev_signo, sighand->sig->sigev_value.sival_ptr);
#endif
		}

		/* And free the container */

		lib_free(sighand);
	}

	sched_unlock();
}
Ejemplo n.º 7
0
Archivo: sig.c Proyecto: jimodb/codes
main()
{
	pid_t pid;
	if(pid=fork()){
		/*父进程:找素数*/
		int a=2;
		int b=100000;
		int i;
		int status;
		union sigval val;
		sched_yield();/*放弃当前执行机会,排到队尾*/
		sleep(1);
		for(i=a;i<b;i++){
			if(IsPrimer(i)){
				/*是素数:发信号给子进程35*/
				val.sival_int=i;
				sigqueue(pid,35,val);/*发送信号给子进程*/
				usleep(1000);
			}
		}
		/*素数查找完毕,通知子进程结束:35*/
		val.sival_int=-1;/*-1:素数查找*/
		sigqueue(pid,35,val);
		wait(&status);/*等待子进程结束*/
		printf("结束!\n");
		exit(0);/*父进程退出*/
	}
	else{
		/*子进程:找孪生素数*/
		struct sigaction  act={0};
		act.sa_sigaction=handle;
		sigemptyset(&act.sa_mask);
		sigfillset(&act.sa_mask);
		act.sa_flags=SA_SIGINFO;		
		sigaction(35,&act,NULL);/*信号处理*/

		sigemptyset(&sigs);
		sigemptyset(&sigsus);
		sigaddset(&sigs,2);
		sigaddset(&sigs,35);
				
		/*屏蔽2信号*/
		sigprocmask(SIG_BLOCK,&sigs,NULL);
		while(1){			
			sigsuspend(&sigsus);/*等待父进程发送的信号*/
		}
		sigprocmask(SIG_UNBLOCK,&sigs,NULL);
	}
}
Ejemplo n.º 8
0
// returns 0 on success, -1 on permanent failure, 1 on temporary failure
int
LLHeartbeat::rawSend()
{
#if LL_WINDOWS
	return 0; // Pretend we succeeded.
#else
	if (mSuppressed)
		return 0; // Pretend we succeeded.

	int result;
#ifndef LL_DARWIN
	union sigval dummy;
	result = sigqueue(getppid(), LL_HEARTBEAT_SIGNAL, dummy);
#else
	result = kill(getppid(), LL_HEARTBEAT_SIGNAL);
#endif
	if (result == 0)
		return 0; // success

	int err = errno;
	if (err == EAGAIN)
		return 1; // failed to queue, try again

	return -1; // other failure.
#endif
}
Ejemplo n.º 9
0
int
main(int argc, char *argv[])
{
    int sig, numSigs, j, sigData;
    union sigval sv;

    if (argc < 4 || strcmp(argv[1], "--help") == 0)
        usageErr("%s pid sig-num data [num-sigs]\n", argv[0]);

    /* Display our PID and UID, so that they can be compared with the
       corresponding fields of the siginfo_t argument supplied to the
       handler in the receiving process */

    printf("%s: PID is %ld, UID is %ld\n", argv[0],
            (long) getpid(), (long) getuid());

    sig = getInt(argv[2], 0, "sig-num");
    sigData = getInt(argv[3], GN_ANY_BASE, "data");
    numSigs = (argc > 4) ? getInt(argv[4], GN_GT_0, "num-sigs") : 1;

    for (j = 0; j < numSigs; j++) {
        sv.sival_int = sigData + j;
        if (sigqueue(getLong(argv[1], 0, "pid"), sig, sv) == -1)
            errExit("sigqueue %d", j);
    }

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 10
0
int
main()
{
	struct sigaction sa;
	union sigval val;
	int ret;
	int i;
	sigset_t set;

	sa.sa_flags = SA_SIGINFO;
	sigemptyset(&sa.sa_mask);
	sa.sa_sigaction = handler;
	sigaction(SIGRTMIN, &sa, NULL);
	sigemptyset(&set);
	sigaddset(&set, SIGRTMIN);
	sigprocmask(SIG_BLOCK, &set, NULL);
	i = 0;
	for (;;) {
		val.sival_int = i;
		ret = sigqueue(getpid(), SIGRTMIN, val);
		if (ret == -1) {
			if (errno != EAGAIN) {
				errx(1, "errno != EAGAIN");
			}
			break;
		}
		i++;
	}
	sigprocmask(SIG_UNBLOCK, &set, NULL);
	if (received != i)
		errx(1, "error, signal lost");
	printf("OK\n");
}
Ejemplo n.º 11
0
int main(){
	//sigqueue发送信号,sigaction处理信号	
	struct sigaction action;
	action.sa_sigaction = fa;
	action.sa_flags = SA_SIGINFO;

	sigaction(40,&action,NULL);

	pid_t pid = fork();
	if(-1 == pid){
		perror("fork");
		exit(0);
	}
	if(pid == 0){
		printf("child %d starts to run\n",getpid());
		union sigval value;
		int i = 0;
		for(i = 0;i<10;i++){
			value.sival_int=i;
			sigqueue(getppid(),40,value);
			//直接传入结构体的变量名即可
		}
		exit(0);
	}
	while(1);
	return 0;
}
Ejemplo n.º 12
0
Archivo: sig3.c Proyecto: yinuo/AA
int main(int argc,char **argv){
	
	//char str[100] = {0};
	int sig2;
	pid_t sig1;
	union sigval val;
		sig2 = atoi(argv[2]);
	sig1 =(pid_t) atoi(argv[1]);

	while(1){
	//sprintf(str,"kill -s %s %s","sig1","sig2");
	sigqueue(sig1,sig2,val);
	//system(str);
	sleep(3);
	}



	//int sigqueue(pid_t pid, int sig, const union sigval val)





	return 0;
}
Ejemplo n.º 13
0
int main(void)
{

	union sigval value;
	value.sival_int = 0;	/* 0 is just an arbitrary value */

	/* We assume process Number 1 is created by root */
	/* and can only be accessed by root */
	/* This test should be run under standard user permissions */
	if (getuid() == 0) {
		if (set_nonroot() != 0) {
			printf("Cannot run this test as non-root user\n");
			return PTS_UNTESTED;
		}
	}

	if (sigqueue(1, 0, value) != -1) {
		printf
		    ("Test FAILED: sigqueue() succeeded even though this program's user id did not match the recieving process's user id\n");
		return PTS_FAIL;
	}

	if (EPERM != errno) {
		printf("Test FAILED: EPERM error not received\n");
		return PTS_FAIL;
	}

	return PTS_PASS;
}
Ejemplo n.º 14
0
int main()
{
	int pid;
	union sigval value;
	struct sigaction act;

	act.sa_flags = SA_SIGINFO;
	act.sa_sigaction = myhandler;
	sigemptyset(&act.sa_mask);
	sigaction(SIGTOTEST, &act, 0);

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

	if ((return_val = sigqueue(pid, SIGTOTEST, value)) != 0) {
		printf("Test UNRESOLVED: call to sigqueue did not return success\n");
		return PTS_UNRESOLVED;
	}

	if (handler_called != 1) {
		printf("Test FAILED: signal was not delivered to process\n");
		return PTS_FAIL;
	}
	return PTS_PASS;
}
Ejemplo n.º 15
0
pwr_tStatus
qos_SignalQueOld (
  pwr_tStatus	*status,
  qdb_sQue	*qp
)
{
  union sigval	value;
  int		ok;
  pwr_dStatus	(sts, status, QCOM__SUCCESS);

  qdb_AssumeLocked;

  if (qp->lock.waiting) {
//    value.sival_int = BUILDPID(getpid(), pthread_self());
    value.sival_int = getpid();
    qp->lock.waiting = FALSE;

    ok = sigqueue(qp->lock.pid, qdb_cSigMsg, value);

    if (ok == -1) {
      *sts = errno_Status(errno);
    }
  }

  return TRUE;
}
Ejemplo n.º 16
0
int main (int argc, char *argv[])
{
    struct sigaction act;
    struct my_s s;
    int j, sig = SIGALRM;
    union sigval sv;

    if (argc > 1)
        sig = atoi (argv[1]);

    memset (&act, 0, sizeof (act));
    act.sa_sigaction = sig_act;
    act.sa_flags = SA_SIGINFO;
    if (sigaction (sig, &act, NULL) < 0)  
        DEATH ("sigaction");

    printf ("pid=%d Successfully installed signal handler for signal=%d\n",
            getpid (), sig);

    for (j = 0; j < 3; j++) {
        printf ("This is a pointless message\n");
        s.x = j * 100;
        strcpy (s.s, "hello buddy");
        sv.sival_ptr = &s;
        printf ("sigqueue returns %d\n",sigqueue (getpid (), sig, sv));
        sleep (1);
    }
    exit (0);
}
Ejemplo n.º 17
0
int main()
{
	int result = 0;
	sigset_t waitset;
	siginfo_t info;
	pid_t cpid;
	union sigval val;

	/* let's disable async handlers and enable signal queue */
	sigemptyset(&waitset);
	sigaddset(&waitset, SIGRTMIN);
	sigprocmask(SIG_BLOCK, &waitset, NULL);
	
	cpid = fork();
	if (cpid == 0) {
		printf("child pid %d\n", getpid());
		timestamp("before sigwaitinfo()");
		/* wait for signal to arrive */
		result = sigwaitinfo(&waitset, &info);
		if (result < 0)
			printf("sigwaitinfo failed : \n");
		/* got signal */
		printf("sigwaitinfo() returned for signal %d\n", info.si_signo);
		timestamp("after sigwaitinfo()");
		exit(0);
	} else {
		val.sival_int = 0;
		sigqueue(cpid, SIGRTMIN, val);
		waitpid(cpid, NULL, 0);
//              printf("end of program \n");
		while (1) ;
	}
	return 0;
}
Ejemplo n.º 18
0
void SendMessageToHALos ()
{
    ofstream ioResponseFile;
    union sigval dummyValue;

    ioResponseFile.open ("HALdisplayDriverToHALos");
    if (!ioResponseFile)
    {
        cout << "HALdisplayDriver: unable to initialize io response buffer" << endl;
        return;
    }

    ioResponseFile << "INTERRUPT" << endl;
    ioResponseFile << "DISPLAY_DRIVER" << endl;
    ioResponseFile << pid << endl;
    ioResponseFile << result << endl;

    ioResponseFile.close ();

    if (sigqueue (HALosPid, SIGRTMIN, dummyValue) == -1)
    {
        cout << "HALdisplayDriver: io response signal not sent to HALos" << endl;
        exit (1);
    }

    return;
}
Ejemplo n.º 19
0
int main(int argc, char** argv)
{
	int sig;
	int numSigs;
	int j;
	int sigData;
	
	union sigval sv;
	if (5 != argc)
	{
		log_info("usage:%s pid sig-num data [num-sigs]\n", argv[0]);
		return -1;
	}
	
	log_info("%s: pid is %ld, uid is %ld\n", argv[0], getpid(), getuid());
	sig = atoi(argv[2]);
	sigData = atoi(argv[3]);
	numSigs = atoi(argv[4]);
	pid_t pid = atoi(argv[1]);
	for (j=0; j<numSigs; ++j)
	{
		sv.sival_int = sigData + 1;
		if (sigqueue(pid, sig, sv) < 0)
		{
			log_info("sigqueue fail\n");
			return -1;
		}	
	}	
	return 0;
}
Ejemplo n.º 20
0
void send_interrupt(int interrupt_type, interrupt_handler_t handler, void* arg){

    interrupt_t interrupt;
    pthread_mutex_lock(&signal_mutex);
    for (;;){
        signal_handled = 0;

        interrupt.arg = arg;
        if(interrupt_type==NETWORK_INTERRUPT_TYPE)
            interrupt.handler = mini_network_handler;
        else if(interrupt_type==READ_INTERRUPT_TYPE)
            interrupt.handler = mini_read_handler;
        else
            abort();

        /* Repeat if signal is not delivered. */
        while(sigqueue(getpid(),SIGRTMAX-2, (union sigval)(void*)&interrupt)==-1);

        /* semaphore_P to wait for main thread signal */
        sem_wait(&interrupt_received_sema);

        /* Check if interrupt was handled */
        if(signal_handled)
            break;

        sleep(0);
        /* resend if necessary */
    }
    pthread_mutex_unlock(&signal_mutex);
}
Ejemplo n.º 21
0
Archivo: 2-2.c Proyecto: 1587/ltp
int main(void)
{
	int failure = 0;
	union sigval value;
	value.sival_int = 0;	/* 0 is just an arbitrary value */

	/*
	 * ESRCH
	 */
	if (-1 == sigqueue(999999, 0, value)) {
		if (ESRCH == errno) {
			printf("ESRCH error received\n");
		} else {
			printf
			    ("sigqueue() failed on ESRCH but errno not set correctly\n");
			failure = 1;
		}
	} else {
		printf("sigqueue() did not return -1 on ESRCH\n");
		failure = 1;
	}

	if (failure) {
		printf("At least one test FAILED -- see output for status\n");
		return PTS_FAIL;
	} else {
		printf("All tests PASSED\n");
		return PTS_PASS;
	}
}
Ejemplo n.º 22
0
int main (int argc , char * argv[]) {

	if ( 2 != argc ) {
		fprintf (stderr , "Bad argument!\nUsage ./post_signal pid\n") ;
		exit (1) ;
	}

	pid_t 	pid = atoi ( argv[argc-1] ) ;
	printf ("Sending signal to %d , by using sigqueue\n" , pid) ;
	sigval_t 	sigval ;
	sigval.sival_int = 8888 ;
	int errcode = 0 ;

	if ( 0 > ( errcode = sigqueue ( pid , SIGUSR1 , sigval ) )) {
		if ( ESRCH == errcode ) {
			fprintf (stderr , "No such process!\n") ;
			exit (1) ;
		} else {
			fprintf (stderr , "sigqueue error "),perror ("")  ;
			exit (1) ;
		}
	}

	printf ("Finished!\n") ;

	return 0 ;
}
Ejemplo n.º 23
0
Archivo: signals.c Proyecto: 5py/ltrace
int 
main ()
{
  struct sigaction act;	
  union sigval mysigval;
  int i;
  int sig;
  pid_t pid;
  
  mysigval.sival_int=0;
  sig = SIGUSR1;
  pid=getpid();
  
  sigemptyset(&act.sa_mask);
  act.sa_sigaction=handler;
  act.sa_flags=SA_SIGINFO;
  
  if(sigaction(sig,&act,NULL) < 0)
    {
      printf("install sigal error\n");
    }
  
  for(i=0; i< LOOP; i++)
    {
      usleep(100);
      sigqueue(pid,sig,mysigval);
    }
  return 0;
}
Ejemplo n.º 24
0
int
main(int argc, char *argv[]) {
  if (argc < 4) {
    helpAndLeave(argv[0], EXIT_FAILURE);
  }

  long pid, signal, data, num_sigs;
  int i;

  union sigval sv;

  num_sigs = 1;

  pid    = extract_long(argv[1], "PID");
  signal = extract_long(argv[2], "signal");
  data   = extract_long(argv[3], "data argument");

  if (argc > 4) {
    num_sigs = extract_long(argv[4], "num-signals argument");
  }

  /* Display process PID and UID for help debugging of the receiver */
  printf("%s: PID: %ld, UID %ld\n", argv[0], (long) getpid(), (long) getuid());

  for (i = 0; i < num_sigs; ++i) {
    sv.sival_int = data + i;
    if (sigqueue(pid, signal, sv) == -1) {
      pexit("sigqueue");
    }
  }

  exit(EXIT_SUCCESS);
}
Ejemplo n.º 25
0
int	zbx_sigusr_send(int flags)
{
	int	ret = FAIL;
	char	error[256];
#ifdef HAVE_SIGQUEUE
	pid_t	pid;

	if (SUCCEED == read_pid_file(CONFIG_PID_FILE, &pid, error, sizeof(error)))
	{
		union sigval	s;

		s.ZBX_SIVAL_INT = flags;

		if (-1 != sigqueue(pid, SIGUSR1, s))
		{
			zbx_error("command sent successfully");
			ret = SUCCEED;
		}
		else
		{
			zbx_snprintf(error, sizeof(error), "cannot send command to PID [%d]: %s",
					(int)pid, zbx_strerror(errno));
		}
	}
#else
	zbx_snprintf(error, sizeof(error), "operation is not supported on the given operating system");
#endif
	if (SUCCEED != ret)
		zbx_error("%s", error);

	return ret;
}
Ejemplo n.º 26
0
int main(void)
{
	struct sigaction act;
	pid_t pid;
	int *p;

	memset(&act, 0, sizeof(act));
	act.sa_sigaction = my_handler;
	act.sa_flags = SA_SIGINFO;
	sigaction(SIGINT, &act, NULL);

	p = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE,
			MAP_SHARED | MAP_ANON, -1, 0);

	pid = fork();
	if (pid == 0)
	//	pause();
		sigsuspend(&old);
	else {
		sigval_t value;
		value.sival_ptr = (void *)p;
		*p = 100;
		//sleep(1);
		sigqueue(pid, SIGINT, value);//

		wait(NULL);
		munmap(p, sizeof(int));
	}

	return 0;
}
Ejemplo n.º 27
0
static void
_aio_notify(struct sigevent *sigevp)
{
#if 0 /* not yet */
	int sig;
	union sigval sv;
	pid_t pid;
#endif
	pthread_t thr;

	switch (sigevp->sigev_notify) {
	case SIGEV_NONE:
		return;

	case SIGEV_THREAD:
		pthread_create(&thr, 
			       sigevp->sigev_notify_attributes,
			       _aio_thr_start,
			       sigevp);
		break;

	case SIGEV_SIGNAL:
#if 0 /* not yet */
		pid = getpid();
		sig = sigevp->sigev_signo;
		sv = sigevp->sigev_value;
		sigqueue(pid, sig, sv);
#endif
		break;

	case SIGEV_KEVENT:
		/* not yet */
		break;
	}
}
Ejemplo n.º 28
0
static void	zbx_signal_process_by_pid(int pid, int flags)
{
	union sigval	s;
	int		i, found = 0;

	s.ZBX_SIVAL_INT = flags;

	for (i = 0; i < threads_num; i++)
	{
		if (0 != pid && threads[i] != ZBX_RTC_GET_DATA(flags))
			continue;

		found = 1;

		if (-1 != sigqueue(threads[i], SIGUSR1, s))
		{
			zabbix_log(LOG_LEVEL_DEBUG, "the signal was redirected to process pid:%d",
					threads[i]);
		}
		else
			zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: %s", zbx_strerror(errno));
	}

	if (0 != ZBX_RTC_GET_DATA(flags) && 0 == found)
	{
		zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: process pid:%d is not a Zabbix child"
				" process", ZBX_RTC_GET_DATA(flags));
	}
}
Ejemplo n.º 29
0
int
main()
{
	struct sigaction sa;
	sigset_t set;
	union sigval val;

	/* test job control with empty signal queue */
	job_control_test();

	/* now full fill signal queue in kernel */
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_SIGINFO;
	sa.sa_sigaction = rtsig_handler;
	sigaction(SIGRTMIN, &sa, NULL);
	sigemptyset(&set);
	sigaddset(&set, SIGRTMIN);
	sigprocmask(SIG_BLOCK, &set, NULL);
	val.sival_int = 1;
	while (sigqueue(getpid(), SIGRTMIN, val))
		;

	/* signal queue is fully filled, test the job control again. */
	job_control_test();
	return (0);
}
Ejemplo n.º 30
0
int main() {
    struct sigaction act;
    union sigval val;
    pid_t pid = getpid();

    val.sival_int = 1234;

    act.sa_sigaction = handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = SA_SIGINFO;
    sigaction(SIGCHLD, &act, NULL);

    kill(pid, SIGCHLD);
    sigqueue(pid, SIGCHLD, val);
    raise(SIGCHLD);

    /* To get a SIGCHLD from the kernel we create a child and
       have it exit immediately. The signal handler exits after
       receiving the signal from the kernel, so we just sleep for
       a while and let the program terminate that way. */

    if (!fork()) exit(0);
    sleep(60);

    return 0;
}