!1119 fix:kill appspawn

Merge pull request !1119 from cheng_jinsong/killappspawn
This commit is contained in:
openharmony_ci 2022-08-24 08:58:26 +00:00 committed by Gitee
commit 91ca5757f8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 11 additions and 2 deletions

View File

@ -63,6 +63,7 @@ void LoadAccessTokenId(void);
Service *AddService(const char *name);
void DumpServiceHookExecute(const char *name, const char *info);
void ProcessControlFd(uint16_t type, const char *serviceCmd, const void *context);
int GetKillServiceSig(const char *name);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -219,7 +219,7 @@ static void DoReset(const struct CmdArgs *ctx)
return;
}
if (service->pid > 0) {
if (kill(service->pid, SIGKILL) != 0) {
if (kill(service->pid, GetKillServiceSig(ctx->argv[0])) != 0) {
INIT_LOGE("stop service %s pid %d failed! err %d.", service->name, service->pid, errno);
return;
}

View File

@ -432,7 +432,7 @@ int ServiceStop(Service *service)
if (IsServiceWithTimerEnabled(service)) {
ServiceStopTimer(service);
}
INIT_ERROR_CHECK(kill(service->pid, SIGKILL) == 0, return SERVICE_FAILURE,
INIT_ERROR_CHECK(kill(service->pid, GetKillServiceSig(service->name)) == 0, return SERVICE_FAILURE,
"stop service %s pid %d failed! err %d.", service->name, service->pid, errno);
NotifyServiceChange(service, SERVICE_STOPPING);
INIT_LOGI("stop service %s, pid %d.", service->name, service->pid);

View File

@ -1091,3 +1091,11 @@ void LoadAccessTokenId(void)
{
GetAccessToken();
}
int GetKillServiceSig(const char *name)
{
if (strcmp(name, "appspawn") == 0 || strcmp(name, "nwebspawn") == 0) {
return SIGTERM;
}
return SIGKILL;
}