xref: /haiku/src/system/libroot/os/launch.cpp (revision ef462ab57f0ba739629194e6c071815d521c7955)
19d69dc09SAxel Dörfler /*
29d69dc09SAxel Dörfler  * Copyright 2015, Axel Dörfler, axeld@pinc-software.de.
39d69dc09SAxel Dörfler  * Distributed under the terms of the MIT License.
49d69dc09SAxel Dörfler  */
59d69dc09SAxel Dörfler 
69d69dc09SAxel Dörfler 
79d69dc09SAxel Dörfler #include <launch.h>
89d69dc09SAxel Dörfler 
99d69dc09SAxel Dörfler #include <TokenSpace.h>
109d69dc09SAxel Dörfler #include <util/KMessage.h>
119d69dc09SAxel Dörfler 
129d69dc09SAxel Dörfler 
139d69dc09SAxel Dörfler static port_id sLaunchDaemonPort = -1;
149d69dc09SAxel Dörfler 
159d69dc09SAxel Dörfler 
169d69dc09SAxel Dörfler port_id
get_launch_daemon_port()179d69dc09SAxel Dörfler BPrivate::get_launch_daemon_port()
189d69dc09SAxel Dörfler {
19*ef462ab5SAxel Dörfler 	if (sLaunchDaemonPort < 0) {
209d69dc09SAxel Dörfler 		sLaunchDaemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME);
219d69dc09SAxel Dörfler 
22*ef462ab5SAxel Dörfler 		port_info info;
23*ef462ab5SAxel Dörfler 		if (get_port_info(sLaunchDaemonPort, &info) == B_OK
24*ef462ab5SAxel Dörfler 			&& info.team == find_thread(NULL)) {
25*ef462ab5SAxel Dörfler 			// Make sure that the launch_daemon doesn't wait on itself
26*ef462ab5SAxel Dörfler 			sLaunchDaemonPort = -1;
27*ef462ab5SAxel Dörfler 			return -1;
28*ef462ab5SAxel Dörfler 		}
29*ef462ab5SAxel Dörfler 	}
30*ef462ab5SAxel Dörfler 
319d69dc09SAxel Dörfler 	return sLaunchDaemonPort;
329d69dc09SAxel Dörfler }
339d69dc09SAxel Dörfler 
349d69dc09SAxel Dörfler 
359d69dc09SAxel Dörfler status_t
send_request_to_launch_daemon(KMessage & request,KMessage & reply)369d69dc09SAxel Dörfler BPrivate::send_request_to_launch_daemon(KMessage& request, KMessage& reply)
379d69dc09SAxel Dörfler {
389d69dc09SAxel Dörfler 	status_t status = request.SendTo(get_launch_daemon_port(),
399d69dc09SAxel Dörfler 		B_PREFERRED_TOKEN, &reply);
409d69dc09SAxel Dörfler 	if (status != B_OK)
419d69dc09SAxel Dörfler 		return status;
429d69dc09SAxel Dörfler 
439d69dc09SAxel Dörfler 	return (status_t)reply.What();
449d69dc09SAxel Dörfler }
459d69dc09SAxel Dörfler 
469d69dc09SAxel Dörfler 
479d69dc09SAxel Dörfler status_t
get_launch_data(const char * signature,KMessage & data)489d69dc09SAxel Dörfler BPrivate::get_launch_data(const char* signature, KMessage& data)
499d69dc09SAxel Dörfler {
509d69dc09SAxel Dörfler 	BPrivate::KMessage request(B_GET_LAUNCH_DATA);
519d69dc09SAxel Dörfler 	request.AddString("name", signature);
529d69dc09SAxel Dörfler 
539d69dc09SAxel Dörfler 	return BPrivate::send_request_to_launch_daemon(request, data);
549d69dc09SAxel Dörfler }
55