-
-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a dbus service name as its app_id #921
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,40 @@ _xdp_parse_app_id_from_unit_name (const char *unit) | |
|
||
return g_steal_pointer (&app_id); | ||
} | ||
|
||
char * | ||
_xdp_parse_app_id_from_dbus_name (const char *unit) | ||
{ | ||
g_autoptr(GRegex) regex = NULL; | ||
g_autoptr(GMatchInfo) match = NULL; | ||
g_autoptr(GError) error = NULL; | ||
g_autofree char *app_id = NULL; | ||
|
||
g_assert (g_str_has_prefix (unit, "dbus-")); | ||
|
||
// Parses a unit name such as dbus-:1.2-org.kde.kdeconnect@7.service | ||
regex = g_regex_new ("^dbus-:[[:digit:]]+\\.[[:digit:]]+-" | ||
"(.+?\\..+?\\..+?)(?:[@\\-][[:alnum:]]*)\\.service$", | ||
0, 0, &error); | ||
g_assert (error == NULL); | ||
if (g_regex_match (regex, unit, 0, &match)) | ||
{ | ||
const char *escaped_app_id; | ||
/* Unescape the unit name which may have \x hex codes in it, e.g. | ||
* "app-gnome-org.gnome.Evolution\x2dalarm\x2dnotify-2437.scope" | ||
*/ | ||
escaped_app_id = g_match_info_fetch (match, 1); | ||
if (cunescape (escaped_app_id, UNESCAPE_RELAX, &app_id) < 0) | ||
app_id = g_strdup (""); | ||
} | ||
else | ||
{ | ||
g_warning("Failed to parse dbus name %s", unit); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will warn on some entirely legitimate unit names. There is a weak convention that a D-Bus service with I don't know of any concrete examples of user services (session bus services) doing this, but systemd's own |
||
app_id = g_strdup (""); | ||
} | ||
|
||
return g_steal_pointer (&app_id); | ||
} | ||
#endif /* HAVE_LIBSYSTEMD */ | ||
|
||
void | ||
|
@@ -206,13 +240,23 @@ set_appid_from_pid (XdpAppInfo *app_info, pid_t pid) | |
* fetching our own systemd units or the unit might not be started by the | ||
* desktop environment (e.g. it's a script run from terminal). | ||
*/ | ||
if (res == -ENODATA || res < 0 || !unit || !g_str_has_prefix (unit, "app-")) | ||
if (res == -ENODATA || res < 0 || !unit) | ||
{ | ||
app_info->id = g_strdup (""); | ||
return; | ||
} | ||
|
||
app_info->id = _xdp_parse_app_id_from_unit_name (unit); | ||
if (g_str_has_prefix (unit, "app-")) | ||
{ | ||
app_info->id = _xdp_parse_app_id_from_unit_name (unit); | ||
} | ||
else if (g_str_has_prefix (unit, "dbus-")) | ||
{ | ||
app_info->id = _xdp_parse_app_id_from_dbus_name (unit); | ||
} | ||
else | ||
{ | ||
app_info->id = g_strdup (""); | ||
} | ||
g_debug ("Assigning app ID \"%s\" to pid %ld which has unit \"%s\"", | ||
app_info->id, (long) pid, unit); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This naming convention for systemd units is specific to dbus-broker.
On systems that have systemd activation available, the reference implementation (dbus-daemon) does not guarantee that activated services are in any sort of systemd service or scope: D-Bus services with
SystemdService=foo.service
are run asfoo.service
(probably also true for dbus-broker), and D-Bus services withoutSystemdService
are run via "traditional activation", mechanically the same as what happens on non-systemd systems like *BSD or Devuan, so they end up as child processes indbus.service
(this behaviour is unlike dbus-broker).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having said that, if a unit name matches this pattern then you can probably be quite confident that it's named according to how dbus-broker does it.