Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit bca496f

Browse files
yadong-intelsysopenci
authored andcommitted
remove duplicated cmd from extra cmd if duplicated
remove duplicated cmd from extra cmd if duplicated with fixed_cmd or previously set command. Tracked-On: OAM-99781 Signed-off-by: Yadong Qi <yadong.qi@linux.ntel.com>
1 parent 326618e commit bca496f

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

src/guest/start.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,35 @@ static int run_extra_service(char *str)
425425
return ret;
426426
}
427427

428+
/* strip parameters if it is already set in previouly set cmd */
429+
static void strip_duplicate(gchar *val, const gchar *inner_cmd)
430+
{
431+
gchar *to_split = NULL;
432+
gchar **sub_str = NULL;
433+
guint i;
434+
435+
if ((!val) || (!inner_cmd))
436+
return;
437+
438+
to_split = g_strconcat(" ", val, NULL);
439+
sub_str = g_strsplit(val, " -", 0);
440+
441+
for (i = 0; sub_str[i]; i++) {
442+
gchar *find = g_strstr_len(inner_cmd, -1, sub_str[i]);
443+
if (find) {
444+
gchar *start = g_strstr_len(val, -1, sub_str[i]);
445+
memset(start, ' ', strlen(sub_str[i]));
446+
*(start - 1) = ' '; //set '-' to ' '
447+
g_strstrip(start - 1);
448+
}
449+
}
450+
451+
if (sub_str)
452+
g_strfreev(sub_str);
453+
if (to_split)
454+
g_free(to_split);
455+
}
456+
428457
int start_guest(char *name)
429458
{
430459
int ret = 0;
@@ -732,6 +761,8 @@ int start_guest(char *name)
732761
/* extra cmds */
733762
val = g_key_file_get_string(gkf, g->name, g->key[EXTRA_CMD], NULL);
734763
if (val != NULL && (strcmp("", val) != 0)) {
764+
strip_duplicate(val, fixed_cmd);
765+
strip_duplicate(val, cmd_str);
735766
cx = snprintf(p, size, " %s", val);
736767
printf("%s: %s\n", g->key[EXTRA_CMD], val);
737768
p += cx; size -= cx;

0 commit comments

Comments
 (0)