-
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Feature signal support #176
Feature signal support #176
Conversation
Hello. Thanks for the PR. I did really quick review on it and I suggest to add Regards |
i think it would also be nice if there was a unified way to tell a service to reload its configuration, without sending an explicit signal; the service file could define the action (with choice between signal and command, e.g. unfortunately there is already |
7bc18fb
to
565e37a
Compare
Thanks . I've added DINIT_CP_SIGNAL to the list of new features. |
I also think this would be a very useful feature. And one that a lot of service managers and services support. Signalling services may have a lot different uses though. I use it e.g. for toggling the visibility of my onscreen keyboard with SIGRTMIN+0. The (implementation details of a) service reloading feature probably deserves its own discussion, as it may impact future usability/expendability. I've started #178 for this purpose (: |
Could someone point me to the right place and to which extend tests should be implemented for this feature? I may be missing some basics here and would appreciate hints for test examples for orientation or general resources/introductions to the topic. |
Sorry for taking a little while to get to looking at your PR properly, and thanks for offering a contribution! The actual code changes look good (minus a few minor style inconsistencies eg spaces around the condition in My main concern is that being forced to specify signals via number rather than name is awkward. There is already a Also the default of USR1 (in fact any default) is unlikely to be useful for most services, so it would be a better interface if the signal could just be specified without a switch, something like:
You could potentially still allow just:
... to send a default signal (USR1 or whatever) but in my opinion this isn't really necessary. |
Probably proctests.cc. Pids are mocked via test-bpsys.cc which also contains mocks for various system functions like |
Actually, since the only thing to really test is the control protocol handling, probably cptests.cc. The complication is that this test needs to use a process-based service which the cptests currently don't do. The proctests should give you an idea of what's necessary; you have to call |
565e37a
to
786dd14
Compare
@davmac314 thank you for the feedback.
I've fixed the white-space inconsistencies.
You are totally right, the interface was rather awkward. I've update the the parameter handling accordingly
I don't know how i could miss the existing I'll have a look at the tests in the next days. |
Hi @james-knippes - just wondering if you were still planning on finishing off this PR? I think that tests are the only thing pending |
786dd14
to
87256b5
Compare
04ed83c
to
1c6b6cc
Compare
9db381b
to
4903e17
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.
I've reviewed this whole thing again and there are a number of things that should be changed or fixed before I'm happy to include this:
- first, let's not make a habit of pushing changes to someone else's repo, even if we do have that ability. In cases like this I think the best thing is to pull the changes from their repo, push them to your own, and open a new PR. That's ok for this time though.
- it looks like "dinitctl signal (signal-name) --list" wouldn't error out, but it should. Correct syntax is either "dinitctl signal (signal-name) (service-name)" or "dinitctl signal --list". Rather than converting the signal name to a number where it currently happens (during arg parsing), it should be done in the argument post-processing (same place it does the special checks for ENABLE_SERVICE, DISABLE_SERVICE, SETENV, etc). Also the check for whether the signal is a number (using
std::stoi
) doesn't currently check if there is junk text after the number, it should (eg it currently would accept "99junk" and treat it as 99 instead of giving an error). - let's rename
DINIT_RP_SIGNAL_BADPID
. It's being used when the service doesn't have a PID, but that's not the same as a "bad" PID. MaybeDINIT_RP_SIGNAL_NO_PID
. And improve the error message in dinitctl by explaining that the service might not be a process service or it might be in the wrong state. sig_num_t
type is defined asint32_t
in two places. This is wrong, it should beint
, and we don't need a typedef for this, just use the right type (int).- signal number validation in control.cc is not necessary and should be removed. Instead the error value from
kill
(bpsys::kill
) should be checked and if it isEINVAL
, then return the BADSIG error reply. The current code uses NSIG which isn't part of POSIX. - can we prune the supported signal list (in
signal_to_int_map
) to a sensible set of signals that you might feasibly need to send to a process manually? - there shouldn't be two versions of base_process_service_test that are doing the same thing, refactor it please.
Edit: some additional:
- remove string_map_size template function, it's not needed - use sizeof instead (sizeof the whole array divided by size of one element gives you the number of elements). Also get rid of
string_to_int_map
struct and just use apair
. Initialisation of the array is also overly verbose,string_to_int_map("none", 0)
could just be{"none", 0}
. - dinitctl man page: sentences should end at a newline
4903e17
to
57b1309
Compare
When I thought about it, it's reasonable to have a small list of predefined signals. My list include these:
signals which I think reasonable. @davmac314 WDYT? |
That looks pretty good to me. I would add |
1a2e227
to
e0718cb
Compare
Some cases I tested it: > src/dinitctl signal
dinitctl: signal number/name must be specified
!1> src/dinitctl signal --list
dinitctl: The following signal names are defined for this platform:
dinitctl: none -> 0 NONE -> 0 HUP -> 1 INT -> 2
dinitctl: QUIT -> 3 KILL -> 9 USR1 -> 10 USR2 -> 12
dinitctl: TERM -> 15 CONT -> 18 STOP -> 19
> src/dinitctl signal HUP
dinitctl: service name must be specified
!1> src/dinitctl -p ./sock signal HUP boot
dinit: Service boot terminated due to signal 1
[STOPPD] boot
[ OK ] boot
> src/dinitctl -p ./sock signal 36 boot # SIGRTMIN+1 on Linux-x86_64
dinit: Service boot terminated due to signal 36
[STOPPD] boot
[ OK ] boot
> src/dinitctl -p ./sock signal 332109 boot
dinit: Requested signal not in valid signal range.
dinitctl: provided signal was invalid.
!1> src/dinitctl -p ./sock signal junk99 boot
dinitctl: 'junk99' is not a valid signal name/number
!1> src/dinitctl -p ./sock signal 99junk boot
dinitctl: '99junk' is not a valid signal name/number
!1> src/dinitctl -p ./sock signal HUP --list
dinitctl: Invalid command line.
Try 'dinitctl --help' for more information.
!1> src/dinitctl -p ./sock signal --list HUP
dinitctl: Invalid command line.
Try 'dinitctl --help' for more information. |
Thanks. I think we need to remove "none" and "NONE" from the list of signals displayed. Have you tried:
? |
Seems like it tries to find "other". Are we need to fix it? |
Invalid command lines should cause an error. |
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 getting there, but still some issues. Also need to fix the error cases noted in the PR discussion.
665c0e8
to
d9e6519
Compare
d9e6519
to
34c6bf3
Compare
34c6bf3
to
6942104
Compare
Co-authored-by: Mobin "Hojjat" Aydinfar <mobin@mobintestserver.ir>
Adds the command 'signal' the optional '--list' option. Updated man page. Co-authored-by: Mobin "Hojjat" Aydinfar <mobin@mobintestserver.ir>
Co-authored-by: Mobin "Hojjat" Aydinfar <mobin@mobintestserver.ir>
Signed-off-by: Mobin "Hojjat" Aydinfar <mobin@mobintestserver.ir>
Signed-off-by: Mobin Aydinfar <mobin@mobintestserver.ir>
6942104
to
78da6c5
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.
This is great, thanks!
Closes #134 |
Hey, sorry for taking so long. Got distracted by life stuff. Should have responded, that I did not have the time. |
@james-knippes no problem, thanks for the work that you did on this. |
This adds support for sending signals to services, as I consider it a generally useful feature and implemented it with hacky scripts parsing the output of
dinitctl status $service
in the past. Many services use signals for reloading configuration files and/or enabling/disabling specific runtime features. The feature is currently requested by #134 and @davmac314 commented thatAs this would be my first contribution to the project I appreciate any feedback. I'm willing to implement changes/improvements.
I've tried to follow contribution guidelines. Tests are still missing. I will add them if the feature is generally considered accepted.
Open questions/limitations:
control.cc
directly as a feature into the (decedents of the)service_record
class ?sigabbrev_np
function is a gnu extension and only works for non realtime signals. Here is howkill
fromutil-linux
does it, but I'm not sure if this kind of conversion is worth it.