Exemplo n.º 1
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();
}
Exemplo n.º 2
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);
}