Add support for compiling for ESX
[fio.git] / init.c
diff --git a/init.c b/init.c
index 8448586847c8db10a74143610a1c233d92b72278..d44eb5b1eaa2fb086afe25b3a6bda335320decf7 100644 (file)
--- a/init.c
+++ b/init.c
@@ -238,15 +238,19 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
 
 void free_threads_shm(void)
 {
-       struct shmid_ds sbuf;
-
        if (threads) {
                void *tp = threads;
+#ifndef CONFIG_NO_SHM
+               struct shmid_ds sbuf;
 
                threads = NULL;
                shmdt(tp);
                shmctl(shm_id, IPC_RMID, &sbuf);
                shm_id = -1;
+#else
+               threads = NULL;
+               free(tp);
+#endif
        }
 }
 
@@ -287,6 +291,7 @@ static int setup_thread_area(void)
                size += file_hash_size;
                size += sizeof(unsigned int);
 
+#ifndef CONFIG_NO_SHM
                shm_id = shmget(0, size, IPC_CREAT | 0600);
                if (shm_id != -1)
                        break;
@@ -294,10 +299,16 @@ static int setup_thread_area(void)
                        perror("shmget");
                        break;
                }
+#else
+               threads = malloc(size);
+               if (threads)
+                       break;
+#endif
 
                max_jobs >>= 1;
        } while (max_jobs);
 
+#ifndef CONFIG_NO_SHM
        if (shm_id == -1)
                return 1;
 
@@ -306,6 +317,7 @@ static int setup_thread_area(void)
                perror("shmat");
                return 1;
        }
+#endif
 
        memset(threads, 0, max_jobs * sizeof(struct thread_data));
        hash = (void *) threads + max_jobs * sizeof(struct thread_data);
@@ -1739,7 +1751,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+");
@@ -1884,8 +1896,14 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                        continue;
 
                                td = get_new_job(global, &def_thread, 1);
-                               if (!td || ioengine_load(td))
-                                       goto out_free;
+                               if (!td || ioengine_load(td)) {
+                                       if (td) {
+                                               put_job(td);
+                                               td = NULL;
+                                       }
+                                       do_exit++;
+                                       break;
+                               }
                                fio_options_set_ioengine_opts(l_opts, td);
                        }
 
@@ -1906,8 +1924,14 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
 
                        if (!ret && !strcmp(opt, "ioengine")) {
                                free_ioengine(td);
-                               if (ioengine_load(td))
-                                       goto out_free;
+                               if (ioengine_load(td)) {
+                                       if (td) {
+                                               put_job(td);
+                                               td = NULL;
+                                       }
+                                       do_exit++;
+                                       break;
+                               }
                                fio_options_set_ioengine_opts(l_opts, td);
                        }
                        break;
@@ -1920,7 +1944,6 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                break;
 
                        ret = fio_cmd_ioengine_option_parse(td, opt, val);
-                       did_arg = 1;
                        break;
                }
                case 'w':
@@ -1936,6 +1959,7 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                        break;
                case 'S':
                        did_arg = 1;
+#ifndef CONFIG_NO_SHM
                        if (nr_clients) {
                                log_err("fio: can't be both client and server\n");
                                do_exit++;
@@ -1946,6 +1970,11 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                fio_server_set_arg(optarg);
                        is_backend = 1;
                        backend = 1;
+#else
+                       log_err("fio: client/server requires SHM support\n");
+                       do_exit++;
+                       exit_val = 1;
+#endif
                        break;
                case 'D':
                        if (pid_file)