Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
1780cb89
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,发现更多精彩内容 >>
提交
1780cb89
编写于
8月 04, 2021
作者:
Z
zhong_ning
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify init
Signed-off-by:
N
zhong_ning
<
zhong_ning@hoperun.com
>
上级
765f82f3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
106 addition
and
2 deletion
+106
-2
services/etc/init.cfg
services/etc/init.cfg
+4
-1
services/src/init_cmds.c
services/src/init_cmds.c
+102
-1
未找到文件。
services/etc/init.cfg
浏览文件 @
1780cb89
...
...
@@ -178,7 +178,10 @@
"chmod 0444 /dev/cpu_variant:${ro.bionic.2nd_arch}",
"chown system system /sys/power/state",
"chown system system /sys/power/wakeup_count",
"chmod 0660 /sys/power/state"
"chmod 0660 /sys/power/state",
"ifup lo",
"hostname localhost",
"domainname localdomain"
]
}, {
"name" : "param:sys.boot_from_charger_mode=1",
...
...
services/src/init_cmds.c
浏览文件 @
1780cb89
...
...
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/resource.h>
#include <sys/stat.h>
...
...
@@ -28,6 +29,7 @@
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <net/if.h>
#ifndef OHOS_LITE
#include <linux/module.h>
#endif
...
...
@@ -217,6 +219,102 @@ void FreeCmd(struct CmdArgs **cmd)
return
;
}
#define EXTRACT_ARGS(cmdname, cmdContent, args) \
struct
CmdArgs
*
ctx
=
GetCmd
(
cmdContent
,
" "
,
args
);
\
if
(
ctx
==
NULL
||
ctx
->
argv
==
NULL
||
ctx
->
argc
!=
args
)
{
\
INIT_LOGE
(
"Command
\"
%s
\"
with invalid arguments: %s"
,
#
cmdname
,
cmdContent
);
\
goto
out
;
\
}
\
static
void
DoSetDomainname
(
const
char
*
cmdContent
,
int
maxArg
)
{
EXTRACT_ARGS
(
domainname
,
cmdContent
,
maxArg
)
int
fd
=
open
(
"/proc/sys/kernel/domainname"
,
O_WRONLY
|
O_CREAT
|
O_CLOEXEC
|
O_TRUNC
,
S_IRUSR
|
S_IWUSR
);
if
(
fd
<
0
)
{
INIT_LOGE
(
"DoSetDomainame failed to open
\"
/proc/sys/kernel/domainname
\"
. err = %d"
,
errno
);
goto
out
;
}
size_t
size
=
strlen
(
ctx
->
argv
[
0
]);
ssize_t
n
=
write
(
fd
,
ctx
->
argv
[
0
],
size
);
if
(
n
!=
(
ssize_t
)
size
)
{
INIT_LOGE
(
"DoSetHostname failed to write %s to
\"
/proc/sys/kernel/domainname
\"
. err = %d"
,
errno
);
}
if
(
fd
>
0
)
{
close
(
fd
);
fd
=
-
1
;
}
out:
FreeCmd
(
&
ctx
);
return
;
}
static
void
DoSetHostname
(
const
char
*
cmdContent
,
int
maxArg
)
{
EXTRACT_ARGS
(
hostname
,
cmdContent
,
maxArg
)
int
fd
=
open
(
"/proc/sys/kernel/hostname"
,
O_WRONLY
|
O_CREAT
|
O_CLOEXEC
|
O_TRUNC
,
S_IRUSR
|
S_IWUSR
);
if
(
fd
<
0
)
{
INIT_LOGE
(
"DoSetHostname failed to open
\"
/proc/sys/kernel/hostname
\"
. err = %d"
,
errno
);
goto
out
;
}
size_t
size
=
strlen
(
ctx
->
argv
[
0
]);
ssize_t
n
=
write
(
fd
,
ctx
->
argv
[
0
],
size
);
if
(
n
!=
(
ssize_t
)
size
)
{
INIT_LOGE
(
"DoSetHostname failed to write %s to
\"
/proc/sys/kernel/hostname
\"
. err = %d"
,
errno
);
}
if
(
fd
>
0
)
{
close
(
fd
);
fd
=
-
1
;
}
out:
FreeCmd
(
&
ctx
);
return
;
}
#ifndef OHOS_LITE
static
void
DoIfup
(
const
char
*
cmdContent
,
int
maxArg
)
{
EXTRACT_ARGS
(
ifup
,
cmdContent
,
maxArg
)
struct
ifreq
interface
;
if
(
strncpy_s
(
interface
.
ifr_name
,
IFNAMSIZ
-
1
,
ctx
->
argv
[
0
],
strlen
(
ctx
->
argv
[
0
]))
!=
EOK
)
{
INIT_LOGE
(
"DoIfup failed to copy interface name"
);
goto
out
;
}
INIT_LOGD
(
"interface name: %s"
,
interface
.
ifr_name
);
int
fd
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
if
(
fd
<
0
)
{
INIT_LOGE
(
"DoIfup failed to create socket, err = %d"
,
errno
);
goto
out
;
}
if
(
ioctl
(
fd
,
SIOCGIFFLAGS
,
&
interface
)
<
0
)
{
INIT_LOGE
(
"DoIfup failed to do ioctl with command
\"
SIOCGIFFLAGS
\"
, err = %d"
,
errno
);
close
(
fd
);
fd
=
-
1
;
goto
out
;
}
interface
.
ifr_flags
|=
IFF_UP
;
if
(
ioctl
(
fd
,
SIOCSIFFLAGS
,
&
interface
)
<
0
)
{
INIT_LOGE
(
"DoIfup failed to do ioctl with command
\"
SIOCSIFFLAGS
\"
, err = %d"
,
errno
);
}
if
(
fd
>
0
)
{
close
(
fd
);
fd
=
-
1
;
}
out:
FreeCmd
(
&
ctx
);
return
;
}
#endif
static
void
DoSleep
(
const
char
*
cmdContent
,
int
maxArg
)
{
struct
CmdArgs
*
ctx
=
GetCmd
(
cmdContent
,
" "
,
maxArg
);
...
...
@@ -1103,13 +1201,16 @@ static const struct CmdTable CMD_TABLE[] = {
{
"setparam "
,
2
,
DoSetParam
},
{
"load_persist_params "
,
1
,
DoLoadPersistParams
},
{
"load_param "
,
1
,
DoLoadDefaultParams
},
{
"ifup "
,
1
,
DoIfup
},
#endif
{
"stop "
,
1
,
DoStop
},
{
"reset "
,
1
,
DoReset
},
{
"copy "
,
2
,
DoCopy
},
{
"reboot "
,
1
,
DoRebootCmd
},
{
"setrlimit "
,
3
,
DoSetrlimit
},
{
"sleep "
,
1
,
DoSleep
}
{
"sleep "
,
1
,
DoSleep
},
{
"hostname "
,
1
,
DoSetHostname
},
{
"domainname "
,
1
,
DoSetDomainname
}
};
void
DoCmdByName
(
const
char
*
name
,
const
char
*
cmdContent
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录