Blob Blame History Raw
From 4342acd8d7862e862e0b661135b10671ffeac119 Mon Sep 17 00:00:00 2001
From: Kairui Song <kasong@redhat.com>
Date: Thu, 22 Jul 2021 03:05:59 +0800
Subject: [PATCH] Disable the communication socket when UI is disabled

The communication socket is added to support the UI, when UI is not
built, also disable the socket.

Signed-off-by: Kairui Song <kasong@redhat.com>
---
 configure.ac | 11 +++++++----
 cputree.c    |  4 ++++
 irqbalance.c | 23 ++++++++++++++++-------
 3 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/configure.ac b/configure.ac
index 92a5113..c45b9ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,10 +41,13 @@ AC_C_INLINE
 AM_PROG_CC_C_O
 
 AC_ARG_WITH([irqbalance-ui],
-	[AC_HELP_STRING([--without-irqbalance-ui],
-			[Dont build the irqbalance ui component])],
-			[with_irqbalanceui=$withval], [with_irqbalanceui=yes])
-
+  [AS_HELP_STRING([--without-irqbalance-ui],
+    [Dont build the irqbalance ui component])],
+    [with_irqbalanceui=$withval], [with_irqbalanceui=yes])
+AS_IF(
+  [test "x$with_irqbalanceui" = "xyes"], [
+    AC_DEFINE([HAVE_IRQBALANCEUI], 1, [Build irqbalance ui component.])
+])
 AM_CONDITIONAL([IRQBALANCEUI], [test x$with_irqbalanceui = xyes])
 
 AC_ARG_WITH([systemd],
diff --git a/cputree.c b/cputree.c
index e4695f2..b716a8f 100644
--- a/cputree.c
+++ b/cputree.c
@@ -39,7 +39,9 @@
 
 #include "irqbalance.h"
 
+#ifdef HAVE_IRQBALANCEUI
 extern char *banned_cpumask_from_ui;
+#endif
 extern char *cpu_ban_string;
 
 GList *cpus;
@@ -113,12 +115,14 @@ static void setup_banned_cpus(void)
 	cpumask_t isolated_cpus;
 	char *env = NULL;
 
+#ifdef HAVE_IRQBALANCEUI
 	/* A manually specified cpumask overrides auto-detection. */
 	if (cpu_ban_string != NULL && banned_cpumask_from_ui != NULL) {
 		cpulist_parse(banned_cpumask_from_ui,
 			strlen(banned_cpumask_from_ui), banned_cpus);
 		goto out;
 	}
+#endif
 
 	/*
 	 * Notes:
diff --git a/irqbalance.c b/irqbalance.c
index 3f94847..07a245f 100644
--- a/irqbalance.c
+++ b/irqbalance.c
@@ -31,22 +31,21 @@
 #include <time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/un.h>
 #include <fcntl.h>
 #include <inttypes.h>
 #ifdef HAVE_GETOPT_LONG 
 #include <getopt.h>
 #endif
-
 #ifdef HAVE_LIBCAP_NG
 #include <cap-ng.h>
 #endif
+#ifdef HAVE_IRQBALANCEUI
+#include <sys/un.h>
+#include <sys/socket.h>
+#endif
 #include "irqbalance.h"
 
 volatile int keep_going = 1;
-int socket_fd;
-char socket_name[64];
 int one_shot_mode;
 int debug_mode;
 int foreground_mode;
@@ -67,9 +66,14 @@ int last_interval;
 GMainLoop *main_loop;
 
 char *cpu_ban_string = NULL;
-char *banned_cpumask_from_ui = NULL;
 unsigned long migrate_ratio = 0;
 
+#ifdef HAVE_IRQBALANCEUI
+int socket_fd;
+char socket_name[64];
+char *banned_cpumask_from_ui = NULL;
+#endif
+
 static void sleep_approx(int seconds)
 {
 	struct timespec ts;
@@ -405,6 +409,7 @@ void get_object_stat(struct topo_obj *object, void *data)
 	}
 }
 
+#ifdef HAVE_IRQBALANCEUI
 gboolean sock_handle(gint fd, GIOCondition condition, gpointer user_data __attribute__((unused)))
 {
 	char buff[500];
@@ -585,6 +590,7 @@ int init_socket()
 	g_unix_fd_add(socket_fd, G_IO_IN, sock_handle, NULL);
 	return 0;
 }
+#endif
 
 int main(int argc, char** argv)
 {
@@ -688,10 +694,12 @@ int main(int argc, char** argv)
 	parse_proc_interrupts();
 	parse_proc_stat();
 
+#ifdef HAVE_IRQBALANCEUI
 	if (init_socket()) {
 		ret = EXIT_FAILURE;
 		goto out;
 	}
+#endif
 	main_loop = g_main_loop_new(NULL, FALSE);
 	last_interval = sleep_interval;
 	g_timeout_add_seconds(sleep_interval, scan, NULL);
@@ -707,11 +715,12 @@ out:
 	/* Remove pidfile */
 	if (!foreground_mode && pidfile)
 		unlink(pidfile);
+#ifdef HAVE_IRQBALANCEUI
 	/* Remove socket */
 	if (socket_fd > 0)
 		close(socket_fd);
 	if (socket_name[0])
 		unlink(socket_name);
-
+#endif
 	return ret;
 }
-- 
2.31.1