Blame SOURCES/fapolicyd-sighup.patch

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