Skip to content

Commit

Permalink
s6: controller: implement SetActivationEnvironment
Browse files Browse the repository at this point in the history
but make it possible to ignore it via a runtime option
  • Loading branch information
st3r4g committed Dec 2, 2021
1 parent 56d35cb commit 1efa513
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
15 changes: 15 additions & 0 deletions controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <assert.h>
#include <libgen.h>
#include <stdbool.h>

static int launcher_add_listener(sd_bus* bus_controller, int fd_listen) {
sd_bus_message *m = NULL;
Expand All @@ -31,6 +32,12 @@ static int launcher_add_listener(sd_bus* bus_controller, int fd_listen) {
return 0;
}

#ifdef HAVE_S6
#include <skalibs/djbunix.h>
#endif

bool ignore_setactivenv = false;

static void parse_set_activation_enviroment(sd_bus_message *m) {
int r = sd_bus_message_enter_container(m, 'a', "{ss}");
assert(r == 1);
Expand All @@ -41,7 +48,15 @@ static void parse_set_activation_enviroment(sd_bus_message *m) {
r = sd_bus_message_read(m, "{ss}", &key, &value);
assert(r >= 0);

#ifdef HAVE_S6
if (!ignore_setactivenv) {
char envfile[256];
snprintf(envfile, 256, ".activation-envdir/%s", key);
openwritenclose_unsafe(envfile, value, strlen(value));
}
#else
fprintf(stderr, "Warning: ignoring SetActivationEnvironment %s=%s\n", key, value);
#endif
}

r = sd_bus_message_exit_container(m);
Expand Down
7 changes: 5 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static const char* default_dbus_socket_path = "/run/dbus/system_bus_socket";
#ifdef HAVE_S6
static const char* default_s6_dbuscandir = "/run/dbus_activated_services";
extern const char* s6_dbuscandir; // TODO: pass around properly
extern bool ignore_setactivenv; // TODO: pass around properly
#endif
static const char* dummy_machine_id = "00000000000000000000000000000001";

Expand All @@ -35,7 +36,8 @@ optional arguments:\n\
-3 notify readiness on fd 3\n"
#ifdef HAVE_S6
"\n\
-a s6 scandir of dbus-activated services (default: %s)\n"
-a s6 scandir of dbus-activated services (default: %s)\n\
-e ignore requests to set the activation environment\n"
#endif
"\n\
-h show this help message and exit\n";
Expand All @@ -50,7 +52,7 @@ int main(int argc, char* argv[]) {

int opt;
#ifdef HAVE_S6
while ((opt = getopt(argc, argv, "d:ha:s3")) != -1) {
while ((opt = getopt(argc, argv, "d:ha:es3")) != -1) {
#else
while ((opt = getopt(argc, argv, "d:hs3")) != -1) {
#endif
Expand All @@ -60,6 +62,7 @@ int main(int argc, char* argv[]) {
case '3': check_3_open(); notif = true; break;
#ifdef HAVE_S6
case 'a': s6_dbuscandir = optarg; break;
case 'e': ignore_setactivenv = true; break;
#endif
default:;
#ifdef HAVE_S6
Expand Down
4 changes: 2 additions & 2 deletions tools/s6-generator
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# /usr/share/dbus-1/system-services/* (for the system bus)
# or /usr/share/dbus-1/services/* (for the session bus)

mkdir -p 'dbus'
mkdir -p 'dbus/.activation-envdir'
cd 'dbus'

for service in "$@"; do
Expand All @@ -17,7 +17,7 @@ for service in "$@"; do
echo "$name_" >> "$name_/data/dbus-activatable-name"
echo 'longrun' >> "$name_/type"
echo '#!/bin/execlineb -P' >> "$name_/run"
echo "$exec_" >> "$name_/run"
echo "s6-envdir ../.activation-envdir $exec_" >> "$name_/run"
chmod +x "$name_/run"
touch "$name_/down"
done

0 comments on commit 1efa513

Please sign in to comment.