X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=init.c;h=7e456b20d3466d8c9b9e83858623833fa1d6ae6d;hb=73a467e6899315b1f78cf8f16bb1b1ac6d21505e;hp=11876b9a98a493114398df5d58f5042bf7f42ef5;hpb=25bd16ce8db9fe2da0091b165967e32ef89f9b0f;p=fio.git diff --git a/init.c b/init.c index 11876b9a..7e456b20 100644 --- a/init.c +++ b/init.c @@ -364,7 +364,7 @@ static struct thread_data *get_new_job(int global, struct thread_data *parent, td->thread_number = thread_number; - if (!parent || !parent->o.group_reporting) + if (!parent->o.group_reporting) stat_number++; set_cmd_options(td); @@ -942,6 +942,7 @@ static char *make_filename(char *buf, struct thread_options *o, { struct fpre_keyword *f; char copy[PATH_MAX]; + size_t dst_left = PATH_MAX; if (!o->filename_format || !strlen(o->filename_format)) { sprintf(buf, "%s.%d.%d", jobname, jobnum, filenum); @@ -969,25 +970,47 @@ static char *make_filename(char *buf, struct thread_options *o, if (pre_len) { strncpy(dst, buf, pre_len); dst += pre_len; + dst_left -= pre_len; } switch (f->key) { - case FPRE_JOBNAME: - dst += sprintf(dst, "%s", jobname); + case FPRE_JOBNAME: { + int ret; + + ret = snprintf(dst, dst_left, "%s", jobname); + if (ret < 0) + break; + dst += ret; + dst_left -= ret; break; - case FPRE_JOBNUM: - dst += sprintf(dst, "%d", jobnum); + } + case FPRE_JOBNUM: { + int ret; + + ret = snprintf(dst, dst_left, "%d", jobnum); + if (ret < 0) + break; + dst += ret; + dst_left -= ret; break; - case FPRE_FILENUM: - dst += sprintf(dst, "%d", filenum); + } + case FPRE_FILENUM: { + int ret; + + ret = snprintf(dst, dst_left, "%d", filenum); + if (ret < 0) + break; + dst += ret; + dst_left -= ret; break; + } default: assert(0); break; } if (post_start) - strcpy(dst, buf + post_start); + strncpy(dst, buf + post_start, dst_left); strcpy(buf, copy); } while (1); @@ -1719,6 +1742,9 @@ int parse_cmd_line(int argc, char *argv[], int client_type) write_bw_log = 1; break; case 'o': + if (f_out) + fclose(f_out); + f_out = fopen(optarg, "w+"); if (!f_out) { perror("fopen output"); @@ -1828,6 +1854,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type) break; } case 'p': + if (exec_profile) + free(exec_profile); exec_profile = strdup(optarg); break; case FIO_GETOPT_JOB: { @@ -1837,7 +1865,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) if (!strncmp(opt, "name", 4) && td) { ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); if (ret) - return 0; + goto out_free; td = NULL; } if (!td) { @@ -1852,7 +1880,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) td = get_new_job(global, &def_thread, 1); if (!td || ioengine_load(td)) - return 0; + goto out_free; fio_options_set_ioengine_opts(l_opts, td); } @@ -1874,7 +1902,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type) if (!ret && !strcmp(opt, "ioengine")) { free_ioengine(td); if (ioengine_load(td)) - return 0; + goto out_free; fio_options_set_ioengine_opts(l_opts, td); } break; @@ -1985,6 +2013,8 @@ int parse_cmd_line(int argc, char *argv[], int client_type) if (is_backend && backend) return fio_start_server(pid_file); + else if (pid_file) + free(pid_file); if (td) { if (!ret) @@ -1998,6 +2028,10 @@ int parse_cmd_line(int argc, char *argv[], int client_type) optind++; } +out_free: + if (pid_file) + free(pid_file); + return ini_idx; } @@ -2033,7 +2067,7 @@ int parse_options(int argc, char *argv[]) if (job_files > 0) { for (i = 0; i < job_files; i++) { - if (fill_def_thread()) + if (i && fill_def_thread()) return 1; if (nr_clients) { if (fio_clients_send_ini(ini_file[i]))