-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add a file exists check to adaptived #24
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 |
---|---|---|
|
@@ -80,6 +80,10 @@ int cgroup_setting_psi_init(struct adaptived_effect * const eff, struct json_obj | |
if (ret) | ||
goto error; | ||
|
||
ret = adaptived_file_exists(cgroup_path_str); | ||
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 I think a better option here would be to do something like:
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. Since there could be some copy-pasta here, you could incorporate this into |
||
if (ret) | ||
goto error; | ||
|
||
opts->cgroup_path = malloc(sizeof(char) * strlen(cgroup_path_str) + 1); | ||
if (!opts->cgroup_path) { | ||
ret = -ENOMEM; | ||
|
@@ -433,6 +437,10 @@ int cgroup_setting_psi_main(struct adaptived_effect * const eff) | |
full_setting_path[strlen(max_cgroup_path) + | ||
strlen(opts->cgroup_setting) + 1] = '\0'; | ||
|
||
ret = adaptived_file_exists(full_setting_path); | ||
if (ret) | ||
goto error; | ||
|
||
ret = calculate_value(opts, full_setting_path, &value); | ||
if (ret) | ||
goto error; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,10 @@ int kill_cgroup_init(struct adaptived_effect * const eff, struct json_object *ar | |
if (ret) | ||
goto error; | ||
|
||
ret = adaptived_file_exists(cgroup_path_str); | ||
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.
|
||
if (ret) | ||
goto error; | ||
|
||
opts->cgroup_path = malloc(sizeof(char) * strlen(cgroup_path_str) + 1); | ||
if (!opts->cgroup_path) { | ||
ret = -ENOMEM; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,10 @@ int kill_cgroup_psi_init(struct adaptived_effect * const eff, struct json_object | |
if (ret) | ||
goto error; | ||
|
||
ret = adaptived_file_exists(cgroup_path_str); | ||
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.
|
||
if (ret) | ||
goto error; | ||
|
||
opts->cgroup_path = malloc(sizeof(char) * strlen(cgroup_path_str) + 1); | ||
if (!opts->cgroup_path) { | ||
ret = -ENOMEM; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,3 +269,20 @@ API void adaptived_path_walk_end(struct adaptived_path_walk_handle **handle) | |
|
||
*handle = NULL; | ||
} | ||
|
||
API int adaptived_file_exists(const char * const path) | ||
{ | ||
char check_path[FILENAME_MAX]; | ||
char *subp; | ||
|
||
strcpy(check_path, path); | ||
subp = strstr(check_path, "*"); | ||
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'm not a fan of replacing I don't think we want this check. |
||
if (subp) | ||
*subp = '\0'; | ||
|
||
if (access(check_path, F_OK) != 0) { | ||
adaptived_err("%s: can't find %s, errno=%d\n", __func__, check_path, errno); | ||
return -EEXIST; | ||
} | ||
return 0; | ||
} |
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.
Also if we're going to check if the file exists, I think we need a way for the user to skip this check.
What if they had a config like this:
A config like the above wouldn't work with the checks as written because the cgroup doesn't exist until the
make_a_cgroup
's main runs.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.
We could mimic the
-ENOENT
logic for other optional flags