Skip to content

Commit 220f798

Browse files
authored
Bring lo0 up on init and make sure to mount cgroups. (#126)
This will be relevant on upcoming socket/dns tests. While here, fixup the order of includes, which was inverted.
1 parent 2ea3da7 commit 220f798

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

init.c

+35-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
// SPDX-License-Identifier: Apache-2.0
22
/* Copyright (c) 2024 Elastic NV */
33

4-
#include <err.h>
5-
#include <stdio.h>
6-
#include <unistd.h>
7-
#include <string.h>
8-
94
#include <linux/reboot.h>
105

6+
#include <sys/ioctl.h>
117
#include <sys/mount.h>
128
#include <sys/reboot.h>
9+
#include <sys/socket.h>
1310
#include <sys/stat.h>
1411
#include <sys/syscall.h>
1512
#include <sys/utsname.h>
1613
#include <sys/wait.h>
1714

15+
#include <net/if.h>
16+
17+
#include <netinet/in.h>
18+
#include <netinet/ip.h>
19+
20+
#include <err.h>
21+
#include <stdio.h>
22+
#include <string.h>
23+
#include <unistd.h>
24+
1825
static void
1926
powerdown(void)
2027
{
@@ -48,6 +55,25 @@ display_banner(char *argv[])
4855
}
4956
}
5057

58+
static void
59+
net_up(void)
60+
{
61+
struct ifreq ifr;
62+
int fd;
63+
64+
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
65+
err(1, "socket");
66+
67+
bzero(&ifr, sizeof(ifr));
68+
strlcpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
69+
if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1)
70+
err(1, "SIOCGIFFLAGS");
71+
ifr.ifr_flags |= IFF_UP;
72+
if (ioctl(fd, SIOCSIFFLAGS, &ifr) == -1)
73+
err(1, "SIOCSIFFLAGS");
74+
close(fd);
75+
}
76+
5177
int
5278
main(int argc, char *argv[])
5379
{
@@ -95,6 +121,10 @@ main(int argc, char *argv[])
95121
errx(1, "couldn't mount tracefs or debugfs");
96122
}
97123
}
124+
if (mount(NULL, "/sys/fs/cgroup", "cgroup2", 0, NULL) == -1)
125+
err(1, "mount /sys/fs/cgroup");
126+
127+
net_up();
98128

99129
display_banner(argv);
100130

0 commit comments

Comments
 (0)