Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit eb59290

Browse files
authored
Merge pull request hyperhq#191 from devimc/topic/remove_busybox_dependency
Use binaries from PATH
2 parents 8fdd03c + b232c8f commit eb59290

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

build/make-initrd.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
#!/bin/bash
22

33
rm -rf /tmp/hyperstart-rootfs
4-
mkdir -p /tmp/hyperstart-rootfs/lib /tmp/hyperstart-rootfs/lib64 /tmp/hyperstart-rootfs/lib/modules
4+
mkdir -p /tmp/hyperstart-rootfs/lib \
5+
/tmp/hyperstart-rootfs/lib64 \
6+
/tmp/hyperstart-rootfs/lib/modules
7+
8+
mkdir -m 0755 -p /tmp/hyperstart-rootfs/dev \
9+
/tmp/hyperstart-rootfs/sys \
10+
/tmp/hyperstart-rootfs/sbin \
11+
/tmp/hyperstart-rootfs/bin \
12+
/tmp/hyperstart-rootfs/proc
513

614
cp ../src/init /tmp/hyperstart-rootfs
715
cp busybox /tmp/hyperstart-rootfs
816
cp iptables /tmp/hyperstart-rootfs
917
cp libm.so.6 /tmp/hyperstart-rootfs/lib64/
1018
tar -xf modules.tar -C /tmp/hyperstart-rootfs/lib/modules
1119

20+
# create symlinks to busybox and iptables
21+
BUSYBOX_BINARIES=(/bin/sh /bin/tar /bin/hwclock /sbin/modprobe /sbin/depmod)
22+
for bin in ${BUSYBOX_BINARIES[@]}
23+
do
24+
mkdir -p /tmp/hyperstart-rootfs/`dirname ${bin}`
25+
ln -sf /busybox /tmp/hyperstart-rootfs/${bin}
26+
done
27+
IPTABLES_BINARIES=(/sbin/iptables /sbin/iptables-restore /sbin/iptables-save)
28+
for bin in ${IPTABLES_BINARIES[@]}
29+
do
30+
mkdir -p /tmp/hyperstart-rootfs/`dirname ${bin}`
31+
ln -sf /iptables /tmp/hyperstart-rootfs/${bin}
32+
done
33+
1234
ldd /tmp/hyperstart-rootfs/init | while read line
1335
do
1436
arr=(${line// / })

src/init.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,14 +1342,6 @@ int main(int argc, char *argv[])
13421342
{
13431343
char *cmdline, *ctl_serial, *tty_serial;
13441344

1345-
if (hyper_mkdir("/dev", 0755) < 0 ||
1346-
hyper_mkdir("/sys", 0755) < 0 ||
1347-
hyper_mkdir("/sbin", 0755) < 0 ||
1348-
hyper_mkdir("/proc", 0755) < 0) {
1349-
perror("create basic directory failed");
1350-
return -1;
1351-
}
1352-
13531345
if (mount("proc", "/proc", "proc", MS_NOSUID| MS_NODEV| MS_NOEXEC, NULL) == -1) {
13541346
perror("mount proc failed");
13551347
return -1;
@@ -1377,21 +1369,6 @@ int main(int argc, char *argv[])
13771369
return -1;
13781370
}
13791371

1380-
if (symlink("/busybox", "/sh") < 0 ||
1381-
symlink("/busybox", "/tar") < 0 ||
1382-
symlink("/busybox", "/sbin/modprobe") < 0 ||
1383-
symlink("/busybox", "/sbin/depmod") < 0) {
1384-
perror("failed to symlink tools to /busybox");
1385-
return -1;
1386-
}
1387-
1388-
if (symlink("/iptables", "/sbin/iptables") < 0 ||
1389-
symlink("/iptables", "/sbin/iptables-restore") < 0 ||
1390-
symlink("/iptables", "/sbin/iptables-save") < 0) {
1391-
perror("failed to symlink tools to /iptables");
1392-
/* TODO disable portmapping */
1393-
}
1394-
13951372
cmdline = read_cmdline();
13961373

13971374
setsid();

src/portmapping.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
int hyper_init_modules()
1818
{
19-
int status = hyper_cmd("/sbin/depmod");
19+
int status = hyper_cmd("depmod");
2020
if (status != 0) {
2121
fprintf(stderr, "depmod failed, status: %d\n", status);
2222
return -1;
@@ -32,10 +32,10 @@ int hyper_setup_iptables_rule(struct ipt_rule rule)
3232
int check = -1;
3333

3434
if (rule.rule != NULL) {
35-
sprintf(check_cmd, "/sbin/iptables -t %s -C %s %s", rule.table, rule.chain, rule.rule);
36-
sprintf(cmd, "/sbin/iptables -t %s %s %s %s", rule.table, rule.op, rule.chain, rule.rule);
35+
sprintf(check_cmd, "iptables -t %s -C %s %s", rule.table, rule.chain, rule.rule);
36+
sprintf(cmd, "iptables -t %s %s %s %s", rule.table, rule.op, rule.chain, rule.rule);
3737
} else {
38-
sprintf(cmd, "/sbin/iptables -t %s %s %s", rule.table, rule.op, rule.chain);
38+
sprintf(cmd, "iptables -t %s %s %s", rule.table, rule.op, rule.chain);
3939
}
4040

4141
if (strlen(check_cmd) > 0) {

src/util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int hyper_list_dir(char *path)
7171
int hyper_copy_dir(char *src, char *dest)
7272
{
7373
char cmd[512];
74-
snprintf(cmd, sizeof(cmd), "/tar cf - -C %s . | /tar fx - -C %s", src, dest);
74+
snprintf(cmd, sizeof(cmd), "tar cf - -C %s . | tar fx - -C %s", src, dest);
7575

7676
return hyper_cmd(cmd);
7777
}
@@ -82,7 +82,7 @@ void hyper_sync_time_hctosys() {
8282
if (pid < 0) {
8383
perror("fail to fork to copy directory");
8484
} else if (pid == 0) {
85-
execlp("/busybox", "hwclock", "-s", NULL);
85+
execlp("hwclock", "hwclock", "-s", NULL);
8686
perror("exec hwclock -s command failed");
8787
exit(-1);
8888
}
@@ -703,7 +703,7 @@ int hyper_cmd(char *cmd)
703703
return -1;
704704
} else {
705705
fprintf(stdout, "executing cmd %s\n", cmd);
706-
execlp("/busybox", "sh", "-c", cmd, NULL);
706+
execlp("sh", "sh", "-c", cmd, NULL);
707707
}
708708

709709
return -1;

0 commit comments

Comments
 (0)