From b64ed295c29c884d06ff9c0024b4d424ff6ad5ee Mon Sep 17 00:00:00 2001 From: cheng_jinsong Date: Tue, 23 Aug 2022 16:33:23 +0800 Subject: [PATCH] fix bug for kill appspawn Signed-off-by: cheng_jinsong --- services/init/include/init_service_manager.h | 1 + services/init/init_common_cmds.c | 2 +- services/init/init_common_service.c | 2 +- services/init/init_service_manager.c | 8 ++++++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/services/init/include/init_service_manager.h b/services/init/include/init_service_manager.h index cc70b389..a007e772 100644 --- a/services/init/include/init_service_manager.h +++ b/services/init/include/init_service_manager.h @@ -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 } diff --git a/services/init/init_common_cmds.c b/services/init/init_common_cmds.c index 3ec6bd02..abbc9b15 100644 --- a/services/init/init_common_cmds.c +++ b/services/init/init_common_cmds.c @@ -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; } diff --git a/services/init/init_common_service.c b/services/init/init_common_service.c index fbc348d2..29a80293 100644 --- a/services/init/init_common_service.c +++ b/services/init/init_common_service.c @@ -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); diff --git a/services/init/init_service_manager.c b/services/init/init_service_manager.c index 47d53e1d..723f1f6b 100755 --- a/services/init/init_service_manager.c +++ b/services/init/init_service_manager.c @@ -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; +} \ No newline at end of file -- GitLab