Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
93bec381
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
93bec381
编写于
2月 10, 2022
作者:
O
openharmony_ci
提交者:
Gitee
2月 10, 2022
浏览文件
操作
浏览文件
下载
差异文件
!284 init: pass fscrypto mount option to sdc
Merge pull request !284 from qilongzhang/for_merge_0128
上级
cb21afdf
1c8e5fee
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
118 addition
and
0 deletion
+118
-0
services/init/include/init_cmds.h
services/init/include/init_cmds.h
+1
-0
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+25
-0
services/init/lite/init_cmds.c
services/init/lite/init_cmds.c
+5
-0
services/init/standard/init_cmds.c
services/init/standard/init_cmds.c
+87
-0
未找到文件。
services/init/include/init_cmds.h
浏览文件 @
93bec381
...
...
@@ -81,6 +81,7 @@ const struct CmdTable *GetCmdByName(const char *name);
void
ExecReboot
(
const
char
*
value
);
char
*
BuildStringFromCmdArg
(
const
struct
CmdArgs
*
ctx
,
int
startIndex
);
void
ExecCmd
(
const
struct
CmdTable
*
cmd
,
const
char
*
cmdContent
);
int
FileCryptEnable
(
char
*
fileCryptOption
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/init/init_common_cmds.c
浏览文件 @
93bec381
...
...
@@ -38,6 +38,8 @@
#include "init_utils.h"
#include "securec.h"
static
char
*
g_fileCryptOptions
=
NULL
;
static
char
*
AddOneArg
(
const
char
*
param
,
size_t
paramLen
)
{
int
valueCount
=
1
;
...
...
@@ -385,6 +387,17 @@ static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const c
WaitForFile
(
source
,
WAIT_MAX_SECOND
);
return
1
;
}
const
char
*
fileCryptPre
=
"filecrypt="
;
size_t
len
=
strlen
(
fileCryptPre
);
if
(
strncmp
(
targetStr
,
fileCryptPre
,
len
)
==
0
)
{
size_t
maxLen
=
strlen
(
targetStr
)
+
1
;
g_fileCryptOptions
=
calloc
(
sizeof
(
char
),
maxLen
);
INIT_ERROR_CHECK
(
g_fileCryptOptions
!=
NULL
,
return
0
,
"Failed to alloc memory"
);
int
ret
=
snprintf_s
(
g_fileCryptOptions
,
maxLen
,
maxLen
-
1
,
"%s"
,
targetStr
+
len
);
INIT_ERROR_CHECK
(
ret
>=
0
,
return
0
,
"Failed to snprintf"
);
return
1
;
}
return
0
;
}
...
...
@@ -426,6 +439,18 @@ static void DoMount(const struct CmdArgs *ctx)
if
(
ret
!=
0
)
{
INIT_LOGE
(
"Failed to mount for %s, err %d."
,
target
,
errno
);
}
if
((
g_fileCryptOptions
!=
NULL
)
&&
(
strncmp
(
target
,
"/data"
,
strlen
(
"/data"
))
==
0
))
{
ret
=
FileCryptEnable
(
g_fileCryptOptions
);
if
(
ret
<
0
)
{
INIT_LOGE
(
"File Crypt enabled failed"
);
free
(
g_fileCryptOptions
);
g_fileCryptOptions
=
NULL
;
return
;
}
free
(
g_fileCryptOptions
);
g_fileCryptOptions
=
NULL
;
INIT_LOGI
(
"File Crypt enabled success"
);
}
}
static
void
DoWrite
(
const
struct
CmdArgs
*
ctx
)
...
...
services/init/lite/init_cmds.c
浏览文件 @
93bec381
...
...
@@ -108,6 +108,11 @@ static void DoLoadCfg(const struct CmdArgs *ctx)
(
void
)
fclose
(
fp
);
}
int
FileCryptEnable
(
char
*
fileCryptOption
)
{
return
0
;
}
static
const
struct
CmdTable
g_cmdTable
[]
=
{
{
"exec "
,
1
,
10
,
DoExec
},
{
"loadcfg "
,
1
,
1
,
DoLoadCfg
},
...
...
services/init/standard/init_cmds.c
浏览文件 @
93bec381
...
...
@@ -41,6 +41,8 @@
#include <policycoreutils.h>
#endif
#define ARRAY_LEN(array) (sizeof(array) / (sizeof(array[0])))
int
GetParamValue
(
const
char
*
symValue
,
unsigned
int
symLen
,
char
*
paramValue
,
unsigned
int
paramLen
)
{
INIT_CHECK_RETURN_VALUE
((
symValue
!=
NULL
)
&&
(
paramValue
!=
NULL
)
&&
(
paramLen
!=
0
),
-
1
);
...
...
@@ -365,6 +367,89 @@ static void DoTimerStop(const struct CmdArgs*ctx)
ServiceStopTimer
(
service
);
}
static
int
SyncExecCommand
(
int
argc
,
char
*
const
*
argv
)
{
if
(
argc
==
0
||
argv
==
NULL
||
argv
[
0
]
==
NULL
)
{
return
-
1
;
}
pid_t
pid
=
fork
();
if
(
pid
<
0
)
{
INIT_LOGE
(
"Fork new process to format failed: %d"
,
errno
);
return
-
1
;
}
if
(
pid
==
0
)
{
execv
(
argv
[
0
],
argv
);
exit
(
-
1
);
}
int
status
;
waitpid
(
pid
,
&
status
,
0
);
if
(
!
WIFEXITED
(
status
)
||
WEXITSTATUS
(
status
)
!=
0
)
{
INIT_LOGE
(
"Command %s failed with status %d"
,
argv
[
0
],
WEXITSTATUS
(
status
));
}
return
WEXITSTATUS
(
status
);
}
static
void
DoInitGlobalKey
(
const
struct
CmdArgs
*
ctx
)
{
INIT_LOGI
(
"DoInitGlobalKey: start"
);
if
(
ctx
==
NULL
||
ctx
->
argc
!=
1
)
{
INIT_LOGE
(
"DoInitGlobalKey: para invalid"
);
return
;
}
const
char
*
dataDir
=
"/data"
;
if
(
strncmp
(
ctx
->
argv
[
0
],
dataDir
,
strlen
(
dataDir
))
!=
0
)
{
INIT_LOGE
(
"DoInitGlobalKey: not data partitation"
);
return
;
}
char
*
const
argv
[]
=
{
"/system/bin/sdc"
,
"filecrypt"
,
"init_global_key"
,
NULL
};
int
argc
=
ARRAY_LEN
(
argv
);
int
ret
=
SyncExecCommand
(
argc
,
argv
);
INIT_LOGI
(
"DoInitGlobalKey: end, ret = %d"
,
ret
);
}
static
void
DoInitMainUser
(
const
struct
CmdArgs
*
ctx
)
{
INIT_LOGI
(
"DoInitMainUser: start"
);
if
(
ctx
==
NULL
)
{
INIT_LOGE
(
"DoInitMainUser: para invalid"
);
return
;
}
char
*
const
argv
[]
=
{
"/system/bin/sdc"
,
"filecrypt"
,
"init_main_user"
,
NULL
};
int
argc
=
ARRAY_LEN
(
argv
);
int
ret
=
SyncExecCommand
(
argc
,
argv
);
INIT_LOGI
(
"DoInitMainUser: end, ret = %d"
,
ret
);
}
int
FileCryptEnable
(
char
*
fileCryptOption
)
{
INIT_LOGI
(
"FileCryptEnable: start"
);
if
(
fileCryptOption
==
NULL
)
{
INIT_LOGE
(
"FileCryptEnable:option null"
);
return
-
EINVAL
;
}
char
*
const
argv
[]
=
{
"/system/bin/sdc"
,
"filecrypt"
,
"enable"
,
fileCryptOption
,
NULL
};
int
argc
=
ARRAY_LEN
(
argv
);
int
ret
=
SyncExecCommand
(
argc
,
argv
);
INIT_LOGI
(
"FileCryptEnable: end, ret = %d"
,
ret
);
return
ret
;
}
static
const
struct
CmdTable
g_cmdTable
[]
=
{
{
"exec "
,
1
,
10
,
DoExec
},
{
"mknode "
,
1
,
5
,
DoMakeNode
},
...
...
@@ -385,6 +470,8 @@ static const struct CmdTable g_cmdTable[] = {
{
"sync "
,
0
,
1
,
DoSync
},
{
"timer_start"
,
1
,
1
,
DoTimerStart
},
{
"timer_stop"
,
1
,
1
,
DoTimerStop
},
{
"init_global_key "
,
1
,
1
,
DoInitGlobalKey
},
{
"init_main_user "
,
0
,
1
,
DoInitMainUser
},
};
const
struct
CmdTable
*
GetCmdTable
(
int
*
number
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录