@@ -347,48 +347,35 @@ static gint ga_strcmp(gconstpointer str1, gconstpointer str2)
347
347
}
348
348
349
349
/* disable commands that aren't safe for fsfreeze */
350
- static void ga_disable_non_whitelisted (void )
350
+ static void ga_disable_non_whitelisted (QmpCommand * cmd , void * opaque )
351
351
{
352
- char * * list_head , * * list ;
353
- bool whitelisted ;
354
- int i ;
355
-
356
- list_head = list = qmp_get_command_list ();
357
- while (* list != NULL ) {
358
- whitelisted = false;
359
- i = 0 ;
360
- while (ga_freeze_whitelist [i ] != NULL ) {
361
- if (strcmp (* list , ga_freeze_whitelist [i ]) == 0 ) {
362
- whitelisted = true;
363
- }
364
- i ++ ;
365
- }
366
- if (!whitelisted ) {
367
- g_debug ("disabling command: %s" , * list );
368
- qmp_disable_command (* list );
352
+ bool whitelisted = false;
353
+ int i = 0 ;
354
+ const char * name = qmp_command_name (cmd );
355
+
356
+ while (ga_freeze_whitelist [i ] != NULL ) {
357
+ if (strcmp (name , ga_freeze_whitelist [i ]) == 0 ) {
358
+ whitelisted = true;
369
359
}
370
- g_free (* list );
371
- list ++ ;
360
+ i ++ ;
361
+ }
362
+ if (!whitelisted ) {
363
+ g_debug ("disabling command: %s" , name );
364
+ qmp_disable_command (name );
372
365
}
373
- g_free (list_head );
374
366
}
375
367
376
368
/* [re-]enable all commands, except those explicitly blacklisted by user */
377
- static void ga_enable_non_blacklisted (GList * blacklist )
369
+ static void ga_enable_non_blacklisted (QmpCommand * cmd , void * opaque )
378
370
{
379
- char * * list_head , * * list ;
380
-
381
- list_head = list = qmp_get_command_list ();
382
- while (* list != NULL ) {
383
- if (g_list_find_custom (blacklist , * list , ga_strcmp ) == NULL &&
384
- !qmp_command_is_enabled (* list )) {
385
- g_debug ("enabling command: %s" , * list );
386
- qmp_enable_command (* list );
387
- }
388
- g_free (* list );
389
- list ++ ;
371
+ GList * blacklist = opaque ;
372
+ const char * name = qmp_command_name (cmd );
373
+
374
+ if (g_list_find_custom (blacklist , name , ga_strcmp ) == NULL &&
375
+ !qmp_command_is_enabled (cmd )) {
376
+ g_debug ("enabling command: %s" , name );
377
+ qmp_enable_command (name );
390
378
}
391
- g_free (list_head );
392
379
}
393
380
394
381
static bool ga_create_file (const char * path )
@@ -424,7 +411,7 @@ void ga_set_frozen(GAState *s)
424
411
return ;
425
412
}
426
413
/* disable all non-whitelisted (for frozen state) commands */
427
- ga_disable_non_whitelisted ( );
414
+ qmp_for_each_command ( ga_disable_non_whitelisted , NULL );
428
415
g_warning ("disabling logging due to filesystem freeze" );
429
416
ga_disable_logging (s );
430
417
s -> frozen = true;
@@ -460,7 +447,7 @@ void ga_unset_frozen(GAState *s)
460
447
}
461
448
462
449
/* enable all disabled, non-blacklisted commands */
463
- ga_enable_non_blacklisted ( s -> blacklist );
450
+ qmp_for_each_command ( ga_enable_non_blacklisted , s -> blacklist );
464
451
s -> frozen = false;
465
452
if (!ga_delete_file (s -> state_filepath_isfrozen )) {
466
453
g_warning ("unable to delete %s, fsfreeze may not function properly" ,
@@ -920,6 +907,11 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)
920
907
return handle ;
921
908
}
922
909
910
+ static void ga_print_cmd (QmpCommand * cmd , void * opaque )
911
+ {
912
+ printf ("%s\n" , qmp_command_name (cmd ));
913
+ }
914
+
923
915
int main (int argc , char * * argv )
924
916
{
925
917
const char * sopt = "hVvdm:p:l:f:F::b:s:t:" ;
@@ -996,15 +988,8 @@ int main(int argc, char **argv)
996
988
daemonize = 1 ;
997
989
break ;
998
990
case 'b' : {
999
- char * * list_head , * * list ;
1000
991
if (is_help_option (optarg )) {
1001
- list_head = list = qmp_get_command_list ();
1002
- while (* list != NULL ) {
1003
- printf ("%s\n" , * list );
1004
- g_free (* list );
1005
- list ++ ;
1006
- }
1007
- g_free (list_head );
992
+ qmp_for_each_command (ga_print_cmd , NULL );
1008
993
return 0 ;
1009
994
}
1010
995
for (j = 0 , i = 0 , len = strlen (optarg ); i < len ; i ++ ) {
@@ -1126,7 +1111,7 @@ int main(int argc, char **argv)
1126
1111
s -> deferred_options .log_filepath = log_filepath ;
1127
1112
}
1128
1113
ga_disable_logging (s );
1129
- ga_disable_non_whitelisted ( );
1114
+ qmp_for_each_command ( ga_disable_non_whitelisted , NULL );
1130
1115
} else {
1131
1116
if (daemonize ) {
1132
1117
become_daemon (pid_filepath );
0 commit comments