X-Git-Url: https://git.saurik.com/apple/configd.git/blobdiff_plain/791b08356c62be042d56dd05c1cc0ace4b068c53..edebe297f772e4cdd76278ebb777820466d2917b:/SystemConfiguration.fproj/SCD.c diff --git a/SystemConfiguration.fproj/SCD.c b/SystemConfiguration.fproj/SCD.c index 188bfaa..797571d 100644 --- a/SystemConfiguration.fproj/SCD.c +++ b/SystemConfiguration.fproj/SCD.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2007 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -33,7 +33,9 @@ #include #include +#include #include +#include #include #include @@ -64,7 +66,7 @@ static const struct sc_errmsg { { kSCStatusNoPrefsSession, "Preference session not active" }, { kSCStatusNotifierActive, "Notifier is currently active" }, { kSCStatusOK, "Success!" }, - { kSCStatusPrefsBusy, "Configuration daemon busy" }, + { kSCStatusPrefsBusy, "Preferences update currently in progress" }, { kSCStatusReachabilityUnknown, "Network reachability cannot be determined" }, { kSCStatusStale, "Write attempted on stale version of object" }, }; @@ -344,8 +346,8 @@ __SCLog(int level, CFStringRef formatString, va_list formatArguments) line = CFStringCreateExternalRepresentation(NULL, CFArrayGetValueAtIndex(lines, i), - kCFStringEncodingMacRoman, - '?'); + kCFStringEncodingUTF8, + (UInt8)'?'); if (line) { syslog (level, "%.*s", (int)CFDataGetLength(line), CFDataGetBytePtr(line)); CFRelease(line); @@ -380,8 +382,8 @@ __SCPrint(FILE *stream, CFStringRef formatString, va_list formatArguments, Boole line = CFStringCreateExternalRepresentation(NULL, str, - kCFStringEncodingMacRoman, - '?'); + kCFStringEncodingUTF8, + (UInt8)'?'); CFRelease(str); if (!line) { return; @@ -389,18 +391,17 @@ __SCPrint(FILE *stream, CFStringRef formatString, va_list formatArguments, Boole pthread_mutex_lock(&lock); if (trace) { - time_t now = time(NULL); - struct tm tm; - - (void)localtime_r(&now, &tm); - fprintf(stream, "%2d:%02d:%02d %.*s%s", - tm.tm_hour, tm.tm_min, tm.tm_sec, - (int)CFDataGetLength(line), CFDataGetBytePtr(line), - addNL ? "\n" : ""); - } else { - fprintf(stream, "%.*s%s", - (int)CFDataGetLength(line), CFDataGetBytePtr(line), - addNL ? "\n" : ""); + struct tm tm_now; + struct timeval tv_now; + + (void)gettimeofday(&tv_now, NULL); + (void)localtime_r(&tv_now.tv_sec, &tm_now); + (void)fprintf(stream, "%2d:%02d:%02d.%03d ", + tm_now.tm_hour, tm_now.tm_min, tm_now.tm_sec, tv_now.tv_usec / 1000); + } + (void)fwrite((const void *)CFDataGetBytePtr(line), (size_t)CFDataGetLength(line), 1, stream); + if (addNL) { + (void)fputc('\n', stream); } fflush (stream); pthread_mutex_unlock(&lock); @@ -420,13 +421,14 @@ SCLog(Boolean condition, int level, CFStringRef formatString, ...) } va_start(formatArguments, formatString); - if (_sc_log) { + if (_sc_log > 0) { __SCLog(level, formatString, formatArguments); - } else { + } + if (_sc_log != 1) { __SCPrint((LOG_PRI(level) > LOG_NOTICE) ? stderr : stdout, formatString, formatArguments, - FALSE, // trace + (_sc_log > 0), // trace TRUE); // add newline } va_end(formatArguments); @@ -498,6 +500,9 @@ __SCThreadSpecificKeyInitialize() } +const CFStringRef kCFErrorDomainSystemConfiguration = CFSTR("com.apple.SystemConfiguration"); + + void _SCErrorSet(int error) { @@ -517,8 +522,56 @@ _SCErrorSet(int error) } +CFErrorRef +SCCopyLastError(void) +{ + CFStringRef domain; + CFErrorRef error; + int i; + int code; + __SCThreadSpecificDataRef tsd; + CFMutableDictionaryRef userInfo = NULL; + + pthread_once(&tsKeyInitialized, __SCThreadSpecificKeyInitialize); + + tsd = pthread_getspecific(tsDataKey); + code = tsd ? tsd->_sc_error : kSCStatusOK; + + for (i = 0; i < (int)nSC_ERRMSGS; i++) { + if (sc_errmsgs[i].status == code) { + CFStringRef str; + + domain = kCFErrorDomainSystemConfiguration; + userInfo = CFDictionaryCreateMutable(NULL, + 0, + &kCFCopyStringDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + str = CFStringCreateWithCString(NULL, + sc_errmsgs[i].message, + kCFStringEncodingASCII); + CFDictionarySetValue(userInfo, kCFErrorDescriptionKey, str); + CFRelease(str); + goto done; + } + } + + if ((code > 0) && (code <= ELAST)) { + domain = kCFErrorDomainPOSIX; + goto done; + } + + domain = kCFErrorDomainMach; + + done : + + error = CFErrorCreate(NULL, domain, code, userInfo); + if (userInfo != NULL) CFRelease(userInfo); + return error; +} + + int -SCError() +SCError(void) { __SCThreadSpecificDataRef tsd; @@ -544,5 +597,9 @@ SCErrorString(int status) return strerror(status); } + if ((status >= BOOTSTRAP_SUCCESS) && (status <= BOOTSTRAP_NO_MEMORY)) { + return bootstrap_strerror(status); + } + return mach_error_string(status); }