Blame SOURCES/fapolicyd-sighup.patch

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