Merge branch 'client-unique-log-names' of https://github.com/bengland2/fio into log...
[fio.git] / client.c
index c8069a0159acb64929be53c75974698d78d5047e..4121ea5f4f17df7a9565570bcbb51816ae0229fb 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1295,6 +1295,7 @@ static int fio_client_handle_iolog(struct fio_client *client,
 {
        struct cmd_iolog_pdu *pdu;
        bool store_direct;
 {
        struct cmd_iolog_pdu *pdu;
        bool store_direct;
+       char *log_pathname;
 
        pdu = convert_iolog(cmd, &store_direct);
        if (!pdu) {
 
        pdu = convert_iolog(cmd, &store_direct);
        if (!pdu) {
@@ -1302,15 +1303,27 @@ static int fio_client_handle_iolog(struct fio_client *client,
                return 1;
        }
 
                return 1;
        }
 
+        /* allocate buffer big enough for next sprintf() call */
+       log_pathname = malloc( 10 + 
+                       strlen((char * )pdu->name) + 
+                       strlen(client->hostname));
+       if (!log_pathname) {
+               log_err("fio: memory allocation of unique pathname failed");
+               return -1;
+       }
+       /* generate a unique pathname for the log file using hostname */
+       sprintf(log_pathname, "%s.%s", pdu->name, client->hostname);
+
        if (store_direct) {
                ssize_t ret;
                size_t sz;
                int fd;
 
        if (store_direct) {
                ssize_t ret;
                size_t sz;
                int fd;
 
-               fd = open((const char *) pdu->name,
+               fd = open((const char *) log_pathname,
                                O_WRONLY | O_CREAT | O_TRUNC, 0644);
                if (fd < 0) {
                                O_WRONLY | O_CREAT | O_TRUNC, 0644);
                if (fd < 0) {
-                       log_err("fio: open log: %s\n", strerror(errno));
+                       log_err("fio: open log %s: %s\n", 
+                               log_pathname, strerror(errno));
                        return 1;
                }
 
                        return 1;
                }
 
@@ -1326,10 +1339,10 @@ static int fio_client_handle_iolog(struct fio_client *client,
                return 0;
        } else {
                FILE *f;
                return 0;
        } else {
                FILE *f;
-
-               f = fopen((const char *) pdu->name, "w");
+               f = fopen((const char *) log_pathname, "w");
                if (!f) {
                if (!f) {
-                       log_err("fio: fopen log: %s\n", strerror(errno));
+                       log_err("fio: fopen log %s : %s\n", 
+                               log_pathname, strerror(errno));
                        return 1;
                }
 
                        return 1;
                }