From: Joy Gu Date: Fri, 20 Oct 2023 21:48:08 +0000 (-0700) Subject: nvme: allow set-features to take input from stdin X-Git-Tag: v2.7~108 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=540e3a5b3079f48326a0b12c203c889b22d420c0;p=users%2Fsagi%2Fnvme-cli.git nvme: allow set-features to take input from stdin Fixes: fed9e5ee04cd ("nvme: auto free nvme_dev resource") --- diff --git a/nvme.c b/nvme.c index 7ec03ece..06bd64cf 100644 --- 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));