-
-
Notifications
You must be signed in to change notification settings - Fork 49
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 capabilities, priority, and oom-score-adjustment support on Linux #404
Conversation
I also wonder if i should add functionality for setting scheduling and i/o priorities while at it, and perhaps oom-killer score adjustment (they are useful to have especially for services that change uid, as any wrapper will already run with decreased privileges)? i could also do it later, but it's simple enough to do... i guess all 3 of these should also be specific to linux at this point, because the implementation will differ and so will the range? should these also be behind an option like cgroups? or just |
this is what the setting of the 3 values would look like without the parsing (the input values for
|
3679b5c
to
16ab75c
Compare
I implemented everything. What's left now is basically
|
No strong objections/opinions from me, though as usual good documentation will be important. nice/io_nice/oom_adj are probably unnecessary when cgroups are used properly. If they were to be supported, documentation must clearly state the requirements, i.e.
I think that's fine tbh. It might be worth gating Linux-specific features behind something other than Setting for nice should be possible on other OSes, |
well, the main non-portability for that is range checking, as the acceptable range of values may vary depending on systems maybe i could
|
Ah right, yeah.
True, but I don't think we need to be overly fussed about checking it ourselves. Perhaps add a flag to indicate whether the value is set rather than relying on INT_MIN as a sentinel value.
Yep, that sounds reasonable to me. |
ok, i think i should have a cleaned up PR sometime this evening... |
I added documentation, feature flags, and improved the resource management for the capabilities IAB object, which should be a lot cleaner now. It should be reviewable now, though I still need to test it a bunch more. |
Will review this weekend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I actually have a few minor things that I think would be good to change, as noted. Thanks for the PR.
b5009d7
to
91f0d98
Compare
bdb249d
to
428b79b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's all good other than the outstanding comments.
how do i set i think it is worthwhile keeping this as a boolean, requiring ps. this is great! i am super excited to see capabilities option added ❤️ |
it goes in |
oops! ignore me 😅 thanks again |
0fc9a1d
to
93f52ca
Compare
I think I addressed all the comments, let me know if there's anything else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one tiny format specifier that I think is incorrect, otherwise, looks good. Sorry for taking a little while to get to it.
if (fd < 0) goto failure_out; | ||
// +4: round up, minus sign, newline, nul terminator | ||
char val_str[std::numeric_limits<int>::digits10 + 4]; | ||
int num_chars = snprintf(val_str, sizeof(val_str), "%hd\n", oom_adj); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%hd
should be just %d
, I believe (the value is a plain int
, not a short int
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i changed it to short as that's what it is in other places, i guess i accidentally made it an int there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. In that case line 354 should have std::numeric_limits<short>
instead of std::numeric_limits<int>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not that it really matters much, just for consistency).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
This is not properly tested yet and does not come with documentation. I mostly want to get an opinion on it for now.
This adds 3 things; when dinit is compiled without support, all of them will raise errors:
capabilities
service field. This is an IAB string; it's parsed withcap_iab_from_string
so it can take any value that can parse, e.g.^cap_sys_time,^cap_net_admin
for ambient caps. It supports the+=
operator, which will append to it, delimiting with a comma.secure-bits
service field, which implements securebits flags as a companion to the above.no-new-privs
which will useprctl
to prevent gaining new privileges acrossexecve
(e.g. suid).For now I want to get an opinion on the overall implementation. One thing I am not sure about for example is the IAB string parsing; I currently do it in
load-service.cc
because it must be done after all the concats have been completed. I find it to be a bit out of place there, however, so maybe there is a better way. Or if you have any other clues about anything, etc...Fixes #398