Skip to content

Commit

Permalink
Set PATH variable in code (#205)
Browse files Browse the repository at this point in the history
Co-authored-by: madelen-at-work <[email protected]>
  • Loading branch information
madelen-at-work and madelen-at-work authored Apr 15, 2024
1 parent dda6f87 commit 8828b53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 24 additions & 0 deletions app/dockerdwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,25 @@ static void parse_command_line(int argc, char** argv, struct log_settings* log_s
(argc == 2 && strcmp(argv[1], "--stdout") == 0) ? log_dest_stdout : log_dest_syslog;
}

static bool set_env_variable(const char* env_var, const char* value) {
log_debug("Setting env: %s=%s", env_var, value);
if (setenv(env_var, value, 1) != 0) {
log_error("Error setting env variable %s to %s", env_var, value);
return false;
}
return true;
}

static bool set_env_variables(void) {
g_autofree char* path =
g_strdup_printf("/bin:/usr/bin:%s:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin",
APP_DIRECTORY);
if (!set_env_variable("PATH", path))
return false;

return true;
}

int main(int argc, char** argv) {
struct app_state app_state = {0};
struct log_settings log_settings = {0};
Expand All @@ -801,6 +820,11 @@ int main(int argc, char** argv) {

log_debug_set(is_app_log_level_debug(app_state.param_handle));

if (!set_env_variables()) {
log_error("Failed to set environment variables");
return EX_SOFTWARE;
}

init_signals();

int fcgi_error = fcgi_start(http_request_callback);
Expand Down
2 changes: 0 additions & 2 deletions app/postinstallscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ cat >>/etc/systemd/system/sdkdockerdwrapper.service <<EOF
BindsTo=containerd.service
After=network-online.target containerd.service var-spool-storage-SD_DISK.mount
Wants=network-online.target
[Service]
Environment=PATH=/usr/local/packages/dockerdwrapper:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
EOF

0 comments on commit 8828b53

Please sign in to comment.