From bd0214b1da66225f410641692e89e492f668472a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 2 Jan 2021 14:46:29 +0100 Subject: Format all code with clang-format --- include/raul/Process.hpp | 89 ++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 44 deletions(-) (limited to 'include/raul/Process.hpp') diff --git a/include/raul/Process.hpp b/include/raul/Process.hpp index d77c3f3..1c5deed 100644 --- a/include/raul/Process.hpp +++ b/include/raul/Process.hpp @@ -30,52 +30,53 @@ namespace Raul { class Process : Noncopyable { public: - /** Launch a sub process. - * - * @param argv List of arguments, where argv[0] is the command name. - * @return True on success. - */ - static bool launch(const char* const argv[]) { - // Use the same double fork() trick as JACK to prevent zombie children - const int child = fork(); - - if (child == 0) { - // (in child) - - // Close all nonstandard file descriptors - struct rlimit max_fds{}; - getrlimit(RLIMIT_NOFILE, &max_fds); - for (rlim_t fd = 3; fd < max_fds.rlim_cur; ++fd) { - close(static_cast(fd)); - } - - // Fork child - const int grandchild = fork(); - switch (grandchild) { - case 0: - // (in grandchild) - setsid(); - execvp(argv[0], const_cast(argv)); - _exit(-1); - - case -1: - // Fork failed, there is no grandchild - _exit(-1); - - default: - // Fork succeeded, return grandchild PID - _exit(grandchild); - } - } else if (child < 0) { - // Fork failed, there is no child - return false; - } - - return true; - } + /** Launch a sub process. + * + * @param argv List of arguments, where argv[0] is the command name. + * @return True on success. + */ + static bool launch(const char* const argv[]) + { + // Use the same double fork() trick as JACK to prevent zombie children + const int child = fork(); + + if (child == 0) { + // (in child) + + // Close all nonstandard file descriptors + struct rlimit max_fds {}; + getrlimit(RLIMIT_NOFILE, &max_fds); + for (rlim_t fd = 3; fd < max_fds.rlim_cur; ++fd) { + close(static_cast(fd)); + } + + // Fork child + const int grandchild = fork(); + switch (grandchild) { + case 0: + // (in grandchild) + setsid(); + execvp(argv[0], const_cast(argv)); + _exit(-1); + + case -1: + // Fork failed, there is no grandchild + _exit(-1); + + default: + // Fork succeeded, return grandchild PID + _exit(grandchild); + } + } else if (child < 0) { + // Fork failed, there is no child + return false; + } + + return true; + } private: - Process() = default; + Process() = default; }; } // namespace Raul -- cgit v1.2.1