static struct fio_option options[] = {
{
- .name = "program",
- .lname = "Program",
- .type = FIO_OPT_STR_STORE,
- .off1 = offsetof(struct exec_options, program),
- .help = "Program to execute",
- .category = FIO_OPT_C_ENGINE,
- .group = FIO_OPT_G_INVALID,
- },
+ .name = "program",
+ .lname = "Program",
+ .type = FIO_OPT_STR_STORE,
+ .off1 = offsetof(struct exec_options, program),
+ .help = "Program to execute",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_INVALID,
+ },
{
- .name = "arguments",
- .lname = "Arguments",
- .type = FIO_OPT_STR_STORE,
- .off1 = offsetof(struct exec_options, arguments),
- .help = "Arguments to pass",
- .category = FIO_OPT_C_ENGINE,
- .group = FIO_OPT_G_INVALID,
- },
+ .name = "arguments",
+ .lname = "Arguments",
+ .type = FIO_OPT_STR_STORE,
+ .off1 = offsetof(struct exec_options, arguments),
+ .help = "Arguments to pass",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_INVALID,
+ },
{
- .name = "grace_time",
- .lname = "Grace time",
- .type = FIO_OPT_INT,
- .minval = 0,
- .def = "1",
- .off1 = offsetof(struct exec_options, grace_time),
- .help = "Grace time before sending a SIGKILL",
- .category = FIO_OPT_C_ENGINE,
- .group = FIO_OPT_G_INVALID,
- },
+ .name = "grace_time",
+ .lname = "Grace time",
+ .type = FIO_OPT_INT,
+ .minval = 0,
+ .def = "1",
+ .off1 = offsetof(struct exec_options, grace_time),
+ .help = "Grace time before sending a SIGKILL",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_INVALID,
+ },
{
- .name = "std_redirect",
- .lname = "Std redirect",
- .type = FIO_OPT_BOOL,
- .def = "1",
- .off1 = offsetof(struct exec_options, std_redirect),
- .help = "Redirect stdout & stderr to files",
- .category = FIO_OPT_C_ENGINE,
- .group = FIO_OPT_G_INVALID,
- },
+ .name = "std_redirect",
+ .lname = "Std redirect",
+ .type = FIO_OPT_BOOL,
+ .def = "1",
+ .off1 = offsetof(struct exec_options, std_redirect),
+ .help = "Redirect stdout & stderr to files",
+ .category = FIO_OPT_C_ENGINE,
+ .group = FIO_OPT_G_INVALID,
+ },
{
- .name = NULL,
- },
+ .name = NULL,
+ },
};
char *str_replace(char *orig, const char *rep, const char *with)
{
/*
- Replace a substring by another.
-
- Returns the new string if occurences were found
- Returns orig if no occurence is found
+ * Replace a substring by another.
+ *
+ * Returns the new string if occurrences were found
+ * Returns orig if no occurrence is found
*/
char *result, *insert, *tmp;
int len_rep, len_with, len_front, count;
- // sanity checks and initialization
+ /* sanity checks and initialization */
if (!orig || !rep)
return orig;
/* %n is replaced by the name of the running job */
expanded_name = str_replace(expanded_runtime, "%n", o->name);
+ free(expanded_runtime);
return expanded_name;
}
/* Creating the stderr & stdout output files */
outfd = open(outfilename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
- if (!outfd) {
+ if (outfd < 0) {
log_err("fio: cannot open output file %s : %s\n",
outfilename, strerror(errno));
free(outfilename);
free(errfilename);
+ free(expanded_arguments);
return -1;
}
errfd = open(errfilename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
- if (!errfd) {
+ if (errfd < 0) {
log_err("fio: cannot open output file %s : %s\n",
errfilename, strerror(errno));
free(outfilename);
free(errfilename);
+ free(expanded_arguments);
+ close(outfd);
return -1;
}
} else {
free(outfilename);
free(errfilename);
}
+ free(expanded_arguments);
return 0;
}
free(outfilename);
free(errfilename);
}
+ free(expanded_arguments);
return -1;
}
/* We are in the worker (child side of the fork) */
if (pid == 0) {
if (eo->std_redirect) {
- dup2(outfd, 1); // replace stdout by the output file we create
- dup2(errfd, 2); // replace stderr by the output file we create
+ /* replace stdout by the output file we create */
+ dup2(outfd, 1);
+ /* replace stderr by the output file we create */
+ dup2(errfd, 2);
close(outfd);
close(errfd);
free(outfilename);
free(errfilename);
}
- /* Let's split the command line into a null terminated array to be passed to the exec'd program
- But don't asprintf expanded_arguments if NULL as it would be converted
- to a '(null)' argument, while we want no arguments at all. */
+ /*
+ * Let's split the command line into a null terminated array to
+ * be passed to the exec'd program.
+ * But don't asprintf expanded_arguments if NULL as it would be
+ * converted to a '(null)' argument, while we want no arguments
+ * at all.
+ */
if (expanded_arguments != NULL) {
- if (asprintf(&exec_cmd, "%s %s", eo->program, expanded_arguments) < 0)
+ if (asprintf(&exec_cmd, "%s %s", eo->program, expanded_arguments) < 0) {
+ free(expanded_arguments);
return -1;
+ }
} else {
if (asprintf(&exec_cmd, "%s", eo->program) < 0)
return -1;
}
- /* Let's build an argv array to based on the program name and arguments */
+ /*
+ * Let's build an argv array to based on the program name and
+ * arguments
+ */
p = exec_cmd;
for (;;) {
p += strspn(p, " ");
(arguments_nb_items + 1) * sizeof(char *));
arguments_array[arguments_nb_items] = NULL;
- /* Replace the fio program from the child fork by the target program */
+ /*
+ * Replace the fio program from the child fork by the target
+ * program
+ */
execvp(arguments_array[0], arguments_array);
}
- // We never reach this place
+ /* We never reach this place */
+ /* Let's free the malloc'ed structures to make static checkers happy */
+ if (expanded_arguments)
+ free(expanded_arguments);
+ if (arguments_array)
+ free(arguments_array);
return 0;
}
if (eo->pid == -1) {
exec_background(o, eo);
} else {
- /* The program is running in background, let's check on a regular basis
- if the time is over and if we need to stop the tool */
+ /*
+ * The program is running in background, let's check on a
+ * regular basis
+ * if the time is over and if we need to stop the tool
+ */
usleep(o->thinktime);
if (utime_since_now(&td->start) > o->timeout) {
/* Let's stop the child */
kill(eo->pid, SIGTERM);
- /* Let's give grace_time (1 sec by default) to the 3rd party tool to stop */
+ /*
+ * Let's give grace_time (1 sec by default) to the 3rd
+ * party tool to stop
+ */
sleep(eo->grace_time);
}
}
/* Saving the current thread state */
td_previous_state = td->runstate;
- /* Reporting that we are preparing the engine
+ /*
+ * Reporting that we are preparing the engine
* This is useful as the qsort() calibration takes time
* This prevents the job from starting before init is completed
*/
o->thinktime_blocks = 1;
o->thinktime_blocks_type = THINKTIME_BLOCKS_TYPE_COMPLETE;
o->thinktime_spin = 0;
- o->thinktime = 50000; /* 50ms pause when waiting for the program to complete */
+ /* 50ms pause when waiting for the program to complete */
+ o->thinktime = 50000;
o->nr_files = o->open_files = 1;