[PATCH] Make the test_profile able to take multiple files

David Howells dhowells at redhat.com
Thu Sep 6 12:14:26 EDT 2018


Make the test_profile program able to take multiple files by sticking in
parameters called "{" and "}" around the set, e.g.:

	./src/util/profile/test_profile { foo.conf bar.conf } query cells openstack.org description

The original still works, but a single file named "{" is now unusable, unless
it is sandwiched with "{" and "}".

---
diff --git a/src/util/profile/test_profile.c b/src/util/profile/test_profile.c
index 6f6fcc7..02e9d0e 100644
--- a/src/util/profile/test_profile.c
+++ b/src/util/profile/test_profile.c
@@ -115,25 +115,48 @@ int main(argc, argv)
 {
     profile_t   profile;
     long        retval;
-    char        **values, *value, **cpp;
+    char        **values, *value, **cpp, **p;
     const char  **names;
     char        *cmd;
     int         print_value = 0;
 
     if (argc < 2) {
         fprintf(stderr, "Usage: %s filename [cmd argset]\n", program_name);
+        fprintf(stderr, "       %s { filename* } [cmd argset]\n", program_name);
         exit(1);
     }
 
     initialize_prof_error_table();
 
-    retval = profile_init_path(argv[1], &profile);
-    if (retval) {
-        com_err(program_name, retval, "while initializing profile");
-        exit(1);
+    if (strcmp(argv[1], "{") != 0) {
+        retval = profile_init_path(argv[1], &profile);
+        if (retval) {
+            com_err(program_name, retval, "while initializing profile");
+            exit(1);
+        }
+        cmd = *(argv+2);
+        names = (const char **) argv+3;
+    } else {
+        for (p = argv + 1; *p; p++)
+            if (strcmp(*p, "}") == 0)
+                break;
+        if (!p[0]) {
+            fprintf(stderr, "Missing closure of filename set.\n");
+            exit(1);
+        }
+        if (!p[1]) {
+            fprintf(stderr, "Missing command name.\n");
+            exit(1);
+        }
+        *p = NULL;
+        retval = profile_init((const char **)argv + 1, &profile);
+        if (retval) {
+            com_err(program_name, retval, "while initializing profile");
+            exit(1);
+        }
+        cmd = p[1];
+        names = (const char **) p + 2;
     }
-    cmd = *(argv+2);
-    names = (const char **) argv+3;
     if (!cmd || !strcmp(cmd, "batch"))
         do_batchmode(profile);
     if (!strcmp(cmd, "query")) {



More information about the krbdev mailing list