Blame SOURCES/fapolicyd-sighup.patch

abc874
diff -up ./src/daemon/fapolicyd.c.sighup ./src/daemon/fapolicyd.c
abc874
--- ./src/daemon/fapolicyd.c.sighup	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./src/daemon/fapolicyd.c	2022-08-04 11:07:10.245069443 +0200
abc874
@@ -527,6 +527,7 @@ int main(int argc, const char *argv[])
abc874
 	while (!stop) {
abc874
 		if (hup) {
abc874
 			hup = 0;
abc874
+			msg(LOG_INFO, "Got SIGHUP");
abc874
 			reconfigure();
abc874
 		}
abc874
 		rc = poll(pfd, 2, -1);
abc874
diff -up ./src/library/database.c.sighup ./src/library/database.c
abc874
--- ./src/library/database.c.sighup	2022-08-04 11:07:10.237069609 +0200
abc874
+++ ./src/library/database.c	2022-08-04 11:08:44.852057119 +0200
abc874
@@ -68,7 +68,7 @@ static int lib_symlink=0, lib64_symlink=
abc874
 static struct pollfd ffd[1] =  { {0, 0, 0} };
abc874
 static const char *fifo_path = "/run/fapolicyd/fapolicyd.fifo";
abc874
 static integrity_t integrity;
abc874
-static atomic_int db_operation;
abc874
+static atomic_int reload_db = 0;
abc874
 
abc874
 static pthread_t update_thread;
abc874
 static pthread_mutex_t update_lock;
abc874
@@ -1147,7 +1147,31 @@ static int handle_record(const char * bu
abc874
 
abc874
 void update_trust_database(void)
abc874
 {
abc874
-	db_operation = RELOAD_DB;
abc874
+	reload_db = 1;
abc874
+}
abc874
+
abc874
+static void do_reload_db(conf_t* config)
abc874
+{
abc874
+	msg(LOG_INFO,"It looks like there was an update of the system... Syncing DB.");
abc874
+
abc874
+	int rc;
abc874
+	backend_close();
abc874
+	backend_init(config);
abc874
+	backend_load(config);
abc874
+
abc874
+	if ((rc = update_database(config))) {
abc874
+		msg(LOG_ERR,
abc874
+			"Cannot update trust database!");
abc874
+		close(ffd[0].fd);
abc874
+		backend_close();
abc874
+		unlink_fifo();
abc874
+		exit(rc);
abc874
+	}
abc874
+
abc874
+	msg(LOG_INFO, "Updated");
abc874
+
abc874
+	// Conserve memory
abc874
+	backend_close();
abc874
 }
abc874
 
abc874
 static void *update_thread_main(void *arg)
abc874
@@ -1158,6 +1182,8 @@ static void *update_thread_main(void *ar
abc874
 	char err_buff[BUFFER_SIZE];
abc874
 	conf_t *config = (conf_t *)arg;
abc874
 
abc874
+	int do_operation = DB_NO_OP;;
abc874
+
abc874
 #ifdef DEBUG
abc874
 	msg(LOG_DEBUG, "Update thread main started");
abc874
 #endif
abc874
@@ -1182,6 +1208,12 @@ static void *update_thread_main(void *ar
abc874
 
abc874
 		rc = poll(ffd, 1, 1000);
abc874
 
abc874
+		// got SIGHUP
abc874
+		if (reload_db) {
abc874
+			reload_db = 0;
abc874
+			do_reload_db(config);
abc874
+		}
abc874
+
abc874
 #ifdef DEBUG
abc874
 		msg(LOG_DEBUG, "Update poll interrupted");
abc874
 #endif
abc874
@@ -1228,17 +1260,17 @@ static void *update_thread_main(void *ar
abc874
 							// assume file name
abc874
 							// operation = 0
abc874
 							if (buff[i] == '/') {
abc874
-								db_operation = ONE_FILE;
abc874
+								do_operation = ONE_FILE;
abc874
 								break;
abc874
 							}
abc874
 
abc874
 							if (buff[i] == '1') {
abc874
-								db_operation = RELOAD_DB;
abc874
+								do_operation = RELOAD_DB;
abc874
 								break;
abc874
 							}
abc874
 
abc874
 							if (buff[i] == '2') {
abc874
-								db_operation = FLUSH_CACHE;
abc874
+								do_operation = FLUSH_CACHE;
abc874
 								break;
abc874
 							}
abc874
 
abc874
@@ -1252,34 +1284,16 @@ static void *update_thread_main(void *ar
abc874
 						*end = '\n';
abc874
 
abc874
 						// got "1" -> reload db
abc874
-						if (db_operation == RELOAD_DB) {
abc874
-							db_operation = DB_NO_OP;
abc874
-							msg(LOG_INFO,
abc874
-								"It looks like there was an update of the system... Syncing DB.");
abc874
-
abc874
-							backend_close();
abc874
-							backend_init(config);
abc874
-							backend_load(config);
abc874
-
abc874
-							if ((rc = update_database(config))) {
abc874
-								msg(LOG_ERR,
abc874
-									"Cannot update trust database!");
abc874
-								close(ffd[0].fd);
abc874
-								backend_close();
abc874
-								unlink_fifo();
abc874
-								exit(rc);
abc874
-							}
abc874
-
abc874
-							msg(LOG_INFO, "Updated");
abc874
+						if (do_operation == RELOAD_DB) {
abc874
+							do_operation = DB_NO_OP;
abc874
+							do_reload_db(config);
abc874
 
abc874
-							// Conserve memory
abc874
-							backend_close();
abc874
 							// got "2" -> flush cache
abc874
-						} else if (db_operation == FLUSH_CACHE) {
abc874
-							db_operation = DB_NO_OP;
abc874
+						} else if (do_operation == FLUSH_CACHE) {
abc874
+							do_operation = DB_NO_OP;
abc874
 							needs_flush = true;
abc874
-						} else if (db_operation == ONE_FILE) {
abc874
-							db_operation = DB_NO_OP;
abc874
+						} else if (do_operation == ONE_FILE) {
abc874
+							do_operation = DB_NO_OP;
abc874
 							if (handle_record(buff))
abc874
 								continue;
abc874
 						}