run_params.notify_fd = notify_pipe[1];
run_params.force_notify_fd = force_notification_fd;
run_params.notify_var = notification_var.c_str();
+ run_params.env_file = env_file.c_str();
run_child_proc(run_params);
}
else {
static void open_control_socket(bool report_ro_failure = true) noexcept;
static void close_control_socket() noexcept;
static void confirm_restart_boot() noexcept;
-static void read_env_file(const char *);
static void control_socket_cb(eventloop_t *loop, int fd);
log(loglevel_t::ERROR, "invalid environment variable setting in environment file (line ", linenum, ")");
}
-// Read and set environment variables from a file.
-static void read_env_file(const char *env_file_path)
+// Read and set environment variables from a file. May throw std::bad_alloc, std::system_error.
+void read_env_file(const char *env_file_path)
{
// Note that we can't use the log in this function; it hasn't been initialised yet.
void rootfs_is_rw() noexcept;
void setup_external_log() noexcept;
+void read_env_file(const char *);
extern eventloop_t event_loop;
const char * const *args; // program arguments including executable (args[0])
const char *working_dir; // working directory
const char *logfile; // log file or nullptr (stdout/stderr); must be valid if !on_console
+ const char *env_file; // file with environment settings (or nullptr)
bool on_console; // whether to run on console
int wpipefd; // pipe to which error status will be sent (if error occurs)
int csfd; // control socket fd (or -1); may be moved
run_proc_params(const char * const *args, const char *working_dir, const char *logfile, int wpipefd,
uid_t uid, gid_t gid, const std::vector<service_rlimits> &rlimits)
- : args(args), working_dir(working_dir), logfile(logfile), on_console(false), wpipefd(wpipefd),
- csfd(-1), socket_fd(-1), notify_fd(-1), force_notify_fd(-1), notify_var(nullptr), uid(uid),
- gid(gid), rlimits(rlimits)
+ : args(args), working_dir(working_dir), logfile(logfile), env_file(nullptr), on_console(false),
+ wpipefd(wpipefd), csfd(-1), socket_fd(-1), notify_fd(-1), force_notify_fd(-1), notify_var(nullptr),
+ uid(uid), gid(gid), rlimits(rlimits)
{ }
};
std::vector<const char *> stop_arg_parts;
string working_dir; // working directory (or empty)
+ string env_file; // file with environment settings for this service
std::vector<service_rlimits> rlimits; // resource limits
stop_arg_parts = separate_args(stop_command, stop_command_offsets);
}
+ void set_env_file(const std::string &env_file_p)
+ {
+ env_file = env_file_p;
+ }
+
void set_rlimits(std::vector<service_rlimits> &&rlimits_p)
{
rlimits = std::move(rlimits_p);
list<pair<unsigned,unsigned>> stop_command_offsets;
string working_dir;
string pid_file;
+ string env_file;
bool do_sub_vars = false;
else if (setting == "working-dir") {
working_dir = read_setting_value(i, end, nullptr);
}
+ else if (setting == "env-file") {
+ env_file = read_setting_value(i, end, nullptr);
+ }
else if (setting == "socket-listen") {
socket_path = read_setting_value(i, end, nullptr);
}
auto rvalps = new process_service(this, string(name), std::move(command),
command_offsets, depends);
rvalps->set_working_dir(working_dir);
+ rvalps->set_env_file(env_file);
rvalps->set_rlimits(std::move(rlimits));
rvalps->set_restart_interval(restart_interval, max_restarts);
rvalps->set_restart_delay(restart_delay);
auto rvalps = new bgproc_service(this, string(name), std::move(command),
command_offsets, depends);
rvalps->set_working_dir(working_dir);
+ rvalps->set_env_file(env_file);
rvalps->set_rlimits(std::move(rlimits));
rvalps->set_pid_file(std::move(pid_file));
rvalps->set_restart_interval(restart_interval, max_restarts);
command_offsets, depends);
rvalps->set_stop_command(stop_command, stop_command_offsets);
rvalps->set_working_dir(working_dir);
+ rvalps->set_env_file(env_file);
rvalps->set_rlimits(std::move(rlimits));
rvalps->set_stop_timeout(stop_timeout);
rvalps->set_start_timeout(start_timeout);
if (notify_fd == -1) goto failure_out;
}
+ // Read environment from file
+ if (params.env_file != nullptr) {
+ try {
+ read_env_file(params.env_file);
+ }
+ catch (std::system_error &sys_err) {
+ errno = sys_err.code().value();
+ }
+ catch (std::bad_alloc &alloc_err) {
+ errno = ENOMEM; goto failure_out;
+ }
+ }
+
// Set up notify-fd variable:
if (notify_var != nullptr && *notify_var != 0) {
// We need to do an allocation: the variable name length, '=', and space for the value,
{
}
+inline void read_env_file(const char *env_file_path)
+{
+}
+
extern eventloop_t event_loop;
#endif