system.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include <stddef.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <sys/wait.h>
  6. /* uClinux-2.0 has vfork, but Linux 2.0 doesn't */
  7. #include <sys/syscall.h>
  8. #if ! defined __NR_vfork
  9. #define vfork fork
  10. #endif
  11. int __libc_system(char *command)
  12. {
  13. int wait_val, pid;
  14. __sighandler_t save_quit, save_int, save_chld;
  15. if (command == 0)
  16. return 1;
  17. save_quit = signal(SIGQUIT, SIG_IGN);
  18. save_int = signal(SIGINT, SIG_IGN);
  19. save_chld = signal(SIGCHLD, SIG_DFL);
  20. if ((pid = vfork()) < 0) {
  21. signal(SIGQUIT, save_quit);
  22. signal(SIGINT, save_int);
  23. signal(SIGCHLD, save_chld);
  24. return -1;
  25. }
  26. if (pid == 0) {
  27. signal(SIGQUIT, SIG_DFL);
  28. signal(SIGINT, SIG_DFL);
  29. signal(SIGCHLD, SIG_DFL);
  30. execl("/bin/sh", "sh", "-c", command, (char *) 0);
  31. _exit(127);
  32. }
  33. /* Signals are not absolutly guarenteed with vfork */
  34. signal(SIGQUIT, SIG_IGN);
  35. signal(SIGINT, SIG_IGN);
  36. #if 0
  37. printf("Waiting for child %d\n", pid);
  38. #endif
  39. if (wait4(pid, &wait_val, 0, 0) == -1)
  40. wait_val = -1;
  41. signal(SIGQUIT, save_quit);
  42. signal(SIGINT, save_int);
  43. signal(SIGCHLD, save_chld);
  44. return wait_val;
  45. }
  46. weak_alias(__libc_system, system)