minor fixes

This commit is contained in:
dragonmuffin 2024-08-19 21:56:18 +05:00
parent 588bc8c834
commit e528e59619
4 changed files with 11 additions and 9 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
/starter/alpine-make-rootfs/
/run
/starter/shared
/starter/starter
/starter/minrootfs
/pkg/go/gen

View file

@ -5,6 +5,7 @@ all:
make generate
init:
git clone https://github.com/alpinelinux/alpine-make-rootfs
rm -rf starter/minrootfs
mv alpine-make-rootfs starter/alpine-make-rootfs
mkrootfs:
starter/create_rootfs.sh

View file

@ -2,7 +2,7 @@
if [[ $(whoami) != root ]]
then
echo "run as root please"
echo -e "\e[38;5;1mrun as root please\e[0m"
exit
fi

View file

@ -22,10 +22,10 @@ void mnt_prepare(char* rootfs, char* shared_mountpoint) {
if (mount(rootfs,rootfs,"ext4",MS_BIND,"")) die("failed to mount %s: %m", rootfs);
//if (mount(shared_mountpoint,shared_mountpoint,"ext4",MS_BIND,"")) die("failed to mount %s: %m",shared_mountpoint);
if (chdir(rootfs)) die("falied to cd:%m");
if (mount("/sys","sys","sysfs",0,"")) die("failed to mount: %m");
//if (mount("/sys","sys","sysfs",0,"")) die("failed to mount sysfs: %m");
//if (mount("/dev","dev","udev",0,"")) die("failed to mount: %m");
if (mkdir("shared", 0777) && errno != EEXIST) die("Failed to mkdir %s: %m\n", shared_mountpoint);
if (mount(shared_folder,"shared","ext4",MS_BIND,"")) die("failed to mount: %m");
if (mount(shared_folder,"shared","ext4",MS_BIND,"")) die("failed to mount shared folder: %m");
if (mkdir(put_old, 0000) && errno != EEXIST) die("Failed to mkdir %s: %m\n", put_old);
if (syscall(SYS_pivot_root, ".", put_old)) die("Failed to pivot_root from %s to %s: %m\n", rootfs, put_old);
if (chdir("/")) die("Failed to chdir to new root: %m\n");
@ -57,9 +57,9 @@ static int nsrun(void* arg) {
struct params *params = (struct params*) arg;
await_setup(params->fd[0]);
if(chdir("shared")) die("failed to chdir: %m");
int out_fd=open("out",O_WRONLY|O_CREAT);
if(out_fd==-1) die("unable to open out file:%m");
else dup2(out_fd,STDOUT_FILENO);
//int out_fd=open("out",O_WRONLY|O_CREAT);
//if(out_fd==-1) die("unable to open out file:%m");
//else dup2(out_fd,STDOUT_FILENO);
if(chdir("..")) die("failed to chdir: %m");
mnt_prepare("minrootfs",params->shared_folder);
sethostname(hostname,sizeof(hostname));