Skip to content

Commit 9b8e9eb

Browse files
nohajcslp
authored andcommitted
init.c: only use KRUN_EXIT_CODE_IOCTL if root is really virtiofs
Signed-off-by: Jan Noha <[email protected]>
1 parent 6e1c448 commit 9b8e9eb

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

init/init.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <sys/resource.h>
1717
#include <sys/socket.h>
1818
#include <sys/stat.h>
19+
#include <sys/statfs.h>
1920
#include <sys/time.h>
2021
#include <sys/types.h>
2122
#include <sys/wait.h>
@@ -956,10 +957,35 @@ int setup_redirects()
956957
return 0;
957958
}
958959

960+
int is_virtiofs(const char *path)
961+
{
962+
struct statfs fs;
963+
964+
if (statfs(path, &fs) != 0) {
965+
perror("statfs");
966+
return -1;
967+
}
968+
969+
// virtiofs magic number: 0x65735546
970+
return (fs.f_type == 0x65735546) ? 1 : 0;
971+
}
972+
959973
void set_exit_code(int code)
960974
{
961975
int fd;
962976
int ret;
977+
int virtiofs_check;
978+
979+
// Only use the ioctl if virtiofs is used for root filesystem
980+
virtiofs_check = is_virtiofs("/");
981+
if (virtiofs_check < 0) {
982+
printf("Warning: Could not determine filesystem type for root\n");
983+
}
984+
985+
if (virtiofs_check == 0) {
986+
// Root filesystem is not virtiofs, skip the ioctl
987+
return;
988+
}
963989

964990
fd = open("/", O_RDONLY);
965991
if (fd < 0) {

0 commit comments

Comments
 (0)