Change function declaration from int to void

Do some code cleanup

Signed-off-by: William Dean <williamsukatube@gmail.com>
This commit is contained in:
William Dean 2022-06-14 00:10:17 +08:00
parent 7902938133
commit e8346b9788
8 changed files with 42 additions and 29 deletions

View File

@ -15,15 +15,7 @@
#include "appspawn_adapter.h"
#include <cerrno>
#include <fcntl.h>
#include <map>
#include <sched.h>
#include <string>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <vector>
@ -37,9 +29,6 @@ using namespace OHOS::HiviewDFX;
using namespace OHOS::AppSpawn;
static constexpr HiLogLabel LABEL = {LOG_CORE, 0, "AppSpawn_SandboxUtil"};
bool g_isPrivAppSandboxCreated = false;
bool g_isAppSandboxCreated = false;
namespace {
#ifdef __aarch64__
const std::string APP_JSON_CONFIG("/system/etc/sandbox/appdata-sandbox64.json");

View File

@ -23,13 +23,11 @@
#include <time.h>
#endif // OHOS_DEBUG
static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result)
static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result)
{
if (content->notifyResToParent != NULL) {
content->notifyResToParent(content, client, result);
}
return 0;
}
static void ProcessExit(void)

View File

@ -62,7 +62,7 @@ typedef struct AppSpawnContent_ {
int (*setUidGid)(struct AppSpawnContent_ *content, AppSpawnClient *client);
int (*setCapabilities)(struct AppSpawnContent_ *content, AppSpawnClient *client);
int (*notifyResToParent)(struct AppSpawnContent_ *content, AppSpawnClient *client, int result);
void (*notifyResToParent)(struct AppSpawnContent_ *content, AppSpawnClient *client, int result);
void (*runChildProcessor)(struct AppSpawnContent_ *content, AppSpawnClient *client);
// for cold start

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "appspawn_message.h"
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
@ -145,6 +146,7 @@ static int GetCaps(const cJSON *curItem, MessageSt *msgSt)
return EC_INVALID;
}
}
msgSt->capsCnt = capsCnt;
return EC_SUCCESS;
}

View File

