X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-unit.c;h=856be46815c6961fd182b0413f71b2bf98a40244;hb=f551ac4966543b360e3458a61615626d71f55a6e;hp=232c4eedec7dbf30762d808a0801029617d37d56;hpb=d23600fbaf5abf4d584d58ff2664fa041e51f259;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-unit.c b/src/wgtpkg-unit.c index 232c4ee..856be46 100644 --- a/src/wgtpkg-unit.c +++ b/src/wgtpkg-unit.c @@ -249,7 +249,7 @@ static int process_one_unit(char *spec, struct unitdesc *desc) * with its given 'closure' and the array descripbing the units. * Return 0 in case of success or a negative value in case of error. */ -static int process_all_units(char *corpus, const struct unitconf *conf, int (*process)(void *closure, const struct generatedesc *desc), void *closure) +static int process_all_units(char *corpus, const struct unitconf *conf, int (*process)(void *closure, const struct generatedesc *desc), void *closure, struct json_object *jdesc) { int rc, rc2; char *beg, *end, *befbeg, *aftend; @@ -257,6 +257,7 @@ static int process_all_units(char *corpus, const struct unitconf *conf, int (*pr struct generatedesc gdesc; gdesc.conf = conf; + gdesc.desc = jdesc; gdesc.units = NULL; gdesc.nunits = 0; rc = rc2 = 0; @@ -343,7 +344,7 @@ static int process_all_units(char *corpus, const struct unitconf *conf, int (*pr /* * Clear the unit generator */ -void unit_generator_off() +void unit_generator_close_template() { free(template); template = NULL; @@ -353,13 +354,13 @@ void unit_generator_off() * Initialises the unit generator with the content of the file of path 'filename'. * Returns 0 in case of success or a negative number in case of error. */ -int unit_generator_on(const char *filename) +int unit_generator_open_template(const char *filename) { size_t size; char *tmp; int rc; - unit_generator_off(); + unit_generator_close_template(); rc = getfile(filename ? : FWK_UNIT_CONF, &template, NULL); if (!rc) { size = pack(template, ';'); @@ -387,7 +388,7 @@ static int add_metadata(struct json_object *jdesc, const struct unitconf *conf) * Applies the object 'jdesc' augmented of meta data coming * from 'conf' to the current unit generator. * The current unit generator will be set to the default one if not unit - * was previously set using the function 'unit_generator_on'. + * was previously set using the function 'unit_generator_open_template'. * The callback function 'process' is then called with the * unit descriptors array and the expected closure. * Return what returned process in case of success or a negative @@ -403,12 +404,12 @@ int unit_generator_process(struct json_object *jdesc, const struct unitconf *con if (rc) ERROR("can't set the metadata. %m"); else { - rc = template ? 0 : unit_generator_on(NULL); + rc = template ? 0 : unit_generator_open_template(NULL); if (!rc) { instance = NULL; rc = apply_mustach(template, jdesc, &instance, &size); if (!rc) - rc = process_all_units(instance, conf, process, closure); + rc = process_all_units(instance, conf, process, closure, jdesc); free(instance); } } @@ -470,36 +471,6 @@ static int get_wants_target(char *path, size_t pathlen, const struct unitdesc *d return rc; } -static int do_send_reload(const struct generatedesc *desc) -{ - int i; - int reloadsys, reloadusr; - const struct unitdesc *u; - - reloadsys = reloadusr = 0; - for (i = 0 ; i < desc->nunits ; i++) { - u = &desc->units[i]; - if (u->wanted_by != NULL) { - switch (u->scope) { - case unitscope_user: - reloadusr = 1; - break; - case unitscope_system: - reloadsys = 1; - break; - default: - break; - } - } - } - - if (reloadusr) - reloadusr = systemd_daemon_reload(1); - if (reloadsys) - reloadsys = systemd_daemon_reload(0); - return reloadsys ? : reloadusr ? : 0; -} - static int do_uninstall_units(void *closure, const struct generatedesc *desc) { int rc, rc2; @@ -527,9 +498,6 @@ static int do_uninstall_units(void *closure, const struct generatedesc *desc) if (rc2 < 0 && rc == 0) rc = rc2; } - rc2 = do_send_reload(desc); - if (rc2 < 0 && rc == 0) - rc = rc2; return rc; } @@ -564,9 +532,6 @@ static int do_install_units(void *closure, const struct generatedesc *desc) if (rc < 0) goto error; } - rc = do_send_reload(desc); - if (rc < 0) - goto error; return 0; error: i = errno;