ETA no longer works when -o specified
[fio.git] / init.c
diff --git a/init.c b/init.c
index fcc135e65eaf1f2f721f310aa8d6355c1331967d..a5468615eafecb7aba579b9da9162bc52c0e598d 100644 (file)
--- a/init.c
+++ b/init.c
@@ -937,7 +937,7 @@ static struct fpre_keyword {
        { .keyword = NULL, },
        };
 
-static char *make_filename(char *buf, struct thread_options *o,
+static char *make_filename(char *buf, size_t buf_size,struct thread_options *o,
                           const char *jobname, int jobnum, int filenum)
 {
        struct fpre_keyword *f;
@@ -952,7 +952,9 @@ static char *make_filename(char *buf, struct thread_options *o,
        for (f = &fpre_keywords[0]; f->keyword; f++)
                f->strlen = strlen(f->keyword);
 
-       strcpy(buf, o->filename_format);
+       buf[buf_size - 1] = '\0';
+       strncpy(buf, o->filename_format, buf_size - 1);
+
        memset(copy, 0, sizeof(copy));
        for (f = &fpre_keywords[0]; f->keyword; f++) {
                do {
@@ -1012,7 +1014,7 @@ static char *make_filename(char *buf, struct thread_options *o,
                        if (post_start)
                                strncpy(dst, buf + post_start, dst_left);
 
-                       strcpy(buf, copy);
+                       strncpy(buf, copy, buf_size - 1);
                } while (1);
        }
 
@@ -1072,7 +1074,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
                        add_file(td, jobname, job_add_num, 0);
                else {
                        for (i = 0; i < o->nr_files; i++)
-                               add_file(td, make_filename(fname, o, jobname, job_add_num, i), job_add_num, 0);
+                               add_file(td, make_filename(fname, sizeof(fname), o, jobname, job_add_num, i), job_add_num, 0);
                }
        }
 
@@ -1714,8 +1716,6 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
        optind = 1;
 
        while ((c = getopt_long_only(argc, argv, ostr, l_opts, &lidx)) != -1) {
-               did_arg = 1;
-
                if ((c & FIO_CLIENT_FLAG) || client_flag_set(c)) {
                        parse_cmd_client(cur_client, argv[optind - 1]);
                        c &= ~FIO_CLIENT_FLAG;
@@ -1739,7 +1739,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        write_bw_log = 1;
                        break;
                case 'o':
-                       if (f_out)
+                       if (f_out && f_out != stdout)
                                fclose(f_out);
 
                        f_out = fopen(optarg, "w+");
@@ -1772,30 +1772,35 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        append_terse_output = 1;
                        break;
                case 'h':
+                       did_arg = 1;
                        if (!cur_client) {
                                usage(argv[0]);
                                do_exit++;
                        }
                        break;
                case 'c':
+                       did_arg = 1;
                        if (!cur_client) {
                                fio_show_option_help(optarg);
                                do_exit++;
                        }
                        break;
                case 'i':
+                       did_arg = 1;
                        if (!cur_client) {
                                fio_show_ioengine_help(optarg);
                                do_exit++;
                        }
                        break;
                case 's':
+                       did_arg = 1;
                        dump_cmdline = 1;
                        break;
                case 'r':
                        read_only = 1;
                        break;
                case 'v':
+                       did_arg = 1;
                        if (!cur_client) {
                                log_info("%s\n", fio_version_string);
                                do_exit++;
@@ -1832,6 +1837,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                do_exit++;
                        break;
                case 'P':
+                       did_arg = 1;
                        parse_only = 1;
                        break;
                case 'x': {
@@ -1851,6 +1857,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        break;
                        }
                case 'p':
+                       did_arg = 1;
                        if (exec_profile)
                                free(exec_profile);
                        exec_profile = strdup(optarg);
@@ -1864,6 +1871,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                if (ret)
                                        goto out_free;
                                td = NULL;
+                               did_arg = 1;
                        }
                        if (!td) {
                                int is_section = !strncmp(opt, "name", 4);
@@ -1926,6 +1934,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        }
                        break;
                case 'S':
+                       did_arg = 1;
                        if (nr_clients) {
                                log_err("fio: can't be both client and server\n");
                                do_exit++;
@@ -1938,19 +1947,21 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        backend = 1;
                        break;
                case 'D':
-                       if (optarg)
-                               free(optarg);
+                       if (pid_file)
+                               free(pid_file);
                        pid_file = strdup(optarg);
                        break;
                case 'I':
                        if ((ret = fio_idle_prof_parse_opt(optarg))) {
                                /* exit on error and calibration only */
+                               did_arg = 1;
                                do_exit++;
-                               if (ret == -1) 
+                               if (ret == -1)
                                        exit_val = 1;
                        }
                        break;
                case 'C':
+                       did_arg = 1;
                        if (is_backend) {
                                log_err("fio: can't be both client and server\n");
                                do_exit++;
@@ -1977,10 +1988,12 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        }
                        break;
                case 'T':
+                       did_arg = 1;
                        do_exit++;
                        exit_val = fio_monotonic_clocktest();
                        break;
                case 'G':
+                       did_arg = 1;
                        do_exit++;
                        exit_val = fio_crctest(optarg);
                        break;
@@ -2020,8 +2033,11 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                free(pid_file);
 
        if (td) {
-               if (!ret)
+               if (!ret) {
                        ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type);
+                       if (ret)
+                               did_arg = 1;
+               }
        }
 
        while (!ret && optind < argc) {