@ -13,13 +13,14 @@
* limitations under the License.
*/
#include "appspawn_message.h"
#include "appspawn_server.h"
#ifdef OHOS_DEBUG
#include <errno.h>
#include <time.h>
#endif // OHOS_DEBUG
#include "appspawn_message.h"
#include "appspawn_server.h"
#include "iproxy_server.h"
#include "iunknown.h"
#include "ipc_skeleton.h"
@ -45,7 +46,7 @@ typedef struct AppSpawnService {
static const char *GetName(Service *service)
{
(void)service;
UNUSED(service);
APPSPAWN_LOGI("[appspawn] get service name %s.", APPSPAWN_SERVICE_NAME);
return APPSPAWN_SERVICE_NAME;
}
@ -67,15 +68,15 @@ static BOOL Initialize(Service *service, Identity identity)
static BOOL MessageHandle(Service *service, Request *msg)
{
(void)service;
(void)msg;
UNUSED(service);
UNUSED(msg);
APPSPAWN_LOGE("[appspawn] message handle not support yet!");
return FALSE;
}
static TaskConfig GetTaskConfig(Service *service)
{
(void)service;
UNUSED(service);
TaskConfig config = {LEVEL_HIGH, PRI_BELOW_NORMAL, 0x800, 20, SHARED_TASK};
return config;
}
@ -121,8 +122,8 @@ static int Invoke(IServerProxy *iProxy, int funcId, void *origin, IpcIo *req, Ip
GetCurTime(&tmStart);
#endif // OHOS_DEBUG
(void)iProxy;
(void)origin;
UNUSED(iProxy);
UNUSED(origin);
if (reply == NULL || funcId != ID_CALL_CREATE_SERVICE || req == NULL) {
APPSPAWN_LOGE("[appspawn] invoke, funcId %d invalid, reply %d.", funcId, INVALID_PID);

View File

@ -14,6 +14,7 @@
*/
#include "appspawn_service.h"
#include "appspawn_adapter.h"
#include <fcntl.h>
#include <stdbool.h>
@ -28,10 +29,8 @@
#include <sys/wait.h>
#include <unistd.h>
#include "appspawn_adapter.h"
#include "securec.h"
#define DEVICE_NULL_STR "/dev/null"
static int SetProcessName(struct AppSpawnContent_ *content, AppSpawnClient *client,
@ -272,7 +271,7 @@ static int ColdStartApp(struct AppSpawnContent_ *content, AppSpawnClient *client
argv[PARAM_INDEX] = param;
argv[0] = param + originLen;
ret = strcpy_s(argv[0], APP_LEN_PROC_NAME, "/system/bin/appspawn");
APPSPAWN_CHECK(ret >= 0, break, "Invalid strdup");
APPSPAWN_CHECK(ret >= 0, break, "Invalid strcpy");
argv[START_INDEX] = strdup("cold-start");
APPSPAWN_CHECK(argv[START_INDEX] != NULL, break, "Invalid strdup");
argv[FD_INDEX] = strdup(buffer);
@ -319,6 +318,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl
APPSPAWN_LOGV("GetAppSpawnClientFromArg %s ", argv[PARAM_INDEX]);
char *end = NULL;
char *start = strtok_r(argv[PARAM_INDEX], ":", &end);
// clientid
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get client id");
client->client.id = atoi(start);
@ -328,6 +328,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl
start = strtok_r(NULL, ":", &end);
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get gid");
client->property.gid = atoi(start);
// gidCount
start = strtok_r(NULL, ":", &end);
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get gidCount");
@ -337,6 +338,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get gidTable");
client->property.gidTable[i] = atoi(start);
}
// processname
start = strtok_r(NULL, ":", &end);
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get processName");
@ -350,6 +352,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get soPath");
ret = strcpy_s(client->property.soPath, sizeof(client->property.soPath), start);
APPSPAWN_CHECK(ret == 0, return -1, "Failed to strcpy soPath");
// accesstoken
start = strtok_r(NULL, ":", &end);
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get accessTokenId");
@ -362,6 +365,7 @@ int GetAppSpawnClientFromArg(int argc, char *const argv[], AppSpawnClientExt *cl
APPSPAWN_CHECK(start != NULL, return -1, "Failed to get renderCmd");
ret = strcpy_s(client->property.renderCmd, sizeof(client->property.renderCmd), start);
APPSPAWN_CHECK(ret == 0, return -1, "Failed to strcpy renderCmd");
return 0;
}

View File

@ -15,6 +15,7 @@
#include "appspawn_service.h"
#include "appspawn_adapter.h"
#include "appspawn_server.h"
#include <fcntl.h>
#include <sys/capability.h>
@ -27,7 +28,6 @@
#include <sys/wait.h>
#include <unistd.h>
#include "appspawn_server.h"
#include "init_hashmap.h"
#include "init_socket.h"
#include "parameter.h"
@ -158,6 +158,7 @@ static void PrintProcessExitInfo(pid_t pid, uid_t uid, int status)
APPSPAWN_CHECK(node != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status);
AppInfo *appInfo = HASHMAP_ENTRY(node, AppInfo, node);
APPSPAWN_CHECK(appInfo != NULL, return, "Handle SIGCHLD from pid:%d status:%d", pid, status);
if (WIFSIGNALED(status)) {
APPSPAWN_LOGW("%s with pid %d exit with signal:%d", appInfo->name, pid, WTERMSIG(status));
}
@ -209,6 +210,7 @@ static void HandleSpecial(AppSpawnClientExt *appProperty)
"com.ohos.medialibrary.MediaScannerAbilityA",
"com.ohos.medialibrary.medialibrarydata"
};
for (size_t i = 0; i < sizeof(specialBundleNames) / sizeof(specialBundleNames[0]); i++) {
if (strcmp(appProperty->property.bundleName, specialBundleNames[i]) == 0) {
if (appProperty->property.gidCount < APP_MAX_GIDS) {
@ -231,6 +233,7 @@ static int WaitChild(int fd, int pid, const AppSpawnClientExt *appProperty)
FD_SET(fd, &rd);
tv.tv_sec = TV_SEC;
tv.tv_usec = 0;
int ret = select(fd + 1, &rd, NULL, NULL, &tv);
if (ret == 0) { // timeout
APPSPAWN_LOGI("Time out for child %s %d fd %d", appProperty->property.processName, pid, fd);
@ -241,6 +244,7 @@ static int WaitChild(int fd, int pid, const AppSpawnClientExt *appProperty)
} else {
(void)read(fd, &result, sizeof(result));
}
return result;
}
@ -249,6 +253,7 @@ static void StartColdApp(AppSpawnClientExt *appProperty)
if (appProperty == NULL) {
return;
}
if (appProperty->property.flags & 0x01) {
char cold[10] = {0}; // 10 cold
int ret = GetParameter("appspawn.cold.boot", "false", cold, sizeof(cold));
@ -280,6 +285,7 @@ static int GetProcessTerminationStatusInner(int32_t pid, int *status)
APPSPAWN_LOGE("waitpid failed, return : %d, pid: %d, status: %d", exitPid, pid, *status);
return -1;
}
RemoveAppInfo(pid);
return 0;
}
@ -306,9 +312,11 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
AppSpawnClientExt *appProperty = (AppSpawnClientExt *)LE_GetUserData(taskHandle);
APPSPAWN_CHECK(appProperty != NULL, LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
return, "alloc client Failed");
int ret = memcpy_s(&appProperty->property, sizeof(appProperty->property), buffer, buffLen);
APPSPAWN_CHECK(ret == 0, LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
return, "Invalid buffer buffLen %u", buffLen);
#ifdef NWEB_SPAWN
// get render process termination status, only nwebspawn need this logic.
if (appProperty->property.code == GET_RENDER_TERMINATION_STATUS) {
@ -316,6 +324,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
return;
}
#endif
APPSPAWN_CHECK(appProperty->property.gidCount <= APP_MAX_GIDS && strlen(appProperty->property.processName) > 0,
LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
return, "Invalid property %u", appProperty->property.gidCount);
@ -333,6 +342,7 @@ static void OnReceiveRequest(const TaskHandle taskHandle, const uint8_t *buffer,
LE_CloseTask(LE_GetDefaultLoop(), taskHandle);
return;
}
APPSPAWN_LOGI("OnReceiveRequest client.id %d appProperty %d processname %s buffLen %d flags 0x%x",
appProperty->client.id, appProperty->property.uid, appProperty->property.processName,
buffLen, appProperty->property.flags);
@ -369,10 +379,12 @@ static int OnConnection(const LoopHandle loopHandle, const TaskHandle server)
info.disConntectComplete = NULL;
info.sendMessageComplete = SendMessageComplete;
info.recvMessage = OnReceiveRequest;
LE_STATUS ret = LE_AcceptStreamClient(LE_GetDefaultLoop(), server, &stream, &info);
APPSPAWN_CHECK(ret == 0, return -1, "Failed to alloc stream");
AppSpawnClientExt *client = (AppSpawnClientExt *)LE_GetUserData(stream);
APPSPAWN_CHECK(client != NULL, return -1, "Failed to alloc stream");
client->stream = stream;
client->client.id = ++clientId;
client->client.flags = 0;
@ -380,7 +392,7 @@ static int OnConnection(const LoopHandle loopHandle, const TaskHandle server)
return 0;
}
static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result)
static void NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *client, int result)
{
AppSpawnClientExt *appProperty = (AppSpawnClientExt *)client;
int fd = appProperty->fd[1];
@ -388,7 +400,6 @@ static int NotifyResToParent(struct AppSpawnContent_ *content, AppSpawnClient *c
write(appProperty->fd[1], &result, sizeof(result));
// close write
close(fd);
return 0;
}
static void AppSpawnInit(AppSpawnContent *content)
@ -425,6 +436,7 @@ void AppSpawnColdRun(AppSpawnContent *content, int argc, char *const argv[])
if (ret == 0 && content->runChildProcessor != NULL) {
content->runChildProcessor(content, &client->client);
}
APPSPAWN_LOGI("App exit %d.", getpid());
free(client);
free(appSpawnContent);
@ -436,6 +448,7 @@ static void AppSpawnRun(AppSpawnContent *content, int argc, char *const argv[])
APPSPAWN_LOGI("AppSpawnRun");
AppSpawnContentExt *appSpawnContent = (AppSpawnContentExt *)content;
APPSPAWN_CHECK(appSpawnContent != NULL, return, "Invalid appspawn content");
LE_STATUS status = LE_CreateSignalTask(LE_GetDefaultLoop(), &appSpawnContent->sigHandler, SignalHandler);
if (status == 0) {
status = LE_AddSignal(LE_GetDefaultLoop(), appSpawnContent->sigHandler, SIGCHLD);
@ -514,6 +527,7 @@ AppSpawnContent *AppSpawnCreateContent(const char *socketName, char *longProcNam
info.server = path;
info.baseInfo.close = NULL;
info.incommingConntect = OnConnection;
ret = LE_CreateStreamServer(LE_GetDefaultLoop(), &appSpawnContent->server, &info);
APPSPAWN_CHECK(ret == 0, free(appSpawnContent);
return NULL, "Failed to create socket for %s", path);

View File

@ -22,10 +22,12 @@ int main(int argc, char *const argv[])
if (argc <= 0) {
return 0;
}
(void)signal(SIGPIPE, SIG_IGN);
uint32_t argvSize = 0;
char *buffer = (char *)argv[0];
int mode = 0;
if ((argc > PARAM_INDEX) && (strcmp(argv[START_INDEX], "cold-start") == 0)) {
buffer = argv[0];
argvSize = APP_LEN_PROC_NAME;
@ -39,15 +41,18 @@ int main(int argc, char *const argv[])
}
argvSize = end - start;
}
APPSPAWN_LOGI("AppSpawnCreateContent argc %d mode %d %u", argc, mode, argvSize);
AppSpawnContent *content = AppSpawnCreateContent(APPSPAWN_SOCKET_NAME, argv[0], argvSize, mode);
APPSPAWN_CHECK(content != NULL, return -1, "Invalid content for appspawn");
APPSPAWN_CHECK(content->initAppSpawn != NULL, return -1, "Invalid content for appspawn");
APPSPAWN_CHECK(content->runAppSpawn != NULL, return -1, "Invalid content for appspawn");
// set common operation
content->loadExtendLib = LoadExtendLib;
content->runChildProcessor = RunChildProcessor;
content->initAppSpawn(content);
content->runAppSpawn(content, argc, argv);
return 0;
}