]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: allow set-features to take input from stdin
authorJoy Gu <jgu@purestorage.com>
Fri, 20 Oct 2023 21:48:08 +0000 (14:48 -0700)
committerDaniel Wagner <wagi@monom.org>
Fri, 3 Nov 2023 07:35:24 +0000 (08:35 +0100)
Fixes: fed9e5ee04cd ("nvme: auto free nvme_dev resource")
nvme.c

diff --git a/nvme.c b/nvme.c
index 7ec03ece9822fd3e6f56194e45c2a2096a46b46f..06bd64cf40f6da5bbd550d382bfde0bb8663d66e 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -5875,16 +5875,18 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
                if (cfg.feature_id == NVME_FEAT_FID_TIMESTAMP && cfg.value) {
                        memcpy(buf, &cfg.value, NVME_FEAT_TIMESTAMP_DATA_SIZE);
                } else {
-                       if (strlen(cfg.file)) {
+                       if (strlen(cfg.file))
                                ffd = open(cfg.file, O_RDONLY);
-                               if (ffd <= 0) {
-                                       nvme_show_error("Failed to open file %s: %s",
-                                                       cfg.file, strerror(errno));
-                                       return -EINVAL;
-                               }
+                       else
+                               ffd = dup(STDIN_FILENO);
+
+                       if (ffd < 0) {
+                               nvme_show_error("Failed to open file %s: %s",
+                                               cfg.file, strerror(errno));
+                               return -EINVAL;
                        }
 
-                       err = read(ffd, (void *)buf, cfg.data_len);
+                       err = read(ffd, buf, cfg.data_len);
                        if (err < 0) {
                                nvme_show_error("failed to read data buffer from input file: %s",
                                                strerror(errno));