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

Improve handling of systemd activation #50

Merged
merged 2 commits into from
Oct 21, 2019

Conversation

lnicola
Copy link
Contributor

@lnicola lnicola commented Oct 20, 2019

  • the sd-notify dependency is now mandatory, but should be harmless on non-systemd distros
  • bumped sd-notify dependency
  • when socket activation is used:
    • the fd number is computed in a nicer way
    • if more than one fd is received, the initialization fails
    • the socket is marked as non-blocking (it wasn't before)
  • service activation should also work now (there's nothing special to do)
  • a minor refactoring now avoids storing the listener in an Option
  • changed the panic message when the timeout was not configured
  • updated licenses for MIT / Apache-2.0 crates

The systemd-daemon feature is still available to configure whether timestamps are included in the logs. That could probably be handled better by checking whether stderr is a TTY.

Untested, the build script fails to link on my system even when disabling the mbed feature.

Signed-off-by: Laurențiu Nicola <[email protected]>
@lnicola lnicola force-pushed the socket-activation branch 3 times, most recently from 499aa77 to af2888b Compare October 20, 2019 22:07
@lnicola
Copy link
Contributor Author

lnicola commented Oct 21, 2019

r? @hug-dev

Copy link
Member

@hug-dev hug-dev left a comment

Choose a reason for hiding this comment

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

Thank you very much @lnicola ! The new function of sd_notify, listen_fds is pretty good and allows us to remove the compile-time flag at many places.
I made some comment about licensing mainly but it all looks good to me.

@ionut-arm The systemd-daemon flag is now only used in the beginning of the main to remove timestamps of logs. Do you think we could remove that flag completely by adding logging options to the configuration file instead?

Also, we should make a note to try to compile our code on Windows and add the target OS conditionial compilation flags where it is needed. Currently the only listener we support is a Unix Domain socket listener so that is not an emergency.

@@ -128,19 +128,19 @@ You will need to understand the [**wire protocol specification**](docs/wire_prot
The software is provided under Apache-2.0. Contributions to this project are accepted under the same license.

This project uses the following third party crates:
* serde (Apache-2.0)
* serde (MIT and Apache-2.0)
Copy link
Member

Choose a reason for hiding this comment

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

When the crate choose a double-licensing option (Apache-2.0 OR MIT), as the following (example uuid):

License

Licensed under either of:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

We explicitely make a choice and choose in that file to use Apache-2.0 license. If it is AND, we keep the two licenses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can revert the licensing change, but that sounds like a false dichotomy. All of those crates are dual-licensed, in the sense that you can pick either of them. The difference you noticed is in the manifest. People used to write MIT/Apache-2.0, but now MIT OR Apache-2.0 is preferred because it's "more machine-readable". Both are equivalent, see the comment in https://doc.rust-lang.org/stable/cargo/reference/manifest.html#package-metadata.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the pointer. What I understand from that is that is is more explicit to use AND or OR instead of a slash (/) but not that they both mean the same thing 😛
But I do not know if the licenses are for use of the library or contributions to it, and if it is for contributions that means that there could be files both licensed under MIT and Apache-2.0 in the same library.
In that case, it is probably better to use AND everywhere as you changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think OR would be a better fit.

But I do not know if the licenses are for use of the library or contributions to it, and if it is for contributions that means that there could be files both licensed under MIT and Apache-2.0 in the same library.

It's for the crate, and dual-licensing means that the user of the crate gets to pick one of the licenses (or both) that fits their project better. By contributing to a crate you implicitly admit that your changes will be licensed under the crate's terms (e.g. both MIT and Apache-2.0).

Copy link
Member

Choose a reason for hiding this comment

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

Would not it feel weird to have OR on this file as we are building a binary and not re-distributing the crates? As in, we are the last one in the chain so should not we make that decision between Apache-2.0 or MIT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes sense to say "PARSEC is licensed under Apache-2.0 and uses the following dependencies, with their associated licenses", but I am not a lawyer :-).

@@ -31,7 +31,7 @@ static SOCKET_PATH: &str = "/tmp/security-daemon-socket";
///
/// Only works on Unix systems.
pub struct DomainSocketListener {
listener: Option<UnixListener>,
Copy link
Member

Choose a reason for hiding this comment

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

Makes sense to remove that to me! As the DomainSocketListener can only be instanciated by the builder, this will never be None.

src/front/domain_socket.rs Show resolved Hide resolved
@hug-dev
Copy link
Member

hug-dev commented Oct 21, 2019

Also

Untested, the build script fails to link on my system even when disabling the mbed feature.

This is fine as the CI checks passed but is it because you need to install clang? If not feel free to raise an issue so we can investigate on that.

@hug-dev hug-dev added the enhancement New feature or request label Oct 21, 2019
Copy link
Member

@ionut-arm ionut-arm left a comment

Choose a reason for hiding this comment

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

Thanks for offering the changes!

@hug-dev hug-dev merged commit 2ec3183 into parallaxsecond:master Oct 21, 2019
@hug-dev hug-dev mentioned this pull request Oct 21, 2019
@lnicola
Copy link
Contributor Author

lnicola commented Oct 21, 2019

This is fine as the CI checks passed but is it because you need to install clang? If not feel free to raise an issue so we can investigate on that.

I think it was a dirty sccache cache, but now I get:

$ $LLVM_CONFIG_PATH --prefix
/usr
$ cargo check
warning: couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
warning: set the LLVM_CONFIG_PATH environment variable to a valid `llvm-config` executable

    Checking parsec v0.1.0 (~/parsec)
error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2336:5
     |
2336 |     pub state: [::std::os::raw::c_uchar; 48usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 48]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 48]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 48]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2459:5
     |
2459 |     pub buffer: [::std::os::raw::c_uchar; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2573:5
     |
2573 |     pub buffer: [::std::os::raw::c_uchar; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2687:5
     |
2687 |     pub buffer: [::std::os::raw::c_uchar; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2814:5
     |
2814 |     pub buffer: [::std::os::raw::c_uchar; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2934:5
     |
2934 |     pub buffer: [::std::os::raw::c_uchar; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3073:5
     |
3073 |     pub buffer: [::std::os::raw::c_uchar; 128usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 128]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 128]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 128]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: `providers::mbed_provider::psa_crypto_binding::psa_hash_operation_s__bindgen_ty_1` doesn't implement `std::fmt::Debug`
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3211:5
     |
3211 |     pub ctx: psa_hash_operation_s__bindgen_ty_1,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `providers::mbed_provider::psa_crypto_binding::psa_hash_operation_s__bindgen_ty_1` cannot be formatted using `{:?}`
     |
     = help: the trait `std::fmt::Debug` is not implemented for `providers::mbed_provider::psa_crypto_binding::psa_hash_operation_s__bindgen_ty_1`
     = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&providers::mbed_provider::psa_crypto_binding::psa_hash_operation_s__bindgen_ty_1`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3353:5
     |
3353 |     pub opad: [u8; 128usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 128]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 128]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 128]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: `providers::mbed_provider::psa_crypto_binding::psa_mac_operation_s__bindgen_ty_1` doesn't implement `std::fmt::Debug`
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3394:5
     |
3394 |     pub ctx: psa_mac_operation_s__bindgen_ty_1,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `providers::mbed_provider::psa_crypto_binding::psa_mac_operation_s__bindgen_ty_1` cannot be formatted using `{:?}`
     |
     = help: the trait `std::fmt::Debug` is not implemented for `providers::mbed_provider::psa_crypto_binding::psa_mac_operation_s__bindgen_ty_1`
     = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&providers::mbed_provider::psa_crypto_binding::psa_mac_operation_s__bindgen_ty_1`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: `providers::mbed_provider::psa_crypto_binding::psa_cipher_operation_s__bindgen_ty_1` doesn't implement `std::fmt::Debug`
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3595:5
     |
3595 |     pub ctx: psa_cipher_operation_s__bindgen_ty_1,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `providers::mbed_provider::psa_crypto_binding::psa_cipher_operation_s__bindgen_ty_1` cannot be formatted using `{:?}`
     |
     = help: the trait `std::fmt::Debug` is not implemented for `providers::mbed_provider::psa_crypto_binding::psa_cipher_operation_s__bindgen_ty_1`
     = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&providers::mbed_provider::psa_crypto_binding::psa_cipher_operation_s__bindgen_ty_1`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3767:5
     |
3767 |     pub prk: [u8; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object tycargo check --no-default-features
    Checking parsec v0.1.0 (/home/grayshade/parsec)
error[E0432]: unresolved import `crate::providers::mbed_provider`
  --> src/utils/service_builder.rs:25:41
   |
25 |     core_provider::CoreProviderBuilder, mbed_provider::MbedProviderBuilder, Provide,
   |                                         ^^^^^^^^^^^^^ could not find `mbed_provider` in `providers`

warning: unused import: `Provide`
  --> src/utils/service_builder.rs:25:77
   |
25 |     core_provider::CoreProviderBuilder, mbed_provider::MbedProviderBuilder, Provide,
   |                                                                             ^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error
pe `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3768:5
     |
3768 |     pub output_block: [u8; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3870:5
     |
3870 |     pub output_block: [u8; 64usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 64]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 64]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 64]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error[E0277]: `providers::mbed_provider::psa_crypto_binding::psa_crypto_generator_s__bindgen_ty_1` doesn't implement `std::fmt::Debug`
    --> src/providers/mbed_provider/psa_crypto_binding.rs:3977:5
     |
3977 |     pub ctx: psa_crypto_generator_s__bindgen_ty_1,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `providers::mbed_provider::psa_crypto_binding::psa_crypto_generator_s__bindgen_ty_1` cannot be formatted using `{:?}`
     |
     = help: the trait `std::fmt::Debug` is not implemented for `providers::mbed_provider::psa_crypto_binding::psa_crypto_generator_s__bindgen_ty_1`
     = note: add `#[derive(Debug)]` or manually implement `std::fmt::Debug`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&providers::mbed_provider::psa_crypto_binding::psa_crypto_generator_s__bindgen_ty_1`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

error: aborting due to 15 previous errors

For more information about this error, try `rustc --explain E0277`.

and

$ cargo check --no-default-features
    Checking parsec v0.1.0 (~/parsec)
error[E0432]: unresolved import `crate::providers::mbed_provider`
  --> src/utils/service_builder.rs:25:41
   |
25 |     core_provider::CoreProviderBuilder, mbed_provider::MbedProviderBuilder, Provide,
   |                                         ^^^^^^^^^^^^^ could not find `mbed_provider` in `providers`

warning: unused import: `Provide`
  --> src/utils/service_builder.rs:25:77
   |
25 |     core_provider::CoreProviderBuilder, mbed_provider::MbedProviderBuilder, Provide,
   |                                                                             ^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error

I saw that CI was working, but I don't know how. The impl Debug errors seem legit AFAICT.

@lnicola lnicola deleted the socket-activation branch October 22, 2019 06:03
@hug-dev
Copy link
Member

hug-dev commented Oct 22, 2019

Hmm rust-bindgen generates the same lines that you but I do not have any errors on those lines.
I have changed the following, on the struct containing line 2336:

#[repr(C)]
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, Debug)]
pub struct mbedtls_md2_context {
    pub cksum: [::std::os::raw::c_uchar; 16usize],
    pub state: [::std::os::raw::c_uchar; 48usize],
    pub buffer: [::std::os::raw::c_uchar; 16usize],
    pub left: usize,
}

and now I have the same error:

error[E0277]: arrays only have std trait implementations for lengths 0..=32
    --> src/providers/mbed_provider/psa_crypto_binding.rs:2336:5
     |
2336 |     pub state: [::std::os::raw::c_uchar; 48usize],
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[u8; 48]`
     |
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `[u8; 48]`
     = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[u8; 48]`
     = note: required for the cast to the object type `dyn std::fmt::Debug`

Does your src/providers/mbed_provider/psa_crypto_binding.rs file have some Debug derive somewhere maybe?
What version of rustc are you using? I use stable Rust (rustc 1.38.0 (625451e37 2019-09-23))

@hug-dev
Copy link
Member

hug-dev commented Oct 22, 2019

Also do you have the same copy of Cargo.lock than in tree? In case the version of rust-bindgen you use is different.
Look rust-lang/rust-bindgen#372

@lnicola
Copy link
Contributor Author

lnicola commented Oct 22, 2019

Yes, my Cargo.lock is the same as the one in-tree, with bindgen 0.50.0.

  #[repr(C)]
  #[derive(Debug, Copy, Clone)]
  pub struct mbedtls_md2_context {
      pub cksum: [::std::os::raw::c_uchar; 16usize],
>>    pub state: [::std::os::raw::c_uchar; 48usize],
      pub buffer: [::std::os::raw::c_uchar; 16usize],
      pub left: usize,
  }

@hug-dev
Copy link
Member

hug-dev commented Oct 22, 2019

Ah! I switched no nightly and have the same error than you 😃
It should work when you are on stable.

@lnicola
Copy link
Contributor Author

lnicola commented Oct 22, 2019

Yeah, sorry, I am on nightly, but beta seems to give the same result. I'm not sure how it affects the bindgen output, though. Stable works fine, though.

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

Successfully merging this pull request may close these issues.

3 participants