| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | #pragma once |
| 3 | |
| 4 | #include <string> |
| 5 | #include <sys/types.h> |
| 6 | #include <vector> |
| 7 | |
| 8 | namespace ExecUtils |
| 9 | { |
| 10 | /** |
| 11 | * @brief Redirect stdout to /tmp/log/<unitbase>/<fileName>.log |
| 12 | */ |
| 13 | void RedirectLogFd(const std::string &unitBase, const std::string &fileName); |
| 14 | |
| 15 | std::string GetRandomString(size_t length = 32); |
| 16 | |
| 17 | /** |
| 18 | * @brief Do fork and execute the given command, with logging redirected to /tmp/log/<unitbase>/<fileName>.log |
| 19 | * and the MOS_SERVICE_TOKEN environment variable set to the given token. |
| 20 | * |
| 21 | * @param exec the command to execute, as a vector of strings |
| 22 | * @param token the token to set in the MOS_SERVICE_TOKEN environment variable |
| 23 | * @param baseId the base ID of the unit, used to create the log directory |
| 24 | * @return pid_t the PID of the child process, or -1 on error |
| 25 | */ |
| 26 | pid_t DoFork(const std::vector<std::string> &exec, const std::string &token, const std::string &baseId); |
| 27 | } // namespace ExecUtils |
| 28 | |