init_cmds.c 17.2 KB
Newer Older
1
/*
Z
zhong_ning 已提交
2
 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "init_cmds.h"

Y
yanmengzhao 已提交
17
#include <dlfcn.h>
18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/sysmacros.h>
#include <sys/wait.h>
#include <unistd.h>
4
411148299@qq.com 已提交
32
#include <linux/module.h>
M
Mupceet 已提交
33 34

#include "bootstage.h"
S
sun_fan 已提交
35
#include "fs_manager/fs_manager.h"
C
cheng_jinsong 已提交
36
#include "init_cmdexecutor.h"
Z
zhong_ning 已提交
37
#include "init_jobs_internal.h"
38 39 40 41
#include "init_log.h"
#include "init_param.h"
#include "init_service_manager.h"
#include "init_utils.h"
X
xionglei6 已提交
42 43
#include "sandbox.h"
#include "sandbox_namespace.h"
44
#include "securec.h"
45
#include "fscrypt_utils.h"
46

S
stesen 已提交
47 48 49 50
#ifdef SUPPORT_PROFILER_HIDEBUG
#include <hidebug_base.h>
#endif

51
#define FSCRYPT_POLICY_BUF_SIZE (60)
C
cheng_jinsong 已提交
52 53
#define DECIMAL 10
#define OCTAL 8
54

55 56
int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, unsigned int paramLen)
{
X
add ut  
xionglei6 已提交
57
    INIT_CHECK_RETURN_VALUE((symValue != NULL) && (paramValue != NULL) && (paramLen != 0), -1);
58
    char tmpName[PARAM_NAME_LEN_MAX] = { 0 };
X
xionglei6 已提交
59
    int ret;
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    uint32_t curr = 0;
    char *start = (char *)symValue;
    char *end = (char *)symValue + symLen;
    do {
        char *begin = strchr(start, '$');
        if (begin == NULL || begin >= end) { // not has '$' copy the original string
            ret = strncpy_s(paramValue + curr, paramLen - curr, start, symLen);
            INIT_ERROR_CHECK(ret == EOK, return -1, "Failed to copy start %s", start);
            break;
        } else {
            ret = memcpy_s(paramValue + curr, paramLen - curr, start, begin - start);
            INIT_ERROR_CHECK(ret == 0, return -1, "Failed to copy first value %s", symValue);
            curr += begin - start;
        }
        while (*begin != '{') {
X
xionglei6 已提交
75
            INIT_CHECK_RETURN_VALUE(*begin != '\0', -1);
76 77 78 79
            begin++;
        }
        begin++;
        char *left = strchr(begin, '}');
X
add ut  
xionglei6 已提交
80 81
        INIT_CHECK_RETURN_VALUE(left != NULL, -1);

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        // copy param name
        ret = strncpy_s(tmpName, PARAM_NAME_LEN_MAX, begin, left - begin);
        INIT_ERROR_CHECK(ret == EOK, return -1, "Invalid param name %s", symValue);
        uint32_t valueLen = paramLen - curr;
        ret = SystemReadParam(tmpName, paramValue + curr, &valueLen);
        INIT_ERROR_CHECK(ret == 0, return -1, "Failed to get param %s", tmpName);
        curr += valueLen;
        left++;
        if ((unsigned int)(left - symValue) >= symLen) {
            break;
        }
        start = left;
    } while (1);
    return 0;
}

C
cheng_jinsong 已提交
98
static void SyncExecCommand(int argc, char * const *argv)
M
Mupceet 已提交
99
{
C
fix log  
cheng_jinsong 已提交
100
    INIT_LOGI("Sync exec: %s", argv[0]);
M
Mupceet 已提交
101
    pid_t pid = fork();
C
cheng_jinsong 已提交
102
    INIT_ERROR_CHECK(!(pid < 0), return, "Fork new process to format failed: %d", errno);
M
Mupceet 已提交
103 104 105 106 107 108 109 110
    if (pid == 0) {
        INIT_CHECK_ONLY_ELOG(execv(argv[0], argv) == 0, "execv %s failed! err %d.", argv[0], errno);
        exit(-1);
    }
    int status;
    pid_t ret = waitpid(pid, &status, 0);
    if (ret != pid) {
        INIT_LOGE("Failed to wait pid %d, errno %d", pid, errno);
C
cheng_jinsong 已提交
111
        return;
M
Mupceet 已提交
112
    }
C
fix log  
cheng_jinsong 已提交
113
    INIT_LOGI("Sync exec: %s result %d %d", argv[0], WEXITSTATUS(status), WIFEXITED(status));
C
cheng_jinsong 已提交
114
    return;
M
Mupceet 已提交
115 116
}

X
add ut  
xionglei6 已提交
117
static void DoIfup(const struct CmdArgs *ctx)
118 119
{
    struct ifreq interface;
X
add ut  
xionglei6 已提交
120 121
    INIT_ERROR_CHECK(strncpy_s(interface.ifr_name, IFNAMSIZ - 1, ctx->argv[0], strlen(ctx->argv[0])) == EOK,
        return, "DoIfup failed to copy interface name");
X
xionglei6 已提交
122
    INIT_LOGV("interface name: %s", interface.ifr_name);
X
add ut  
xionglei6 已提交
123

124
    int fd = socket(AF_INET, SOCK_DGRAM, 0);
X
add ut  
xionglei6 已提交
125
    INIT_ERROR_CHECK(fd >= 0, return, "DoIfup failed to create socket, err = %d", errno);
126 127 128

    if (ioctl(fd, SIOCGIFFLAGS, &interface) >= 0) {
        interface.ifr_flags |= IFF_UP;
X
add ut  
xionglei6 已提交
129 130
        INIT_CHECK_ONLY_ELOG(ioctl(fd, SIOCSIFFLAGS, &interface) >= 0,
            "DoIfup failed to do ioctl with command \"SIOCSIFFLAGS\", err = %d", errno);
131 132
    }
    close(fd);
X
add ut  
xionglei6 已提交
133
    fd = -1;
134 135 136
}

// format insmod <ko name> [-f] [options]
X
add ut  
xionglei6 已提交
137
static void DoInsmod(const struct CmdArgs *ctx)
138 139 140 141 142 143 144 145
{
    int index = 0;
    int flags = 0;
    char *fileName = NULL;
    if (ctx->argc > index) {
        fileName = ctx->argv[index];
        index++;
    }
X
add ut  
xionglei6 已提交
146
    INIT_ERROR_CHECK(fileName != NULL, return, "Can not find file name from param %s", ctx->argv[0]);
X
xionglei6 已提交
147
    INIT_LOGV("Install mode %s ", fileName);
148
    char *realPath = GetRealPath(fileName);
X
add ut  
xionglei6 已提交
149
    INIT_ERROR_CHECK(realPath != NULL, return, "Can not get real file name from param %s", ctx->argv[0]);
X
xionglei6 已提交
150
    if (ctx->argc > 1 && ctx->argv[1] != NULL && strcmp(ctx->argv[1], "-f") == 0) { // [-f]
151
        flags = MODULE_INIT_IGNORE_VERMAGIC | MODULE_INIT_IGNORE_MODVERSIONS;
X
xionglei6 已提交
152 153
        index++;
    }
154 155 156 157 158
    char *options = BuildStringFromCmdArg(ctx, index); // [options]
    int fd = open(realPath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
    if (fd >= 0) {
        int rc = syscall(__NR_finit_module, fd, options, flags);
        if (rc == -1) {
X
xionglei6 已提交
159
            INIT_LOGE("Failed to install kernel module for %s failed options %s err: %d", realPath, options, errno);
160 161 162 163 164 165 166 167 168 169 170 171
        }
    }
    if (options != NULL) {
        free(options);
    }
    if (fd >= 0) {
        close(fd);
    }
    free(realPath);
    return;
}

X
add ut  
xionglei6 已提交
172
static void DoSetParam(const struct CmdArgs *ctx)
173
{
X
xionglei6 已提交
174
    INIT_LOGV("set param name: %s, value %s ", ctx->argv[0], ctx->argv[1]);
175 176 177
    SystemWriteParam(ctx->argv[0], ctx->argv[1]);
}

X
add ut  
xionglei6 已提交
178
static void DoLoadPersistParams(const struct CmdArgs *ctx)
179
{
M
Mupceet 已提交
180
    INIT_LOGV("LoadPersistParams");
181
    LoadPersistParams();
H
handyohos 已提交
182
    HookMgrExecute(GetBootStageHookMgr(), INIT_POST_PERSIST_PARAM_LOAD, NULL, NULL);
183 184
}

X
add ut  
xionglei6 已提交
185
static void DoTriggerCmd(const struct CmdArgs *ctx)
186
{
X
xionglei6 已提交
187
    INIT_LOGV("DoTrigger :%s", ctx->argv[0]);
X
add ut  
xionglei6 已提交
188
    DoTriggerExec(ctx->argv[0]);
189 190
}

X
add ut  
xionglei6 已提交
191
static void DoLoadDefaultParams(const struct CmdArgs *ctx)
192 193 194 195 196
{
    int mode = 0;
    if (ctx->argc > 1 && strcmp(ctx->argv[1], "onlyadd") == 0) {
        mode = LOAD_PARAM_ONLY_ADD;
    }
X
xionglei6 已提交
197
    INIT_LOGV("DoLoadDefaultParams args : %s %d", ctx->argv[0], mode);
198 199 200
    LoadDefaultParams(ctx->argv[0], mode);
}

M
Mupceet 已提交
201 202 203
static void DoSyncExec(const struct CmdArgs *ctx)
{
    // format: syncexec /xxx/xxx/xxx xxx
C
codex  
chengjinsong 已提交
204
    INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoSyncExec: invalid arguments");
C
cheng_jinsong 已提交
205
    SyncExecCommand(ctx->argc, ctx->argv);
M
Mupceet 已提交
206 207 208
    return;
}

X
add ut  
xionglei6 已提交
209
static void DoExec(const struct CmdArgs *ctx)
210 211
{
    // format: exec /xxx/xxx/xxx xxx
C
codex  
chengjinsong 已提交
212
    INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoExec: invalid arguments");
213
    pid_t pid = fork();
X
add ut  
xionglei6 已提交
214 215
    INIT_ERROR_CHECK(pid >= 0, return, "DoExec: failed to fork child process to exec \"%s\"", ctx->argv[0]);

216
    if (pid == 0) {
M
Mupceet 已提交
217
        OpenHidebug(ctx->argv[0]);
X
add ut  
xionglei6 已提交
218
        int ret = execv(ctx->argv[0], ctx->argv);
L
laiguizhong 已提交
219
        INIT_CHECK_ONLY_ELOG(ret != -1, "DoExec: execute \"%s\" failed: %d.", ctx->argv[0], errno);
220 221 222 223 224
        _exit(0x7f);
    }
    return;
}

X
add ut  
xionglei6 已提交
225
static void DoSymlink(const struct CmdArgs *ctx)
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
{
    // format: symlink /xxx/xxx/xxx /xxx/xxx/xxx
    int ret = symlink(ctx->argv[0], ctx->argv[1]);
    if (ret != 0 && errno != EEXIST) {
        INIT_LOGE("DoSymlink: link %s to %s failed: %d", ctx->argv[0], ctx->argv[1], errno);
    }
}

static mode_t GetDeviceMode(const char *deviceStr)
{
    switch (*deviceStr) {
        case 'b':
        case 'B':
            return S_IFBLK;
        case 'c':
        case 'C':
            return S_IFCHR;
        case 'f':
        case 'F':
            return S_IFIFO;
        default:
            return -1;
    }
}

X
add ut  
xionglei6 已提交
251
static void DoMakeNode(const struct CmdArgs *ctx)
252 253 254 255 256 257
{
    // format: mknod path b 0644 1 9
    const int deviceTypePos = 1;
    const int authorityPos = 2;
    const int majorDevicePos = 3;
    const int minorDevicePos = 4;
X
add ut  
xionglei6 已提交
258
    INIT_ERROR_CHECK(access(ctx->argv[1], F_OK), return, "DoMakeNode failed, path has sexisted");
259 260
    mode_t deviceMode = GetDeviceMode(ctx->argv[deviceTypePos]);
    errno = 0;
C
cheng_jinsong 已提交
261
    unsigned int major = strtoul(ctx->argv[majorDevicePos], NULL, DECIMAL);
262
    INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[majorDevicePos]);
C
cheng_jinsong 已提交
263
    unsigned int minor = strtoul(ctx->argv[minorDevicePos], NULL, DECIMAL);
264
    INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[minorDevicePos]);
C
cheng_jinsong 已提交
265
    mode_t authority = strtoul(ctx->argv[authorityPos], NULL, OCTAL);
266 267 268 269 270 271 272
    INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[authorityPos]);
    int ret = mknod(ctx->argv[0], deviceMode | authority, makedev(major, minor));
    if (ret != 0) {
        INIT_LOGE("DoMakeNode: path: %s failed: %d", ctx->argv[0], errno);
    }
}

X
add ut  
xionglei6 已提交
273
static void DoMakeDevice(const struct CmdArgs *ctx)
274 275 276
{
    // format: makedev major minor
    errno = 0;
C
cheng_jinsong 已提交
277
    unsigned int major = strtoul(ctx->argv[0], NULL, DECIMAL);
278
    INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[0]);
C
cheng_jinsong 已提交
279
    unsigned int minor = strtoul(ctx->argv[1], NULL, DECIMAL);
280 281
    INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[1]);
    dev_t deviceId = makedev(major, minor);
X
add ut  
xionglei6 已提交
282 283 284
    INIT_CHECK_ONLY_ELOG(deviceId >= 0, "DoMakedevice \" major:%s, minor:%s \" failed :%d ", ctx->argv[0],
        ctx->argv[1], errno);
    return;
285 286
}

X
add ut  
xionglei6 已提交
287
static void DoMountFstabFile(const struct CmdArgs *ctx)
288 289
{
    INIT_LOGI("Mount partitions from fstab file \" %s \"", ctx->argv[0]);
C
cheng_jinsong 已提交
290 291
    int ret = MountAllWithFstabFile(ctx->argv[0], 0);
    INIT_LOGI("Mount partitions from fstab file \" %s \" finish ret %d", ctx->argv[0], ret);
292 293
}

X
add ut  
xionglei6 已提交
294
static void DoUmountFstabFile(const struct CmdArgs *ctx)
295 296 297 298 299 300 301 302 303 304
{
    INIT_LOGI("Umount partitions from fstab file \" %s \"", ctx->argv[0]);
    int rc = UmountAllWithFstabFile(ctx->argv[0]);
    if (rc < 0) {
        INIT_LOGE("Run command umount_fstab failed");
    } else {
        INIT_LOGI("Umount partitions from fstab done");
    }
}

R
renwei 已提交
305 306
static void DoRestorecon(const struct CmdArgs *ctx)
{
C
cheng_jinsong 已提交
307
    PluginExecCmdByName("restoreContentRecurse", ctx->argv[0]);
R
renwei 已提交
308 309 310
    return;
}

311 312 313 314 315
static void DoLoadAccessTokenId(const struct CmdArgs *ctx)
{
    LoadAccessTokenId();
}

X
xionglei6 已提交
316 317 318 319 320 321 322 323 324 325 326 327
static int FilterService(const Service *service, const char **exclude, int size)
{
    for (int i = 0; i < size; i++) {
        if (exclude[i] != NULL && strcmp(service->name, exclude[i]) == 0) {
            return 0;
        }
    }
    return 1;
}

static void DoStopAllServices(const struct CmdArgs *ctx)
{
X
xionglei6 已提交
328 329 330 331 332 333 334
    int flags = SERVICE_ATTR_INVALID;
    if (ctx->argc >= 1 && strcmp(ctx->argv[0], "true") == 0) {
        flags |= SERVICE_ATTR_NEEDWAIT;
        StopAllServices(flags, (const char **)(&ctx->argv[1]), ctx->argc - 1, FilterService);
    } else {
        StopAllServices(flags, (const char **)ctx->argv, ctx->argc, FilterService);
    }
X
xionglei6 已提交
335 336 337 338 339 340
    return;
}

static void DoUmount(const struct CmdArgs *ctx)
{
    INIT_LOGI("DoUmount %s",  ctx->argv[0]);
C
umount  
chengjinsong 已提交
341 342 343
    MountStatus status = GetMountStatusForMountPoint(ctx->argv[0]);
    if (status == MOUNT_MOUNTED) {
        int ret = umount(ctx->argv[0]);
344
        if ((ret != 0) && (ctx->argc > 1) && (strcmp(ctx->argv[1], "MNT_FORCE") == 0)) {
X
xionglei6 已提交
345 346
            ret = umount2(ctx->argv[0], MNT_FORCE);
        }
C
umount  
chengjinsong 已提交
347 348 349 350 351
        INIT_CHECK_ONLY_ELOG(ret == 0, "Failed to umount %s, errno %d", ctx->argv[0], errno);
    } else if (status == MOUNT_UMOUNTED) {
        INIT_LOGI("%s is already umounted", ctx->argv[0]);
    } else {
        INIT_LOGE("Failed to get %s mount status", ctx->argv[0]);
X
xionglei6 已提交
352 353 354 355 356 357 358 359
    }
}

static void DoSync(const struct CmdArgs *ctx)
{
    sync();
}

X
xionglei6 已提交
360
static void DoTimerStart(const struct CmdArgs *ctx)
X
xionglei6 已提交
361 362 363 364 365 366 367 368 369 370 371 372
{
    INIT_LOGI("Timer start service with arg = %s", ctx->argv[0]);
    char *arg = ctx->argv[0];
    int count = 0;
    int expectedCount = 2;
    char **splitArgs = SplitStringExt(ctx->argv[0], "|", &count, expectedCount);
    if (splitArgs == NULL) {
        INIT_LOGE("Call timer_start with invalid arguments");
        return;
    }

    if (count != expectedCount) {
373
        INIT_LOGE("Call timer_start with unexpected arguments %s", arg);
X
xionglei6 已提交
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
        FreeStringVector(splitArgs, count);
        return;
    }

    Service *service = GetServiceByName(splitArgs[0]);
    if (service == NULL) {
        INIT_LOGE("Cannot find service in timer_start command");
        FreeStringVector(splitArgs, count);
        return;
    }

    errno = 0;
    uint64_t timeout = strtoull(splitArgs[1], NULL, DECIMAL_BASE);
    if (errno != 0) {
        INIT_LOGE("call timer_start with invalid timer");
        FreeStringVector(splitArgs, count);
        return;
    }
    // not need this anymore , release memory.
    FreeStringVector(splitArgs, count);
    ServiceStartTimer(service, timeout);
}

X
xionglei6 已提交
397
static void DoTimerStop(const struct CmdArgs *ctx)
X
xionglei6 已提交
398 399 400 401 402 403 404 405 406 407 408
{
    INIT_LOGI("Stop service timer with arg = %s", ctx->argv[0]);
    const char *serviceName = ctx->argv[0];
    Service *service = GetServiceByName(serviceName);
    if (service == NULL) {
        INIT_LOGE("Cannot find service in timer_stop command");
        return;
    }
    ServiceStopTimer(service);
}

409 410
static bool InitFscryptPolicy(void)
{
411
    char policy[FSCRYPT_POLICY_BUF_SIZE];
C
cheng_jinsong 已提交
412 413 414 415
    if (LoadFscryptPolicy(policy, FSCRYPT_POLICY_BUF_SIZE) == 0) {
        if (SetFscryptSysparam(policy) == 0) {
            return true;
        }
416 417 418 419
    }
    return false;
}

Z
zhangqilong 已提交
420 421
static void DoInitGlobalKey(const struct CmdArgs *ctx)
{
C
fix log  
cheng_jinsong 已提交
422
    INIT_LOGV("Do init global key start");
Z
zhangqilong 已提交
423 424
    const char *dataDir = "/data";
    if (strncmp(ctx->argv[0], dataDir, strlen(dataDir)) != 0) {
C
fix log  
cheng_jinsong 已提交
425
        INIT_LOGE("Not data partitation");
Z
zhangqilong 已提交
426 427
        return;
    }
428
    if (!InitFscryptPolicy()) {
C
fix log  
cheng_jinsong 已提交
429
        INIT_LOGW("Init fscrypt failed, not enable fscrypt");
430 431 432
        return;
    }

X
xionglei6 已提交
433
    char * const argv[] = {
Z
zhangqilong 已提交
434 435 436 437 438
        "/system/bin/sdc",
        "filecrypt",
        "init_global_key",
        NULL
    };
M
Mupceet 已提交
439
    int argc = ARRAY_LENGTH(argv);
C
cheng_jinsong 已提交
440
    SyncExecCommand(argc, argv);
Z
zhangqilong 已提交
441 442 443 444
}

static void DoInitMainUser(const struct CmdArgs *ctx)
{
X
xionglei6 已提交
445
    char * const argv[] = {
Z
zhangqilong 已提交
446 447 448 449 450
        "/system/bin/sdc",
        "filecrypt",
        "init_main_user",
        NULL
    };
M
Mupceet 已提交
451
    int argc = ARRAY_LENGTH(argv);
C
cheng_jinsong 已提交
452
    SyncExecCommand(argc, argv);
Z
zhangqilong 已提交
453 454
}

C
CY Fan 已提交
455 456 457 458 459 460 461
static void DoMkswap(const struct CmdArgs *ctx)
{
    char *const argv[] = {
        "/system/bin/mkswap",
        ctx->argv[0],
        NULL
    };
M
Mupceet 已提交
462
    int argc = ARRAY_LENGTH(argv);
C
cheng_jinsong 已提交
463
    SyncExecCommand(argc, argv);
C
CY Fan 已提交
464 465 466 467 468 469 470 471 472
}

static void DoSwapon(const struct CmdArgs *ctx)
{
    char *const argv[] = {
        "/system/bin/swapon",
        ctx->argv[0],
        NULL
    };
M
Mupceet 已提交
473
    int argc = ARRAY_LENGTH(argv);
C
cheng_jinsong 已提交
474
    SyncExecCommand(argc, argv);
C
CY Fan 已提交
475 476
}

X
xionglei6 已提交
477 478
static void DoMkSandbox(const struct CmdArgs *ctx)
{
C
fix log  
cheng_jinsong 已提交
479
    INIT_LOGV("Do make sandbox start");
X
xionglei6 已提交
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
    const char *sandbox = ctx->argv[0];
    InitDefaultNamespace();
    if (!InitSandboxWithName(sandbox)) {
        INIT_LOGE("Failed to init sandbox with name %s.", sandbox);
    }

    if (PrepareSandbox(sandbox) != 0) {
        INIT_LOGE("Failed to prepare sandbox %s.", sandbox);
        DestroySandbox(sandbox);
    }
    if (EnterDefaultNamespace() < 0) {
        INIT_LOGE("Failed to set default namespace.");
    }
    CloseDefaultNamespace();
}

4
411148299@qq.com 已提交
496
static const struct CmdTable g_cmdTable[] = {
M
Mupceet 已提交
497
    { "syncexec ", 1, 10, DoSyncExec },
498
    { "exec ", 1, 10, DoExec },
C
cheng_jinsong 已提交
499
    { "mknode ", 5, 5, DoMakeNode },
500 501
    { "makedev ", 2, 2, DoMakeDevice },
    { "symlink ", 2, 2, DoSymlink },
C
cheng_jinsong 已提交
502
    { "trigger ", 0, 1, DoTriggerCmd },
503 504
    { "insmod ", 1, 10, DoInsmod },
    { "setparam ", 2, 2, DoSetParam },
C
cheng_jinsong 已提交
505
    { "load_persist_params ", 0, 1, DoLoadPersistParams },
506
    { "load_param ", 1, 2, DoLoadDefaultParams },
C
cheng_jinsong 已提交
507
    { "load_access_token_id ", 0, 1, DoLoadAccessTokenId },
508 509 510
    { "ifup ", 1, 1, DoIfup },
    { "mount_fstab ", 1, 1, DoMountFstabFile },
    { "umount_fstab ", 1, 1, DoUmountFstabFile },
R
renwei 已提交
511
    { "restorecon ", 1, 1, DoRestorecon },
X
xionglei6 已提交
512 513 514 515 516
    { "stopAllServices ", 0, 10, DoStopAllServices },
    { "umount ", 1, 1, DoUmount },
    { "sync ", 0, 1, DoSync },
    { "timer_start", 1, 1, DoTimerStart },
    { "timer_stop", 1, 1, DoTimerStop },
Z
zhangqilong 已提交
517 518
    { "init_global_key ", 1, 1, DoInitGlobalKey },
    { "init_main_user ", 0, 1, DoInitMainUser },
C
CY Fan 已提交
519 520
    { "mkswap", 1, 1, DoMkswap},
    { "swapon", 1, 1, DoSwapon},
X
xionglei6 已提交
521
    { "mksandbox", 1, 1, DoMkSandbox},
522 523 524 525
};

const struct CmdTable *GetCmdTable(int *number)
{
4
411148299@qq.com 已提交
526 527
    *number = (int)ARRAY_LENGTH(g_cmdTable);
    return g_cmdTable;
528
}
M
Mupceet 已提交
529 530 531 532

void OpenHidebug(const char *name)
{
#ifdef SUPPORT_PROFILER_HIDEBUG
S
stesen 已提交
533
    InitEnvironmentParam(name);
M
Mupceet 已提交
534
#endif
Y
yanmengzhao 已提交
535
}
536 537 538 539 540 541 542 543 544

int SetFileCryptPolicy(const char *dir)
{
    if (dir == NULL) {
        INIT_LOGE("SetFileCryptPolicy:dir is null");
        return -EINVAL;
    }
    return FscryptPolicyEnable(dir);
}