BProcess.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @file BProcess.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_SYSTEM_BPROCESS_H
  23. #define BADVPN_SYSTEM_BPROCESS_H
  24. #include <stdint.h>
  25. #include <unistd.h>
  26. #include <misc/debug.h>
  27. #include <misc/dead.h>
  28. #include <structure/LinkedList2.h>
  29. #include <system/DebugObject.h>
  30. #include <system/BUnixSignal.h>
  31. #include <system/BPending.h>
  32. typedef struct {
  33. BReactor *reactor;
  34. BUnixSignal signal;
  35. LinkedList2 processes;
  36. BPending wait_job;
  37. DebugObject d_obj;
  38. } BProcessManager;
  39. typedef void (*BProcess_handler) (void *user, int normally, uint8_t normally_exit_status);
  40. typedef struct {
  41. BProcessManager *m;
  42. BProcess_handler handler;
  43. void *user;
  44. pid_t pid;
  45. LinkedList2Node list_node; // node in BProcessManager.processes
  46. DebugObject d_obj;
  47. #ifndef NDEBUG
  48. dead_t d_dead;
  49. #endif
  50. } BProcess;
  51. int BProcessManager_Init (BProcessManager *o, BReactor *reactor) WARN_UNUSED;
  52. void BProcessManager_Free (BProcessManager *o);
  53. int BProcess_Init (BProcess *o, BProcessManager *m, BProcess_handler handler, void *user, const char *file, char *const argv[], const char *username) WARN_UNUSED;
  54. void BProcess_Free (BProcess *o);
  55. int BProcess_Terminate (BProcess *o);
  56. int BProcess_Kill (BProcess *o);
  57. #endif