X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-udb.c;h=80cc7158f1dc0418d673ea79a9270993cb0dbdd6;hb=f551ac4966543b360e3458a61615626d71f55a6e;hp=e3d5d77a44f6d7dd910ea89f4b7a7c4319d7b165;hpb=f2580ca3a5ec951216fe7cb2c092b13e8ffbdbe4;p=src%2Fapp-framework-main.git diff --git a/src/afm-udb.c b/src/afm-udb.c index e3d5d77..80cc715 100644 --- a/src/afm-udb.c +++ b/src/afm-udb.c @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -33,7 +34,6 @@ #include "afm-udb.h" - static const char x_afm_prefix[] = "X-AFM-"; static const char service_extension[] = ".service"; static const char key_unit_path[] = "-unit-path"; @@ -224,6 +224,8 @@ static int addunit( { struct json_object *priv, *pub, *id; const char *strid; + char *un = NULL; + size_t len; /* create the application structure */ priv = json_object_new_object(); @@ -234,12 +236,30 @@ static int addunit( if (!pub) goto error; + /* make the unit name */ + len = strlen(unitname); + assert(len >= (sizeof service_extension - 1)); + assert(!memcmp(&unitname[len - (sizeof service_extension - 1)], service_extension, sizeof service_extension)); + if (unitname[len - sizeof service_extension] == '@') { + char buffer[40]; + size_t l = (size_t)snprintf(buffer, sizeof buffer, "%d", (int)getuid()); + un = malloc(len + l + 1); + if (!un) + goto error; + memcpy(&un[0], unitname, len - (sizeof service_extension - 1)); + if (l) + memcpy(&un[len - (sizeof service_extension - 1)], buffer, l); + memcpy(&un[len - (sizeof service_extension - 1) + l], service_extension, sizeof service_extension); + } + /* adds the values */ if (add_fields_of_content(priv, pub, content, length) || add_field(priv, pub, key_unit_path, unitpath) - || add_field(priv, pub, key_unit_name, unitname) + || add_field(priv, pub, key_unit_name, un ? : unitname) || add_field(priv, pub, key_unit_scope, isuser ? scope_user : scope_system)) goto error; + free(un); + un = NULL; /* get the id */ if (!json_object_object_get_ex(pub, key_id, &id)) { @@ -258,6 +278,7 @@ static int addunit( return 0; error: + free(un); json_object_put(pub); json_object_put(priv); return -1; @@ -345,12 +366,14 @@ static int update_cb(void *closure, const char *name, const char *path, int isus /* reads the file */ rc = read_unit_file(path, &content, &length); if (rc < 0) - return rc; + return 0; /* process the file */ rc = addunit(&updt->applications, isuser, path, name, content, length); + /* TODO: if (rc < 0) + ERROR("Ignored boggus unit %s (error: %m)", path); */ free(content); - return rc; + return 0; } /*