__private_extern__ void SystemLoad_prime(void) { systemLoadKey = SCDynamicStoreKeyCreate( kCFAllocatorDefault, CFSTR("%@%@"), kSCDynamicStoreDomainState, CFSTR("/IOKit/PowerManagement/SystemLoad")); systemLoadDetailedKey = SCDynamicStoreKeyCreate( kCFAllocatorDefault, CFSTR("%@%@"), kSCDynamicStoreDomainState, CFSTR("/IOKit/PowerManagement/SystemLoad/Detailed")); notify_register_check(kIOSystemLoadAdvisoryNotifyName, &gNotifyToken); // If this is a desktop, then we won't get any battery notifications. // Let's prime the battery pump right here with an initial coll. SystemLoadBatteriesHaveChanged(_batteries()); SystemLoadPrefsHaveChanged(); #if !TARGET_OS_EMBEDDED SystemLoadUserStateHasChanged(); #endif SystemLoadCPUPowerHasChanged(NULL); }
OSThermalNotificationLevel _OSThermalNotificationLevelForBehavior(int behavior) { uint64_t val = OSThermalNotificationLevelAny; if (behavior >= 0 && behavior < kOSThermalMitigationCount) { dispatch_once(&predicates[behavior], ^{ (void)notify_register_check(kOSThermalMitigationNames[behavior], &tokens[behavior]); });
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; } } }
static const char * whatsmyhostname() { static dispatch_once_t once; int check, status; dispatch_once(&once, ^{ snprintf(myname, sizeof(myname), "%s", "localhost"); notify_register_check(kNotifySCHostNameChange, &name_change_token); });
static void init_context_once(void *ctx) { krb5_context context = ctx; #ifdef HAVE_NOTIFY_H notify_register_check(KRB5_CONFIGURATION_CHANGE_NOTIFY_NAME, &check_token); #endif krb5_load_plugins(context, "krb5", sysplugin_dirs); bindtextdomain(HEIMDAL_TEXTDOMAIN, HEIMDAL_LOCALEDIR); }
void initializeDates() { #ifndef NDEBUG static bool alreadyInitialized; ASSERT(!alreadyInitialized++); #endif equivalentYearForDST(2000); // Need to call once to initialize a static used in this function. #if PLATFORM(DARWIN) // Register for a notification whenever the time zone changes. uint32_t status = notify_register_check("com.apple.system.timezone", &s_notificationToken); if (status == NOTIFY_STATUS_OK) { s_cachedUTCOffset = calculateUTCOffset(); s_haveCachedUTCOffset = true; } #endif }
/* 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, ¬ifyToken); if (NOTIFY_STATUS_OK == status) { notify_get_state(notifyToken, &newval); notify_cancel(notifyToken); _gt = (IOSystemLoadAdvisoryLevel)newval; } return _gt; }
static void timer_register_time_change(void) { int status; if (S_time_change_registered) { return; } status = notify_register_check(kNotifyClockSet, &S_time_change_token); if (status != NOTIFY_STATUS_OK) { my_log(LOG_ERR, "timer: notify_register_check(%s) failed, %d", kNotifyClockSet, status); return; } S_time_change_registered = TRUE; /* throw away the first check, since it always says check=1 */ timer_notify_check(); return; }
static int _asl_notify_open(int do_lock) { char *notify_name; uint32_t status; if (do_lock != 0) pthread_mutex_lock(&_asl_global.lock); _asl_global.notify_count++; if (_asl_global.notify_token != -1) { if (do_lock != 0) pthread_mutex_unlock(&_asl_global.lock); return 0; } if (_asl_global.rc_change_token == -1) { status = notify_register_check(NOTIFY_RC, &_asl_global.rc_change_token); if (status != NOTIFY_STATUS_OK) _asl_global.rc_change_token = -1; } if (_asl_global.master_token == -1) { status = notify_register_plain(NOTIFY_SYSTEM_MASTER, &_asl_global.master_token); if (status != NOTIFY_STATUS_OK) _asl_global.master_token = -1; } notify_name = asl_remote_notify_name(); if (notify_name != NULL) { status = notify_register_plain(notify_name, &_asl_global.notify_token); free(notify_name); if (status != NOTIFY_STATUS_OK) _asl_global.notify_token = -1; } if (do_lock != 0) pthread_mutex_unlock(&_asl_global.lock); if (_asl_global.notify_token == -1) return -1; return 0; }
static ff_cache_t * prep_cache(int cat, ff_cache_t *cache) { u_int32_t status, check; char *s; ff_cache_t *c; if (cache == NULL) return NULL; if (cache->notify_token == -1) { s = NULL; asprintf(&s, "%s.%s", NOTIFY_PREFIX, categoryFilename[cat]); status = notify_register_check(s, &(cache->notify_token)); free(s); if (status != NOTIFY_STATUS_OK) return NULL; s = NULL; asprintf(&s, "%s/%s", DEFAULT_FF_DIR, categoryFilename[cat]); status = notify_monitor_file(cache->notify_token, s, 0); free(s); if (status != NOTIFY_STATUS_OK) return NULL; } pthread_mutex_lock(&(cache->lock)); check = 1; if (cache->modtime != 0) { status = notify_check(cache->notify_token, &check); if ((status == NOTIFY_STATUS_OK) && (check == 0)) { pthread_mutex_unlock(&(cache->lock)); return cache; } } c = load_cache(cat, cache); pthread_mutex_unlock(&(cache->lock)); return c; }
STATIC Boolean prefs_did_change(uint32_t * gen_p) { Boolean changed; int check = 0; uint32_t notify_status; STATIC uint32_t S_generation; STATIC int S_token; STATIC Boolean S_token_valid = FALSE; changed = FALSE; if (!S_token_valid) { notify_status = notify_register_check(kEAPSIMAKAPrefsChangedNotification, &S_token); if (notify_status != NOTIFY_STATUS_OK) { EAPLOG_FL(LOG_NOTICE, "notify_register_check returned %d", notify_status); goto done; } S_token_valid = TRUE; } notify_status = notify_check(S_token, &check); if (notify_status != NOTIFY_STATUS_OK) { EAPLOG_FL(LOG_NOTICE, "notify_check returned %d", notify_status); goto done; } if (check != 0) { S_generation++; } if (*gen_p != S_generation) { changed = TRUE; } *gen_p = S_generation; done: return (changed); }
/* * GuizmOVPN_get_user_pass(char *username,char *password,const int capacity, char * prefix) : * Request username/password from the user */ void GuizmOVPN_get_user_pass(char *username,char *password,const int capacity, char * prefix) { int token, status, check; status = notify_register_check("com.guizmo.openvpn/ReceivedUserPass", &token); notify_check(token, &check); if (status != NOTIFY_STATUS_OK) { msg (M_FATAL, "Unable to receive authentification"); } // Check which user/pass request to handle if(!strcmp(prefix,"token-insertion-request")) { notify_post("com.guizmo.openvpn/RequestTokenInsertionPass"); } else if(!strcmp(prefix,"Auth")) { notify_post("com.guizmo.openvpn/RequestAuthUserPass"); } else if(!strcmp(prefix,"HTTP Proxy")) { notify_post("com.guizmo.openvpn/RequestProxyUserPass"); } else if(!strcmp(prefix,"pkcs11-id-request")) { notify_post("com.guizmo.openvpn/RequestPKCS11UserPass"); } else if(!strcmp(prefix,"Private Key")) { notify_post("com.guizmo.openvpn/RequestPrivateKeyPass"); } else if(!strstr(prefix," token")) { notify_post("com.guizmo.openvpn/RequestTokenPIN"); } else { msg (M_FATAL, "Unknown user/pass request : %s",prefix); return; } msg (M_INFO, "Waiting for username/password (%s)",prefix); // May need to do a cleaner wait int received=0; while(!received) { status = notify_check(token, &check); if ((status == NOTIFY_STATUS_OK) && (check != 0)) { msg (M_INFO,"Username/password received"); received=1; } sleep(1); } // Read the username/password from file const char *path="/tmp/guizmovpn_temp_auth"; FILE *fp = fopen (path, "r"); if (!fp) { msg (M_FATAL, "Error receiving authentification"); } if (fgets (username, capacity, fp) == NULL || fgets (password, capacity, fp) == NULL) { msg (M_FATAL, "Error receiving authentification"); } fclose (fp); unlink(path); chomp (username); chomp (password); return; }
__private_extern__ int si_inet_config(uint32_t *inet4, uint32_t *inet6) { int status, checkit; struct ifaddrs *ifa, *ifap; pthread_mutex_lock(&net_config_mutex); checkit = 1; #if NOTIFY_SUPPORT if (net_config_token < 0) { status = notify_register_check(kNotifySCNetworkChange, &net_config_token); if (status != 0) net_config_token = -1; } if (net_config_token >= 0) { status = notify_check(net_config_token, &checkit); if (status != 0) checkit = 1; } #endif status = 0; if (checkit != 0) { if (getifaddrs(&ifa) < 0) { status = -1; } else { net_v4_count = 0; net_v6_count = 0; for (ifap = ifa; ifap != NULL; ifap = ifap->ifa_next) { if (ifap->ifa_addr == NULL) continue; if ((ifap->ifa_flags & IFF_UP) == 0) continue; if (ifap->ifa_addr->sa_family == AF_INET) { net_v4_count++; } else if (ifap->ifa_addr->sa_family == AF_INET6) { net_v6_count++; } } } freeifaddrs(ifa); } if (inet4 != NULL) *inet4 = net_v4_count; if (inet6 != NULL) *inet6 = net_v6_count; pthread_mutex_unlock(&net_config_mutex); return status; }