coldplug.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
  3. * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License version 2.1
  7. * as published by the Free Software Foundation
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <sys/stat.h>
  15. #include <sys/types.h>
  16. #include <sys/mount.h>
  17. #include <unistd.h>
  18. #include "../procd.h"
  19. #include "../libc-compat.h"
  20. #include "hotplug.h"
  21. static struct uloop_process udevtrigger;
  22. static void coldplug_complete(struct uloop_timeout *t)
  23. {
  24. DEBUG(4, "Coldplug complete\n");
  25. hotplug_last_event(NULL);
  26. procd_state_next();
  27. }
  28. static void udevtrigger_complete(struct uloop_process *proc, int ret)
  29. {
  30. DEBUG(4, "Finished udevtrigger\n");
  31. hotplug_last_event(coldplug_complete);
  32. }
  33. void procd_coldplug(void)
  34. {
  35. char *argv[] = { "udevtrigger", NULL };
  36. unsigned int oldumask = umask(0);
  37. umount2("/dev/pts", MNT_DETACH);
  38. umount2("/dev/", MNT_DETACH);
  39. mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755,size=512K");
  40. ignore(symlink("/tmp/shm", "/dev/shm"));
  41. mkdir("/dev/pts", 0755);
  42. umask(oldumask);
  43. mount("devpts", "/dev/pts", "devpts", MS_NOEXEC | MS_NOSUID, 0);
  44. udevtrigger.cb = udevtrigger_complete;
  45. udevtrigger.pid = fork();
  46. if (!udevtrigger.pid) {
  47. execvp(argv[0], argv);
  48. ERROR("Failed to start coldplug\n");
  49. exit(-1);
  50. }
  51. if (udevtrigger.pid <= 0) {
  52. ERROR("Failed to start new coldplug instance\n");
  53. return;
  54. }
  55. uloop_process_add(&udevtrigger);
  56. DEBUG(4, "Launched coldplug instance, pid=%d\n", (int) udevtrigger.pid);
  57. }