I am trying to change the root of my process to new file system that I mounted at /tmp/mount_dir and i have created another directory inside it /tmp/mount_dir/inner_mount_dir, and according to the man page pivot_root(2) there is no glibc wrapper for this system call so I made my own
int pivot_root(const char *new_root, const char *put_old){
return(syscall(SYS_pivot_root, new_root, put_old));
}
and I call it in this code after creating the two nested directories as specified by the man page
fprintf(stderr,"-->Changing the process's root...");
if(pivot_root(mount_dir, inner_mount_dir)){
fprintf(stderr,"Failed..%m\n");
return -1;
}else{
fprintf(stderr,"Success\n");
}
The system call returns a success, but the issue is that the system goes into a crashing state, first all the icons from the gnome dash are gone, i cannot interact with the system at all (the system freezes i can only change windows at first then all terminates), and the screen turns into a blank black screen with a "-" at the upper left corner as if the system is shutting down, but freezes at that state until i force shutdown.