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

Add support to store and retrieve file descriptors in the service manager #2

Closed
wants to merge 1 commit into from

Conversation

oliakremmyda
Copy link
Contributor

@oliakremmyda oliakremmyda commented Mar 5, 2019

Adds the bindings for sd_pid_notify_with_fds and sd_listen_fds_with_names
functions.

notify_with_fds method can send a file descriptor with a name to
service manager to store and to pass it to the main process again on next
invocation.

sample use:

  read_fd, write_fd = IO.pipe
  state = {
    FDSTORE: 1,
    FDNAME: pid
  }
  SystemdDaemon::Notify.notify_with_fds(0, state, read_fd.to_i)

listen_fds_with_names method checks if there are any file descriptors
passed and if there are, it returns a hash with their names as keys and
their descriptors as values.

sample use:

  fds_hash = SystemdDaemon::Notify.listen_fds_with_names
  # fds_hash = {"5304"=>3, "5301"=>4, "5298"=>5, "5295"=>6}

For more details you can check sd_notify(3) and sd_listen_fds(3).

…ager.

Adds the bindings for sd_pid_notify_with_fds and sd_listen_fds_with_names
functions.

`notify_with_fds` method can send a file descriptor with a name to
service manager to store and to pass it to the main process again on next
invocation.

sample use:
```
  read_fd, write_fd = IO.pipe
  state = {
    FDSTORE: 1,
    FDNAME: pid
  }
  SystemdDaemon::Notify.notify_with_fds(0, state, read_fd.to_i)
```

`listen_fds_with_names` method checks if there are any file descriptors
passed and if there are, it returns a hash with their names as keys and
their descriptors as values.

sample use:
```
  fds_hash = SystemdDaemon::Notify.listen_fds_with_names
  # fds_hash = {"5304"=>3, "5301"=>4, "5298"=>5, "5295"=>6}
```

For more details you can check sd_notify(3) and sd_listen_fds(3).

def test_listen_fds_with_names
expected_names = { "bar" => 4, "foo" => 3 }
with_env('LISTEN_FDNAMES' => expected_names.keys.reverse.join(':'),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.reverse feels a bit odd. The names should be ordered by their fd number, and this is not explicit. I'd suggest to just hard-code the value and add a comment stating that order is important. e.g.

'LISTEN_FDNAMES' => "foo:bar", # ordered by fd

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.

None yet

2 participants