diff --git a/src/servers/launch/Job.cpp b/src/servers/launch/Job.cpp index 374a526dd9..13ccd9cec1 100644 --- a/src/servers/launch/Job.cpp +++ b/src/servers/launch/Job.cpp @@ -244,50 +244,6 @@ Job::Init(const Finder& finder, std::set& dependencies) } } - // Create ports - // TODO: prefix system ports with "system:" - - bool defaultPort = false; - - for (PortMap::iterator iterator = fPortMap.begin(); - iterator != fPortMap.end(); iterator++) { - BString name(Name()); - const char* suffix = iterator->second.GetString("name"); - if (suffix != NULL) - name << ':' << suffix; - else - defaultPort = true; - - const int32 capacity = iterator->second.GetInt32("capacity", - B_LOOPER_PORT_DEFAULT_CAPACITY); - - port_id port = create_port(capacity, name.String()); - if (port < 0) { - fInitStatus = port; - break; - } - iterator->second.SetInt32("port", port); - - if (name == "x-vnd.haiku-registrar:auth") { - // Allow the launch_daemon to access the registrar authentication - BPrivate::set_registrar_authentication_port(port); - } - } - - if (fInitStatus == B_OK && fCreateDefaultPort && !defaultPort) { - BMessage data; - data.AddInt32("capacity", B_LOOPER_PORT_DEFAULT_CAPACITY); - - port_id port = create_port(B_LOOPER_PORT_DEFAULT_CAPACITY, Name()); - if (port < 0) { - // TODO: log error - fInitStatus = port; - } else { - data.SetInt32("port", port); - AddPort(data); - } - } - return fInitStatus; } @@ -351,10 +307,7 @@ Job::Launch() BString signature("application/"); signature << Name(); - status_t status = BRoster::Private().Launch(signature.String(), NULL, - NULL, 0, NULL, &environment[0], &fTeam, NULL, false); - _SetLaunchStatus(status); - return status; + return _Launch(signature.String(), NULL, 0, NULL, &environment[0]); } // Build argument vector @@ -377,10 +330,7 @@ Job::Launch() } // Launch via entry_ref - status = BRoster::Private().Launch(NULL, &ref, NULL, count, &args[0], - &environment[0], &fTeam, NULL, false); - _SetLaunchStatus(status); - return status; + return _Launch(NULL, &ref, count, &args[0], &environment[0]); } @@ -505,3 +455,80 @@ Job::_SendPendingLaunchDataReplies() fPendingLaunchDataReplies.MakeEmpty(); } + + +status_t +Job::_CreateAndTransferPorts() +{ + // TODO: prefix system ports with "system:" + + bool defaultPort = false; + + for (PortMap::iterator iterator = fPortMap.begin(); + iterator != fPortMap.end(); iterator++) { + BString name(Name()); + const char* suffix = iterator->second.GetString("name"); + if (suffix != NULL) + name << ':' << suffix; + else + defaultPort = true; + + const int32 capacity = iterator->second.GetInt32("capacity", + B_LOOPER_PORT_DEFAULT_CAPACITY); + + port_id port = create_port(capacity, name.String()); + if (port < 0) + return port; + + status_t result = set_port_owner(port, fTeam); + if (result != B_OK) + return result; + + iterator->second.SetInt32("port", port); + + if (name == "x-vnd.haiku-registrar:auth") { + // Allow the launch_daemon to access the registrar authentication + BPrivate::set_registrar_authentication_port(port); + } + } + + if (fCreateDefaultPort && !defaultPort) { + BMessage data; + data.AddInt32("capacity", B_LOOPER_PORT_DEFAULT_CAPACITY); + + port_id port = create_port(B_LOOPER_PORT_DEFAULT_CAPACITY, Name()); + if (port < 0) + return port; + + status_t result = set_port_owner(port, fTeam); + if (result != B_OK) + return result; + + data.SetInt32("port", port); + AddPort(data); + } + + return B_OK; +} + + +status_t +Job::_Launch(const char* signature, entry_ref* ref, int argCount, + const char* const* args, const char** environment) +{ + thread_id mainThread = -1; + status_t result = BRoster::Private().Launch(signature, ref, NULL, argCount, + args, environment, &fTeam, &mainThread, true); + + if (result == B_OK) { + result = _CreateAndTransferPorts(); + + if (result == B_OK) + resume_thread(mainThread); + else + kill_thread(mainThread); + } + + _SetLaunchStatus(result); + return result; +} diff --git a/src/servers/launch/Job.h b/src/servers/launch/Job.h index 63afeae97a..137491db49 100644 --- a/src/servers/launch/Job.h +++ b/src/servers/launch/Job.h @@ -24,6 +24,8 @@ class BMessage; class Finder; class Target; +struct entry_ref; + typedef std::map PortMap; @@ -87,6 +89,12 @@ private: status_t _SendLaunchDataReply(BMessage* message); void _SendPendingLaunchDataReplies(); + status_t _CreateAndTransferPorts(); + + status_t _Launch(const char* signature, entry_ref* ref, + int argCount, const char* const* args, + const char** environment); + private: BStringList fArguments; BStringList fRequirements;