/*
- * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
#include <mach/mach.h>
#include <mach/mach_error.h>
+#include <servers/bootstrap.h>
#include <pthread.h>
+#include <sys/time.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <SystemConfiguration/SCPrivate.h>
{ 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" },
};
line = CFStringCreateExternalRepresentation(NULL,
CFArrayGetValueAtIndex(lines, i),
- kCFStringEncodingMacRoman,
- '?');
+ kCFStringEncodingUTF8,
+ (UInt8)'?');
if (line) {
syslog (level, "%.*s", (int)CFDataGetLength(line), CFDataGetBytePtr(line));
CFRelease(line);
line = CFStringCreateExternalRepresentation(NULL,
str,
- kCFStringEncodingMacRoman,
- '?');
+ kCFStringEncodingUTF8,
+ (UInt8)'?');
CFRelease(str);
if (!line) {
return;
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);
}
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);
}
+const CFStringRef kCFErrorDomainSystemConfiguration = CFSTR("com.apple.SystemConfiguration");
+
+
void
_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;
return strerror(status);
}
+ if ((status >= BOOTSTRAP_SUCCESS) && (status <= BOOTSTRAP_NO_MEMORY)) {
+ return bootstrap_strerror(status);
+ }
+
return mach_error_string(status);
}