test_procservice.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef TEST_PROCSERVICE
  2. #define TEST_PROCSERVICE
  3. // Friend interface to access base_process_service private/protected members.
  4. class base_process_service_test
  5. {
  6. public:
  7. static void exec_succeeded(base_process_service *bsp)
  8. {
  9. bsp->waiting_for_execstat = false;
  10. bsp->exec_succeeded();
  11. }
  12. static void exec_failed(base_process_service *bsp, int errcode)
  13. {
  14. run_proc_err err;
  15. err.stage = exec_stage::DO_EXEC;
  16. err.st_errno = errcode;
  17. bsp->waiting_for_execstat = false;
  18. bsp->pid = -1;
  19. bsp->exec_failed(err);
  20. }
  21. static void handle_exit(base_process_service *bsp, int exit_status)
  22. {
  23. bsp->pid = -1;
  24. bsp->handle_exit_status(bp_sys::exit_status(true, false, exit_status));
  25. }
  26. static void handle_signal_exit(base_process_service *bsp, int signo)
  27. {
  28. bsp->pid = -1;
  29. bsp->handle_exit_status(bp_sys::exit_status(false, true, signo));
  30. }
  31. static void handle_stop_exit(process_service *ps, int exit_status)
  32. {
  33. ps->stop_pid = -1;
  34. ps->waiting_for_execstat = false;
  35. ps->stop_status = bp_sys::exit_status(true, false, exit_status);
  36. ps->handle_stop_exit();
  37. }
  38. static int get_notification_fd(base_process_service *bsp)
  39. {
  40. return bsp->notification_fd;
  41. }
  42. };
  43. namespace bp_sys {
  44. // last signal sent:
  45. extern int last_sig_sent;
  46. extern pid_t last_forked_pid;
  47. }
  48. static time_val default_restart_interval = time_val(0, 200000000); // 200 milliseconds
  49. static void init_service_defaults(base_process_service &ps)
  50. {
  51. ps.set_restart_interval(time_val(10,0), 3);
  52. ps.set_restart_delay(default_restart_interval); // 200 milliseconds
  53. ps.set_stop_timeout(time_val(10,0));
  54. }
  55. #endif /* TEST_PROCSERVICE */