提交 ba65620e 编写于 作者: C changcheng-weng 提交者: Gitee

update src/appspawn_process.c.

上级 9dbe284f
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "ability_main.h"
#include "appspawn_adapter.h" #include "appspawn_adapter.h"
#include "log.h" #include "log.h"
#include "securec.h" #include "securec.h"
...@@ -31,17 +32,12 @@ extern "C" { ...@@ -31,17 +32,12 @@ extern "C" {
#define DEFAULT_UMASK 022 #define DEFAULT_UMASK 022
#define CAP_NUM 2 #define CAP_NUM 2
#define ABILITY_EXE_FILE_FULL_PATH "/bin/abilityMain"
#define ABILITY_EXE_FILE_NAME "abilityMain"
#define ENV_TITLE "LD_LIBRARY_PATH=" #define ENV_TITLE "LD_LIBRARY_PATH="
#define UPPER_BOUND_GID 999 #define UPPER_BOUND_GID 999
#define LOWER_BOUND_GID 100 #define LOWER_BOUND_GID 100
#define GRP_NUM 2 #define GRP_NUM 2
#define DEVMGR_GRP 99 #define DEVMGR_GRP 99
static const unsigned int MAX_IDENTITY_ID_LENGTH = 25;
static const unsigned int MAX_PROCESS_NAME_LENGTH = 130;
static int SetPerms(uid_t uID, gid_t gID) static int SetPerms(uid_t uID, gid_t gID)
{ {
gid_t groups[GRP_NUM]; gid_t groups[GRP_NUM];
...@@ -118,35 +114,11 @@ static char* GetEnvStrs(const MessageSt* msgSt) ...@@ -118,35 +114,11 @@ static char* GetEnvStrs(const MessageSt* msgSt)
pid_t CreateProcess(const MessageSt* msgSt) pid_t CreateProcess(const MessageSt* msgSt)
{ {
char identityIDStr[MAX_IDENTITY_ID_LENGTH];
char processNameStr[MAX_PROCESS_NAME_LENGTH];
if (memset_s(identityIDStr, MAX_IDENTITY_ID_LENGTH, '\0', MAX_IDENTITY_ID_LENGTH) != EOK ||
memset_s(processNameStr, MAX_PROCESS_NAME_LENGTH, '\0', MAX_PROCESS_NAME_LENGTH) != EOK) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] create service, memset_s failed.");
return -1;
}
if (sprintf_s(identityIDStr, MAX_IDENTITY_ID_LENGTH, "%s", msgSt->identityID) <= 0 ||
sprintf_s(processNameStr, MAX_PROCESS_NAME_LENGTH, "%s", msgSt->bundleName) <= 0) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sprintf_s failed. id %{public}s, name %{public}s.",\
msgSt->identityID, msgSt->bundleName);
return -1;
}
char* envStr = GetEnvStrs(msgSt); char* envStr = GetEnvStrs(msgSt);
if (envStr == NULL) { if (envStr == NULL) {
return -1; return -1;
} }
// check if the exe file exists
struct stat pathStat = {0};
if (stat(ABILITY_EXE_FILE_FULL_PATH, &pathStat) != 0) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] stat %{public}s failed, err %{public}d.",\
ABILITY_EXE_FILE_FULL_PATH, errno);
free(envStr);
return -1;
}
pid_t newPID = fork(); pid_t newPID = fork();
if (newPID < 0) { if (newPID < 0) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] create process, fork failed! err %{public}d.", errno); HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] create process, fork failed! err %{public}d.", errno);
...@@ -158,18 +130,18 @@ pid_t CreateProcess(const MessageSt* msgSt) ...@@ -158,18 +130,18 @@ pid_t CreateProcess(const MessageSt* msgSt)
if (newPID == 0) { if (newPID == 0) {
// set permissions // set permissions
if (SetPerms(msgSt->uID, msgSt->gID) != 0) { if (SetPerms(msgSt->uID, msgSt->gID) != 0) {
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] process %{public}s exit!", processNameStr); HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] process %{public}s exit!", msgSt->bundleName);
_exit(0x7f); // 0x7f: user specified exit(0x7f); // 0x7f: user specified
} }
char* argv[] = {ABILITY_EXE_FILE_NAME, identityIDStr, processNameStr, NULL}; (void) prctl(PR_SET_NAME, msgSt->bundleName);
char* env[] = {envStr, NULL}; if (AbilityMain(msgSt->identityID) != 0) {
if (execve(ABILITY_EXE_FILE_FULL_PATH, argv, env) != 0) { HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] AbilityMain execute failed, pid %{public}d.", getpid());
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] execve %{public}s failed! err %{public}d.",\ exit(0x7f); // 0x7f: user specified
ABILITY_EXE_FILE_FULL_PATH, errno);
} }
HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sub-process exit, pid %{public}d.", getpid()); HILOG_ERROR(HILOG_MODULE_HIVIEW, "[appspawn] sub-process exit, pid %{public}d.", getpid());
_exit(0x7f); // 0x7f: user specified exit(0x7f); // 0x7f: user specified
} }
free(envStr); free(envStr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册