1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "init_cmds.h"
16
17 #include <dlfcn.h>
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <net/if.h>
21 #include <stdbool.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/ioctl.h>
25 #include <sys/mount.h>
26 #include <sys/resource.h>
27 #include <sys/stat.h>
28 #include <sys/syscall.h>
29 #include <sys/sysmacros.h>
30 #include <sys/wait.h>
31 #include <unistd.h>
32 #include <linux/module.h>
33
34 #include "bootstage.h"
35 #include "fs_manager/fs_manager.h"
36 #include "init_cmdexecutor.h"
37 #include "init_jobs_internal.h"
38 #include "init_log.h"
39 #include "init_param.h"
40 #include "init_service_manager.h"
41 #include "init_utils.h"
42 #include "sandbox.h"
43 #include "sandbox_namespace.h"
44 #include "securec.h"
45 #include "fscrypt_utils.h"
46
47 #ifdef SUPPORT_PROFILER_HIDEBUG
48 #include <hidebug_base.h>
49 #endif
50
51 #define FSCRYPT_POLICY_BUF_SIZE (60)
52 #define DECIMAL 10
53 #define OCTAL 8
54
GetParamValue(const char * symValue,unsigned int symLen,char * paramValue,unsigned int paramLen)55 int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, unsigned int paramLen)
56 {
57 INIT_CHECK_RETURN_VALUE((symValue != NULL) && (paramValue != NULL) && (paramLen != 0), -1);
58 char tmpName[PARAM_NAME_LEN_MAX] = { 0 };
59 int ret;
60 uint32_t curr = 0;
61 char *start = (char *)symValue;
62 if (symLen > strlen(symValue)) {
63 return -1;
64 }
65 char *end = (char *)symValue + symLen;
66 do {
67 char *begin = strchr(start, '$');
68 if (begin == NULL || begin >= end) { // not has '$' copy the original string
69 ret = strncpy_s(paramValue + curr, paramLen - curr, start, symLen);
70 INIT_ERROR_CHECK(ret == EOK, return -1, "Failed to copy start %s", start);
71 break;
72 } else {
73 ret = memcpy_s(paramValue + curr, paramLen - curr, start, begin - start);
74 INIT_ERROR_CHECK(ret == 0, return -1, "Failed to copy first value %s", symValue);
75 curr += begin - start;
76 }
77 while (*begin != '{') {
78 INIT_CHECK_RETURN_VALUE(*begin != '\0', -1);
79 begin++;
80 }
81 begin++;
82 char *left = strchr(begin, '}');
83 INIT_CHECK_RETURN_VALUE(left != NULL, -1);
84
85 // copy param name
86 ret = strncpy_s(tmpName, PARAM_NAME_LEN_MAX, begin, left - begin);
87 INIT_ERROR_CHECK(ret == EOK, return -1, "Invalid param name %s", symValue);
88 if (paramLen < curr) {
89 INIT_LOGE("Failed to get param value over max length");
90 return -1;
91 }
92 uint32_t valueLen = paramLen - curr;
93 ret = SystemReadParam(tmpName, paramValue + curr, &valueLen);
94 INIT_ERROR_CHECK(ret == 0, return -1, "Failed to get param %s", tmpName);
95 curr += valueLen;
96 left++;
97 if ((unsigned int)(left - symValue) >= symLen) {
98 break;
99 }
100 start = left;
101 } while (1);
102 return 0;
103 }
104
SyncExecCommand(int argc,char * const * argv)105 static int SyncExecCommand(int argc, char * const *argv)
106 {
107 INIT_LOGI("Sync exec: %s", argv[0]);
108 pid_t pid = fork();
109 INIT_ERROR_CHECK(!(pid < 0), return -1, "Fork new process to format failed: %d", errno);
110 if (pid == 0) {
111 INIT_CHECK_ONLY_ELOG(execv(argv[0], argv) == 0, "execv %s failed! err %d.", argv[0], errno);
112 exit(-1);
113 }
114 int status;
115 pid_t ret = waitpid(pid, &status, 0);
116 if (ret != pid) {
117 INIT_LOGE("Failed to wait pid %d, errno %d", pid, errno);
118 return -1;
119 }
120 INIT_LOGI("Sync exec: %s result %d %d", argv[0], WEXITSTATUS(status), WIFEXITED(status));
121 return WEXITSTATUS(status);
122 }
123
DoIfup(const struct CmdArgs * ctx)124 static void DoIfup(const struct CmdArgs *ctx)
125 {
126 struct ifreq interface;
127 INIT_ERROR_CHECK(strncpy_s(interface.ifr_name, IFNAMSIZ - 1, ctx->argv[0], strlen(ctx->argv[0])) == EOK,
128 return, "DoIfup failed to copy interface name");
129 INIT_LOGV("interface name: %s", interface.ifr_name);
130
131 int fd = socket(AF_INET, SOCK_DGRAM, 0);
132 INIT_ERROR_CHECK(fd >= 0, return, "DoIfup failed to create socket, err = %d", errno);
133
134 if (ioctl(fd, SIOCGIFFLAGS, &interface) >= 0) {
135 interface.ifr_flags |= IFF_UP;
136 INIT_CHECK_ONLY_ELOG(ioctl(fd, SIOCSIFFLAGS, &interface) >= 0,
137 "DoIfup failed to do ioctl with command \"SIOCSIFFLAGS\", err = %d", errno);
138 }
139 close(fd);
140 }
141
142 // format insmod <ko name> [-f] [options]
DoInsmod(const struct CmdArgs * ctx)143 static void DoInsmod(const struct CmdArgs *ctx)
144 {
145 int index = 0;
146 int flags = 0;
147 char *fileName = NULL;
148 if (ctx->argc > index) {
149 fileName = ctx->argv[index];
150 index++;
151 }
152 INIT_ERROR_CHECK(fileName != NULL, return, "Can not find file name from param %s", ctx->argv[0]);
153 INIT_LOGV("Install mode %s ", fileName);
154 char *realPath = GetRealPath(fileName);
155 INIT_ERROR_CHECK(realPath != NULL, return, "Can not get real file name from param %s", ctx->argv[0]);
156 if (ctx->argc > 1 && ctx->argv[1] != NULL && strcmp(ctx->argv[1], "-f") == 0) { // [-f]
157 flags = MODULE_INIT_IGNORE_VERMAGIC | MODULE_INIT_IGNORE_MODVERSIONS;
158 index++;
159 }
160 char *options = BuildStringFromCmdArg(ctx, index); // [options]
161 int fd = open(realPath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
162 if (fd >= 0) {
163 int rc = syscall(__NR_finit_module, fd, options, flags);
164 if (rc == -1) {
165 INIT_LOGE("Failed to install kernel module for %s failed options %s err: %d", realPath, options, errno);
166 }
167 }
168 if (options != NULL) {
169 free(options);
170 }
171 if (fd >= 0) {
172 close(fd);
173 }
174 free(realPath);
175 return;
176 }
177
DoSetParam(const struct CmdArgs * ctx)178 static void DoSetParam(const struct CmdArgs *ctx)
179 {
180 INIT_LOGV("set param name: %s, value %s ", ctx->argv[0], ctx->argv[1]);
181 SystemWriteParam(ctx->argv[0], ctx->argv[1]);
182 }
183
DoLoadPersistParams(const struct CmdArgs * ctx)184 static void DoLoadPersistParams(const struct CmdArgs *ctx)
185 {
186 INIT_LOGV("LoadPersistParams");
187 LoadPersistParams();
188 HookMgrExecute(GetBootStageHookMgr(), INIT_POST_PERSIST_PARAM_LOAD, NULL, NULL);
189 }
190
DoTriggerCmd(const struct CmdArgs * ctx)191 static void DoTriggerCmd(const struct CmdArgs *ctx)
192 {
193 INIT_LOGV("DoTrigger :%s", ctx->argv[0]);
194 DoTriggerExec(ctx->argv[0]);
195 }
196
DoLoadDefaultParams(const struct CmdArgs * ctx)197 static void DoLoadDefaultParams(const struct CmdArgs *ctx)
198 {
199 int mode = 0;
200 if (ctx->argc > 1 && strcmp(ctx->argv[1], "onlyadd") == 0) {
201 mode = LOAD_PARAM_ONLY_ADD;
202 }
203 INIT_LOGV("DoLoadDefaultParams args : %s %d", ctx->argv[0], mode);
204 LoadDefaultParams(ctx->argv[0], mode);
205 }
206
DoSyncExec(const struct CmdArgs * ctx)207 static void DoSyncExec(const struct CmdArgs *ctx)
208 {
209 // format: syncexec /xxx/xxx/xxx xxx
210 INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoSyncExec: invalid arguments");
211 SyncExecCommand(ctx->argc, ctx->argv);
212 return;
213 }
214
DoExec(const struct CmdArgs * ctx)215 static void DoExec(const struct CmdArgs *ctx)
216 {
217 // format: exec /xxx/xxx/xxx xxx
218 INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoExec: invalid arguments");
219 pid_t pid = fork();
220 INIT_ERROR_CHECK(pid >= 0, return, "DoExec: failed to fork child process to exec \"%s\"", ctx->argv[0]);
221
222 if (pid == 0) {
223 OpenHidebug(ctx->argv[0]);
224 int ret = execv(ctx->argv[0], ctx->argv);
225 INIT_CHECK_ONLY_ELOG(ret != -1, "DoExec: execute \"%s\" failed: %d.", ctx->argv[0], errno);
226 _exit(0x7f);
227 }
228 return;
229 }
230
DoSymlink(const struct CmdArgs * ctx)231 static void DoSymlink(const struct CmdArgs *ctx)
232 {
233 // format: symlink /xxx/xxx/xxx /xxx/xxx/xxx
234 int ret = symlink(ctx->argv[0], ctx->argv[1]);
235 if (ret != 0 && errno != EEXIST) {
236 INIT_LOGE("DoSymlink: link %s to %s failed: %d", ctx->argv[0], ctx->argv[1], errno);
237 }
238 }
239
GetDeviceMode(const char * deviceStr)240 static mode_t GetDeviceMode(const char *deviceStr)
241 {
242 switch (*deviceStr) {
243 case 'b':
244 case 'B':
245 return S_IFBLK;
246 case 'c':
247 case 'C':
248 return S_IFCHR;
249 case 'f':
250 case 'F':
251 return S_IFIFO;
252 default:
253 return -1;
254 }
255 }
256
DoMakeNode(const struct CmdArgs * ctx)257 static void DoMakeNode(const struct CmdArgs *ctx)
258 {
259 // format: mknod path b 0644 1 9
260 const int deviceTypePos = 1;
261 const int authorityPos = 2;
262 const int majorDevicePos = 3;
263 const int minorDevicePos = 4;
264 INIT_ERROR_CHECK(access(ctx->argv[1], F_OK), return, "DoMakeNode failed, path has sexisted");
265 mode_t deviceMode = GetDeviceMode(ctx->argv[deviceTypePos]);
266 errno = 0;
267 unsigned int major = strtoul(ctx->argv[majorDevicePos], NULL, DECIMAL);
268 INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[majorDevicePos]);
269 unsigned int minor = strtoul(ctx->argv[minorDevicePos], NULL, DECIMAL);
270 INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[minorDevicePos]);
271 mode_t authority = strtoul(ctx->argv[authorityPos], NULL, OCTAL);
272 INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[authorityPos]);
273 int ret = mknod(ctx->argv[0], deviceMode | authority, makedev(major, minor));
274 if (ret != 0) {
275 INIT_LOGE("DoMakeNode: path: %s failed: %d", ctx->argv[0], errno);
276 }
277 }
278
DoMakeDevice(const struct CmdArgs * ctx)279 static void DoMakeDevice(const struct CmdArgs *ctx)
280 {
281 // format: makedev major minor
282 errno = 0;
283 unsigned int major = strtoul(ctx->argv[0], NULL, DECIMAL);
284 INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[0]);
285 unsigned int minor = strtoul(ctx->argv[1], NULL, DECIMAL);
286 INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[1]);
287 dev_t deviceId = makedev(major, minor);
288 INIT_CHECK_ONLY_ELOG(deviceId >= 0, "DoMakedevice \" major:%s, minor:%s \" failed :%d ", ctx->argv[0],
289 ctx->argv[1], errno);
290 return;
291 }
292
DoMountFstabFile(const struct CmdArgs * ctx)293 static void DoMountFstabFile(const struct CmdArgs *ctx)
294 {
295 INIT_LOGI("Mount partitions from fstab file \" %s \"", ctx->argv[0]);
296 int ret = MountAllWithFstabFile(ctx->argv[0], 0);
297 INIT_LOGI("Mount partitions from fstab file \" %s \" finish ret %d", ctx->argv[0], ret);
298 HookMgrExecute(GetBootStageHookMgr(), INIT_MOUNT_STAGE, NULL, NULL);
299 }
300
DoUmountFstabFile(const struct CmdArgs * ctx)301 static void DoUmountFstabFile(const struct CmdArgs *ctx)
302 {
303 INIT_LOGI("Umount partitions from fstab file \" %s \"", ctx->argv[0]);
304 int rc = UmountAllWithFstabFile(ctx->argv[0]);
305 if (rc < 0) {
306 INIT_LOGE("Run command umount_fstab failed");
307 } else {
308 INIT_LOGI("Umount partitions from fstab done");
309 }
310 }
311
DoRestorecon(const struct CmdArgs * ctx)312 static void DoRestorecon(const struct CmdArgs *ctx)
313 {
314 int ret;
315 INIT_CMD_INFO cmdInfo;
316 cmdInfo.cmdName = "restorecon";
317 cmdInfo.cmdContent = ctx->argv[0];
318 cmdInfo.reserved = NULL;
319
320 HOOK_EXEC_OPTIONS options;
321 options.flags = TRAVERSE_STOP_WHEN_ERROR;
322 options.preHook = NULL;
323 options.postHook = NULL;
324 ret = HookMgrExecute(GetBootStageHookMgr(), INIT_RESTORECON, (void*)(&cmdInfo), (void*)(&options));
325 if (ret == 0) {
326 return;
327 }
328 PluginExecCmdByName("restoreContentRecurse", ctx->argv[0]);
329 return;
330 }
331
DoLoadAccessTokenId(const struct CmdArgs * ctx)332 static void DoLoadAccessTokenId(const struct CmdArgs *ctx)
333 {
334 LoadAccessTokenId();
335 }
336
FilterService(const Service * service,const char ** exclude,int size)337 static int FilterService(const Service *service, const char **exclude, int size)
338 {
339 for (int i = 0; i < size; i++) {
340 if (exclude[i] != NULL && strcmp(service->name, exclude[i]) == 0) {
341 return 1;
342 }
343 }
344 return 0;
345 }
346
DoStopAllServices(const struct CmdArgs * ctx)347 static void DoStopAllServices(const struct CmdArgs *ctx)
348 {
349 int flags = SERVICE_ATTR_INVALID;
350 if (ctx->argc >= 1 && strcmp(ctx->argv[0], "true") == 0) {
351 flags |= SERVICE_ATTR_NEEDWAIT;
352 StopAllServices(flags, (const char **)(&ctx->argv[1]), ctx->argc - 1, FilterService);
353 } else {
354 StopAllServices(flags, (const char **)ctx->argv, ctx->argc, FilterService);
355 }
356 return;
357 }
358
DoUmount(const struct CmdArgs * ctx)359 static void DoUmount(const struct CmdArgs *ctx)
360 {
361 INIT_LOGI("DoUmount %s", ctx->argv[0]);
362 MountStatus status = GetMountStatusForMountPoint(ctx->argv[0]);
363 if (status == MOUNT_MOUNTED) {
364 int ret = umount(ctx->argv[0]);
365 if ((ret != 0) && (ctx->argc > 1) && (strcmp(ctx->argv[1], "MNT_FORCE") == 0)) {
366 ret = umount2(ctx->argv[0], MNT_FORCE);
367 }
368 INIT_CHECK_ONLY_ELOG(ret == 0, "Failed to umount %s, errno %d", ctx->argv[0], errno);
369 } else if (status == MOUNT_UMOUNTED) {
370 INIT_LOGI("%s is already umounted", ctx->argv[0]);
371 } else {
372 INIT_LOGE("Failed to get %s mount status", ctx->argv[0]);
373 }
374 }
375
DoSync(const struct CmdArgs * ctx)376 static void DoSync(const struct CmdArgs *ctx)
377 {
378 sync();
379 }
380
DoTimerStart(const struct CmdArgs * ctx)381 static void DoTimerStart(const struct CmdArgs *ctx)
382 {
383 INIT_LOGI("Timer start service with arg = %s", ctx->argv[0]);
384 char *arg = ctx->argv[0];
385 int count = 0;
386 int expectedCount = 2;
387 char **splitArgs = SplitStringExt(ctx->argv[0], "|", &count, expectedCount);
388 if (splitArgs == NULL) {
389 INIT_LOGE("Call timer_start with invalid arguments");
390 return;
391 }
392
393 if (count != expectedCount) {
394 INIT_LOGE("Call timer_start with unexpected arguments %s", arg);
395 FreeStringVector(splitArgs, count);
396 return;
397 }
398
399 Service *service = GetServiceByName(splitArgs[0]);
400 if (service == NULL) {
401 INIT_LOGE("Cannot find service in timer_start command");
402 FreeStringVector(splitArgs, count);
403 return;
404 }
405
406 errno = 0;
407 uint64_t timeout = strtoull(splitArgs[1], NULL, DECIMAL_BASE);
408 if (errno != 0) {
409 INIT_LOGE("call timer_start with invalid timer");
410 FreeStringVector(splitArgs, count);
411 return;
412 }
413 // not need this anymore , release memory.
414 FreeStringVector(splitArgs, count);
415 ServiceStartTimer(service, timeout);
416 }
417
DoTimerStop(const struct CmdArgs * ctx)418 static void DoTimerStop(const struct CmdArgs *ctx)
419 {
420 INIT_LOGI("Stop service timer with arg = %s", ctx->argv[0]);
421 const char *serviceName = ctx->argv[0];
422 Service *service = GetServiceByName(serviceName);
423 if (service == NULL) {
424 INIT_LOGE("Cannot find service in timer_stop command");
425 return;
426 }
427 ServiceStopTimer(service);
428 }
429
InitFscryptPolicy(void)430 static bool InitFscryptPolicy(void)
431 {
432 char policy[FSCRYPT_POLICY_BUF_SIZE];
433 if (LoadFscryptPolicy(policy, FSCRYPT_POLICY_BUF_SIZE) == 0) {
434 if (SetFscryptSysparam(policy) == 0) {
435 return true;
436 }
437 }
438 return false;
439 }
440
DoInitGlobalKey(const struct CmdArgs * ctx)441 static void DoInitGlobalKey(const struct CmdArgs *ctx)
442 {
443 INIT_LOGV("Do init global key start");
444 const char *dataDir = "/data";
445 if (strncmp(ctx->argv[0], dataDir, strlen(dataDir)) != 0) {
446 INIT_LOGE("Not data partitation");
447 return;
448 }
449 if (!InitFscryptPolicy()) {
450 INIT_LOGW("Init fscrypt failed, not enable fscrypt");
451 return;
452 }
453
454 char * const argv[] = {
455 "/system/bin/sdc",
456 "filecrypt",
457 "init_global_key",
458 NULL
459 };
460 int argc = ARRAY_LENGTH(argv);
461 int ret = SyncExecCommand(argc, argv);
462 INIT_CMD_INFO cmdInfo;
463 cmdInfo.cmdName = "init_global_key";
464 cmdInfo.cmdContent = (const char *)&ret;
465 cmdInfo.reserved = NULL;
466 HookMgrExecute(GetBootStageHookMgr(), INIT_POST_DATA_UNENCRYPT, (void*)(&cmdInfo), NULL);
467 }
468
DoInitMainUser(const struct CmdArgs * ctx)469 static void DoInitMainUser(const struct CmdArgs *ctx)
470 {
471 char * const argv[] = {
472 "/system/bin/sdc",
473 "filecrypt",
474 "init_main_user",
475 NULL
476 };
477 int argc = ARRAY_LENGTH(argv);
478 int ret = SyncExecCommand(argc, argv);
479 INIT_CMD_INFO cmdInfo;
480 cmdInfo.cmdName = "init_main_user";
481 cmdInfo.cmdContent = (const char *)&ret;
482 cmdInfo.reserved = NULL;
483 HookMgrExecute(GetBootStageHookMgr(), INIT_POST_DATA_UNENCRYPT, (void*)(&cmdInfo), NULL);
484 }
485
DoMkswap(const struct CmdArgs * ctx)486 static void DoMkswap(const struct CmdArgs *ctx)
487 {
488 char *const argv[] = {
489 "/system/bin/mkswap",
490 ctx->argv[0],
491 NULL
492 };
493 int argc = ARRAY_LENGTH(argv);
494 SyncExecCommand(argc, argv);
495 }
496
DoSwapon(const struct CmdArgs * ctx)497 static void DoSwapon(const struct CmdArgs *ctx)
498 {
499 char *const argv[] = {
500 "/system/bin/swapon",
501 ctx->argv[0],
502 NULL
503 };
504 int argc = ARRAY_LENGTH(argv);
505 SyncExecCommand(argc, argv);
506 }
507
DoMkSandbox(const struct CmdArgs * ctx)508 static void DoMkSandbox(const struct CmdArgs *ctx)
509 {
510 INIT_LOGV("Do make sandbox start");
511 const char *sandbox = ctx->argv[0];
512 InitDefaultNamespace();
513 if (!InitSandboxWithName(sandbox)) {
514 INIT_LOGE("Failed to init sandbox with name %s.", sandbox);
515 }
516
517 if (PrepareSandbox(sandbox) != 0) {
518 INIT_LOGE("Failed to prepare sandbox %s.", sandbox);
519 DestroySandbox(sandbox);
520 }
521 if (EnterDefaultNamespace() < 0) {
522 INIT_LOGE("Failed to set default namespace.");
523 }
524 CloseDefaultNamespace();
525 }
526
527 static const struct CmdTable g_cmdTable[] = {
528 { "syncexec ", 1, 10, 0, DoSyncExec },
529 { "exec ", 1, 10, 0, DoExec },
530 { "mknode ", 5, 5, 0, DoMakeNode },
531 { "makedev ", 2, 2, 0, DoMakeDevice },
532 { "symlink ", 2, 2, 1, DoSymlink },
533 { "trigger ", 0, 1, 0, DoTriggerCmd },
534 { "insmod ", 1, 10, 1, DoInsmod },
535 { "setparam ", 2, 2, 0, DoSetParam },
536 { "load_persist_params ", 0, 1, 0, DoLoadPersistParams },
537 { "load_param ", 1, 2, 0, DoLoadDefaultParams },
538 { "load_access_token_id ", 0, 1, 0, DoLoadAccessTokenId },
539 { "ifup ", 1, 1, 1, DoIfup },
540 { "mount_fstab ", 1, 1, 0, DoMountFstabFile },
541 { "umount_fstab ", 1, 1, 0, DoUmountFstabFile },
542 { "restorecon ", 1, 1, 1, DoRestorecon },
543 { "stopAllServices ", 0, 10, 0, DoStopAllServices },
544 { "umount ", 1, 1, 0, DoUmount },
545 { "sync ", 0, 1, 0, DoSync },
546 { "timer_start", 1, 1, 0, DoTimerStart },
547 { "timer_stop", 1, 1, 0, DoTimerStop },
548 { "init_global_key ", 1, 1, 0, DoInitGlobalKey },
549 { "init_main_user ", 0, 1, 0, DoInitMainUser },
550 { "mkswap", 1, 1, 0, DoMkswap},
551 { "swapon", 1, 1, 0, DoSwapon},
552 { "mksandbox", 1, 1, 0, DoMkSandbox},
553 };
554
GetCmdTable(int * number)555 const struct CmdTable *GetCmdTable(int *number)
556 {
557 *number = (int)ARRAY_LENGTH(g_cmdTable);
558 return g_cmdTable;
559 }
560
OpenHidebug(const char * name)561 void OpenHidebug(const char *name)
562 {
563 #ifdef SUPPORT_PROFILER_HIDEBUG
564 InitEnvironmentParam(name);
565 #endif
566 }
567
SetFileCryptPolicy(const char * dir)568 int SetFileCryptPolicy(const char *dir)
569 {
570 if (dir == NULL) {
571 INIT_LOGE("SetFileCryptPolicy:dir is null");
572 return -EINVAL;
573 }
574 return FscryptPolicyEnable(dir);
575 }
576