Paste P557

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Mar 16 2020, 4:28 PM.
diff --git a/src/launch/launcher.c b/src/launch/launcher.c
index b1d4e60..5696a03 100644
--- a/src/launch/launcher.c
+++ b/src/launch/launcher.c
@@ -588,8 +588,8 @@ static int launcher_load_service_file(Launcher *launcher, const char *path, cons
_c_cleanup_(c_ini_group_unrefp) CIniGroup *group = NULL;
_c_cleanup_(c_freep) char **argv = NULL;
_c_cleanup_(service_freep) Service *service = NULL;
- CIniEntry *name_entry = NULL, *unit_entry = NULL, *exec_entry = NULL, *user_entry = NULL;
- const char *name = NULL, *unit = NULL, *exec = NULL, *user = NULL;
+ CIniEntry *name_entry = NULL, *unit_entry = NULL, *transient_service_name_entry = NULL, *exec_entry = NULL, *user_entry = NULL;
+ const char *name = NULL, *unit = NULL, *transient_service_name = NULL, *exec = NULL, *user = NULL;
size_t argc = 0, n_exec, n_name;
CRBNode **slot, *parent;
uid_t uid;
@@ -601,6 +601,7 @@ static int launcher_load_service_file(Launcher *launcher, const char *path, cons
name_entry = c_ini_group_find(group, "Name", -1);
unit_entry = c_ini_group_find(group, "SystemdService", -1);
+ transient_service_name_entry = c_ini_group_find(group, "SystemdTransientService", -1);
exec_entry = c_ini_group_find(group, "Exec", -1);
user_entry = c_ini_group_find(group, "User", -1);
@@ -653,6 +654,10 @@ static int launcher_load_service_file(Launcher *launcher, const char *path, cons
if (unit_entry)
unit = c_ini_entry_get_value(unit_entry, NULL);
+ if (transient_service_name_entry)
+ transient_service_name = c_ini_entry_get_value(transient_service_name_entry, NULL);
+
+
if (exec_entry) {
exec = c_ini_entry_get_value(exec_entry, &n_exec);
@@ -699,7 +704,7 @@ static int launcher_load_service_file(Launcher *launcher, const char *path, cons
slot = c_rbtree_find_slot(&launcher->services_by_name, service_compare_by_name, name, &parent);
if (slot) {
- r = service_new(&service, launcher, name, slot, parent, path, unit, argc, argv, user, uid);
+ r = service_new(&service, launcher, name, slot, parent, path, unit, transient_service_name, argc, argv, user, uid);
if (r)
return error_trace(r);
@@ -709,7 +714,7 @@ static int launcher_load_service_file(Launcher *launcher, const char *path, cons
if (!old_service->reload_tag) {
old_service->reload_tag = true;
- r = service_update(old_service, path, unit, argc, argv, user, uid);
+ r = service_update(old_service, path, unit, transient_service_name, argc, argv, user, uid);
if (r)
return error_trace(r);
} else {
diff --git a/src/launch/service.c b/src/launch/service.c
index 1dbf72b..eaeaab3 100644
--- a/src/launch/service.c
+++ b/src/launch/service.c
@@ -92,9 +92,10 @@ Service *service_free(Service *service) {
return NULL;
}
-int service_update(Service *service, const char *path, const char *unit, size_t argc, char **argv, const char *user, uid_t uid) {
+int service_update(Service *service, const char *path, const char *unit, const char *transient_service_name, size_t argc, char **argv, const char *user, uid_t uid) {
service->path = c_free(service->path);
service->unit = c_free(service->unit);
+ service->transient_service_name = c_free(service->transient_service_name);
service->argc = 0;
service->argv = c_free(service->argv);
service->user = c_free(service->user);
@@ -112,6 +113,13 @@ int service_update(Service *service, const char *path, const char *unit, size_t
return error_origin(-ENOMEM);
}
+ if (transient_service_name) {
+ service->transient_service_name = strdup(transient_service_name);
+ if (!service->transient_service_name)
+ return error_origin(-ENOMEM);
+ }
+
+
if (argc > 0) {
service->argv = calloc(1, argc * sizeof(char*));
if (!service->argv)
@@ -142,6 +150,7 @@ int service_new(Service **servicep,
CRBNode *parent_by_name,
const char *path,
const char *unit,
+ const char *transient_service_name,
size_t argc,
char **argv,
const char *user,
@@ -163,7 +172,7 @@ int service_new(Service **servicep,
if (!service->name)
return error_origin(-ENOMEM);
- r = service_update(service, path, unit, argc, argv, user, uid);
+ r = service_update(service, path, unit, transient_service_name, argc, argv, user, uid);
if (r)
return error_trace(r);
@@ -324,7 +333,12 @@ static int service_start_transient_unit(Service *service) {
if (r < 0)
return error_origin(r);
- r = asprintf(&unit, "dbus-%s-%s@%"PRIu64".service", unique_name, service->name, service->instance++);
+ static int rnd = 0;
+
+ if (service->transient_service_name)
+ r = asprintf(&unit, "%s-%d.service", service->transient_service_name, rnd++);
+ else
+ r = asprintf(&unit, "dbus-%s-%s@%"PRIu64".service", unique_name, service->name, service->instance++);
if (r < 0)
return error_origin(-errno);
diff --git a/src/launch/service.h b/src/launch/service.h
index 0337e21..9e628ca 100644
--- a/src/launch/service.h
+++ b/src/launch/service.h
@@ -23,6 +23,7 @@ struct Service {
char *path;
char *name;
char *unit;
+ char *transient_service_name;
size_t argc;
char **argv;
char *user;
@@ -40,6 +41,7 @@ int service_new(Service **servicep,
CRBNode *parent_by_name,
const char *path,
const char *unit,
+ const char *transient_service_name,
size_t argc,
char **argv,
const char *user,
@@ -48,7 +50,7 @@ Service *service_free(Service *service);
C_DEFINE_CLEANUP(Service *, service_free);
-int service_update(Service *service, const char *path, const char *unit, size_t argc, char **argv, const char *user, uid_t uid);
+int service_update(Service *service, const char *path, const char *unit, const char *transient_service_name, size_t argc, char **argv, const char *user, uid_t uid);
int service_compare(CRBTree *t, void *k, CRBNode *n);
int service_compare_by_name(CRBTree *t, void *k, CRBNode *n);
davidedmundson edited the content of this paste. (Show Details)Mar 16 2020, 4:28 PM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.