Beispiel #1
0
pid_t
maildrop_setup(uint32_t session_id, int pair[2], struct passwd *pw)
{
	struct imsgev		iev_session;
	struct event		ev_sigint, ev_sigterm;
	struct m_backend	*mb;
	pid_t			pid;
	extern int		mtype;

	if ((pid = fork()) != 0)
		return (pid);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("cannot drop privileges");

	close(pair[0]);
	setproctitle("maildrop");
	if ((mb = m_backend_lookup(mtype)) == NULL)
		fatalx("maildrop: invalid backend");

	event_init();
	signal_set(&ev_sigint, SIGINT, sig_handler, NULL);
	signal_set(&ev_sigterm, SIGTERM, sig_handler, NULL);
	signal_add(&ev_sigint, NULL);
	signal_add(&ev_sigterm, NULL);
	imsgev_init(&iev_session, pair[1], mb, session_imsgev, needfd);
	if (event_dispatch() < 0)
		fatal("event_dispatch");

	logit(LOG_INFO, "%zu: maildrop process exiting", session_id);
	_exit(0);
}
static int child( euca_opts *args, java_home_t *data, uid_t uid, gid_t gid ) {
	int ret = 0;
    jboolean r=0;
	__write_pid( GETARG(args,pidfile) );
	setpgrp( );
	__die(java_init( args, data ) != 1, "Failed to initialize Eucalyptus.");
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.init))==0,"Failed to init Eucalyptus.");
	__abort(4, set_keys_ownership( GETARG( args, home ), uid, gid ) != 0,"Setting ownership of keyfile failed." );
	__abort(4, linuxset_user_group( GETARG( args, user ), uid, gid ) != 0,"Setting the user failed." );
	__abort(4, (set_caps(0)!=0), "set_caps (0) failed");
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.load))==0,"Failed to load Eucalyptus.");
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.start))==0,"Failed to start Eucalyptus.");
	handle._hup = signal_set( SIGHUP, handler );
	handle._term = signal_set( SIGTERM, handler );
	handle._int = signal_set( SIGINT, handler );
	child_pid = getpid( );
	__debug( "Waiting for a signal to be delivered" );
	while( !stopping ) sleep( 60 );
	__debug( "Shutdown or reload requested: exiting" );
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.stop))==0,"Failed to stop Eucalyptus.");
	if( doreload == 1 ) ret = EUCA_RET_RELOAD;
	else ret = 0;
    __die((r=(*env)->CallBooleanMethod(env,bootstrap.instance,bootstrap.destroy))==0,"Failed to destroy Eucalyptus.");
	__die((JVM_destroy( ret ) != 1), "Failed trying to destroy JVM... bailing out seems like the right thing to do" );
	return ret;
}
Beispiel #3
0
static void signal_setup(void)
{
	static struct event ev_sighup;
	static struct event ev_sigterm;
	static struct event ev_sigint;

	sigset_t set;
	int err;

	/* block SIGPIPE */
	sigemptyset(&set);
	sigaddset(&set, SIGPIPE);
	err = sigprocmask(SIG_BLOCK, &set, NULL);
	if (err < 0)
		fatal_perror("sigprocmask");

	/* catch signals */
	signal_set(&ev_sighup, SIGHUP, handle_sighup, NULL);
	err = signal_add(&ev_sighup, NULL);
	if (err < 0)
		fatal_perror("signal_add");

	signal_set(&ev_sigterm, SIGTERM, handle_sigterm, NULL);
	err = signal_add(&ev_sigterm, NULL);
	if (err < 0)
		fatal_perror("signal_add");

	signal_set(&ev_sigint, SIGINT, handle_sigint, NULL);
	err = signal_add(&ev_sigint, NULL);
	if (err < 0)
		fatal_perror("signal_add");
}
Beispiel #4
0
LUALIB_API int
luaopen_sys (lua_State *L)
{
    luaL_register(L, LUA_SYSLIBNAME, sys_lib);
    createmeta(L);

    luaopen_sys_mem(L);
    luaopen_sys_thread(L);

#ifdef _WIN32
#ifdef _WIN32_WCE
    is_WinNT = 1;
#else
    /* Is Win32 NT platform? */
    {
	OSVERSIONINFO osvi;

	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	is_WinNT = (GetVersionEx(&osvi)
	 && osvi.dwPlatformId == VER_PLATFORM_WIN32_NT);
    }
#endif

    luaopen_sys_win32(L);
#else
    /* Ignore sigpipe or it will crash us */
    signal_set(SIGPIPE, SIG_IGN);
    /* To interrupt blocking syscalls */
    signal_set(SYS_SIGINTR, NULL);
#endif
    return 1;
}
Beispiel #5
0
pid_t
ca(void)
{
	pid_t		 pid;
	struct passwd	*pw;
	struct event	 ev_sigint;
	struct event	 ev_sigterm;

	switch (pid = fork()) {
	case -1:
		fatal("ca: cannot fork");
	case 0:
		post_fork(PROC_CA);
		break;
	default:
		return (pid);
	}

	purge_config(PURGE_LISTENERS|PURGE_TABLES|PURGE_RULES);

	if ((pw = getpwnam(SMTPD_USER)) == NULL)
		fatalx("unknown user " SMTPD_USER);

	if (chroot(PATH_CHROOT) == -1)
		fatal("ca: chroot");
	if (chdir("/") == -1)
		fatal("ca: chdir(\"/\")");

	config_process(PROC_CA);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("ca: cannot drop privileges");

	imsg_callback = ca_imsg;
	event_init();

	signal_set(&ev_sigint, SIGINT, ca_sig_handler, NULL);
	signal_set(&ev_sigterm, SIGTERM, ca_sig_handler, NULL);
	signal_add(&ev_sigint, NULL);
	signal_add(&ev_sigterm, NULL);
	signal(SIGPIPE, SIG_IGN);
	signal(SIGHUP, SIG_IGN);

	config_peer(PROC_CONTROL);
	config_peer(PROC_PARENT);
	config_peer(PROC_PONY);
	config_done();

	/* Ignore them until we get our config */
	mproc_disable(p_pony);

	if (event_dispatch() < 0)
		fatal("event_dispatch");
	ca_shutdown();

	return (0);
}
Beispiel #6
0
/* CHECK Child signal handling */
static void
check_signal_init(void)
{
	signal_handler_init();
	signal_set(SIGHUP, sighup_check, NULL);
	signal_set(SIGINT, sigend_check, NULL);
	signal_set(SIGTERM, sigend_check, NULL);
	signal_ignore(SIGPIPE);
}
Beispiel #7
0
/* Initialize signal handler */
void
signal_init(void)
{
	signal_handler_init();
	signal_set(SIGHUP, sighup, NULL);
	signal_set(SIGINT, sigend, NULL);
	signal_set(SIGTERM, sigend, NULL);
	signal_ignore(SIGPIPE);
}
Beispiel #8
0
pid_t
ypldap_dns(int pipe_ntp[2], struct passwd *pw)
{
	pid_t			 pid;
	struct event	 ev_sigint;
	struct event	 ev_sigterm;
	struct event	 ev_sighup;
	struct env	 env;

	switch (pid = fork()) {
	case -1:
		fatal("cannot fork");
		break;
	case 0:
		break;
	default:
		return (pid);
	}

	setproctitle("dns engine");
	close(pipe_ntp[0]);

	if (setgroups(1, &pw->pw_gid) ||
	    setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
	    setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
		fatal("can't drop privileges");
	endservent();

	if (pledge("stdio dns", NULL) == -1)
		fatal("pledge");

	event_init();
	signal_set(&ev_sigint, SIGINT, dns_sig_handler, NULL);
	signal_set(&ev_sigterm, SIGTERM, dns_sig_handler, NULL);
	signal_set(&ev_sighup, SIGHUP, dns_sig_handler, NULL);
	signal_add(&ev_sigint, NULL);
	signal_add(&ev_sigterm, NULL);
	signal_add(&ev_sighup, NULL);

	if ((env.sc_iev = calloc(1, sizeof(*env.sc_iev))) == NULL)
		fatal(NULL);

	env.sc_iev->events = EV_READ;
	env.sc_iev->data = &env;
	imsg_init(&env.sc_iev->ibuf, pipe_ntp[1]);
	env.sc_iev->handler = dns_dispatch_imsg;
	event_set(&env.sc_iev->ev, env.sc_iev->ibuf.fd, env.sc_iev->events,
	    env.sc_iev->handler, &env);
	event_add(&env.sc_iev->ev, NULL);

	event_dispatch();
	dns_shutdown();

	return (0);
}
Beispiel #9
0
/* Reload thread */
int
reload_vrrp_thread(thread * thread_obj)
{
	/* set the reloading flag */
	SET_RELOAD;
    SYS_VRRP_LOG_INFO("VRRP configure have been reload.");

	/* Close sockpool */
	free_vrrp_sockpool(vrrp_data);

	/* Signal handling */
	signal_reset();
	signal_set(SIGHUP, sighup_vrrp, NULL);
	signal_set(SIGINT, sigend_vrrp, NULL);
	signal_set(SIGTERM, sigend_vrrp, NULL);
	signal_ignore(SIGPIPE);

	/* Destroy master thread */
	thread_destroy_master(master);
	master = thread_make_master();
	free_global_data(data);
	/* add by zhouben */
	backup_if_queue();
	kernel_netlink_close();
	free_vrrp_buffer();
	gratuitous_arp_close();
	ndisc_close();
	vrrp_trackip_close();

	/* Save previous conf data */
	old_vrrp_data = vrrp_data;
	vrrp_data = NULL;

#ifdef _WITH_LVS_
	/* Clean ipvs related */
	//ipvs_stop();
#endif

	/* Reload the conf */
	mem_allocated = 0;
	vrrp_signal_init();
	signal_set(SIGCHLD, thread_child_handler, master);
	start_vrrp();

	/* free backup data */
	free_old_interface_queue_only();
	free_vrrp_data(old_vrrp_data);
	UNSET_RELOAD;

       /*end of reload, store the state to file*/
       reloading = 0;
       vrrp_state_store();
	return 0;
}
Beispiel #10
0
/* VRRP Child signal handling */
void
vrrp_signal_init(void)
{
	signal_handler_init();
	signal_set(SIGHUP, sighup_vrrp, NULL);
	signal_set(SIGINT, sigend_vrrp, NULL);
	signal_set(SIGTERM, sigend_vrrp, NULL);
	signal_set(SIGUSR1, sigusr1_vrrp, NULL);
	signal_set(SIGUSR2, sigusr2_vrrp, NULL);
	signal_ignore(SIGPIPE);
}
Beispiel #11
0
/* Initialize signal handler */
void
signal_init(void)
{
	signal_handler_init();
	signal_set(SIGHUP, propogate_signal, NULL);
	signal_set(SIGUSR1, propogate_signal, NULL);
	signal_set(SIGUSR2, propogate_signal, NULL);
	signal_set(SIGINT, sigend, NULL);
	signal_set(SIGTERM, sigend, NULL);
	signal_ignore(SIGPIPE);
}
Beispiel #12
0
__dead void
client_main(void)
{
	struct event		ev_sigcont, ev_sigterm, ev_sigwinch;
	struct sigaction	sigact;

	logfile("client");

	/* Note: event_init() has already been called. */

	/* Set up signals. */
	memset(&sigact, 0, sizeof sigact);
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = SA_RESTART;
	sigact.sa_handler = SIG_IGN;
	if (sigaction(SIGINT, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGUSR1, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
		fatal("sigaction failed");

	signal_set(&ev_sigcont, SIGCONT, client_signal, NULL);
	signal_add(&ev_sigcont, NULL);
	signal_set(&ev_sigterm, SIGTERM, client_signal, NULL);
	signal_add(&ev_sigterm, NULL);
	signal_set(&ev_sigwinch, SIGWINCH, client_signal, NULL);
	signal_add(&ev_sigwinch, NULL);

	/*
	 * imsg_read in the first client poll loop (before the terminal has
	 * been initialised) may have read messages into the buffer after the
	 * MSG_READY switched to here. Process anything outstanding now to
	 * avoid hanging waiting for messages that have already arrived.
	 */
	if (client_dispatch() != 0)
		goto out;

	/* Set the event and dispatch. */
	client_update_event();
	event_dispatch();

out:
	/* Print the exit message, if any, and exit. */
	if (client_exitmsg != NULL && !login_shell)
		printf("[%s]\n", client_exitmsg);
	exit(client_exitval);
}
Beispiel #13
0
EVQ_API void
signal_init (void)
{
  if (g_SignalInit) return;
  g_SignalInit = 1;

  /* Initialize critical section */
  pthread_mutex_init(&g_Signal.cs, NULL);
  /* Ignore sigpipe or it will crash us */
  signal_set(SIGPIPE, SIG_IGN);
  /* To interrupt blocking syscalls */
  signal_set(SYS_SIGINTR, signal_handler);
}
Beispiel #14
0
/* Initialize signal handlers. */
void
signal_init(void) {
  signal_set(SIGINT,   sigint);
  signal_set(SIGTSTP,  sigtstp);
  signal_set(SIGALRM,  sigalarm);
  signal_set(SIGPIPE,  SIG_IGN);
  signal_set(SIGQUIT,  SIG_IGN);
  signal_set(SIGTTIN,  SIG_IGN);
  signal_set(SIGTTOU,  SIG_IGN);
  signal_set(SIGTERM,  sigterm);
  signal_set(SIGHUP,   SIG_IGN);
  signal_set(SIGWINCH, sigwinch);
}
Beispiel #15
0
static int
signal_del (struct event_queue *evq, struct event *ev)
{
  const int signo = (ev->flags & EVENT_PID) ? EVQ_SIGCHLD
   : (int) ev->fd;
  struct event **sig_evp = signal_gethead(signo);
  int res = 0;

  pthread_mutex_lock(&g_Signal.cs);
  if (*sig_evp == ev) {
    if (!(*sig_evp = ev->next_object)) {
#ifndef USE_KQUEUE
      (void) evq;
#else
      res |= signal_kqueue(evq, signo, EV_DELETE);
#endif
      res |= signal_set(signo, SIG_DFL);
    }
  } else {
    struct event *sig_ev = *sig_evp;

    while (sig_ev->next_object != ev)
      sig_ev = sig_ev->next_object;
    sig_ev->next_object = ev->next_object;
  }
  pthread_mutex_unlock(&g_Signal.cs);
  return res;
}
Beispiel #16
0
static int
signal_add (struct event_queue *evq, struct event *ev)
{
  const int signo = (ev->flags & EVENT_PID) ? EVQ_SIGCHLD : (int) ev->fd;
  struct event **sig_evp = signal_gethead(signo);

  if (!sig_evp) return -1;

  pthread_mutex_lock(&g_Signal.cs);
  if (*sig_evp)
    ev->next_object = *sig_evp;
  else {
#ifdef USE_KQUEUE
    if (signal_kqueue(evq, signo, EV_ADD))
      goto err;
#endif
    if (signal_set(signo, signal_handler))
      goto err;
    ev->next_object = NULL;
  }
  *sig_evp = ev;
  pthread_mutex_unlock(&g_Signal.cs);

  evq->nevents++;
  return 0;
 err:
  pthread_mutex_unlock(&g_Signal.cs);
  return -1;
}
Beispiel #17
0
void
rspamd_worker_set_signal_handler (int signo, struct rspamd_worker *worker,
		struct event_base *base,
		void (*handler)(struct rspamd_worker_signal_handler *sigh, void *),
		void *handler_data)
{
	struct rspamd_worker_signal_handler *sigh;
	struct rspamd_worker_signal_cb *cb;

	sigh = g_hash_table_lookup (worker->signal_events, GINT_TO_POINTER (signo));

	if (sigh == NULL) {
		sigh = g_malloc0 (sizeof (*sigh));
		sigh->signo = signo;
		sigh->worker = worker;
		sigh->base = base;
		sigh->enabled = TRUE;

		signal_set (&sigh->ev, signo, rspamd_worker_signal_handler, sigh);
		event_base_set (base, &sigh->ev);
		signal_add (&sigh->ev, NULL);

		g_hash_table_insert (worker->signal_events,
				GINT_TO_POINTER (signo),
				sigh);
	}

	cb = g_malloc0 (sizeof (*cb));
	cb->handler = handler;
	cb->handler_data = handler_data;
	DL_APPEND (sigh->cb, cb);
}
Beispiel #18
0
/* SIGINT handler.  This function takes care of ^C input. */
static void
sigint(int signo) {
  /* Debug */
  if (0) {
    printf("signo %d\n", signo);
  }

  /* Reinstall signal. */
  signal_set(SIGINT, sigint);

  /* Wait child process. */
  if (process_list) {
    process_wait_for();
  } else {
    printf("\n");
  }

  /* Make it sure cclient is reset. */
  cclient_stop(shell->cclient);

  /* Long jump flag check. */
  if (! jmpflag) {
    return;
  }

  jmpflag = 0;

  /* Back to main command loop. */
  siglongjmp(jmpbuf, 1);
}
Beispiel #19
0
void AsyncSignalHandler::registerSignalHandler(int signum) {
  pair<SignalEventMap::iterator, bool> ret =
    signalEvents_.insert(make_pair(signum, event()));
  if (!ret.second) {
    // This signal has already been registered
    throw std::runtime_error(folly::to<string>(
                               "handler already registered for signal ",
                               signum));
  }

  struct event* ev = &(ret.first->second);
  try {
    signal_set(ev, signum, libeventCallback, this);
    if (event_base_set(eventBase_->getLibeventBase(), ev) != 0 ) {
      throw std::runtime_error(folly::to<string>(
                                 "error initializing event handler for signal ",
                                 signum));
    }

    if (event_add(ev, nullptr) != 0) {
      throw std::runtime_error(folly::to<string>(
                                 "error adding event handler for signal ",
                                 signum));
    }
  } catch (...) {
    signalEvents_.erase(ret.first);
    throw;
  }
}
Beispiel #20
0
void
signal_init (struct thread_master *m, int sigc,
             struct quagga_signal_t signals[])
{

    int i = 0;
    struct quagga_signal_t *sig;

    /* First establish some default handlers that can be overridden by
       the application. */
    trap_default_signals();

    while (i < sigc)
    {
        sig = &signals[i];
        if ( signal_set (sig->signal) < 0 ) {
            zlog_notice("signal_init exit(-1)\n");
            EXIT(-1);

        }
        i++;
    }

    sigmaster.sigc = sigc;
    sigmaster.signals = signals;

#ifdef SIGEVENT_SCHEDULE_THREAD
    sigmaster.t =
        thread_add_timer (m, quagga_signal_timer, &sigmaster,
                          QUAGGA_SIGNAL_TIMER_INTERVAL);
#endif /* SIGEVENT_SCHEDULE_THREAD */
}
Beispiel #21
0
/* SIGTSTP handler.  This function takes care of ^Z input. */
static void
sigtstp(int signo) {
  /* Debug */
  if (0) {
    printf("signo %d\n", signo);
  }

  /* Reinstall signal. */
  signal_set(SIGTSTP, sigtstp);

  /* Do nothing when sub-process is running. */
  if (process_list) {
    return;
  }

  /* New line. */
  printf("\n");

  /* Make it sure cclient is reset. */
  cclient_stop(shell->cclient);

  /* Long jump flag check. */
  if (! jmpflag) {
    return;
  }

  jmpflag = 0;

  /* Back to main command loop. */
  siglongjmp(jmpbuf, 1);
}
Beispiel #22
0
void
proc_set_signals(struct tmuxproc *tp, void (*signalcb)(int))
{
	struct sigaction	sa;

	tp->signalcb = signalcb;

	memset(&sa, 0, sizeof sa);
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sa.sa_handler = SIG_IGN;

	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGPIPE, &sa, NULL);
	sigaction(SIGTSTP, &sa, NULL);

	signal_set(&tp->ev_sighup, SIGHUP, proc_signal_cb, tp);
	signal_add(&tp->ev_sighup, NULL);
	signal_set(&tp->ev_sigchld, SIGCHLD, proc_signal_cb, tp);
	signal_add(&tp->ev_sigchld, NULL);
	signal_set(&tp->ev_sigcont, SIGCONT, proc_signal_cb, tp);
	signal_add(&tp->ev_sigcont, NULL);
	signal_set(&tp->ev_sigterm, SIGTERM, proc_signal_cb, tp);
	signal_add(&tp->ev_sigterm, NULL);
	signal_set(&tp->ev_sigusr1, SIGUSR1, proc_signal_cb, tp);
	signal_add(&tp->ev_sigusr1, NULL);
	signal_set(&tp->ev_sigusr2, SIGUSR2, proc_signal_cb, tp);
	signal_add(&tp->ev_sigusr2, NULL);
	signal_set(&tp->ev_sigwinch, SIGWINCH, proc_signal_cb, tp);
	signal_add(&tp->ev_sigwinch, NULL);
}
Beispiel #23
0
/**
 * The ``main'' function of the adns helper process (server).
 *
 * Simply reads requests (queries) from fd_in, performs a DNS lookup for it
 * and writes the result to fd_out. All operations should be blocking. Exits
 * in case of non-recoverable error during read or write.
 */
static void
adns_helper(int fd_in, int fd_out)
{
	g_set_prgname(adns_process_title);
	gm_setproctitle(g_get_prgname());

#ifdef SIGQUIT 
	signal_set(SIGQUIT, SIG_IGN);	/* Avoid core dumps on SIGQUIT */
#endif

	is_helper = TRUE;

	for (;;) {
		struct adns_request req;
		struct adns_response ans;
		size_t size;
		void *buf;

		if (!adns_do_read(fd_in, &req.common, sizeof req.common))
			break;

		if (ADNS_COMMON_MAGIC != req.common.magic)
			break;
	
		if (req.common.reverse) {	
			size = sizeof req.query.reverse;
			buf = &req.query.reverse;
		} else {
			size = sizeof req.query.by_addr;
			buf = &req.query.by_addr;
		}

		if (!adns_do_read(fd_in, buf, size))
			break;

		adns_gethostbyname(&req, &ans);

		if (!adns_do_write(fd_out, &ans.common, sizeof ans.common))
			break;

		if (ans.common.reverse) {	
			size = sizeof ans.reply.reverse;
			buf = &ans.reply.reverse;
		} else {
			size = sizeof ans.reply.by_addr;
			buf = &ans.reply.by_addr;
		}

		if (!adns_do_write(fd_out, buf, size))
			break;
	}

	fd_close(&fd_in);
	fd_close(&fd_out);
	_exit(EXIT_SUCCESS);
}
Beispiel #24
0
int dect_event_ops_init(struct dect_ops *ops)
{

	ev_base = event_init();
	if (ev_base == NULL)
		return -1;
	ops->event_ops = &dect_event_ops;

	signal_set(&sig_event, SIGINT, sig_callback, NULL);
	signal_add(&sig_event, NULL);
	return 0;
}
Beispiel #25
0
void
set_signals(void (*handler)(int, short, void *), void *arg)
{
	struct sigaction	sigact;

	memset(&sigact, 0, sizeof sigact);
	sigemptyset(&sigact.sa_mask);
	sigact.sa_flags = SA_RESTART;
	sigact.sa_handler = SIG_IGN;
	if (sigaction(SIGINT, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGPIPE, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGUSR2, &sigact, NULL) != 0)
		fatal("sigaction failed");
	if (sigaction(SIGTSTP, &sigact, NULL) != 0)
		fatal("sigaction failed");

	signal_set(&ev_sighup, SIGHUP, handler, arg);
	signal_add(&ev_sighup, NULL);
	signal_set(&ev_sigchld, SIGCHLD, handler, arg);
	signal_add(&ev_sigchld, NULL);
	signal_set(&ev_sigcont, SIGCONT, handler, arg);
	signal_add(&ev_sigcont, NULL);
	signal_set(&ev_sigterm, SIGTERM, handler, arg);
	signal_add(&ev_sigterm, NULL);
	signal_set(&ev_sigusr1, SIGUSR1, handler, arg);
	signal_add(&ev_sigusr1, NULL);
	signal_set(&ev_sigwinch, SIGWINCH, handler, arg);
	signal_add(&ev_sigwinch, NULL);
}
Beispiel #26
0
EVQ_API int
evq_ignore_signal (struct event_queue *evq, const int signo, const int ignore)
{
#ifndef USE_KQUEUE
  (void) evq;
#else
  if (signal_kqueue(evq, signo, ignore ? EV_DELETE : EV_ADD))
    return -1;
#endif
  if (ignore)
    return signal_set(signo, SIG_IGN);
  else {
    struct event **sig_evp = signal_gethead(signo);
    int res;

    pthread_mutex_lock(&g_Signal.cs);
    res = signal_set(signo,
     (sig_evp && *sig_evp ? signal_handler : SIG_DFL));
    pthread_mutex_unlock(&g_Signal.cs);
    return res;
  }
}
Beispiel #27
0
struct ub_event*
ub_signal_new(struct ub_event_base* base, int fd,
	void (*cb)(int, short, void*), void* arg)
{
	struct event *ev = (struct event*)calloc(1, sizeof(struct event));

	if (!ev)
		return NULL;

	signal_set(ev, fd, cb, arg);
	if (event_base_set(AS_EVENT_BASE(base), ev) != 0) {
		free(ev);
		return NULL;
	}
	return AS_UB_EVENT(ev);
}
Beispiel #28
0
static void
signal_handlers_clear(void *state)
{
	/* Ensure no more pending signals */
	signal_set(SIGHUP, state, NULL);
	signal_set(SIGINT, state, NULL);
	signal_set(SIGTERM, state, NULL);
	signal_set(SIGCHLD, state, NULL);
	signal_set(SIGUSR1, state, NULL);
	signal_set(SIGUSR2, state, NULL);
}
Beispiel #29
0
void signal_test()
{
       // 初始化  
       base=event_init();  
       struct event evsignal;  
	   int arg = SIGINT;
      // 设置信号事件  
        signal_set(&evsignal, SIGINT,handler,&arg);  
      // 添加信号事件  
        event_add(&evsignal, NULL); 
		//设置为base事件
		event_base_set(base, &evsignal); 
        // 事件调度循环  
        event_dispatch();  
	   event_base_free(base);
		
}
Beispiel #30
0
/* Reload thread */
int
reload_vrrp_thread(thread_t * thread)
{
	/* set the reloading flag */
	SET_RELOAD;

	/* Signal handling */
	signal_handler_reset();

	/* Destroy master thread */
	vrrp_dispatcher_release(vrrp_data);
	kernel_netlink_close();
	thread_destroy_master(master);
	master = thread_make_master();
	free_global_data(global_data);
	free_interface_queue();
	free_vrrp_buffer();
	gratuitous_arp_close();
	ndisc_close();

#ifdef _WITH_LVS_
	if (vrrp_ipvs_needed()) {
		/* Clean ipvs related */
		ipvs_stop();
	}
#endif

	/* Save previous conf data */
	old_vrrp_data = vrrp_data;
	vrrp_data = NULL;

	/* Reload the conf */
#ifdef _DEBUG_
	mem_allocated = 0;
#endif
	vrrp_signal_init();
	signal_set(SIGCHLD, thread_child_handler, master);
	start_vrrp();

	/* free backup data */
	free_vrrp_data(old_vrrp_data);
	UNSET_RELOAD;

	return 0;
}