From 321d38db8e8f24f8680af408a81d23f9e987d288 Mon Sep 17 00:00:00 2001 From: mhorky Date: Mon, 15 Jan 2024 16:16:04 +0100 Subject: [PATCH] Remove automatic registration delay for rhsmcertd * Card ID: CCT-67 The delay was introduced in early versions of the code when Python was not reliable for long-running tasks. Since we want to make automatic registration in both standard and anonymous flow to be as fast as possible, this delay is removed. This splay period is now performed by the Python code in case the we have obtained the anonymous entitlement certificates; before we ask for the identity certificate. --- src/daemons/rhsmcertd.c | 63 ++++------------------------------------- 1 file changed, 6 insertions(+), 57 deletions(-) diff --git a/src/daemons/rhsmcertd.c b/src/daemons/rhsmcertd.c index 29790747ac..b7568af375 100644 --- a/src/daemons/rhsmcertd.c +++ b/src/daemons/rhsmcertd.c @@ -67,8 +67,6 @@ typedef enum { #define N_(x) x #define CONFIG_KEY_NOT_FOUND (0) -#define MAX_AUTO_REGISTER_ATTEMPTS 3 - #if defined(__linux) # if LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0) # ifdef HAVE_LINUX_GETRANDOM @@ -93,7 +91,6 @@ static gint arg_reg_interval_minutes = -1; static gboolean arg_no_splay = FALSE; static gboolean arg_auto_registration = FALSE; static int fd_lock = -1; -static int auto_register_attempt = 0; struct CertCheckData { int interval_seconds; @@ -419,14 +416,8 @@ auto_register(gpointer data) exit (EXIT_FAILURE); } if (pid == 0) { - if (auto_register_attempt < MAX_AUTO_REGISTER_ATTEMPTS) { - debug ("(Auto-registration) executing: %s --auto-register", WORKER); - execl (WORKER, WORKER_NAME, "--auto-register", NULL); - } else { - warn ("(Auto-registration) the number of attempts reached the max limit: %d", MAX_AUTO_REGISTER_ATTEMPTS); - // Return False to not repeat this again - return false; - } + debug ("(Auto-registration) executing: %s --auto-register", WORKER); + execl (WORKER, WORKER_NAME, "--auto-register", NULL); } waitpid (pid, &status, 0); @@ -434,19 +425,10 @@ auto_register(gpointer data) if (status == 0) { info ("(Auto-registration) performed successfully."); - // No need to repeat this action again return false; } else { - auto_register_attempt++; - if (auto_register_attempt < MAX_AUTO_REGISTER_ATTEMPTS) { - warn ("(Auto-registration) failed (%d), retry will occur on next run.", status); - } else { - warn ("(Auto-registration) failed (%d), the number of attempts reached the max limit: %d", - status, MAX_AUTO_REGISTER_ATTEMPTS); - // Return False to not repeat this again - return false; - } - return true; + warn ("(Auto-registration) failed (%d)", status); + return false; } } @@ -488,30 +470,6 @@ cert_check (gboolean heal) return TRUE; } - -static gboolean -initial_auto_register (gpointer data) -{ - struct CertCheckData *cert_data = data; - gboolean repeat_attempts; - - repeat_attempts = auto_register(cert_data); - - // When first attempt was not successful, then try to do other - // auto-registration attempts - if (repeat_attempts == true) { - // Add the timeout to begin waiting on interval but offset by the initial - // delay. - g_timeout_add(cert_data->interval_seconds * 1000, - (GSourceFunc) auto_register, cert_data); - // Update timestamp - log_update(cert_data->interval_seconds, cert_data->next_update_file); - } - // Return false so that the timer does - // not run this again. - return false; -} - static gboolean initial_cert_check (gpointer data) { @@ -915,13 +873,11 @@ main (int argc, char *argv[]) // NOTE: We put the initial checks on a timer so that in the case of systemd, // we can ensure that the network interfaces are all up before the initial // checks are done. - int auto_reg_initial_delay = 0; int auto_attach_initial_delay = 0; int cert_check_initial_delay = 0; if (run_now) { info ("Initial checks will be run now!"); } else { - int auto_reg_offset = 0; int auto_attach_offset = 0; int cert_check_offset = 0; if (splay_enabled == true) { @@ -960,16 +916,10 @@ main (int argc, char *argv[]) } #endif srand((unsigned int) seed); - auto_reg_offset = gen_random(auto_reg_interval_seconds); auto_attach_offset = gen_random(heal_interval_seconds); cert_check_offset = gen_random(cert_interval_seconds); } - if (auto_reg_enabled) { - auto_reg_initial_delay = INITIAL_DELAY_SECONDS + auto_reg_offset; - info ("Waiting %.1f minutes plus %d splay seconds [%d seconds total] before performing first auto-register", - INITIAL_DELAY_SECONDS / 60.0, auto_reg_offset, auto_reg_initial_delay); - } auto_attach_initial_delay = INITIAL_DELAY_SECONDS + auto_attach_offset; info ("Waiting %.1f minutes plus %d splay seconds [%d seconds total] before performing first auto-attach.", INITIAL_DELAY_SECONDS / 60.0, auto_attach_offset, auto_attach_initial_delay); @@ -994,8 +944,7 @@ main (int argc, char *argv[]) auto_attach_data.next_update_file = NEXT_AUTO_ATTACH_UPDATE_FILE; if (auto_reg_enabled) { - g_timeout_add(auto_reg_initial_delay * 1000, - (GSourceFunc) initial_auto_register, (gpointer) &auto_register_data); + auto_register((gpointer) &auto_register_data); } g_timeout_add (cert_check_initial_delay * 1000, (GSourceFunc) initial_cert_check, (gpointer) &cert_check_data); @@ -1006,7 +955,7 @@ main (int argc, char *argv[]) // time. This works for most users, since the cert_interval aligns with // runs of heal_interval (i.e., heal_interval % cert_interval = 0) if (auto_reg_enabled) { - log_update (auto_reg_initial_delay, NEXT_AUTO_REGISTER_UPDATE_FILE); + log_update (0, NEXT_AUTO_REGISTER_UPDATE_FILE); } log_update (cert_check_initial_delay, NEXT_CERT_UPDATE_FILE); log_update (auto_attach_initial_delay, NEXT_AUTO_ATTACH_UPDATE_FILE);