]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/buffer: accept "-" as stdin
authorPatrick Donnelly <pdonnell@ibm.com>
Fri, 21 Mar 2025 16:53:38 +0000 (12:53 -0400)
committerPatrick Donnelly <pdonnell@ibm.com>
Mon, 29 Dec 2025 22:29:57 +0000 (17:29 -0500)
These methods are used for reading files from tools like "authtool". Read from
stdin if the conventional "-" filename is passed.

Signed-off-by: Patrick Donnelly <pdonnell@ibm.com>
src/common/buffer.cc

index d5184036f858df8e320f5e75bbdcf375d49d3ef5..e0c6841ebb4747bd04aa439191b24c5b824571cb 100644 (file)
@@ -1725,7 +1725,13 @@ void buffer::list::decode_base64(buffer::list& e)
 
 ssize_t buffer::list::pread_file(const char *fn, uint64_t off, uint64_t len, std::string *error)
 {
-  int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
+  int fd;
+  if (strcmp(fn, "-") == 0) {
+    /* FIXME dup3 for O_CLOEXEC */
+    fd = TEMP_FAILURE_RETRY(::dup(STDIN_FILENO));
+  } else {
+    fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
+  }
   if (fd < 0) {
     int err = errno;
     std::ostringstream oss;
@@ -1785,7 +1791,13 @@ ssize_t buffer::list::pread_file(const char *fn, uint64_t off, uint64_t len, std
 
 int buffer::list::read_file(const char *fn, std::string *error)
 {
-  int fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
+  int fd;
+  if (strcmp(fn, "-") == 0) {
+    /* FIXME dup3 for O_CLOEXEC */
+    fd = TEMP_FAILURE_RETRY(::dup(STDIN_FILENO));
+  } else {
+    fd = TEMP_FAILURE_RETRY(::open(fn, O_RDONLY|O_CLOEXEC|O_BINARY));
+  }
   if (fd < 0) {
     int err = errno;
     std::ostringstream oss;