chroot.cpp 442 B

123456789101112131415161718192021222324252627
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. int main(int argc, char** argv)
  4. {
  5. if (argc != 2) {
  6. printf("usage: chroot <path>\n");
  7. return 0;
  8. }
  9. if (chroot(argv[1]) < 0) {
  10. perror("chroot");
  11. return 1;
  12. }
  13. if (chdir("/") < 0) {
  14. perror("chdir(/)");
  15. return 1;
  16. }
  17. if (execl("/bin/Shell", "Shell", nullptr) < 0) {
  18. perror("execl");
  19. return 1;
  20. }
  21. return 0;
  22. }