X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafm-urun.c;h=0249a6077dcc13fc0081b678eb4602ba645379ab;hb=b13e73d8452f5e40a8465b37b22e8a299fb036ae;hp=b6418ac16714b69cf5a91e94add0a8b5bd2e8d42;hpb=dd87fc32c026b4fba9b13ab52f032e3b403b04bf;p=src%2Fapp-framework-main.git diff --git a/src/afm-urun.c b/src/afm-urun.c index b6418ac..0249a60 100644 --- a/src/afm-urun.c +++ b/src/afm-urun.c @@ -1,5 +1,5 @@ /* - Copyright 2015, 2016, 2017 IoT.bzh + Copyright (C) 2015-2018 IoT.bzh author: José Bollo @@ -110,9 +110,9 @@ static int get_basis(struct json_object *appli, int *isuser, const char **dpath, /* get dpath of userid */ nun = alloca((size_t)(arodot - uname) + strlen(userid) + strlen(arodot) + 1); stpcpy(stpcpy(stpncpy(nun, uname, (size_t)(arodot - uname)), userid), arodot); - dp = systemd_unit_dpath_by_name(*isuser, uname, 1); + dp = systemd_unit_dpath_by_name(*isuser, nun, 1); if (dp == NULL) { - ERROR("Can't load unit of name %s for %s: %m", uname, uscope); + ERROR("Can't load unit of name %s for %s: %m", nun, uscope); goto error; } /* record the dpath */ @@ -255,7 +255,7 @@ int afm_urun_once(struct json_object *appli, int uid) if (rc < 0) { j_read_string_at(appli, "unit-scope", &uscope); j_read_string_at(appli, "unit-name", &uname); - ERROR("can't start %s unit %s", uscope, uname); + ERROR("can't start %s unit %s for uid %d", uscope, uname, uid); goto error; } @@ -263,13 +263,13 @@ int afm_urun_once(struct json_object *appli, int uid) if (state == NULL) { j_read_string_at(appli, "unit-scope", &uscope); j_read_string_at(appli, "unit-name", &uname); - ERROR("can't wait %s unit %s: %m", uscope, uname); + ERROR("can't wait %s unit %s for uid %d: %m", uscope, uname, uid); goto error; } if (state != SysD_State_Active) { j_read_string_at(appli, "unit-scope", &uscope); j_read_string_at(appli, "unit-name", &uname); - ERROR("start error %s unit %s: %s", uscope, uname, state); + ERROR("start error %s unit %s for uid %d: %s", uscope, uname, uid, state); goto error; } @@ -277,7 +277,7 @@ int afm_urun_once(struct json_object *appli, int uid) if (rc < 0) { j_read_string_at(appli, "unit-scope", &uscope); j_read_string_at(appli, "unit-name", &uname); - ERROR("can't getpid of %s unit %s: %m", uscope, uname); + ERROR("can't getpid of %s unit %s for uid %d: %m", uscope, uname, uid); goto error; } @@ -424,3 +424,26 @@ end: return result; } +/* + * Search the runid, if any, of the application of 'id' for the user 'uid'. + * Returns the pid (a positive not null number) or -1 in case of error. + */ +int afm_urun_search_runid(struct afm_udb *db, const char *id, int uid) +{ + int isuser, pid; + const char *udpath; + struct json_object *appli; + + appli = afm_udb_get_application_private(db, id, uid); + if (!appli) { + NOTICE("Unknown appid %s", id); + errno = ENOENT; + pid = -1; + } else if (get_basis(appli, &isuser, &udpath, 0, uid) < 0) { + pid = -1; + } else { + pid = systemd_unit_pid_of_dpath(isuser, udpath); + } + return pid; +} +