-
Notifications
You must be signed in to change notification settings - Fork 83
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
Daemon exit status available in the API #15
base: master
Are you sure you want to change the base?
Daemon exit status available in the API #15
Conversation
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.
LGTM
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.
How is the field supposed to be accessed? Directly via the daemon_t structure?
If so, I suggest adding an accessor function. Also, the status must have a clear value representing that the process is still running (ie. the current status is not available because the process is still running). This being 0 is OK with me, but it needs to be documented in the header of the accessor function.
The previous commit add an API to get the exit status. |
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 think this is going in wrong direction. The idea of the daemon
module is to take as much of the burden off of the caller as possible. The module itself should (and does) log all the details about the exit status.
Judging by the code in https://github.com/plume-design/opensync/pull/16/files#diff-053599008b20818e4dfcc63a39ad1221R73, the implementation of the 'atexit' callback merely tries to log something that was already logged.
As it is, the implementation of pwm_DHCP_option82_at_exit()
should probably be:
(void)daemon;
LOGE("DHCP option82 process exited unexpectedly");
return true;
... which means this PR (#15) is not needed at all.
AFAICS, the daemon module does not call the callback if the caller requests the daemon to stop. Therefore it makes sense to log an error whenever the callback is called. After all, even if the process exited gracefully, the caller expected it to be running, therefore this is an undesired situation.
But the main purpose of this callback is not logging, rather it is to take a suitable action (e.g. stop advertising a service that depends on this deamon).
I see some room for improvement here:
... here:
... and here:
The level is intentionally set to |
Exit status of a daemon could be useful for managers to know if the daemon executed sucessfully or not, and can be used then in some logic. This commit makes the exit status of the daemon availble in the API. Signed-off-by: Simon Batardiere <[email protected]>
Create a getter in the daemon API to hide the daemon structure details outside the API. Signed-off-by: Simon Batardiere <[email protected]>
Hi Lars, I see two usages of the daemon API:
I agree with you in the context of the daemon, and your comment on the PR for PWM is right. But in the case of a long command, the daemon API is the only valid option. If we use the other APIs, like cmd_log, we will block the event loop for a while, which is always a bad thing. So here we also need to use the daemon API. And the caller may be interested by the exit status of the long command (like the curl). This is why this PR is still useful. |
Hi Simon, Regarding the two usages:
Considering the above, and without an immediate need for this change, I am reluctant to give it my approval. Regardless, here are some additional comments: 1 - @ https://github.com/plume-design/opensync/pull/15/files#diff-6a0c177f1dce309d321ec6382d55b041R417
Return value of WEXITSTATUS may be undefined here (e.g. if the process was signaled). A possible solution would be to use:
...
...
2 - daemon_get_exit_status() could theoretically be called not only from within the callback, but at any time, asynchronously. Alternatively, one could use -1 for 'still running', and '-2' instead of -(WTERMSIG(wstatus)) above. Not super clean, but should suffice for typical use. |
No description provided.