|
1 | 1 | // SPDX-License-Identifier: Apache-2.0
|
2 | 2 | /* Copyright (c) 2024 Elastic NV */
|
3 | 3 |
|
4 |
| -#include <err.h> |
5 |
| -#include <stdio.h> |
6 |
| -#include <unistd.h> |
7 |
| -#include <string.h> |
8 |
| - |
9 | 4 | #include <linux/reboot.h>
|
10 | 5 |
|
| 6 | +#include <sys/ioctl.h> |
11 | 7 | #include <sys/mount.h>
|
12 | 8 | #include <sys/reboot.h>
|
| 9 | +#include <sys/socket.h> |
13 | 10 | #include <sys/stat.h>
|
14 | 11 | #include <sys/syscall.h>
|
15 | 12 | #include <sys/utsname.h>
|
16 | 13 | #include <sys/wait.h>
|
17 | 14 |
|
| 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 | + |
18 | 25 | static void
|
19 | 26 | powerdown(void)
|
20 | 27 | {
|
@@ -48,6 +55,25 @@ display_banner(char *argv[])
|
48 | 55 | }
|
49 | 56 | }
|
50 | 57 |
|
| 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 | + |
51 | 77 | int
|
52 | 78 | main(int argc, char *argv[])
|
53 | 79 | {
|
@@ -95,6 +121,10 @@ main(int argc, char *argv[])
|
95 | 121 | errx(1, "couldn't mount tracefs or debugfs");
|
96 | 122 | }
|
97 | 123 | }
|
| 124 | + if (mount(NULL, "/sys/fs/cgroup", "cgroup2", 0, NULL) == -1) |
| 125 | + err(1, "mount /sys/fs/cgroup"); |
| 126 | + |
| 127 | + net_up(); |
98 | 128 |
|
99 | 129 | display_banner(argv);
|
100 | 130 |
|
|
0 commit comments