[PATCH] Allow job file to be last argument
[fio.git] / fio-ini.c
index b360e9715ba169b215a6f2cd31115415c6a75fb5..23810bafd2423210f7bb3b015e31695090d5bba2 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -81,11 +81,11 @@ static void setup_log(struct io_log **log)
 
 void finish_log(struct thread_data *td, struct io_log *log, const char *name)
 {
 
 void finish_log(struct thread_data *td, struct io_log *log, const char *name)
 {
-       char file_name[128];
+       char file_name[256];
        FILE *f;
        unsigned int i;
 
        FILE *f;
        unsigned int i;
 
-       sprintf(file_name, "client%d_%s.log", td->thread_number, name);
+       snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
        f = fopen(file_name, "w");
        if (!f) {
                perror("fopen log");
        f = fopen(file_name, "w");
        if (!f) {
                perror("fopen log");
@@ -218,7 +218,7 @@ static int add_job(struct thread_data *td, const char *jobname, int prioclass,
                else
                        sprintf(td->file_name, "%s.%d", jobname, td->jobnum);
        } else
                else
                        sprintf(td->file_name, "%s.%d", jobname, td->jobnum);
        } else
-               strcpy(td->file_name, jobname);
+               strncpy(td->file_name, jobname, sizeof(td->file_name) - 1);
 
        sem_init(&td->mutex, 0, 0);
 
 
        sem_init(&td->mutex, 0, 0);
 
@@ -391,6 +391,14 @@ static void strip_blank_end(char *p)
        }
 }
 
        }
 }
 
+static void terminate_line(char *p)
+{
+       while (*p != '\n' && *p != '\0')
+               p++;
+
+       *p = '\0';
+}
+
 typedef int (str_cb_fn)(struct thread_data *, char *);
 
 static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
 typedef int (str_cb_fn)(struct thread_data *, char *);
 
 static int check_str(char *p, char *name, str_cb_fn *cb, struct thread_data *td)
@@ -620,6 +628,13 @@ static int str_ioengine_cb(struct thread_data *td, char *str)
        return 1;
 }
 
        return 1;
 }
 
+static int str_iolog_cb(struct thread_data *td, char *file)
+{
+       terminate_line(file);
+       strncpy(td->iolog_file, file, sizeof(td->iolog_file) - 1);
+
+       return 0;
+}
 
 int parse_jobs_ini(char *file)
 {
 
 int parse_jobs_ini(char *file)
 {
@@ -634,7 +649,7 @@ int parse_jobs_ini(char *file)
 
        f = fopen(file, "r");
        if (!f) {
 
        f = fopen(file, "r");
        if (!f) {
-               perror("fopen");
+               perror("fopen job file");
                return 1;
        }
 
                return 1;
        }
 
@@ -664,6 +679,7 @@ int parse_jobs_ini(char *file)
                                continue;
                        if (strstr(p, "["))
                                break;
                                continue;
                        if (strstr(p, "["))
                                break;
+
                        if (!check_int(p, "prio", &prio)) {
 #ifndef FIO_HAVE_IOPRIO
                                fprintf(stderr, "io priorities not available\n");
                        if (!check_int(p, "prio", &prio)) {
 #ifndef FIO_HAVE_IOPRIO
                                fprintf(stderr, "io priorities not available\n");
@@ -829,8 +845,14 @@ int parse_jobs_ini(char *file)
                                fgetpos(f, &off);
                                continue;
                        }
                                fgetpos(f, &off);
                                continue;
                        }
+                       if (!check_str(p, "iolog", str_iolog_cb, td)) {
+                               td->iolog = 1;
+                               fgetpos(f, &off);
+                               continue;
+                       }
 
                        printf("Client%d: bad option %s\n",td->thread_number,p);
 
                        printf("Client%d: bad option %s\n",td->thread_number,p);
+                       return 1;
                }
                fsetpos(f, &off);
 
                }
                fsetpos(f, &off);
 
@@ -947,6 +969,9 @@ static void parse_cmd_line(int argc, char *argv[])
                                exit(0);
                }
        }
                                exit(0);
                }
        }
+
+       if (!ini_file && argc > 1 && argv[argc - 1][0] != '-')
+               ini_file = strdup(argv[argc - 1]);
 }
 
 static void free_shm(void)
 }
 
 static void free_shm(void)
@@ -1008,8 +1033,10 @@ int parse_options(int argc, char *argv[])
                return 1;
        }
 
                return 1;
        }
 
-       if (parse_jobs_ini(ini_file))
+       if (parse_jobs_ini(ini_file)) {
+               usage(argv[0]);
                return 1;
                return 1;
+       }
 
        return 0;
 }
 
        return 0;
 }