Пример #1
0
/*
 * Sysevent-based event delivery
 */
static void *
sev_open(const char *chan)
{
	evchan_t *hdl;

	if (chan == NULL)
		chan = FM_ERROR_CHAN;

	if ((errno = sysevent_evc_bind(chan, &hdl,
	    EVCH_CREAT | EVCH_HOLD_PEND)) != 0)
		die("can't bind to error channel %s", chan);

	return (hdl);
}
Пример #2
0
static evchan_t *
bind_channel(boolean_t priv, fmev_pri_t pri)
{
	evchan_t **evcpp = &CHAN_BINDING(priv, pri);
	evchan_t *evc;

	if (*evcpp != NULL)
		return (*evcpp);

	if (sysevent_evc_bind(CHAN_NAME(priv, pri), &evc,
	    EVCH_CREAT | CHAN_FLAGS(priv, pri)) != 0)
		return (NULL);

	if (atomic_cas_ptr(evcpp, NULL, evc) != NULL)
		(void) sysevent_evc_unbind(evc);

	return (*evcpp);
}
Пример #3
0
static void
probe_output(ipmp_handle_t ih, ofmt_handle_t ofmt)
{
	char sub[MAX_SUBID_LEN];
	evchan_t *evch;
	ipmpstat_probe_state_t ps = { ih, ofmt };
	uint_t nenabled = 0;

	/*
	 * Check if any interfaces are enabled for probe-based failure
	 * detection.  If not, immediately fail.
	 */
	walk_if(ih, probe_enabled_cbfunc, &nenabled);
	if (nenabled == 0)
		die("probe-based failure detection is disabled\n");

	probe_output_start = gethrtime();

	/*
	 * Unfortunately, until 4791900 is fixed, only privileged processes
	 * can bind and thus receive sysevents.
	 */
	errno = sysevent_evc_bind(IPMP_EVENT_CHAN, &evch, EVCH_CREAT);
	if (errno != 0) {
		if (errno == EPERM)
			die("insufficient privileges for -p\n");
		die("sysevent_evc_bind to channel %s failed", IPMP_EVENT_CHAN);
	}

	/*
	 * The subscriber must be unique in order for sysevent_evc_subscribe()
	 * to succeed, so combine our name and pid.
	 */
	(void) snprintf(sub, sizeof (sub), "%d-%s", getpid(), progname);

	errno = sysevent_evc_subscribe(evch, sub, EC_IPMP, probe_event, &ps, 0);
	if (errno != 0)
		die("sysevent_evc_subscribe for class %s failed", EC_IPMP);

	for (;;)
		(void) pause();
}
Пример #4
0
/*
 * fps_post_ereport(nvlist_t *ereport) posts an
 * ereport to the sysevent error channel.  The error
 * channel is assumed to be established by fps-transport.so.
 */
static int
fps_post_ereport(nvlist_t *ereport)
{
	evchan_t *scp;

	if (sysevent_evc_bind(CHANNEL, &scp, BIND_FLAGS) != 0) {
		return (1);
	}

	if (sysevent_evc_publish(scp, CLASS, SUBCLASS, VENDOR,
	    PUBLISHER, ereport, EVCH_NOSLEEP) != 0) {
		return (1);
	}

	(void) sleep(1);

	(void) fflush(NULL);
	(void) sysevent_evc_unbind(scp);

	return (0);
}
Пример #5
0
int
zone_events_init()
{
  int res;
  evchan_t *ch;
  char subid[16];

  if ((res = sysevent_evc_bind(ZONE_EVENT_CHANNEL, &ch, 0)) != 0) {
    fprintf(stderr, "failed to bind to sysevent channel: %d\n", res);

    return (-1);
  }

  snprintf(subid, sizeof (subid), "gate-%ld", (long int)getpid());

  if ((res = sysevent_evc_subscribe(ch, subid, ZONE_EVENT_STATUS_CLASS,
      sysev_evc_handler, (void *)ZONE_EVENT_CHANNEL, 0)) != 0) {
    fprintf(stderr, "failed to subscribe to channel: %d\n", res);

    return (-1);
  }

  return (0);
}