Fio 1.99.5
[fio.git] / server.c
index 339bb66a6f3b980e6a031434e23a5344f544b9c5..dcce37eea822be362221aa9867733b638c446706 100644 (file)
--- a/server.c
+++ b/server.c
@@ -77,6 +77,8 @@ int fio_send_data(int sk, const void *p, unsigned int len)
                        break;
                else if (errno == EAGAIN || errno == EINTR)
                        continue;
+               else
+                       break;
        } while (!exit_backend);
 
        if (!len)
@@ -100,6 +102,8 @@ int fio_recv_data(int sk, void *p, unsigned int len)
                        break;
                else if (errno == EAGAIN || errno == EINTR)
                        continue;
+               else
+                       break;
        } while (!exit_backend);
 
        if (!len)
@@ -295,7 +299,7 @@ int fio_net_send_simple_cmd(int sk, uint16_t opcode, uint64_t tag,
 
        cmd = malloc(sizeof(*cmd));
 
-       fio_init_net_cmd(&cmd->cmd, opcode, NULL, 0, (uint64_t) cmd);
+       fio_init_net_cmd(&cmd->cmd, opcode, NULL, 0, (uintptr_t) cmd);
        fio_net_cmd_crc(&cmd->cmd);
 
        INIT_FLIST_HEAD(&cmd->list);
@@ -394,6 +398,8 @@ static int handle_probe_cmd(struct fio_net_cmd *cmd)
        probe.os        = FIO_OS;
        probe.arch      = FIO_ARCH;
 
+       probe.bpp       = sizeof(void *);
+
        return fio_net_send_cmd(server_fd, FIO_NET_CMD_PROBE, &probe, sizeof(probe), cmd->tag);
 }
 
@@ -403,7 +409,10 @@ static int handle_send_eta_cmd(struct fio_net_cmd *cmd)
        size_t size;
        int i;
 
-       size = sizeof(*je) + thread_number * sizeof(char);
+       if (!thread_number)
+               return 0;
+
+       size = sizeof(*je) + thread_number * sizeof(char) + 1;
        je = malloc(size);
        memset(je, 0, size);
 
@@ -662,9 +671,10 @@ void fio_server_send_ts(struct thread_stat *ts, struct group_run_stats *rs)
        p.ts.clat_percentiles   = cpu_to_le64(ts->clat_percentiles);
 
        for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
-               fio_fp64_t *fp = &p.ts.percentile_list[i];
+               fio_fp64_t *src = &ts->percentile_list[i];
+               fio_fp64_t *dst = &p.ts.percentile_list[i];
 
-               fp->u.i = __cpu_to_le64(fio_double_to_uint64(fp->u.f));
+               dst->u.i = __cpu_to_le64(fio_double_to_uint64(src->u.f));
        }
 
        for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
@@ -965,25 +975,14 @@ static int fio_server(void)
        return ret;
 }
 
-static void sig_int(int sig)
-{
-       fio_terminate_threads(TERMINATE_ALL);
-       exit_backend = 1;
-}
-
-static void server_signal_handler(void)
+void fio_server_got_signal(int signal)
 {
-       struct sigaction act;
-
-       memset(&act, 0, sizeof(act));
-       act.sa_handler = sig_int;
-       act.sa_flags = SA_RESTART;
-       sigaction(SIGINT, &act, NULL);
-
-       memset(&act, 0, sizeof(act));
-       act.sa_handler = sig_int;
-       act.sa_flags = SA_RESTART;
-       sigaction(SIGTERM, &act, NULL);
+       if (signal == SIGPIPE)
+               server_fd = -1;
+       else {
+               log_info("\nfio: terminating on signal %d\n", signal);
+               exit_backend = 1;
+       }
 }
 
 static int check_existing_pidfile(const char *pidfile)
@@ -1008,7 +1007,7 @@ static int check_existing_pidfile(const char *pidfile)
 
        pid = atoi(buf);
        if (kill(pid, SIGCONT) < 0)
-               return 0;
+               return errno != ESRCH;
 
        return 1;
 }
@@ -1036,8 +1035,6 @@ int fio_start_server(char *pidfile)
        pid_t pid;
        int ret;
 
-       server_signal_handler();
-
        if (!pidfile)
                return fio_server();