Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dinitctl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2076,7 +2076,7 @@ static std::pair<int,int> find_service_desc(const char *svc_name, const std::vec
}

for (std::string path : paths) {

Copy link
Copy Markdown
Owner

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 just std::string &path if it can't be const, though I think that will be fine).

std::string test_path = combine_paths(path, ::string_view(svc_name, at_ptr - svc_name));
std::string test_path = combine_paths(path, svc_name);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 at_ptr - svc_name is the correct length if svc_name hasn't been reassigned) - so use the calculated length, just fix it so that it won't use a wrong value if svc_name does get reassigned on line 2075.


auto sdf_fds = open_with_dir(path.c_str(), svc_name);
if (sdf_fds.first != -1 || sdf_fds.second != ENOENT) {
Expand Down
58 changes: 57 additions & 1 deletion src/igr-tests/igr-runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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");
Expand Down Expand Up @@ -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()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This is in general so much of a copy of offline_enable_test that it should be incorporated into it, I don't think it makes sense to have another test especially as it's basically copy-pasted code.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Or alternatively factor out the common parts into one or more functions.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I will refactor the offline-enable test to also test against a service with an argument, in this PR.

{
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(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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

Yes but

  1. this is a test, not "the real world"
  2. real service names typically reflect what program or service they run

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 service in comparison to A

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So I go with A for now.

@davmac314 davmac314 Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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:

  • you should always be consistent with existing code/practice, unless there's a good reason for an exception - and in that case, make it clear what that reason is, in the PR (PR description, and/or comments in the code).
  • if you think the existing code/practice isn't good, you should either:
    • make it clear (in the PR description) that you have deliberately broken the convention, and make a case that we should change it going forward, or
    • open a discussion about it (either an issue, or email, or whatever), and if there's agreement then you can fix every case in a separate PR, rather than just the current one. In that case the current PR should be consistent with existing practice.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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.

if you think the existing code/practice isn't good, you should either:
make it clear (in the PR description) that you have deliberately broken the convention, and make a case that we should change it going forward, or
open a discussion about it (either an issue, or email, or whatever), and if there's agreement then you can fix every case in a separate PR, rather than just the current one. In that case the current PR should be consistent with existing practice.

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());
}
1 change: 1 addition & 0 deletions src/igr-tests/svc-arg-enable-offline/sd/AAAAAAAAAAAAAAAA
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type = internal
2 changes: 2 additions & 0 deletions src/igr-tests/svc-arg-enable-offline/sd/boot
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type = internal
waits-for.d = boot.d
Loading