[krbdev.mit.edu #6287] Provide SPI to switch the mach port lookup for kipc
Zhanna Tsitkova via RT
rt-comment at krbdev.mit.edu
Thu Dec 4 13:46:53 EST 2008
diff -Nur -x '*~' -x '*.orig' -x '*.rej' -x '*.pbxbtree' -x '*.pbxindex' -x lha.mode1v3 -x lha.mode2v3 -x lha.pbxuser -x windows -x .DS_Store Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/ccapi/server/mac/ccs_os_server.c Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/ccapi/server/mac/ccs_os_server.c
--- Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/ccapi/server/mac/ccs_os_server.c 2008-11-25 10:41:46.000000000 -0800
+++ Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/ccapi/server/mac/ccs_os_server.c 2008-11-25 15:50:29.000000000 -0800
@@ -102,7 +102,8 @@
cc_int32 ccs_os_server_listen_loop (int argc, const char *argv[])
{
- return cci_check_error (k5_ipc_server_listen_loop ());
+ k5_ipc_server_listen();
+ dispatch_main();
}
/* ------------------------------------------------------------------------ */
diff -Nur -x '*~' -x '*.orig' -x '*.rej' -x '*.pbxbtree' -x '*.pbxindex' -x lha.mode1v3 -x lha.mode2v3 -x lha.pbxuser -x windows -x .DS_Store Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/kim/agent/mac/KerberosAgentListener.m Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/kim/agent/mac/KerberosAgentListener.m
--- Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/kim/agent/mac/KerberosAgentListener.m 2008-11-07 11:24:46.000000000 -0800
+++ Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/kim/agent/mac/KerberosAgentListener.m 2008-11-25 15:58:01.000000000 -0800
@@ -30,43 +30,9 @@
@implementation KerberosAgentListener
- at synthesize thread;
-
- (id) init
{
- self = [super init];
- if (self != nil) {
- self.thread = [[NSThread alloc] initWithTarget:self selector:@selector(threadMain) object:nil];
- }
- return self;
-}
-
-static KerberosAgentListener *sharedListener = nil;
-
-+ (KerberosAgentListener *) sharedListener
-{
- @synchronized(self) {
- if (sharedListener == nil) {
- [[self alloc] init]; // assignment not done here
- }
- }
- return sharedListener;
-}
-
-+ (id)allocWithZone:(NSZone *)zone
-{
- @synchronized(self) {
- if (sharedListener == nil) {
- sharedListener = [super allocWithZone:zone];
- return sharedListener; // assignment and return on first allocation
- }
- }
- return nil; //on subsequent allocation attempts return nil
-}
-
-- (id)copyWithZone:(NSZone *)zone
-{
- return self;
+ return [super init];
}
- (id)retain
@@ -74,7 +40,7 @@
return self;
}
-- (unsigned)retainCount
+- (NSUInteger)retainCount
{
return UINT_MAX; //denotes an object that cannot be released
}
@@ -94,30 +60,7 @@
// called from main thread to start listen thread
+ (void) startListening
{
-// NSLog(@"%s %@ thread", __FUNCTION__, ([NSThread isMainThread]) ? @"main" : @"not main");
-
- [[KerberosAgentListener sharedListener].thread start];
-}
-
-- (void) threadMain
-{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- int32_t err = 0;
-
-// NSLog(@"%s starting up", __FUNCTION__);
-
- while (!err && ![self.thread isCancelled]) {
- err = kim_agent_listen_loop();
- if (!err) {
-// NSLog (@"%s loop resetting %@", __FUNCTION__, [[NSThread currentThread] description]);
- } else {
- NSLog (@"%s got error %d (%@) %@", __FUNCTION__, err, [KIMUtilities stringForLastKIMError:err], [[NSThread currentThread] description]);
- err = 0; /* The server quit unexpectedly -- just try again */
- }
- sleep(10);
- }
-
- [pool release];
+ return k5_ipc_server_listen();
}
#pragma mark IPC handlers
diff -Nur -x '*~' -x '*.orig' -x '*.rej' -x '*.pbxbtree' -x '*.pbxindex' -x lha.mode1v3 -x lha.mode2v3 -x lha.pbxuser -x windows -x .DS_Store Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.c Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.c
--- Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.c 2008-11-25 10:41:46.000000000 -0800
+++ Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.c 2008-11-25 15:51:00.000000000 -0800
@@ -34,14 +34,9 @@
#include <mach/mach.h>
#include <servers/bootstrap.h>
#include <dispatch/dispatch.h>
+#include <launch.h>
#include <string.h>
-/* Global variables for servers (used by k5_ipc_request_demux) */
-static mach_port_t g_service_port = MACH_PORT_NULL;
-static mach_port_t g_notify_port = MACH_PORT_NULL;
-static boolean_t g_ready_to_quit = 0;
-
-
/* ------------------------------------------------------------------------ */
static boolean_t k5_ipc_request_demux (mach_msg_header_t *request,
@@ -53,13 +48,6 @@
handled = k5_ipc_request_server (request, reply);
}
- /* Our session has a send right. If that goes away it's time to quit. */
- if (!handled && (request->msgh_id == MACH_NOTIFY_NO_SENDERS &&
- request->msgh_local_port == g_notify_port)) {
- g_ready_to_quit = 1;
- handled = 1;
- }
-
/* Check here for a client death. If so remove it */
if (!handled && request->msgh_id == MACH_NOTIFY_NO_SENDERS) {
kern_return_t err = KERN_SUCCESS;
@@ -228,85 +216,53 @@
return err;
}
+static void
+start_mach_service(launch_data_t obj, const char *key, void *context)
+{
+ dispatch_source_t source;
+
+ if (launch_data_get_type(obj) == LAUNCH_DATA_MACHPORT) {
+ mach_port_t port = launch_data_get_machport(obj);
+ dispatch_source_mig_create(port,
+ K5_IPC_MAX_MSG_SIZE,
+ NULL,
+ dispatch_get_main_queue(),
+ k5_ipc_request_demux);
+ } else {
+ syslog(LOG_NOTICE, "%s: not a mach port", key);
+ }
+}
+
#pragma mark -
/* ------------------------------------------------------------------------ */
-int32_t k5_ipc_server_listen_loop (void)
+int32_t k5_ipc_server_listen (void)
{
- /* Run the Mach IPC listen loop.
- * This will call k5_ipc_server_create_client_connection for new clients
- * and k5_ipc_server_request for existing clients */
-
- kern_return_t err = KERN_SUCCESS;
- char *service = NULL;
- char *lookup = NULL;
- mach_port_t lookup_port = MACH_PORT_NULL;
- mach_port_t boot_port = MACH_PORT_NULL;
- mach_port_t previous_notify_port = MACH_PORT_NULL;
- dispatch_queue_t queue;
+ launch_data_t resp, tmp, msg;
+
+ msg = launch_data_new_string(LAUNCH_KEY_CHECKIN);
-
- if (!err) {
- err = k5_ipc_server_get_lookup_and_service_names (&lookup, &service);
+ resp = launch_msg(msg);
+ if (resp == NULL) {
+ syslog(LOG_NOTICE, "launch_msg(): %s", strerror(errno));
+ return 1;
}
- if (!err) {
- /* Get the bootstrap port */
- err = task_get_bootstrap_port (mach_task_self (), &boot_port);
+ if (launch_data_get_type(resp) == LAUNCH_DATA_ERRNO) {
+ errno = launch_data_get_errno(resp);
+ syslog(LOG_NOTICE, "launch_msg() response: %s", strerror(errno));
+ return 1;
}
- if (!err) {
- /* We are an on-demand server so our lookup port already exists. */
- err = bootstrap_check_in (boot_port, lookup, &lookup_port);
- }
-
- if (!err) {
- /* We are an on-demand server so our service port already exists. */
- err = bootstrap_check_in (boot_port, service, &g_service_port);
- }
-
- if (!err) {
- /* Create the port set that the server will listen on */
- err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE,
- &g_notify_port);
- }
+ tmp = launch_data_dict_lookup(resp, LAUNCH_JOBKEY_MACHSERVICES);
- if (!err) {
- /* Ask for notification when the server port has no more senders
- * A send-once right != a send right so our send-once right will
- * not interfere with the notification */
- err = mach_port_request_notification (mach_task_self (), g_service_port,
- MACH_NOTIFY_NO_SENDERS, true,
- g_notify_port,
- MACH_MSG_TYPE_MAKE_SEND_ONCE,
- &previous_notify_port);
+ if (tmp == NULL) {
+ syslog(LOG_NOTICE, "No mach services found!");
+ } else {
+ launch_data_dict_iterate(tmp, start_mach_service, NULL);
}
-
- queue = dispatch_get_main_queue();
-
- dispatch_source_mig_create(g_notify_port, K5_IPC_MAX_MSG_SIZE, NULL,
- queue, k5_ipc_request_demux);
- dispatch_source_mig_create(lookup_port, K5_IPC_MAX_MSG_SIZE, NULL,
- queue, k5_ipc_request_demux);
- dispatch_source_mig_create(g_service_port, K5_IPC_MAX_MSG_SIZE, NULL,
- queue, k5_ipc_request_demux);
-
- dispatch_main();
-
- /* Clean up the ports and strings */
- if (MACH_PORT_VALID (g_notify_port)) {
- mach_port_destroy (mach_task_self (), g_notify_port);
- g_notify_port = MACH_PORT_NULL;
- }
- if (MACH_PORT_VALID (boot_port)) {
- mach_port_deallocate (mach_task_self (), boot_port);
- }
-
- free (service);
- free (lookup);
-
- return err;
+ return 0;
}
/* ------------------------------------------------------------------------ */
@@ -366,5 +322,4 @@
void k5_ipc_server_quit (void)
{
- g_ready_to_quit = 1;
}
diff -Nur -x '*~' -x '*.orig' -x '*.rej' -x '*.pbxbtree' -x '*.pbxindex' -x lha.mode1v3 -x lha.mode2v3 -x lha.pbxuser -x windows -x .DS_Store Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.h Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.h
--- Kerberos.AEP-6.5fc1.orig/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.h 2008-11-07 11:26:00.000000000 -0800
+++ Kerberos.AEP-6.5fc1/KerberosFramework/Kerberos5/Sources/util/mac/k5_mig_server.h 2008-11-25 15:51:15.000000000 -0800
@@ -41,8 +41,7 @@
/* Server control functions */
-/* WARNING: Currently only supports running server loop on a single thread! */
-int32_t k5_ipc_server_listen_loop (void);
+int32_t k5_ipc_server_listen (void);
int32_t k5_ipc_server_send_reply (mach_port_t in_reply_pipe,
k5_ipc_stream in_reply_stream);
More information about the krb5-bugs
mailing list