client: parse env variables before sending job-file contents to server
[fio.git] / client.c
index 96cc35e66bdc9c44f8991aec8ce9ab7bdc44dcf2..60f7c6ab82767cab31cf30443e07affa15c32b51 100644 (file)
--- a/client.c
+++ b/client.c
@@ -118,6 +118,49 @@ static int read_data(int fd, void *data, size_t size)
        return 0;
 }
 
        return 0;
 }
 
+static int read_ini_data(int fd, void *data, size_t size)
+{
+       char *p = data;
+       int ret = 0;
+       FILE *fp;
+
+       fp = fdopen(dup(fd), "r");
+       if (!fp)
+               return errno;
+
+       while (1) {
+               ssize_t len;
+               char buf[OPT_LEN_MAX+1], *sub;
+
+               if (!fgets(buf, sizeof(buf), fp)) {
+                       if (ferror(fp)) {
+                               if (errno == EAGAIN || errno == EINTR)
+                                       continue;
+                               ret = errno;
+                       }
+                       break;
+               }
+
+               sub = fio_option_dup_subs(buf);
+               len = strlen(sub);
+               if (len + 1 > size) {
+                       log_err("fio: no space left to read data\n");
+                       free(sub);
+                       ret = ENOSPC;
+                       break;
+               }
+
+               memcpy(p, sub, len);
+               free(sub);
+               p += len;
+               *p = '\0';
+               size -= len;
+       }
+
+       fclose(fp);
+       return ret;
+}
+
 static void fio_client_json_init(void)
 {
        char time_buf[32];
 static void fio_client_json_init(void)
 {
        char time_buf[32];
@@ -763,13 +806,17 @@ static int __fio_client_send_local_ini(struct fio_client *client,
                return ret;
        }
 
                return ret;
        }
 
+       /*
+        * Add extra space for variable expansion, but doesn't guarantee.
+        */
+       sb.st_size += OPT_LEN_MAX;
        p_size = sb.st_size + sizeof(*pdu);
        pdu = malloc(p_size);
        buf = pdu->buf;
 
        len = sb.st_size;
        p = buf;
        p_size = sb.st_size + sizeof(*pdu);
        pdu = malloc(p_size);
        buf = pdu->buf;
 
        len = sb.st_size;
        p = buf;
-       if (read_data(fd, p, len)) {
+       if (read_ini_data(fd, p, len)) {
                log_err("fio: failed reading job file %s\n", filename);
                close(fd);
                free(pdu);
                log_err("fio: failed reading job file %s\n", filename);
                close(fd);
                free(pdu);