Beispiel #1
0
void
__dns_close_notify()
{
	if (resolv1_token != -1) notify_cancel(resolv1_token);
	resolv1_token = -1;

	if (resolv2_token != -1) notify_cancel(resolv2_token);
	resolv2_token = -1;
}
Beispiel #2
0
void
__dns_open_notify()
{
	uint32_t status;

	if (resolv1_token == -1)
	{
		status = notify_register_check(RESOLV1_NOTIFY_NAME, &resolv1_token);
		if (status == NOTIFY_STATUS_OK)
		{
			status = notify_monitor_file(resolv1_token, "/var/run/resolv.conf", 0);
			if (status != NOTIFY_STATUS_OK)
			{
				notify_cancel(resolv1_token);
				resolv1_token = -1;
			}
		}
		else 
		{
			resolv1_token = -1;
		}
	}

	if ((resolv1_token != -1 ) && (resolv2_token == -1))
	{
		status = notify_register_check(RESOLV2_NOTIFY_NAME, &resolv2_token);
		if (status == NOTIFY_STATUS_OK)
		{
			status = notify_monitor_file(resolv2_token, "/private/etc/resolver", 0);
			if (status != NOTIFY_STATUS_OK)
			{
				notify_cancel(resolv1_token);
				notify_cancel(resolv2_token);
				resolv1_token = -1;
				resolv2_token = -1;
			}
		}
		else 
		{
			notify_cancel(resolv1_token);
			resolv1_token = -1;
			resolv2_token = -1;
		}
	}
}
    ~universal_notifier_notifyd_t()
    {
        if (token != 0)
        {
#if FISH_NOTIFYD_AVAILABLE
            notify_cancel(token);
#endif
        }
    }
int
OSMemoryNotificationDestroy(OSMemoryNotificationRef note)
{
	if (NOTIFY_STATUS_OK != notify_cancel(note->token))
		return EINVAL;

	if (KERN_SUCCESS != mach_port_deallocate(mach_task_self(), note->port))
		return EINVAL;

	free(note);

	return 0;
}
Beispiel #5
0
static void
_asl_notify_close()
{
	pthread_mutex_lock(&_asl_global.lock);

	if (_asl_global.notify_count > 0) _asl_global.notify_count--;

	if (_asl_global.notify_count > 0)
	{
		pthread_mutex_unlock(&_asl_global.lock);
		return;
	}

	if (_asl_global.rc_change_token >= 0) notify_cancel(_asl_global.rc_change_token);
	_asl_global.rc_change_token = -1;

	if (_asl_global.master_token >= 0) notify_cancel(_asl_global.master_token);
	_asl_global.master_token = -1;

	if (_asl_global.notify_token >= 0) notify_cancel(_asl_global.notify_token);
	_asl_global.notify_token = -1;

	pthread_mutex_unlock(&_asl_global.lock);
}
Beispiel #6
0
/* IOGetSystemLoadAdvisory
 * In case of error, or inability to find system load advisory level,
 * returns kIOSystemLoadAdvisoryLevelOK.
 */
