feat(recovery): strengthen debugging capabilities of preinit
Some checks failed
build liminix / build_vm_qemu_mips (push) Failing after 27s
Some checks failed
build liminix / build_vm_qemu_mips (push) Failing after 27s
Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
parent
73ea02b982
commit
9fcfae3eae
1 changed files with 38 additions and 1 deletions
|
@ -4,9 +4,13 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
|
#include <asm/setup.h> /* for COMMAND_LINE_SIZE */
|
||||||
|
|
||||||
|
@ -44,6 +48,25 @@ static int fork_exec(char * command, char *args[])
|
||||||
return execve(command, args, NULL);
|
return execve(command, args, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void debug_listdir(const char * path)
|
||||||
|
{
|
||||||
|
DIR *mydir;
|
||||||
|
struct dirent *myfile;
|
||||||
|
struct stat mystat;
|
||||||
|
|
||||||
|
char buf[512];
|
||||||
|
mydir = opendir(path);
|
||||||
|
while((myfile = readdir(mydir)) != NULL)
|
||||||
|
{
|
||||||
|
sprintf(buf, "%s/%s", path, myfile->d_name);
|
||||||
|
stat(buf, &mystat);
|
||||||
|
printf("%llu", mystat.st_size);
|
||||||
|
printf(" %s\n", myfile->d_name);
|
||||||
|
}
|
||||||
|
closedir(mydir);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
char banner[] = "Running pre-init...\n";
|
char banner[] = "Running pre-init...\n";
|
||||||
char buf[COMMAND_LINE_SIZE];
|
char buf[COMMAND_LINE_SIZE];
|
||||||
|
|
||||||
|
@ -108,7 +131,12 @@ int main(int argc, char *argv[], char *envp[])
|
||||||
"bind", MS_BIND, NULL));
|
"bind", MS_BIND, NULL));
|
||||||
|
|
||||||
char *exec_args[] = { "activate", "/target", NULL };
|
char *exec_args[] = { "activate", "/target", NULL };
|
||||||
AVER(fork_exec("/target/persist/activate", exec_args));
|
if (fork_exec("/target/persist/activate", exec_args) < 0) {
|
||||||
|
ERR("failed to activate the system\n");
|
||||||
|
pr_u32(errno); ERR ( " - "); ERR(strerror(errno)); ERR("\n");
|
||||||
|
goto failsafe;
|
||||||
|
}
|
||||||
|
|
||||||
AVER(chdir("/target"));
|
AVER(chdir("/target"));
|
||||||
|
|
||||||
AVER(mount("/target", "/", "bind", MS_BIND | MS_REC, NULL));
|
AVER(mount("/target", "/", "bind", MS_BIND | MS_REC, NULL));
|
||||||
|
@ -120,13 +148,22 @@ int main(int argc, char *argv[], char *envp[])
|
||||||
AVER(execve("/persist/init", argv, envp));
|
AVER(execve("/persist/init", argv, envp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failsafe:
|
||||||
|
debug_listdir("/");
|
||||||
|
debug_listdir("/target");
|
||||||
|
|
||||||
ERR("failed to mount the rootfs\n");
|
ERR("failed to mount the rootfs\n");
|
||||||
ERR("final stand using the failsafe initialization method\n");
|
ERR("final stand using the failsafe initialization method\n");
|
||||||
ERR("the boot process is manual from now on\n");
|
ERR("the boot process is manual from now on\n");
|
||||||
|
|
||||||
argv[0] = "init";
|
argv[0] = "init";
|
||||||
argv[1] = NULL;
|
argv[1] = NULL;
|
||||||
|
// Attempt to unmount the /target mount-bind.
|
||||||
|
AVER(umount("/target"));
|
||||||
AVER(execve("/failsafe-init", argv, envp));
|
AVER(execve("/failsafe-init", argv, envp));
|
||||||
|
|
||||||
|
debug_listdir("/");
|
||||||
|
debug_listdir("/target");
|
||||||
|
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue