Skip to content
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

conf: avoid spawning unnecessary subshells #2022

Merged
merged 1 commit into from Dec 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/lxc/conf.c
Expand Up @@ -355,10 +355,11 @@ static int run_script_argv(const char *name, const char *section,

size += strlen(hook) + 1;

size += strlen("exec");
Copy link
Member

Choose a reason for hiding this comment

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

That escaped me that should be a static sizeof("exec"). Fixing this in #2026 since I need to touch that code anyway. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want to use sizeof instead, it should be sizeof("exec") - 1. The compiler should be smart enough to do the right thing though

Copy link
Member

Choose a reason for hiding this comment

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

If you want to use sizeof instead, it should be sizeof("exec") - 1.

No, not really I'm just leaveing it as sizeof("exec") since this automatically accounts for the added ' '. In my branch I'm doing a size++ after each strlen(). In this case I'm just going to leave the sizeof() and not do a size++. But feel free to comment on the #2026. :)

The compiler should be smart enough to do the right thing though

Yeah, I agree but I like the code to reflect that this is information that is available statically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, cleaner indeed ;)

size += strlen(script);
size += strlen(name);
size += strlen(section);
size += 3;
size += 4;

if (size > INT_MAX)
return -1;
Expand All @@ -370,7 +371,7 @@ static int run_script_argv(const char *name, const char *section,
}

ret =
snprintf(buffer, size, "%s %s %s %s", script, name, section, hook);
snprintf(buffer, size, "exec %s %s %s %s", script, name, section, hook);
if (ret < 0 || (size_t)ret >= size) {
ERROR("Script name too long.");
return -1;
Expand Down Expand Up @@ -405,10 +406,11 @@ int run_script(const char *name, const char *section, const char *script, ...)
size += strlen(p) + 1;
va_end(ap);

size += strlen("exec");
size += strlen(script);
size += strlen(name);
size += strlen(section);
size += 3;
size += 4;

if (size > INT_MAX)
return -1;
Expand All @@ -419,7 +421,7 @@ int run_script(const char *name, const char *section, const char *script, ...)
return -1;
}

ret = snprintf(buffer, size, "%s %s %s", script, name, section);
ret = snprintf(buffer, size, "exec %s %s %s", script, name, section);
if (ret < 0 || ret >= size) {
ERROR("Script name too long.");
return -1;
Expand Down