]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
json: allow 'NULL' argument to json_update_config()
authorHannes Reinecke <hare@suse.de>
Thu, 30 Sep 2021 09:42:37 +0000 (11:42 +0200)
committerHannes Reinecke <hare@suse.de>
Fri, 8 Oct 2021 11:22:52 +0000 (13:22 +0200)
Allow a 'NULL' argument to json_update_config() to indicate that
the contents should be written to stdout.

Signed-off-by: Hannes Reinecke <hare@suse.de>
src/nvme/json.c

index faadf2d383080d37683f4f61377fc48485d6d6a3..09791d2a14aecb62cdb86cb618a7a2b76d45c0fd 100644 (file)
@@ -267,10 +267,15 @@ int json_update_config(nvme_root_t r, const char *config_file)
                        json_object_put(subsys_array);
                json_object_array_add(json_root, host_obj);
        }
-       if (json_object_to_file_ext(config_file, json_root,
-                                   JSON_C_TO_STRING_PRETTY) < 0) {
-               nvme_msg(LOG_ERR, "Failed to write %s, %s\n",
-                       config_file, json_util_get_last_err());
+       if (!config_file)
+               ret = json_object_to_fd(1, json_root, JSON_C_TO_STRING_PRETTY);
+       else
+               ret = json_object_to_file_ext(config_file, json_root,
+                                             JSON_C_TO_STRING_PRETTY);
+       if (ret < 0) {
+               nvme_msg(LOG_ERR, "Failed to write to %s, %s\n",
+                        config_file ? "stdout" : config_file,
+                        json_util_get_last_err());
                ret = -1;
                errno = EIO;
        }