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

Replace strtok in systemd-sonic-generator #11710

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Changes from 1 commit
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
20 changes: 12 additions & 8 deletions src/systemd-sonic-generator/systemd-sonic-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ static int get_install_targets_from_line(char* target_string, char* install_type
***/
char* token;
char* target;
char* saveptr;
char final_target[PATH_MAX];
int num_targets = 0;

Expand All @@ -135,8 +136,8 @@ static int get_install_targets_from_line(char* target_string, char* install_type
strip_trailing_newline(target);

if (strstr(target, "%") != NULL) {
char* prefix = strtok(target, ".");
char* suffix = strtok(NULL, ".");
char* prefix = strtok_r(target, ".", &saveptr);
char* suffix = strtok_r(NULL, ".", &saveptr);
int prefix_len = strlen(prefix);

strncpy(final_target, prefix, prefix_len - 2);
Expand Down Expand Up @@ -516,6 +517,8 @@ int get_num_of_asic() {
char *line = NULL;
char* token;
char* platform;
char* saveptr1;
char* saveptr2;
size_t len = 0;
ssize_t nread;
bool ans;
Expand All @@ -534,8 +537,8 @@ int get_num_of_asic() {
while ((nread = getline(&line, &len, fp)) != -1) {
if ((strstr(line, "onie_platform") != NULL) ||
(strstr(line, "aboot_platform") != NULL)) {
token = strtok(line, "=");
platform = strtok(NULL, "=");
token = strtok_r(line, "=", &saveptr1);
platform = strtok_r(NULL, "=", &saveptr1);
strip_trailing_newline(platform);
break;
}
Expand All @@ -547,8 +550,8 @@ int get_num_of_asic() {
if (fp != NULL) {
while ((nread = getline(&line, &len, fp)) != -1) {
if (strstr(line, "NUM_ASIC") != NULL) {
token = strtok(line, "=");
str_num_asic = strtok(NULL, "=");
token = strtok_r(line, "=", &saveptr2);
SuvarnaMeenakshi marked this conversation as resolved.
Show resolved Hide resolved
str_num_asic = strtok_r(NULL, "=", &saveptr2);
strip_trailing_newline(str_num_asic);
if (str_num_asic != NULL){
sscanf(str_num_asic, "%d",&num_asic);
Expand All @@ -571,6 +574,7 @@ int ssg_main(int argc, char **argv) {
char* unit_instance;
char* prefix;
char* suffix;
char* saveptr;
int num_unit_files;
int num_targets;
int r;
Expand All @@ -589,8 +593,8 @@ int ssg_main(int argc, char **argv) {
for (int i = 0; i < num_unit_files; i++) {
unit_instance = strdup(unit_files[i]);
if ((num_asics == 1) && strstr(unit_instance, "@") != NULL) {
prefix = strtok(unit_instance, "@");
suffix = strtok(NULL, "@");
prefix = strtok_r(unit_instance, "@", &saveptr);
suffix = strtok_r(NULL, "@", &saveptr);

strcpy(unit_instance, prefix);
strcat(unit_instance, suffix);
Expand Down