IOSystemLoadAdvisoryLevel IOGetSystemLoadAdvisory( void )
{
    IOSystemLoadAdvisoryLevel   _gt = kIOSystemLoadAdvisoryLevelOK;
    int                         notifyToken = 0;
    int                         status;
    uint64_t                    newval;

    status = notify_register_check(kIOSystemLoadAdvisoryNotifyName, &notifyToken);
    if (NOTIFY_STATUS_OK == status)
    {
        notify_get_state(notifyToken, &newval);
        notify_cancel(notifyToken);
        _gt = (IOSystemLoadAdvisoryLevel)newval;
    }
    
    return _gt;
}
mDNSlocal int RegisterNotification(mDNS *const m, unsigned int interval)
{
    int len = strlen("com.apple.system.notify.service.timer:+") + 21; // 21 bytes to accomodate the interval
    char buffer[len];
    unsigned int blen;
    int status;

    // Starting "interval" second from now (+ below indicates relative) register for a notification
    blen = mDNS_snprintf(buffer, sizeof(buffer), "com.apple.system.notify.service.timer:+%us", interval);
    if (blen >= sizeof(buffer))
    {
        LogMsg("RegisterNotification: Buffer too small blen %d, buffer size %d", blen, sizeof(buffer));
        return -1;
    } 
    LogInfo("RegisterNotification: buffer %s", buffer);
    if (m->notifyToken)
    {
        notify_cancel(m->notifyToken);
        m->notifyToken = 0;
    }
    status = notify_register_dispatch(buffer, &m->notifyToken,
                dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
                ^(int t) { (void) t; FetchRootTA(m); });
Beispiel #8
0
int runDaemonRun(void) {
	// Register for all the notifications
	int fd;
	int quitToken = 0;
	if (notify_register_file_descriptor(quitNotification, &fd, 0, &quitToken) != NOTIFY_STATUS_OK) {
		return 0x10;
	}
	int startToken = 0;
	if (notify_register_file_descriptor(startNotification, &fd, NOTIFY_REUSE, &startToken) != NOTIFY_STATUS_OK) {
		return 0x11;
	}
	int stopToken = 0;
	if (notify_register_file_descriptor(stopNotification, &fd, NOTIFY_REUSE, &stopToken) != NOTIFY_STATUS_OK) {
		return 0x12;
	}
	int debugToken = 0;
	if (notify_register_file_descriptor(debugNotification, &fd, NOTIFY_REUSE, &debugToken) != NOTIFY_STATUS_OK) {
		return 0x14;
	}

	print_message(0, "Started as %d(%d):%d(%d)\n", getuid(), geteuid(), getgid(), getegid());

	fd_set readfds;
	FD_ZERO(&readfds);
	FD_SET(fd, &readfds);

	pid_t ngircdPid = 0;
	int ps;
	char debug = 1;

	char shouldContinue = 1;
	while (shouldContinue) {
		int status = select(fd + 1, &readfds, NULL, NULL, NULL);
		if (status <= 0 || !FD_ISSET(fd, &readfds)) {
			continue;
		}

		int t;
		status = read(fd, &t, sizeof(int));
		if (status < 0) {
			continue;
		}
		t = ntohl(t); // notify_register_file_descriptor docs: "The value is sent in network byte order."

		// Value in file descriptor matches token for quit notification
		if (t == quitToken) {
			if (debug) print_message(0, "Quitting\n");
			shouldContinue = 0;
		}

		// Value in file descriptor matches token for start notification
		if (t == startToken) {
			if (debug) print_message(0, "Starting\n");
			// Start ngircd as non-daemon, using custom config file
			const char *args[] = {"ngircd", "-n", "-f", "/Library/Application Support/IRCyslog/ircyslog.conf", NULL};
			if (!ngircdPid) {
				ps = posix_spawn(&ngircdPid, "/usr/sbin/ngircd", NULL, NULL, (char *const *)args, NULL);
				if (!ps) {
					if (debug) print_message(0, "Started ngircd with pid:%d\n", ngircdPid);
				}
			}

			// Start the IRC bot
			// ...

		}

		// Value in file descriptor matches token for stop notification
		// or the quit notification was posted
		if (t == stopToken || !shouldContinue) {
			if (debug) print_message(0, "stopping");

			// Stop the IRC bot
			// ...

			if (!ps) { // If the server is running, kill it
				if (debug) print_message(0, "Calling kill with (%d, %d)\n", ngircdPid, SIGTERM);
				int k = kill(ngircdPid, SIGTERM);
				if (debug) print_message(0, "kill'd with exit status %d\n", k);

				// Wait for the server to finish and purge from the process list
				int st;
				if (debug) print_message(0, "Calling waitpid with (%d,%d)\n", ngircdPid, 0);
				int w = waitpid(ngircdPid, &st, 0);
				if (debug) print_message(0, "waitpid'd with exit status %d, stat_loc %d\n", w, st);
			}
		}

		// Value in file descriptor matches token for debug notification
		if (t == debugToken) {
			debug = !debug;
			print_message(0, "debug is %s\n", debug ? "ON" : "OFF");
		}
	}

	// Cancel notification watching
	print_message(0, "Cancelling notifications\n");
	notify_cancel(quitToken);
	notify_cancel(startToken);
	notify_cancel(stopToken);
	notify_cancel(debugToken);

	return 0;
}