error.ipp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // Copyright (c) 2021 Klemens D. Morgenstern
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PROCESS_V2_IMPL_ERROR_IPP
  6. #define BOOST_PROCESS_V2_IMPL_ERROR_IPP
  7. #include <boost/process/v2/detail/config.hpp>
  8. #include <boost/process/v2/error.hpp>
  9. #include <boost/process/v2/exit_code.hpp>
  10. #include <cstdlib>
  11. #if defined(BOOST_PROCESS_V2_POSIX)
  12. #include <sys/wait.h>
  13. #endif
  14. BOOST_PROCESS_V2_BEGIN_NAMESPACE
  15. namespace error
  16. {
  17. namespace detail
  18. {
  19. struct utf8_category final : public error_category
  20. {
  21. utf8_category() : error_category(0xDAEDu) {}
  22. const char* name() const noexcept
  23. {
  24. return "process.v2.utf8";
  25. }
  26. std::string message(int value) const
  27. {
  28. switch (static_cast<utf8_conv_error>(value))
  29. {
  30. case utf8_conv_error::insufficient_buffer:
  31. return "A supplied buffer size was not large enough";
  32. case utf8_conv_error::invalid_character:
  33. return "Invalid characters were found in a string.";
  34. default:
  35. return "process.v2.utf8 error";
  36. }
  37. }
  38. };
  39. struct exit_code_category final : public error_category
  40. {
  41. exit_code_category() : error_category(0xDAEEu) {}
  42. const char* name() const noexcept
  43. {
  44. return "process.v2.exit_code";
  45. }
  46. std::string message(int status) const
  47. {
  48. switch (evaluate_exit_code(status))
  49. {
  50. case v2::detail::still_active:
  51. return "still-active";
  52. case EXIT_SUCCESS:
  53. return "exit_success";
  54. case EXIT_FAILURE:
  55. return "exit_failure";
  56. default:
  57. #if defined(BOOST_PROCESS_V2_POSIX)
  58. if (WIFCONTINUED(status))
  59. return "continued";
  60. switch (WTERMSIG(status))
  61. {
  62. # if defined(SIGABRT)
  63. case SIGABRT: return "SIGABRT: Abort signal from abort(3)";
  64. # endif
  65. # if defined(SIGALRM)
  66. case SIGALRM: return "SIGALRM: Timer signal from alarm(2)";
  67. # endif
  68. # if defined(SIGBUS)
  69. case SIGBUS: return "SIGBUS: Bus error (bad memory access)";
  70. # endif
  71. # if defined(SIGCHLD)
  72. case SIGCHLD: return "SIGCHLD: Child stopped or terminated";
  73. # endif
  74. # if defined(SIGCONT)
  75. case SIGCONT: return "SIGCONT: Continue if stopped";
  76. # endif
  77. # if defined(SIGEMT)
  78. case SIGEMT: return "SIGEMT: Emulator trap";
  79. # endif
  80. # if defined(SIGFPE)
  81. case SIGFPE: return "SIGFPE: Floating-point exception";
  82. # endif
  83. # if defined(SIGHUP)
  84. case SIGHUP: return "SIGHUP: Hangup detected on controlling terminal";
  85. # endif
  86. # if defined(SIGILL)
  87. case SIGILL: return "SIGILL: Illegal Instruction";
  88. # endif
  89. # if defined(SIGINFO)
  90. case SIGINFO: return "SIGINFO: A synonym for SIGPWR";
  91. # endif
  92. # if defined(SIGINT)
  93. case SIGINT: return "SIGINT: Interrupt from keyboard";
  94. # endif
  95. # if defined(SIGIO)
  96. case SIGIO: return "SIGIO: I/O now possible (4.2BSD)";
  97. # endif
  98. # if defined(SIGKILL)
  99. case SIGKILL: return "SIGKILL: Kill signal";
  100. # endif
  101. # if defined(SIGLOST)
  102. case SIGLOST: return "SIGLOST: File lock lost (unused)";
  103. # endif
  104. # if defined(SIGPIPE)
  105. case SIGPIPE: return "SIGPIPE: Broken pipe: write to pipe with no";
  106. # endif
  107. # if defined(SIGPOLL) && !defined(SIGIO)
  108. case SIGPOLL: return "SIGPOLL: Pollable event (Sys V);";
  109. # endif
  110. # if defined(SIGPROF)
  111. case SIGPROF: return "SIGPROF: Profiling timer expired";
  112. # endif
  113. # if defined(SIGPWR)
  114. case SIGPWR: return "SIGPWR: Power failure (System V)";
  115. # endif
  116. # if defined(SIGQUIT)
  117. case SIGQUIT: return "SIGQUIT: Quit from keyboard";
  118. # endif
  119. # if defined(SIGSEGV)
  120. case SIGSEGV: return "SIGSEGV: Invalid memory reference";
  121. # endif
  122. # if defined(SIGSTKFLT)
  123. case SIGSTKFLT: return "SIGSTKFLT: Stack fault on coprocessor (unused)";
  124. # endif
  125. # if defined(SIGSTOP)
  126. case SIGSTOP: return "SIGSTOP: Stop process";
  127. # endif
  128. # if defined(SIGTSTP)
  129. case SIGTSTP: return "SIGTSTP: Stop typed at terminal";
  130. # endif
  131. # if defined(SIGSYS)
  132. case SIGSYS: return "SIGSYS: Bad system call (SVr4);";
  133. # endif
  134. # if defined(SIGTERM)
  135. case SIGTERM: return "SIGTERM: Termination signal";
  136. # endif
  137. # if defined(SIGTRAP)
  138. case SIGTRAP: return "SIGTRAP: Trace/breakpoint trap";
  139. # endif
  140. # if defined(SIGTTIN)
  141. case SIGTTIN: return "SIGTTIN: Terminal input for background process";
  142. # endif
  143. # if defined(SIGTTOU)
  144. case SIGTTOU: return "SIGTTOU: Terminal output for background process";
  145. # endif
  146. # if defined(SIGURG)
  147. case SIGURG: return "SIGURG: Urgent condition on socket (4.2BSD)";
  148. # endif
  149. # if defined(SIGUSR1)
  150. case SIGUSR1: return "SIGUSR1: User-defined signal 1";
  151. # endif
  152. # if defined(SIGUSR2)
  153. case SIGUSR2: return "SIGUSR2: User-defined signal 2";
  154. # endif
  155. # if defined(SIGVTALRM)
  156. case SIGVTALRM: return "SIGVTALRM: Virtual alarm clock (4.2BSD)";
  157. # endif
  158. # if defined(SIGXCPU)
  159. case SIGXCPU: return "SIGXCPU: CPU time limit exceeded (4.2BSD);";
  160. # endif
  161. # if defined(SIGXFSZ)
  162. case SIGXFSZ: return "SIGXFSZ: File size limit exceeded (4.2BSD);";
  163. # endif
  164. # if defined(SIGWINCH)
  165. case SIGWINCH: return "SIGWINCH: Window resize signal (4.3BSD, Sun)";
  166. # endif
  167. default: return "Unknown signal";
  168. }
  169. #endif
  170. return "exited with other error";
  171. }
  172. }
  173. };
  174. } // namespace detail
  175. BOOST_PROCESS_V2_DECL const error_category& get_utf8_category()
  176. {
  177. static detail::utf8_category instance;
  178. return instance;
  179. }
  180. BOOST_PROCESS_V2_DECL const error_category& get_exit_code_category()
  181. {
  182. static detail::exit_code_category instance;
  183. return instance;
  184. }
  185. }
  186. BOOST_PROCESS_V2_END_NAMESPACE
  187. #endif //BOOST_PROCESS_V2_IMPL_ERROR_IPP