[haiku-commits] BRANCH axeld-github.launch_daemon [a1b3ae48e341] src/system/kernel/debug src/servers/launch src/kits/app headers/private src/system/libroot/os

  • From: axeld-github.launch_daemon <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 21 Apr 2015 19:01:46 +0200 (CEST)

added 4 changesets to branch 'refs/remotes/axeld-github/launch_daemon'
old head: a37e85afeed520d3882515f9f810a52619ccfc66
new head: a1b3ae48e3416910d55f995673955dba078f8386
overview: https://github.com/axeld/haiku/compare/a37e85afeed5...a1b3ae48e341

----------------------------------------------------------------------------

76d96bfee9d8: launch_daemon: added support for arbitrary ports.

* Dropped "create_port" -- this is now the default for services.
* Additionally (or alternatively, if you use the "legacy" mode), you can
now create named ports, and specify their capacity.
* Added convenience methods to BLaunchRoster that automatically use the
signature of the current be_app.

4321d47e87bd: libroot: added ability to communicate with the launch_daemon.

* These methods don't really work yet, as BMessage doesn't support
replying with a KMessage; the request is received, but the reply
never gets to the target.

993ae1f42e06: syslog_daemon: Converted to BServer.

* Instead of letting the kernel search for the syslog port, the
daemon now registers itself with the kernel (which even solves
a TODO).
* A port is created for the actual log messages from the launch_daemon,
and used on start.
* However, the SyslogTest does not yet work, due to the BMessage <->
KMessage communication problems.

a1b3ae48e341: BMessage: WIP of reply with KMessage support.

* Doesn't yet work, not is it complete.

[ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

24 files changed, 387 insertions(+), 175 deletions(-)
data/launch/system | 18 ++-
headers/build/private/app/MessagePrivate.h | 6 +-
headers/private/app/LaunchRoster.h | 4 +-
headers/private/app/MessagePrivate.h | 6 +-
headers/private/kernel/debug.h | 7 +-
headers/private/libroot/launch.h | 29 +++++
headers/private/syslog_daemon/syslog_daemon.h | 4 +-
headers/private/system/syscalls.h | 3 +-
src/kits/app/Application.cpp | 2 +-
src/kits/app/Jamfile | 2 +-
src/kits/app/LaunchRoster.cpp | 36 ++++--
src/kits/app/Message.cpp | 11 +-
src/kits/app/MessageAdapter.cpp | 5 +-
src/servers/launch/LaunchDaemon.cpp | 135 ++++++++++++++++-----
src/servers/syslog_daemon/Jamfile | 3 +-
src/servers/syslog_daemon/SyslogDaemon.cpp | 26 ++--
src/servers/syslog_daemon/SyslogDaemon.h | 5 +-
src/servers/syslog_daemon/syslog_output.cpp | 12 +-
src/system/kernel/debug/debug.cpp | 141 +++++++++++-----------
src/system/libroot/os/Jamfile | 3 +-
src/system/libroot/os/launch.cpp | 45 +++++++
src/system/libroot/posix/syslog.cpp | 30 ++++-
src/tests/system/libroot/posix/Jamfile | 10 +-
src/tests/system/libroot/posix/SyslogTest.cpp | 19 +--

############################################################################

Commit: 76d96bfee9d8c35bed600d666b8b22726c9819ba
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Tue Apr 21 16:40:26 2015 UTC

launch_daemon: added support for arbitrary ports.

* Dropped "create_port" -- this is now the default for services.
* Additionally (or alternatively, if you use the "legacy" mode), you can
now create named ports, and specify their capacity.
* Added convenience methods to BLaunchRoster that automatically use the
signature of the current be_app.

----------------------------------------------------------------------------

diff --git a/data/launch/system b/data/launch/system
index 8398134..0653e5f 100644
--- a/data/launch/system
+++ b/data/launch/system
@@ -1,11 +1,9 @@
service x-vnd.Haiku-registrar {
launch /system/servers/registrar
- create_port
}

service x-vnd.Haiku-app_server {
launch /system/servers/app_server
- create_port
}

service x-vnd.Haiku-debug_server {
@@ -14,57 +12,69 @@ service x-vnd.Haiku-debug_server {

service x-vnd.Haiku-package_daemon {
launch /system/servers/package_daemon
- create_port
}

-service x-vnd.Haiku-syslog_daemon {
+service x-vnd.Haiku-SystemLogger {
launch /system/servers/syslog_daemon
+ port logger {
+ capacity 256
+ }
}

service x-vnd.Haiku-mount_server {
launch /system/servers/mount_server
+ legacy
}

service x-vnd.Haiku-media_server {
launch /system/servers/media_server
no_safemode
+ legacy
}

service x-vnd.Haiku-midi_server {
launch /system/servers/midi_server
no_safemode
+ legacy
}

service x-vnd.Haiku-mail_daemon {
launch /system/servers/mail_daemon -E
no_safemode
+ legacy
}

service x-vnd.Haiku-cddb_daemon {
launch /system/servers/cddb_daemon
no_safemode
+ legacy
}

service x-vnd.Haiku-print_server {
launch /system/servers/print_server
no_safemode
+ legacy
}

service x-vnd.Haiku-notification_server {
launch /system/servers/notification_server
no_safemode
+ legacy
}

service x-vnd.Haiku-power_daemon {
launch /system/servers/power_daemon
no_safemode
+ legacy
}

# The following will be moved into the user launch data
service x-vnd.Be-TRAK {
launch /system/Tracker
+ legacy
}

service x-vnd.Be-TSKB {
launch /system/Deskbar
+ legacy
}
diff --git a/headers/private/app/LaunchRoster.h
b/headers/private/app/LaunchRoster.h
index 5c50284..3fd3b17 100644
--- a/headers/private/app/LaunchRoster.h
+++ b/headers/private/app/LaunchRoster.h
@@ -16,9 +16,11 @@ public:

status_t InitCheck() const;

+ status_t GetData(BMessage& data);
status_t GetData(const char*
signature, BMessage& data);
+ port_id GetPort(const char*
name = NULL);
port_id GetPort(const char*
signature,
- const
char* name = NULL);
+ const
char* name);

private:
void _InitMessenger();
diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp
index 661d302..a2e54a3 100644
--- a/src/kits/app/Application.cpp
+++ b/src/kits/app/Application.cpp
@@ -530,7 +530,7 @@ DBG(OUT("BApplication::InitData() done\n"));
port_id
BApplication::_GetPort(const char* signature)
{
- return BLaunchRoster().GetPort(signature);
+ return BLaunchRoster().GetPort(signature, NULL);
}


diff --git a/src/kits/app/LaunchRoster.cpp b/src/kits/app/LaunchRoster.cpp
index 0e50b19..20d3e3b 100644
--- a/src/kits/app/LaunchRoster.cpp
+++ b/src/kits/app/LaunchRoster.cpp
@@ -9,6 +9,7 @@

#include <LaunchRoster.h>

+#include <Application.h>
#include <String.h>

#include <LaunchDaemonDefs.h>
@@ -40,6 +41,16 @@ BLaunchRoster::InitCheck() const


status_t
+BLaunchRoster::GetData(BMessage& data)
+{
+ if (be_app == NULL)
+ return B_BAD_VALUE;
+
+ return GetData(be_app->Signature(), data);
+}
+
+
+status_t
BLaunchRoster::GetData(const char* signature, BMessage& data)
{
if (signature == NULL || signature[0] == '\0')
@@ -55,13 +66,23 @@ BLaunchRoster::GetData(const char* signature, BMessage&
data)

// evaluate the reply
if (status == B_OK)
- status = data.GetInt32("error", B_OK);
+ status = data.what;

return status;
}


port_id
+BLaunchRoster::GetPort(const char* name)
+{
+ if (be_app == NULL)
+ return B_BAD_VALUE;
+
+ return GetPort(be_app->Signature(), name);
+}
+
+
+port_id
BLaunchRoster::GetPort(const char* signature, const char* name)
{
BLaunchRoster launchRoster;
@@ -69,12 +90,10 @@ BLaunchRoster::GetPort(const char* signature, const char*
name)
status_t status = launchRoster.GetData(signature, data);
if (status == B_OK) {
BString fieldName;
- if (name == NULL)
- fieldName = "port";
- else {
- fieldName = name;
- fieldName << "_port";
- }
+ if (name != NULL)
+ fieldName << name << "_";
+ fieldName << "port";
+
port_id port = data.GetInt32(fieldName.String(),
B_NAME_NOT_FOUND);
if (port >= 0)
return port;
diff --git a/src/servers/launch/LaunchDaemon.cpp
b/src/servers/launch/LaunchDaemon.cpp
index 877f1dc..5de107a 100644
--- a/src/servers/launch/LaunchDaemon.cpp
+++ b/src/servers/launch/LaunchDaemon.cpp
@@ -30,11 +30,17 @@ using namespace BPrivate;
static const char* kLaunchDirectory = "launch";


+const static settings_template kPortTemplate[] = {
+ {B_STRING_TYPE, "name", NULL, true},
+ {B_INT32_TYPE, "capacity", NULL},
+};
+
const static settings_template kJobTemplate[] = {
{B_STRING_TYPE, "name", NULL, true},
{B_BOOL_TYPE, "disabled", NULL},
{B_STRING_TYPE, "launch", NULL},
- {B_BOOL_TYPE, "create_port", NULL},
+ {B_BOOL_TYPE, "legacy", NULL},
+ {B_MESSAGE_TYPE, "port", kPortTemplate},
{B_BOOL_TYPE, "no_safemode", NULL},
{0, NULL, NULL}
};
@@ -46,6 +52,9 @@ const static settings_template kSettingsTemplate[] = {
};


+typedef std::map<BString, BMessage> PortMap;
+
+
class Job {
public:
Job(const char*
name);
@@ -59,8 +68,10 @@ public:
bool IsService() const;
void SetService(bool
service);

- bool CreatePort() const;
- void SetCreatePort(bool
createPort);
+ bool CreateDefaultPort()
const;
+ void
SetCreateDefaultPort(bool createPort);
+
+ void AddPort(BMessage& data);

bool LaunchInSafeMode()
const;
void
SetLaunchInSafeMode(bool launch);
@@ -73,7 +84,9 @@ public:
status_t InitCheck() const;

team_id Team() const;
- port_id Port() const;
+
+ const PortMap& Ports() const;
+ port_id Port(const char* name =
NULL) const;

status_t Launch();
bool IsLaunched() const;
@@ -83,9 +96,9 @@ private:
BStringList fArguments;
bool fEnabled;
bool fService;
- bool fCreatePort;
+ bool fCreateDefaultPort;
bool fLaunchInSafeMode;
- port_id fPort;
+ PortMap fPortMap;
status_t fInitStatus;
team_id fTeam;
};
@@ -141,9 +154,8 @@ Job::Job(const char* name)
fName(name),
fEnabled(true),
fService(false),
- fCreatePort(false),
+ fCreateDefaultPort(false),
fLaunchInSafeMode(true),
- fPort(-1),
fInitStatus(B_NO_INIT),
fTeam(-1)
{
@@ -153,8 +165,12 @@ Job::Job(const char* name)

Job::~Job()
{
- if (fPort >= 0)
- delete_port(fPort);
+ PortMap::const_iterator iterator = Ports().begin();
+ for (; iterator != Ports().end(); iterator++) {
+ port_id port = iterator->second.GetInt32("port", -1);
+ if (port >= 0)
+ delete_port(port);
+ }
}


@@ -194,16 +210,24 @@ Job::SetService(bool service)


bool
-Job::CreatePort() const
+Job::CreateDefaultPort() const
{
- return fCreatePort;
+ return fCreateDefaultPort;
}


void
-Job::SetCreatePort(bool createPort)
+Job::SetCreateDefaultPort(bool createPort)
{
- fCreatePort = createPort;
+ fCreateDefaultPort = createPort;
+}
+
+
+void
+Job::AddPort(BMessage& data)
+{
+ const char* name = data.GetString("name");
+ fPortMap.insert(std::pair<BString, BMessage>(BString(name), data));
}


@@ -247,11 +271,42 @@ Job::Init()
{
fInitStatus = B_OK;

- if (fCreatePort) {
- // TODO: prefix system ports with "system:"
- fPort = create_port(B_LOOPER_PORT_DEFAULT_CAPACITY, Name());
- if (fPort < 0)
- fInitStatus = fPort;
+ // 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 (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)
+ fInitStatus = port;
+ else {
+ data.SetInt32("port", port);
+ AddPort(data);
+ }
}

return fInitStatus;
@@ -272,10 +327,21 @@ Job::Team() const
}


+const PortMap&
+Job::Ports() const
+{
+ return fPortMap;
+}
+
+
port_id
-Job::Port() const
+Job::Port(const char* name) const
{
- return fPort;
+ PortMap::const_iterator found = fPortMap.find(name);
+ if (found != fPortMap.end())
+ return found->second.GetInt32("port", -1);
+
+ return B_NAME_NOT_FOUND;
}


@@ -366,18 +432,27 @@ LaunchDaemon::MessageReceived(BMessage* message)
switch (message->what) {
case B_GET_LAUNCH_DATA:
{
- BMessage reply;
+ BMessage reply((uint32)B_OK);
Job* job = _Job(get_leaf(message->GetString("name")));
if (job == NULL) {
- reply.AddInt32("error", B_NAME_NOT_FOUND);
+ reply.what = B_NAME_NOT_FOUND;
} else {
// If the job has not been launched yet, we'll
pass on our
// team here. The rationale behind this is that
this team
// will temporarily own the synchronous reply
ports.
reply.AddInt32("team", job->Team() < 0
? current_team() : job->Team());
- if (job->CreatePort())
- reply.AddInt32("port", job->Port());
+
+ PortMap::const_iterator iterator =
job->Ports().begin();
+ for (; iterator != job->Ports().end();
iterator++) {
+ BString name;
+ if (iterator->second.HasString("name"))
+ name <<
iterator->second.GetString("name") << "_";
+ name << "port";
+
+ reply.AddInt32(name.String(),
+
iterator->second.GetInt32("port", -1));
+ }

// Launch job now if it isn't running yet
if (!job->IsLaunched())
@@ -447,7 +522,7 @@ LaunchDaemon::_ReadFile(const char* context, BEntry& entry)
BMessage job;
for (int32 index = 0; message.FindMessage("service", index,
&job) == B_OK; index++) {
- _AddJob(false, job);
+ _AddJob(true, job);
}

for (int32 index = 0; message.FindMessage("job", index, &job)
== B_OK;
@@ -475,10 +550,16 @@ LaunchDaemon::_AddJob(bool service, BMessage& message)

job->SetEnabled(!message.GetBool("disabled", !job->IsEnabled()));
job->SetService(service);
- job->SetCreatePort(message.GetBool("create_port", job->CreatePort()));
+ job->SetCreateDefaultPort(!message.GetBool("legacy", !service));
job->SetLaunchInSafeMode(
!message.GetBool("no_safemode", !job->LaunchInSafeMode()));

+ BMessage portMessage;
+ for (int32 index = 0;
+ message.FindMessage("port", index, &portMessage) ==
B_OK; index++) {
+ job->AddPort(portMessage);
+ }
+
const char* argument;
for (int32 index = 0;
message.FindString("launch", index, &argument) == B_OK;
index++) {

############################################################################

Commit: 4321d47e87bd870ecd35d3f8e02e52da1bed68f0
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Tue Apr 21 16:44:24 2015 UTC

libroot: added ability to communicate with the launch_daemon.

* These methods don't really work yet, as BMessage doesn't support
replying with a KMessage; the request is received, but the reply
never gets to the target.

----------------------------------------------------------------------------

diff --git a/headers/private/libroot/launch.h b/headers/private/libroot/launch.h
new file mode 100644
index 0000000..55122ef
--- /dev/null
+++ b/headers/private/libroot/launch.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _LIBROOT_LAUNCH_H
+#define _LIBROOT_LAUNCH_H
+
+
+#include <LaunchDaemonDefs.h>
+#include <OS.h>
+
+
+#ifdef __cplusplus
+namespace BPrivate {
+
+
+class KMessage;
+
+
+port_id get_launch_daemon_port();
+status_t send_request_to_launch_daemon(KMessage& request, KMessage&
reply);
+status_t get_launch_data(const char* signature, KMessage& data);
+
+
+} // namespace BPrivate
+#endif // __cplusplus
+
+
+#endif // _LIBROOT_LAUNCH_H
diff --git a/src/kits/app/Jamfile b/src/kits/app/Jamfile
index 8de9740..57cccff 100644
--- a/src/kits/app/Jamfile
+++ b/src/kits/app/Jamfile
@@ -18,7 +18,7 @@ if $(RUN_WITHOUT_APP_SERVER) != 0 {
}

UseLibraryHeaders icon ;
-UsePrivateHeaders shared app interface kernel locale notification ;
+UsePrivateHeaders shared app interface kernel libroot locale notification ;

SetSubDirSupportedPlatforms haiku libbe_test ;

diff --git a/src/kits/app/LaunchRoster.cpp b/src/kits/app/LaunchRoster.cpp
index 20d3e3b..bdb558c 100644
--- a/src/kits/app/LaunchRoster.cpp
+++ b/src/kits/app/LaunchRoster.cpp
@@ -12,6 +12,7 @@
#include <Application.h>
#include <String.h>

+#include <launch.h>
#include <LaunchDaemonDefs.h>
#include <MessengerPrivate.h>

@@ -107,7 +108,7 @@ void
BLaunchRoster::_InitMessenger()
{
// find the launch_daemon port
- port_id daemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME);
+ port_id daemonPort = BPrivate::get_launch_daemon_port();
port_info info;
if (daemonPort >= 0 && get_port_info(daemonPort, &info) == B_OK) {
BMessenger::Private(fMessenger).SetTo(info.team, daemonPort,
diff --git a/src/system/libroot/os/Jamfile b/src/system/libroot/os/Jamfile
index b273012..572f892 100644
--- a/src/system/libroot/os/Jamfile
+++ b/src/system/libroot/os/Jamfile
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src system libroot os ;

UsePrivateHeaders kernel ;
# for util/KMessage.h
-UsePrivateHeaders libroot runtime_loader shared ;
+UsePrivateHeaders app libroot runtime_loader shared ;

local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
@@ -28,6 +28,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
fs_query.cpp
fs_volume.c
image.cpp
+ launch.cpp
memory.cpp
parsedate.cpp
port.c
diff --git a/src/system/libroot/os/launch.cpp b/src/system/libroot/os/launch.cpp
new file mode 100644
index 0000000..d3812e1
--- /dev/null
+++ b/src/system/libroot/os/launch.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <launch.h>
+
+#include <TokenSpace.h>
+#include <util/KMessage.h>
+
+
+static port_id sLaunchDaemonPort = -1;
+
+
+port_id
+BPrivate::get_launch_daemon_port()
+{
+ if (sLaunchDaemonPort < 0)
+ sLaunchDaemonPort = find_port(B_LAUNCH_DAEMON_PORT_NAME);
+
+ return sLaunchDaemonPort;
+}
+
+
+status_t
+BPrivate::send_request_to_launch_daemon(KMessage& request, KMessage& reply)
+{
+ status_t status = request.SendTo(get_launch_daemon_port(),
+ B_PREFERRED_TOKEN, &reply);
+ if (status != B_OK)
+ return status;
+
+ return (status_t)reply.What();
+}
+
+
+status_t
+BPrivate::get_launch_data(const char* signature, KMessage& data)
+{
+ BPrivate::KMessage request(B_GET_LAUNCH_DATA);
+ request.AddString("name", signature);
+
+ return BPrivate::send_request_to_launch_daemon(request, data);
+}

############################################################################

Commit: 993ae1f42e0601a76967852e9824f9737bdec14c
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Tue Apr 21 16:49:37 2015 UTC

syslog_daemon: Converted to BServer.

* Instead of letting the kernel search for the syslog port, the
daemon now registers itself with the kernel (which even solves
a TODO).
* A port is created for the actual log messages from the launch_daemon,
and used on start.
* However, the SyslogTest does not yet work, due to the BMessage <->
KMessage communication problems.

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/debug.h b/headers/private/kernel/debug.h
index 5cca136..45332e4 100644
--- a/headers/private/kernel/debug.h
+++ b/headers/private/kernel/debug.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ * Copyright 2002-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
* Distributed under the terms of the Haiku License.
*
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -221,8 +221,9 @@ extern bool debug_is_debugged_team(team_id teamID);

extern struct arch_debug_registers* debug_get_debug_registers(int32 cpu);

-extern status_t _user_kernel_debugger(const char *message);
-extern void _user_debug_output(const char *userString);
+extern status_t _user_kernel_debugger(const char *message);
+extern void _user_register_syslog_daemon(port_id port);
+extern void _user_debug_output(const char *userString);

#ifdef __cplusplus
}
diff --git a/headers/private/syslog_daemon/syslog_daemon.h
b/headers/private/syslog_daemon/syslog_daemon.h
index 513f9b7..9897eb4 100644
--- a/headers/private/syslog_daemon/syslog_daemon.h
+++ b/headers/private/syslog_daemon/syslog_daemon.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2003-2006, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. All rights
reserved.
+ * Copyright 2003-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. All rights
reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef SYSLOG_DAEMON_H
@@ -9,7 +9,7 @@
#include <OS.h>


-#define SYSLOG_PORT_NAME "syslog_daemon"
+#define B_SYSTEM_LOGGER_SIGNATURE "application/x-vnd.Haiku-SystemLogger"

#define SYSLOG_MESSAGE '_Syl'
#define SYSLOG_ADD_LISTENER 'aSyl'
diff --git a/headers/private/system/syscalls.h
b/headers/private/system/syscalls.h
index 86d407b..5031150 100644
--- a/headers/private/system/syscalls.h
+++ b/headers/private/system/syscalls.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2011, Haiku, Inc. All rights reserved.
+ * Copyright 2004-2015, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _SYSTEM_SYSCALLS_H
@@ -469,6 +469,7 @@ extern status_t
_kern_get_port_message_info_etc(port_id port,

// debug support functions
extern status_t _kern_kernel_debugger(const char *message);
+extern void _kern_register_syslog_daemon(port_id port);
extern void _kern_debugger(const char *message);
extern int _kern_disable_debugger(int state);

diff --git a/src/servers/syslog_daemon/Jamfile
b/src/servers/syslog_daemon/Jamfile
index 1d37179..db32952 100644
--- a/src/servers/syslog_daemon/Jamfile
+++ b/src/servers/syslog_daemon/Jamfile
@@ -1,6 +1,7 @@
SubDir HAIKU_TOP src servers syslog_daemon ;

-UsePrivateHeaders syslog_daemon ;
+UsePrivateHeaders app syslog_daemon ;
+UsePrivateSystemHeaders ;

AddResources syslog_daemon : SyslogDaemon.rdef ;

diff --git a/src/servers/syslog_daemon/SyslogDaemon.cpp
b/src/servers/syslog_daemon/SyslogDaemon.cpp
index 2ae8561..8bc9cba 100644
--- a/src/servers/syslog_daemon/SyslogDaemon.cpp
+++ b/src/servers/syslog_daemon/SyslogDaemon.cpp
@@ -16,6 +16,10 @@
#include <Path.h>
#include <TextView.h>

+#include <LaunchRoster.h>
+#include <syscalls.h>
+#include <syslog_daemon.h>
+
#include "listener_output.h"
#include "syslog_output.h"

@@ -24,12 +28,9 @@
#define B_TRANSLATION_CONTEXT "SyslogDaemon"


-const char* kSignature = "application/x-vnd.Haiku-SystemLogger";
-
-
SyslogDaemon::SyslogDaemon()
:
- BApplication(kSignature),
+ BApplication(B_SYSTEM_LOGGER_SIGNATURE),
fHandlerLock("handler lock")
{
}
@@ -38,10 +39,12 @@ SyslogDaemon::SyslogDaemon()
void
SyslogDaemon::ReadyToRun()
{
- fPort = create_port(256, SYSLOG_PORT_NAME);
- fDaemon = spawn_thread(daemon_thread, "daemon", B_NORMAL_PRIORITY,
this);
+ fPort = BLaunchRoster().GetPort("logger");
+ fDaemon = spawn_thread(_DaemonThread, "daemon", B_NORMAL_PRIORITY,
this);
+
+ if (fPort >= 0 && fDaemon >= 0) {
+ _kern_register_syslog_daemon(fPort);

- if (fPort >= B_OK && fDaemon >= B_OK) {
init_syslog_output(this);
init_listener_output(this);

@@ -128,7 +131,7 @@ SyslogDaemon::AddHandler(handler_func function)


void
-SyslogDaemon::Daemon()
+SyslogDaemon::_Daemon()
{
char buffer[SYSLOG_MESSAGE_BUFFER_SIZE + 1];
syslog_message& message = *(syslog_message*)buffer;
@@ -168,13 +171,16 @@ SyslogDaemon::Daemon()


int32
-SyslogDaemon::daemon_thread(void* data)
+SyslogDaemon::_DaemonThread(void* data)
{
- ((SyslogDaemon*)data)->Daemon();
+ ((SyslogDaemon*)data)->_Daemon();
return B_OK;
}


+// #pragma mark -
+
+
int
main(int argc, char** argv)
{
diff --git a/src/servers/syslog_daemon/SyslogDaemon.h
b/src/servers/syslog_daemon/SyslogDaemon.h
index 10986bf..b544762 100644
--- a/src/servers/syslog_daemon/SyslogDaemon.h
+++ b/src/servers/syslog_daemon/SyslogDaemon.h
@@ -28,8 +28,9 @@ public:

void AddHandler(handler_func
function);

- void Daemon();
- static int32 daemon_thread(void* data);
+private:
+ void _Daemon();
+ static int32 _DaemonThread(void* data);

private:
thread_id fDaemon;
diff --git a/src/servers/syslog_daemon/syslog_output.cpp
b/src/servers/syslog_daemon/syslog_output.cpp
index 457449c..0678ee2 100644
--- a/src/servers/syslog_daemon/syslog_output.cpp
+++ b/src/servers/syslog_daemon/syslog_output.cpp
@@ -6,16 +6,16 @@

#include "syslog_output.h"

-#include <FindDirectory.h>
-#include <Path.h>
-#include <driver_settings.h>
-
-#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
#include <sys/stat.h>
+#include <syslog.h>
+#include <unistd.h>
+
+#include <FindDirectory.h>
+#include <Path.h>
+#include <driver_settings.h>


static const char *kFacilities[] = {
diff --git a/src/system/kernel/debug/debug.cpp
b/src/system/kernel/debug/debug.cpp
index 7e9266d..1672d78 100644
--- a/src/system/kernel/debug/debug.cpp
+++ b/src/system/kernel/debug/debug.cpp
@@ -1,6 +1,6 @@
/*
* Copyright 2008-2011, Ingo Weinhold, ingo_weinhold@xxxxxx.
- * Copyright 2002-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2002-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
* Distributed under the terms of the MIT License.
*
* Copyright 2001, Travis Geiselbrecht. All rights reserved.
@@ -98,6 +98,8 @@ static spinlock sSpinlock = B_SPINLOCK_INITIALIZER;
static int32 sDebuggerOnCPU = -1;

static sem_id sSyslogNotify = -1;
+static thread_id sSyslogWriter = -1;
+static port_id sSyslogPort = -1;
static struct syslog_message* sSyslogMessage;
static struct ring_buffer* sSyslogBuffer;
static size_t sSyslogBufferOffset = 0;
@@ -1188,8 +1190,6 @@ cmd_switch_cpu(int argc, char** argv)
static status_t
syslog_sender(void* data)
{
- status_t error = B_BAD_PORT_ID;
- port_id port = -1;
bool bufferPending = false;
int32 length = 0;

@@ -1208,69 +1208,56 @@ syslog_sender(void* data)

sSyslogMessage->when = real_time_clock();

- if (error == B_BAD_PORT_ID) {
- // last message couldn't be sent, try to locate the
syslog_daemon
- port = find_port(SYSLOG_PORT_NAME);
- if (port < 0) {
- // Don't recheck too quickly, since find_port)
is rather
- // expensive.
- // TODO: Maybe using the port notification
mechanism would be
- // the better option here. Alternatively, and
probably even
- // better, the syslog daemon could register
itself via a syscall
- // (like the messaging service). We could even
wait with
- // starting this thread before that happened
(end exit as soon
- // as the port is gone).
- snooze(1000000);
- continue;
+ if (!bufferPending) {
+ // We need to have exclusive access to our syslog buffer
+ cpu_status state = disable_interrupts();
+ acquire_spinlock(&sSpinlock);
+
+ length = ring_buffer_readable(sSyslogBuffer)
+ - sSyslogBufferOffset;
+ if (length > (int32)SYSLOG_MAX_MESSAGE_LENGTH)
+ length = SYSLOG_MAX_MESSAGE_LENGTH;
+
+ length = ring_buffer_peek(sSyslogBuffer,
sSyslogBufferOffset,
+ (uint8*)sSyslogMessage->message, length);
+ sSyslogBufferOffset += length;
+ if (sSyslogDropped) {
+ // Add drop marker - since parts had to be
dropped, it's
+ // guaranteed that we have enough space in the
buffer now.
+ ring_buffer_write(sSyslogBuffer,
(uint8*)"<DROP>", 6);
+ sSyslogDropped = false;
}
- }
-
- if (port >= B_OK) {
- if (!bufferPending) {
- // we need to have exclusive access to our
syslog buffer
- cpu_status state = disable_interrupts();
- acquire_spinlock(&sSpinlock);
-
- length = ring_buffer_readable(sSyslogBuffer)
- - sSyslogBufferOffset;
- if (length > (int32)SYSLOG_MAX_MESSAGE_LENGTH)
- length = SYSLOG_MAX_MESSAGE_LENGTH;
-
- length = ring_buffer_peek(sSyslogBuffer,
sSyslogBufferOffset,
- (uint8*)sSyslogMessage->message,
length);
- sSyslogBufferOffset += length;
- if (sSyslogDropped) {
- // Add drop marker - since parts had to
be dropped, it's
- // guaranteed that we have enough space
in the buffer now.
- ring_buffer_write(sSyslogBuffer,
(uint8*)"<DROP>", 6);
- sSyslogDropped = false;
- }

- release_spinlock(&sSpinlock);
- restore_interrupts(state);
- }
+ release_spinlock(&sSpinlock);
+ restore_interrupts(state);
+ }

- if (length == 0) {
- // the buffer we came here for might have been
sent already
- bufferPending = false;
- continue;
- }
+ if (length == 0) {
+ // The buffer we came here for might have been sent
already
+ bufferPending = false;
+ continue;
+ }

- error = write_port_etc(port, SYSLOG_MESSAGE,
sSyslogMessage,
- sizeof(struct syslog_message) + length,
B_RELATIVE_TIMEOUT, 0);
+ status_t status = write_port_etc(sSyslogPort, SYSLOG_MESSAGE,
+ sSyslogMessage, sizeof(struct syslog_message) + length,
+ B_RELATIVE_TIMEOUT, 0);
+ if (status == B_BAD_PORT_ID) {
+ // The port is gone, there is no need to run anymore
+ sSyslogWriter = -1;
+ return status;
+ }

- if (error < B_OK) {
- // sending has failed - just wait, maybe it'll
work later.
- bufferPending = true;
- continue;
- }
+ if (status != B_OK) {
+ // Sending has failed - just wait, maybe it'll work
later.
+ bufferPending = true;
+ continue;
+ }

- if (bufferPending) {
- // we could write the last pending buffer, try
to read more
- // from the syslog ring buffer
- release_sem_etc(sSyslogNotify, 1,
B_DO_NOT_RESCHEDULE);
- bufferPending = false;
- }
+ if (bufferPending) {
+ // We could write the last pending buffer, try to read
more
+ // from the syslog ring buffer
+ release_sem_etc(sSyslogNotify, 1, B_DO_NOT_RESCHEDULE);
+ bufferPending = false;
}
}

@@ -1318,12 +1305,8 @@ syslog_init_post_threads(void)
return B_OK;

sSyslogNotify = create_sem(0, "syslog data");
- if (sSyslogNotify >= B_OK) {
- thread_id thread = spawn_kernel_thread(syslog_sender, "syslog
sender",
- B_LOW_PRIORITY, NULL);
- if (thread >= B_OK && resume_thread(thread) == B_OK)
- return B_OK;
- }
+ if (sSyslogNotify >= 0)
+ return B_OK;

// initializing kernel syslog service failed -- disable it

@@ -2275,18 +2258,17 @@ debug_is_debugged_team(team_id teamID)


status_t
-_user_kernel_debugger(const char *userMessage)
+_user_kernel_debugger(const char* userMessage)
{
if (geteuid() != 0)
return B_NOT_ALLOWED;

char message[512];
strcpy(message, "USER: ");
- size_t len = strlen(message);
+ size_t length = strlen(message);

- if (userMessage == NULL || !IS_USER_ADDRESS(userMessage)
- || user_strlcpy(message + len, userMessage,
sizeof(message) - len)
- < 0) {
+ if (userMessage == NULL || !IS_USER_ADDRESS(userMessage) ||
user_strlcpy(
+ message + length, userMessage, sizeof(message) -
length) < 0) {
return B_BAD_ADDRESS;
}

@@ -2296,6 +2278,23 @@ _user_kernel_debugger(const char *userMessage)


void
+_user_register_syslog_daemon(port_id port)
+{
+ if (geteuid() != 0 || !sSyslogOutputEnabled || sSyslogNotify < 0)
+ return;
+
+ sSyslogPort = port;
+
+ if (sSyslogWriter < 0) {
+ sSyslogWriter = spawn_kernel_thread(syslog_sender, "syslog
sender",
+ B_LOW_PRIORITY, NULL);
+ if (sSyslogWriter >= 0)
+ resume_thread(sSyslogWriter);
+ }
+}
+
+
+void
_user_debug_output(const char* userString)
{
if (!sSerialDebugEnabled && !sSyslogOutputEnabled)
diff --git a/src/system/libroot/posix/syslog.cpp
b/src/system/libroot/posix/syslog.cpp
index 97d5b3c..71482c6 100644
--- a/src/system/libroot/posix/syslog.cpp
+++ b/src/system/libroot/posix/syslog.cpp
@@ -1,18 +1,21 @@
/*
- * Copyright 2003-2008, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Copyright 2003-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
* Distributed under the terms of the MIT License.
*/


-#include <syslog_daemon.h>
-#include <TLS.h>
-
#include <syslog.h>
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

+#include <launch.h>
+#include <syslog_daemon.h>
+#include <TLS.h>
+#include <util/KMessage.h>
+

struct syslog_context {
char ident[B_OS_NAME_LENGTH];
@@ -28,6 +31,7 @@ static syslog_context sTeamContext = {
LOG_CONS
};
static int32 sThreadContextSlot = -1;
+static port_id sSystemLoggerPort = -1;


static syslog_context *
@@ -102,6 +106,22 @@ message_to_console(syslog_context *context, const char
*text, va_list args)
}


+/*! Retrieves the port of the system logger from the launch_daemon.
+*/
+static port_id
+get_system_logger_port()
+{
+ if (sSystemLoggerPort >= 0)
+ return sSystemLoggerPort;
+
+ BPrivate::KMessage data;
+ if (BPrivate::get_launch_data(B_SYSTEM_LOGGER_SIGNATURE, data) == B_OK)
+ sSystemLoggerPort = data.GetInt32("logger_port", -1);
+
+ return sSystemLoggerPort;
+}
+
+
/*! Creates the message from the given context and sends it to the syslog
daemon, if the priority mask matches.
If the message couldn't be delivered, and LOG_CONS was set, it will
@@ -117,7 +137,7 @@ send_syslog_message(syslog_context *context, int priority,
const char *text,
if ((context->mask & LOG_MASK(SYSLOG_PRIORITY(priority))) == 0)
return;

- port_id port = find_port(SYSLOG_PORT_NAME);
+ port_id port = get_system_logger_port();
if ((options & LOG_PERROR) != 0
|| ((options & LOG_CONS) != 0 && port < B_OK)) {
// if asked for, print out the (simplified) message on stderr
diff --git a/src/tests/system/libroot/posix/Jamfile
b/src/tests/system/libroot/posix/Jamfile
index f93588e..92b09df 100644
--- a/src/tests/system/libroot/posix/Jamfile
+++ b/src/tests/system/libroot/posix/Jamfile
@@ -1,15 +1,12 @@
SubDir HAIKU_TOP src tests system libroot posix ;

-UsePrivateHeaders libroot syslog_daemon ;
-
-
# filter warnings about strftime()-formats in locale_test
TARGET_WARNING_C++FLAGS_$(TARGET_PACKAGING_ARCH)
on [ FGristFiles locale_test.o ] += -Wno-format ;

# POSIX/libc tests
SimpleTest abort_test : abort_test.cpp ;
-SimpleTest SyslogTest : SyslogTest.cpp syslog.cpp ;
+SimpleTest SyslogTest : SyslogTest.cpp ;
SimpleTest clearenv : clearenv.cpp ;
SimpleTest dirent_test : dirent_test.cpp ;
SimpleTest flock_test : flock_test.cpp ;
@@ -72,10 +69,5 @@ SimpleTest test_wctype : test_wctype.c ;
SimpleTest wcs_test : wcs_test.cpp ;


-# Tell Jam where to find these sources
-SEARCH on [ FGristFiles
- syslog.cpp
- ] = [ FDirName $(HAIKU_TOP) src system libroot posix ] ;
-
SubInclude HAIKU_TOP src tests system libroot posix math ;
SubInclude HAIKU_TOP src tests system libroot posix string ;
diff --git a/src/tests/system/libroot/posix/SyslogTest.cpp
b/src/tests/system/libroot/posix/SyslogTest.cpp
index 616126e..6c74c7b 100644
--- a/src/tests/system/libroot/posix/SyslogTest.cpp
+++ b/src/tests/system/libroot/posix/SyslogTest.cpp
@@ -1,27 +1,20 @@
-/*
-** Copyright 2003, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. All rights reserved.
-** Distributed under the terms of the OpenBeOS License.
-*/
+/*
+ * Copyright 2003-2015, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
+ * Distributed under the terms of the MIT License.
+ */


-#include <syslog_daemon.h>
-#include <OS.h>
-
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>


-int
+int
main(int argc, char **argv)
{
- port_id port = find_port(SYSLOG_PORT_NAME);
- if (port < B_OK)
- fprintf(stderr, "The (new) syslog_daemon should be running!\n");
-
openlog_team("SyslogTest", LOG_PID, LOG_USER);
-
+
log_team(LOG_ERR, "this is %.", "a test");

int mask = setlogmask_team(LOG_MASK(LOG_CRIT));

############################################################################

Commit: a1b3ae48e3416910d55f995673955dba078f8386
Author: Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date: Tue Apr 21 16:52:13 2015 UTC

BMessage: WIP of reply with KMessage support.

* Doesn't yet work, not is it complete.

----------------------------------------------------------------------------

diff --git a/headers/build/private/app/MessagePrivate.h
b/headers/build/private/app/MessagePrivate.h
index 7fe1227..e634dd8 100644
--- a/headers/build/private/app/MessagePrivate.h
+++ b/headers/build/private/app/MessagePrivate.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2009, Haiku Inc. All rights reserved.
+ * Copyright 2005-2015, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -8,6 +8,7 @@
#ifndef _MESSAGE_PRIVATE_H_
#define _MESSAGE_PRIVATE_H_

+
#include <Message.h>
#include <Messenger.h>
#include <MessengerPrivate.h>
@@ -30,7 +31,8 @@ enum {
MESSAGE_FLAG_WAS_DELIVERED = 0x0010,
MESSAGE_FLAG_HAS_SPECIFIERS = 0x0020,
MESSAGE_FLAG_WAS_DROPPED = 0x0040,
- MESSAGE_FLAG_PASS_BY_AREA = 0x0080
+ MESSAGE_FLAG_PASS_BY_AREA = 0x0080,
+ MESSAGE_FLAG_REPLY_AS_KMESSAGE = 0x0100
};


diff --git a/headers/private/app/MessagePrivate.h
b/headers/private/app/MessagePrivate.h
index dc749a0..9e6a611 100644
--- a/headers/private/app/MessagePrivate.h
+++ b/headers/private/app/MessagePrivate.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2010, Haiku Inc. All rights reserved.
+ * Copyright 2005-2015, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -8,6 +8,7 @@
#ifndef _MESSAGE_PRIVATE_H_
#define _MESSAGE_PRIVATE_H_

+
#include <Message.h>
#include <Messenger.h>
#include <MessengerPrivate.h>
@@ -30,7 +31,8 @@ enum {
MESSAGE_FLAG_WAS_DELIVERED = 0x0010,
MESSAGE_FLAG_HAS_SPECIFIERS = 0x0020,
MESSAGE_FLAG_WAS_DROPPED = 0x0040,
- MESSAGE_FLAG_PASS_BY_AREA = 0x0080
+ MESSAGE_FLAG_PASS_BY_AREA = 0x0080,
+ MESSAGE_FLAG_REPLY_AS_KMESSAGE = 0x0100
};


diff --git a/src/kits/app/Message.cpp b/src/kits/app/Message.cpp
index 2b14449..1062c12 100644
--- a/src/kits/app/Message.cpp
+++ b/src/kits/app/Message.cpp
@@ -913,6 +913,8 @@ BMessage::SendReply(BMessage* reply, BMessenger replyTo,
bigtime_t timeout)
BMessenger::Private messengerPrivate(messenger);
messengerPrivate.SetTo(fHeader->reply_team, fHeader->reply_port,
fHeader->reply_target);
+ if ((fHeader->flags & MESSAGE_FLAG_REPLY_AS_KMESSAGE) != 0)
+ reply->fHeader->flags |= MESSAGE_FLAG_REPLY_AS_KMESSAGE;

if ((fHeader->flags & MESSAGE_FLAG_REPLY_REQUIRED) != 0) {
if ((fHeader->flags & MESSAGE_FLAG_REPLY_DONE) != 0)
@@ -923,11 +925,9 @@ BMessage::SendReply(BMessage* reply, BMessenger replyTo,
bigtime_t timeout)
status_t result = messenger.SendMessage(reply, replyTo,
timeout);
reply->fHeader->flags &= ~MESSAGE_FLAG_IS_REPLY;

- if (result != B_OK) {
- if (set_port_owner(messengerPrivate.Port(),
+ if (result != B_OK && set_port_owner(messengerPrivate.Port(),
messengerPrivate.Team()) == B_BAD_TEAM_ID) {
- delete_port(messengerPrivate.Port());
- }
+ delete_port(messengerPrivate.Port());
}

return result;
@@ -2164,6 +2164,9 @@ BMessage::_SendMessage(port_id port, team_id portOwner,
int32 token,
header->message_area = transfered;
}
#endif
+ } else if ((fHeader->flags & MESSAGE_FLAG_REPLY_AS_KMESSAGE) != 0) {
+ printf("kmessage reply!\n");
+ return B_ERROR;
} else {
size = FlattenedSize();
buffer = (char*)malloc(size);
diff --git a/src/kits/app/MessageAdapter.cpp b/src/kits/app/MessageAdapter.cpp
index 7e2c5e4..3cdc670 100644
--- a/src/kits/app/MessageAdapter.cpp
+++ b/src/kits/app/MessageAdapter.cpp
@@ -1,11 +1,13 @@
/*
- * Copyright 2005-2007, Haiku Inc. All rights reserved.
+ * Copyright 2005-2015, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
* Michael Lotz <mmlr@xxxxxxxx>
*/
+
+
#include <MessageAdapter.h>
#include <MessagePrivate.h>
#include <MessageUtils.h>
@@ -252,6 +254,7 @@ MessageAdapter::_ConvertKMessage(const KMessage
*fromMessage,
toPrivate.SetTarget(fromMessage->TargetToken());
toPrivate.SetReply(B_SYSTEM_TEAM, fromMessage->ReplyPort(),
fromMessage->ReplyToken());
+ toPrivate.GetMessageHeader()->flags |= MESSAGE_FLAG_REPLY_AS_KMESSAGE;

// iterate through the fields and import them in the target message
KMessageField field;


Other related posts:

  • » [haiku-commits] BRANCH axeld-github.launch_daemon [a1b3ae48e341] src/system/kernel/debug src/servers/launch src/kits/app headers/private src/system/libroot/os - axeld-github . launch_daemon