Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Implement listening on activation environment changes #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

q66
Copy link
Sponsor Contributor

@q66 q66 commented Oct 3, 2024

This implements a protocol that lets a connection to the control socket listen on changes in the global environment issued by dinitctl setenv. This opens up a range of possibilities - such as special services that trigger other services when an environment variable appears.

It also implements a dinit-monitor environment watching mode as a proof of functionality, though likely not acceptable as is (likely at least the string_view will need getting rid of?)

I intentionally did not implement things like protocol checking and whatnot yet since I want your feedback first.

I should probably also change the protocol a bit - at very least, the envevent should contain information about whether the envvar is newly created or if it overwrites a previous one.

Let me know what you think :)

@q66
Copy link
Sponsor Contributor Author

q66 commented Oct 3, 2024

i think the code quality in this is ok now, what's missing from my side is imo:

  1. documentation
  2. tests
  3. the protocol bit about new/overriden envvars

@q66
Copy link
Sponsor Contributor Author

q66 commented Oct 4, 2024

i also added an option to dinit-monitor that makes it exit upon first issued command; that means you can invoke something like

$ dinit-monitor --initial --env --exit --command /usr/bin/true FOO BAR BAZ

as a way to wait until either of the given environment variables becomes available (with --initial it should be race-free and will simply exit when it's already available)

@q66
Copy link
Sponsor Contributor Author

q66 commented Oct 4, 2024

There is another thing I would like to have while at it and that is unsetting of environment vars. As I see it, we don't have to add a protocol message for it; we can repurpose the SETENV message and instead of raising BADREQ when the value has no =, we could just change

    eq = envVar.find('=');
    if (!eq || eq == envVar.npos) {
        // Not found or at the beginning of the string
        goto badreq;
    }

    main_env.set_var(std::move(envVar));

to

    eq = envVar.find('=');
    if (eq == envVar.npos) {
        // Unset
        main_env.undefine_var(std::move(envVar));
    } else if (!eq) {
        // At the beginning of the string
        goto badreq;
    } else {
        main_env.set_var(std::move(envVar));
    }

and add a new command to dinitctl that will invoke the protocol in this form...

thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant