client: exit if no jobs were sent and client is idle

If we invoke the client without arguments, it gets the probe
response and then waits for further response from the server.
But if no command line or job files were sent, the server
is idle. In that case, just quit.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/client.c b/client.c
index ace70d3..8c85d2b 100644
--- a/client.c
+++ b/client.c
@@ -48,6 +48,7 @@
 	unsigned int jobs;
 	int error;
 	int ipv6;
+	int sent_job;
 
 	struct flist_head eta_list;
 	struct client_eta *eta_in_flight;
@@ -481,6 +482,7 @@
 		return 1;
 	}
 
+	client->sent_job = 1;
 	ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0);
 	free(buf);
 	close(fd);
@@ -497,6 +499,8 @@
 
 		if (fio_client_send_ini(client, filename))
 			remove_client(client);
+
+		client->sent_job = 1;
 	}
 
 	return !nr_clients;
@@ -978,8 +982,6 @@
 
 int fio_handle_clients(void)
 {
-	struct fio_client *client;
-	struct flist_head *entry;
 	struct pollfd *pfds;
 	int i, ret = 0, retval = 0;
 
@@ -992,15 +994,27 @@
 	init_group_run_stat(&client_gs);
 
 	while (!exit_backend && nr_clients) {
+		struct flist_head *entry, *tmp;
+		struct fio_client *client;
+
 		i = 0;
-		flist_for_each(entry, &client_list) {
+		flist_for_each_safe(entry, tmp, &client_list) {
 			client = flist_entry(entry, struct fio_client, list);
 
+			if (!client->sent_job &&
+			    flist_empty(&client->cmd_list)) {
+				remove_client(client);
+				continue;
+			}
+
 			pfds[i].fd = client->fd;
 			pfds[i].events = POLLIN;
 			i++;
 		}
 
+		if (!nr_clients)
+			break;
+
 		assert(i == nr_clients);
 
 		do {