2 Commits 3e2cf01bdc ... d2ad46c380

Author SHA1 Message Date
  Michael Buesch d2ad46c380 razerd: Avoid fast infinite loop, if select failed. 1 month ago
  Grant Miller a2f9b86e11 Close client fd on disconnect 1 month ago
1 changed files with 11 additions and 1 deletions
  1. 11 1
      razerd/razerd.c

+ 11 - 1
razerd/razerd.c

@@ -702,6 +702,7 @@ static void disconnect_client(struct client **client_list, struct client *client
 		logdebug("Privileged client disconnected (fd=%d)\n", client->fd);
 	else
 		logdebug("Client disconnected (fd=%d)\n", client->fd);
+	close(client->fd);
 	free_client(client);
 }
 
@@ -2067,6 +2068,7 @@ static int mainloop(void)
 {
 	struct client *client;
 	int err;
+	int errcount = 0;
 	fd_set wait_fdset;
 
 	loginfo("Razer device service daemon\n");
@@ -2092,7 +2094,15 @@ static int mainloop(void)
 			FD_SET(client->fd, &wait_fdset);
 		for (client = privileged_clients; client; client = client->next)
 			FD_SET(client->fd, &wait_fdset);
-		select(FD_SETSIZE, &wait_fdset, NULL, NULL, NULL);
+		err = select(FD_SETSIZE, &wait_fdset, NULL, NULL, NULL);
+		if (err <= 0) { /* error or no fd ready. */
+			if (errcount >= 3)
+				razer_msleep(10);
+			else
+				errcount++;
+			continue;
+		}
+		errcount = 0;
 
 		check_control_socket(privsock, &privileged_clients);
 		check_privileged_connections();