diff --git a/src/systemd-sonic-generator/systemd-sonic-generator.c b/src/systemd-sonic-generator/systemd-sonic-generator.c index 1d1a53dbcef..d9bb75fea2b 100644 --- a/src/systemd-sonic-generator/systemd-sonic-generator.c +++ b/src/systemd-sonic-generator/systemd-sonic-generator.c @@ -141,6 +141,9 @@ static int get_install_targets_from_line(char* target_string, char* install_type char final_target[PATH_MAX]; int num_targets = 0; + assert(target_string); + assert(install_type); + while ((token = strtok_r(target_string, " ", &target_string))) { if (num_targets + existing_targets >= MAX_NUM_TARGETS) { fputs("Number of targets found exceeds MAX_NUM_TARGETS\n", stderr); @@ -269,7 +272,7 @@ int get_install_targets(char* unit_file, char* targets[]) { char* token; char* line = NULL; bool first; - char* target_suffix; + char* target_suffix = NULL; char *instance_name; char *dot_ptr; @@ -306,6 +309,8 @@ int get_install_targets(char* unit_file, char* targets[]) { } else if (strstr(token, "WantedBy") != NULL) { target_suffix = ".wants"; + } else { + break; } } else { diff --git a/src/systemd-sonic-generator/tests/testfiles/test.service b/src/systemd-sonic-generator/tests/testfiles/test.service index e8b37f641fd..ebc8b1f8d70 100644 --- a/src/systemd-sonic-generator/tests/testfiles/test.service +++ b/src/systemd-sonic-generator/tests/testfiles/test.service @@ -7,4 +7,5 @@ Type=oneshot RemainAfterExit=yes ExecStart=/usr/bin/test.sh start [Install] +Alias=test.service WantedBy=multi-user.target