coldplug.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "hotplug.h"
  20. static struct uloop_process udevtrigger;
  21. static void coldplug_complete(struct uloop_timeout *t)
  22. {
  23. DEBUG(2, "Coldplug complete\n");
  24. hotplug_last_event(NULL);
  25. procd_state_next();
  26. }
  27. static void udevtrigger_complete(struct uloop_process *proc, int ret)
  28. {
  29. DEBUG(2, "Finished udevtrigger\n");
  30. hotplug_last_event(coldplug_complete);
  31. }
  32. void procd_coldplug(void)
  33. {
  34. char *argv[] = { "udevtrigger", NULL };
  35. umount2("/dev/pts", MNT_DETACH);
  36. umount2("/dev/", MNT_DETACH);
  37. mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755,size=512K");
  38. mkdir("/dev/shm", 0755);
  39. mkdir("/dev/pts", 0755);
  40. mount("devpts", "/dev/pts", "devpts", 0, 0);
  41. udevtrigger.cb = udevtrigger_complete;
  42. udevtrigger.pid = fork();
  43. if (!udevtrigger.pid) {
  44. execvp(argv[0], argv);
  45. ERROR("Failed to start coldplug\n");
  46. exit(-1);
  47. }
  48. if (udevtrigger.pid <= 0) {
  49. ERROR("Failed to start new coldplug instance\n");
  50. return;
  51. }
  52. uloop_process_add(&udevtrigger);
  53. DEBUG(2, "Launched coldplug instance, pid=%d\n", (int) udevtrigger.pid);
  54. }