Repository navigation
dinitctl: fix a possible oom on offline enable/disable with service@arg #596
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2076,7 +2076,7 @@ static std::pair<int,int> find_service_desc(const char *svc_name, const std::vec | |
| } | ||
|
|
||
| for (std::string path : paths) { | ||
| std::string test_path = combine_paths(path, ::string_view(svc_name, at_ptr - svc_name)); | ||
| std::string test_path = combine_paths(path, svc_name); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By specifying svc_name here, you are forcing the string length to be counted again in order to construct a string_view. The length was basically just calculated by the loop above (the original |
||
|
|
||
| auto sdf_fds = open_with_dir(path.c_str(), svc_name); | ||
| if (sdf_fds.first != -1 || sdf_fds.second != ENOENT) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ void cycles_test(); | |
| void svc_arg_test(); | ||
| void svc_arg_consumer_test(); | ||
| void svc_arg_enable_test(); | ||
| void svc_arg_enable_offline_test(); | ||
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
|
|
@@ -63,7 +64,8 @@ int main(int argc, char **argv) | |
| { "catlog", catlog_test }, { "offline-enable", offline_enable_test }, | ||
| { "xdg-config", xdg_config_test }, { "cycles", cycles_test }, | ||
| { "svc-arg", svc_arg_test }, { "svc-arg-consumer", svc_arg_consumer_test }, | ||
| { "svc-arg-enable", svc_arg_enable_test } }; | ||
| { "svc-arg-enable", svc_arg_enable_test }, | ||
| { "svc-arg-enable-offline" , svc_arg_enable_offline_test} }; | ||
|
|
||
| dinit_bindir = "../.."; | ||
| char *env_dinit_bindir = getenv("DINIT_BINDIR"); | ||
|
|
@@ -1173,3 +1175,57 @@ void svc_arg_enable_test() | |
| igr_assert(file_gone, "Service A@1 not disabled after disable command; sd/boot.d/A@1 still exists"); | ||
| rm_tree(sd_dir.c_str()); | ||
| } | ||
|
|
||
| void svc_arg_enable_offline_test() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is in general so much of a copy of
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I.e. in modify that test to test both a service without argument and service with argument).
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or alternatively factor out the common parts into one or more functions.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it's fine to leave the refactoring out of this PR, if you prefer. Either you can do it as a separate PR or I can manage it.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will refactor the |
||
| { | ||
| igr_test_setup setup("svc-arg-enable-offline"); | ||
|
|
||
| std::string sd_dir = setup.get_output_dir() + "/sd"; | ||
|
|
||
| if (faccessat(AT_FDCWD, sd_dir.c_str(), F_OK, AT_EACCESS) == -1) { | ||
| if (errno != ENOENT) { | ||
| throw std::system_error(errno, std::generic_category(), std::string("faccessat: ") + sd_dir); | ||
| } | ||
| } | ||
| else { | ||
| rm_r(sd_dir.c_str()); | ||
| } | ||
|
|
||
| mkdir(sd_dir.c_str(), S_IRWXU); | ||
| cp_file((igr_input_basedir + "/svc-arg-enable-offline/sd/AAAAAAAAAAAAAAAA").c_str(), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filename seems like it's screaming at me. AAAAAAAA..... I know the other offline disable test also uses a capital letter (A) but it's an exception to the general style of the tests (probably should be changed) and it's more of a "capital at the start" scenario. This just looks really odd - and more significantly there is no explanation at all why such a filename is used (you could even have made the name self-explanatory in this case! But a comment as well would help).
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the real world, most service names have more length than 1 character. I probably change it to another name that makes more sense.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes but
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I mean is that, it can be closer to the real world. I personally prefer something like
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be consistent with the other tests, unless there is a reason not to be.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I go with
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Things like this seem to come up a bit, so let me be clear:
Don't just open a PR with new code or change that is inconsistent with what's already in the codebase, not saying anything at all, and then argue when I ask for consistency, please.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really didn't think it was breaking the convention, now looking at it, it does break the convention.
I'm still working on my communication skills, sorry. |
||
| (sd_dir + "/AAAAAAAAAAAAAAAA").c_str()); | ||
| cp_file((igr_input_basedir + "/svc-arg-enable-offline/sd/boot").c_str(), (sd_dir + "/boot").c_str()); | ||
| mkdir((sd_dir + "/boot.d").c_str(), S_IRWXU); | ||
|
|
||
| // dinitctl -d "$IGR_OUTPUT/sd" -o enable AAAAAAAAAAAAAAAA@1 | ||
| dinitctl_proc dinitctl_p; | ||
| dinitctl_p.start("svc-arg-enable-offline", {"-d", sd_dir.c_str(), "-o", "enable", | ||
| "AAAAAAAAAAAAAAAA@1"}); | ||
| int status = dinitctl_p.wait_for_term({1, 0}); /* max 1 second */ | ||
| igr_assert(status == 0, "dinitctl did not exit cleanly"); | ||
|
|
||
| if (faccessat(AT_FDCWD, (sd_dir + "/boot.d/AAAAAAAAAAAAAAAA@1").c_str(), F_OK, AT_EACCESS) == -1) { | ||
| throw std::system_error(errno, std::generic_category(), std::string("faccessat: ") | ||
| + sd_dir + "/boot.d/AAAAAAAAAAAAAAAA@1"); | ||
| } | ||
|
|
||
| dinitctl_p.start("svc-arg-enable-offline", {"-d", sd_dir.c_str(), "-o", "disable", | ||
| "AAAAAAAAAAAAAAAA@1"}); | ||
| status = dinitctl_p.wait_for_term({1, 0}); /* max 1 second */ | ||
| igr_assert(status == 0, "dinitctl did not exit cleanly"); | ||
|
|
||
| bool file_gone = false; | ||
| if (faccessat(AT_FDCWD, (sd_dir + "/boot.d/AAAAAAAAAAAAAAAA@1").c_str(), F_OK, AT_EACCESS) == -1) { | ||
| if (errno == ENOENT) { | ||
| file_gone = true; | ||
| } | ||
| else { | ||
| throw std::system_error(errno, std::generic_category(), std::string("faccessat: ") + sd_dir); | ||
| } | ||
| } | ||
|
|
||
| igr_assert(file_gone, | ||
| "Service AAAAAAAAAAAAAAAA@1 not disabled after disable command;" | ||
| "sd/boot.d/AAAAAAAAAAAAAAAA@1 still exists"); | ||
| rm_tree(sd_dir.c_str()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| type = internal |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| type = internal | ||
| waits-for.d = boot.d |
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 isn't a problem with your change, but could you please change path to
const std::string &path(or juststd::string &pathif it can't be const, though I think that will be fine).