Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.3KB

  1. /*
  2. * Carla process utils
  3. * Copyright (C) 2019-2020 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_PROCESS_UTILS_HPP_INCLUDED
  18. #define CARLA_PROCESS_UTILS_HPP_INCLUDED
  19. #include "CarlaUtils.hpp"
  20. #ifndef CARLA_OS_WIN
  21. # include <csignal>
  22. # include <csetjmp>
  23. #endif
  24. // --------------------------------------------------------------------------------------------------------------------
  25. // process functions
  26. /*
  27. * Set current process name.
  28. */
  29. void carla_setProcessName(const char* const name) noexcept;
  30. /*
  31. * Set flag to automatically terminate ourselves if parent process dies.
  32. */
  33. void carla_terminateProcessOnParentExit(const bool kill) noexcept;
  34. // --------------------------------------------------------------------------------------------------------------------
  35. // process utility classes
  36. /*
  37. * Catches SIGABRT for a function scope.
  38. */
  39. class ScopedAbortCatcher {
  40. public:
  41. ScopedAbortCatcher();
  42. ~ScopedAbortCatcher();
  43. inline bool wasTriggered() const
  44. {
  45. return s_triggered;
  46. }
  47. private:
  48. static bool s_triggered;
  49. #ifndef CARLA_OS_WIN
  50. static jmp_buf s_env;
  51. static sig_t s_oldsig;
  52. static void sig_handler(const int signum);
  53. #endif
  54. CARLA_DECLARE_NON_COPY_CLASS(ScopedAbortCatcher)
  55. CARLA_PREVENT_HEAP_ALLOCATION
  56. };
  57. /*
  58. * Store and restore all signal handlers for a function scope.
  59. */
  60. class CarlaSignalRestorer {
  61. public:
  62. CarlaSignalRestorer();
  63. ~CarlaSignalRestorer();
  64. private:
  65. #ifndef CARLA_OS_WIN
  66. struct ::sigaction sigs[16];
  67. #endif
  68. CARLA_DECLARE_NON_COPY_CLASS(CarlaSignalRestorer)
  69. CARLA_PREVENT_HEAP_ALLOCATION
  70. };
  71. // --------------------------------------------------------------------------------------------------------------------
  72. #endif // CARLA_PROCESS_UTILS_HPP_INCLUDED