Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
3c8df8bc
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3c8df8bc
编写于
2月 07, 2022
作者:
X
xionglei6
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init: fix bugs
Signed-off-by:
N
xionglei6
<
xionglei6@huawei.com
>
上级
f416a865
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
53 deletion
+55
-53
services/begetctl/misc_daemon.cpp
services/begetctl/misc_daemon.cpp
+22
-40
services/begetctl/shell/shell_bas.c
services/begetctl/shell/shell_bas.c
+25
-3
services/etc/init.cfg
services/etc/init.cfg
+0
-6
services/etc/init.without_two_stages.cfg
services/etc/init.without_two_stages.cfg
+8
-4
未找到文件。
services/begetctl/misc_daemon.cpp
浏览文件 @
3c8df8bc
...
...
@@ -26,9 +26,10 @@
#include <vector>
#include "begetctl.h"
#include "sys_param.h"
#include "fs_manager/fs_manager.h"
#include "param_wrapper.h"
#include "shell.h"
#include "shell_utils.h"
#include "sys_param.h"
constexpr
int
MAX_LOGO_SIZE
=
1024
*
2038
;
constexpr
int
PARTITION_INFO_POS
=
1144
;
...
...
@@ -36,11 +37,6 @@ constexpr int PARTITION_INFO_MAX_LENGTH = 256;
constexpr
int
BLOCK_SZIE_1
=
512
;
constexpr
uint64_t
LOGO_MAGIC
=
0XABCABCAB
;
struct
option
g_options
[]
=
{
{
"write_logo"
,
required_argument
,
nullptr
,
0
},
{
nullptr
,
0
,
nullptr
,
0
},
};
static
std
::
string
GetMiscDevicePath
()
{
char
miscDevice
[
PATH_MAX
]
=
{
0
};
...
...
@@ -113,47 +109,47 @@ static int WriteLogo(int fd, const std::string &logoPath)
}
int
addrOffset
=
(
PARTITION_INFO_POS
+
PARTITION_INFO_MAX_LENGTH
+
BLOCK_SZIE_1
-
1
)
/
BLOCK_SZIE_1
;
if
(
lseek
(
fd
,
addrOffset
*
BLOCK_SZIE_1
,
SEEK_SET
)
<
0
)
{
std
::
cout
<<
"Failed to seek file
\n
"
;
BSH_LOGI
(
"Failed lseek logoPath %s errno %d "
,
logoPath
.
c_str
(),
errno
)
;
return
-
1
;
}
uint32_t
magic
=
0
;
if
(
read
(
fd
,
&
magic
,
sizeof
(
uint32_t
))
!=
sizeof
(
uint32_t
))
{
std
::
cout
<<
"Failed to read magic number
\n
"
;
BSH_LOGI
(
"Failed magic logoPath %s errno %d "
,
logoPath
.
c_str
(),
errno
)
;
return
-
1
;
}
if
(
magic
==
LOGO_MAGIC
)
{
std
::
cout
<<
"Get matched magic number, logo already written
\n
"
;
BSH_LOGI
(
"Get matched magic number, logo already written
\n
"
)
;
return
0
;
}
struct
stat
st
{};
magic
=
LOGO_MAGIC
;
lseek
(
fd
,
addrOffset
*
BLOCK_SZIE_1
,
SEEK_SET
);
if
(
write
(
fd
,
&
magic
,
sizeof
(
magic
))
!=
sizeof
(
magic
))
{
std
::
cout
<<
"Write magic number failed
\n
"
;
BSH_LOGI
(
"Write magic number failed %d"
,
errno
)
;
return
-
1
;
}
if
(
stat
(
logoPath
.
c_str
(),
&
st
)
<
0
)
{
if
(
errno
==
ENOENT
)
{
std
::
cout
<<
logoPath
<<
" is not exist
\n
"
;
BSH_LOGI
(
"%s is not exist"
,
logoPath
.
c_str
())
;
}
else
{
std
::
cout
<<
"Failed to get "
<<
logoPath
<<
" stat
\n
"
;
BSH_LOGI
(
"Failed to get %s stat"
,
logoPath
.
c_str
())
;
}
ClearLogo
(
fd
);
return
-
1
;
}
if
(
st
.
st_size
<
0
||
st
.
st_size
>
MAX_LOGO_SIZE
)
{
std
::
cout
<<
"Invalid logo file with size
\n
"
;
BSH_LOGE
(
"Invalid logo file with size "
)
;
ClearLogo
(
fd
);
return
-
1
;
}
uint32_t
logoSize
=
static_cast
<
uint32_t
>
(
st
.
st_size
);
if
(
write
(
fd
,
&
logoSize
,
sizeof
(
logoSize
))
!=
sizeof
(
logoSize
))
{
std
::
cout
<<
"Write logo size failed
\n
"
;
BSH_LOGE
(
"Write logo size failed "
)
;
ClearLogo
(
fd
);
return
-
1
;
}
...
...
@@ -172,15 +168,15 @@ static void WriteLogoToMisc(const std::string &logoPath)
if
(
miscDev
.
empty
())
{
return
;
}
BSH_LOGI
(
"WriteLogoToMisc miscDev %s "
,
miscDev
.
c_str
());
int
fd
=
open
(
miscDev
.
c_str
(),
O_RDWR
|
O_CLOEXEC
,
S_IRUSR
|
S_IWUSR
|
S_IRGRP
|
S_IROTH
);
if
(
fd
<
0
)
{
std
::
cout
<<
"Failed to open "
<<
miscDev
<<
", err = "
<<
errno
<<
std
::
endl
;
BSH_LOGI
(
"Failed to writeLogoToMisc miscDev %s errno %d "
,
miscDev
.
c_str
(),
errno
)
;
return
;
}
if
(
WriteLogo
(
fd
,
logoPath
)
<
0
)
{
std
::
cout
<<
"Write logo to "
<<
miscDev
<<
" failed"
<<
std
::
endl
;
BSH_LOGI
(
"Failed WriteLogo miscDev %s errno %d "
,
miscDev
.
c_str
(),
errno
)
;
}
close
(
fd
);
int
addrOffset
=
(
PARTITION_INFO_POS
+
PARTITION_INFO_MAX_LENGTH
+
BLOCK_SZIE_1
-
1
)
/
BLOCK_SZIE_1
;
...
...
@@ -189,7 +185,7 @@ static void WriteLogoToMisc(const std::string &logoPath)
return
;
}
if
(
lseek
(
fd1
,
addrOffset
*
BLOCK_SZIE_1
,
SEEK_SET
)
<
0
)
{
std
::
cout
<<
"Failed to seek file
\n
"
;
BSH_LOGI
(
"Failed lseek miscDev %s errno %d "
,
miscDev
.
c_str
(),
errno
)
;
close
(
fd1
);
return
;
}
...
...
@@ -197,12 +193,12 @@ static void WriteLogoToMisc(const std::string &logoPath)
uint32_t
magic
=
0
;
uint32_t
size
=
0
;
if
(
read
(
fd1
,
&
magic
,
sizeof
(
uint32_t
))
!=
sizeof
(
uint32_t
))
{
std
::
cout
<<
"Failed to read magic number
\n
"
;
BSH_LOGI
(
"Failed read miscDev %s errno %d "
,
miscDev
.
c_str
(),
errno
)
;
close
(
fd1
);
return
;
}
if
(
read
(
fd1
,
&
size
,
sizeof
(
uint32_t
))
!=
sizeof
(
uint32_t
))
{
std
::
cout
<<
"Failed to read magic number
\n
"
;
BSH_LOGI
(
"Failed read migic miscDev %s errno %d "
,
miscDev
.
c_str
(),
errno
)
;
close
(
fd1
);
return
;
}
...
...
@@ -212,25 +208,11 @@ static void WriteLogoToMisc(const std::string &logoPath)
static
int
main_cmd
(
BShellHandle
shell
,
int
argc
,
char
**
argv
)
{
int
rc
=
-
1
;
int
optIndex
=
-
1
;
while
((
rc
=
getopt_long
(
argc
,
argv
,
""
,
g_options
,
&
optIndex
))
!=
-
1
)
{
switch
(
rc
)
{
case
0
:
{
std
::
string
optionName
=
g_options
[
optIndex
].
name
;
if
(
optionName
==
"write_logo"
)
{
std
::
string
logoPath
=
optarg
;
WriteLogoToMisc
(
logoPath
);
}
break
;
}
case
'?'
:
std
::
cout
<<
"Invalid arugment
\n
"
;
break
;
default:
std
::
cout
<<
"Invalid arugment
\n
"
;
break
;
}
if
(
argc
>=
2
&&
strcmp
((
char
*
)
"--write_logo"
,
argv
[
0
])
==
0
)
{
// 2 min arg
WriteLogoToMisc
(
argv
[
1
]);
}
else
{
char
*
helpArgs
[]
=
{(
char
*
)
"misc_daemon"
,
NULL
};
BShellCmdHelp
(
shell
,
1
,
helpArgs
);
}
return
0
;
}
...
...
services/begetctl/shell/shell_bas.c
浏览文件 @
3c8df8bc
...
...
@@ -551,15 +551,33 @@ int32_t BShellEnvRegitsterCmd(BShellHandle handle, CmdInfo *cmdInfo)
return
0
;
}
static
const
char
*
GetRealCmdName
(
const
char
*
name
)
{
int
i
=
0
;
int
last
=
0
;
while
(
*
(
name
+
i
)
!=
'\0'
)
{
if
(
*
(
name
+
i
)
==
'/'
)
{
last
=
i
;
}
i
++
;
}
if
((
last
!=
0
)
&&
(
name
+
last
!=
NULL
))
{
return
name
+
last
+
1
;
}
else
{
return
name
;
}
}
BShellCommand
*
BShellEnvGetCmd
(
BShellHandle
handle
,
int32_t
argc
,
char
*
argv
[])
{
BSH_CHECK
(
handle
!=
NULL
,
return
NULL
,
"Invalid shell env"
);
BSH_CHECK
(
argc
>=
1
,
return
NULL
,
"Invalid argc"
);
BSH_LOGV
(
"BShellEnvGetCmd %s"
,
argv
[
0
]);
const
char
*
cmdName
=
GetRealCmdName
(
argv
[
0
]);
BSH_LOGV
(
"BShellEnvGetCmd %s cmd %s"
,
argv
[
0
],
cmdName
);
BShellEnv
*
shell
=
(
BShellEnv
*
)
handle
;
BShellCommand
*
cmd
=
shell
->
command
;
while
(
cmd
!=
NULL
)
{
if
(
strcmp
(
cmd
->
name
,
argv
[
0
]
)
!=
0
)
{
if
(
strcmp
(
cmd
->
name
,
cmdName
)
!=
0
)
{
cmd
=
cmd
->
next
;
continue
;
}
...
...
@@ -571,7 +589,11 @@ BShellCommand *BShellEnvGetCmd(BShellHandle handle, int32_t argc, char *argv[])
if
(
cmd
->
multikeys
[
i
]
==
NULL
)
{
return
cmd
;
}
if
(
strcmp
(
cmd
->
multikeys
[
i
],
argv
[
i
])
!=
0
)
{
char
*
tmp
=
argv
[
i
];
if
(
i
==
0
)
{
tmp
=
(
char
*
)
cmdName
;
}
if
(
strcmp
(
cmd
->
multikeys
[
i
],
tmp
)
!=
0
)
{
break
;
}
}
...
...
services/etc/init.cfg
浏览文件 @
3c8df8bc
...
...
@@ -413,12 +413,6 @@
"cmds" : [
"write /proc/sys/kernel/perf_event_paranoid 3"
]
}, {
"name" : "boot && param:const.debuggable=1",
"condition" : "boot && const.debuggable=1",
"cmds" : [
"start console"
]
}, {
"name" : "boot && param:const.debuggable=1",
"condition" : "boot && const.debuggable=1",
...
...
services/etc/init.without_two_stages.cfg
浏览文件 @
3c8df8bc
...
...
@@ -433,24 +433,28 @@
"services" : [{
"name" : "ueventd",
"path" : ["/system/bin/ueventd"],
"critical" : 1
"critical" : 1,
"start-mode" : "condition"
}, {
"name" : "console",
"path" : ["/system/bin/sh"],
"disabled" : 1,
"console" : 1,
"uid" : "root",
"gid" : ["shell", "log", "readproc"]
"gid" : ["shell", "log", "readproc"],
"start-mode" : "condition"
}, {
"name" : "watchdog_service",
"path" : ["/system/bin/watchdog_service", "10", "2"],
"disabled" : 1,
"uid" : "root",
"gid" : ["shell", "log", "readproc"]
"gid" : ["shell", "log", "readproc"],
"start-mode" : "condition"
}, {
"name" : "misc",
"path" : ["/system/bin/misc_daemon", "--write_logo", "/vendor/logo.rgb"],
"once" : 1
"once" : 1,
"start-mode" : "condition"
}
]
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录