client/rhel/rhnsd/rhnsd.c | 118 +++++++++++++++++++++++++++++++++++++++++--
client/rhel/rhnsd/rhnsd.init | 2
2 files changed, 115 insertions(+), 5 deletions(-)
New commits:
commit 941dce7fb5b2c544e2a93de9d63e207038d20f8f
Author: Justin Sherrill <jsherril(a)redhat.com>
Date: Mon Nov 30 17:35:02 2009 -0500
502234 - fixing issue where the rhnsd init script would fail to reload the
configuration, a forward port of a patch from rhel 4
diff --git a/client/rhel/rhnsd/rhnsd.c b/client/rhel/rhnsd/rhnsd.c
index d41f7a0..c2d0583 100644
--- a/client/rhel/rhnsd/rhnsd.c
+++ b/client/rhel/rhnsd/rhnsd.c
@@ -26,10 +26,12 @@
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
+#include <limits.h>
#include <regex.h>
#define RHN_CHECK "/usr/sbin/rhn_check" /* XXX: fix me */
#define RHN_UP2DATE "/etc/sysconfig/rhn/up2date"
+#define RHNSD_CONFIG_FILE "/etc/sysconfig/rhn/rhnsd"
#define MAX_PATH_SIZE 512
@@ -64,6 +66,16 @@ static const char doc[] = N_("Red Hat Network Services
Daemon");
#define PROGRAM "rhnsd"
#define VERSION "1.0.2"
+/* Configuration parameters */
+static const char* param_name_interval = "interval";
+
+typedef struct _config_param
+{
+ char *key;
+ char *data;
+} config_param;
+
+
/* Prototype for option handler. */
static error_t parse_opt __P ((int key, char *arg, struct argp_state *state));
@@ -76,10 +88,14 @@ static struct argp argp = {
static void termination_handler (int);
static int rhn_init(void);
static int rhn_do_action(void);
+static void read_configuration();
+static void setInterval(char *arg);
+
static int parse_systemid_path(char* systemid_path, int systemid_path_length);
static void set_signal_handlers (void);
static void unset_signal_handlers (void);
+static void SIGHUP_handler(int);
/* Arguments */
#define MIN_INTERVAL 1 /* minimal sane interval; RHN will blacklist
@@ -109,6 +125,11 @@ int main (int argc, char **argv)
bindtextdomain(PROGRAM, "/usr/share/locale");
textdomain(PROGRAM);
+ /* Read default configuration file and allow command line
+ * options to override initial configuration file entries
+ **/
+ read_configuration();
+
/* Parse and process arguments. */
argp_parse(&argp, argc, argv, 0, &remaining, NULL);
@@ -191,6 +212,8 @@ int main (int argc, char **argv)
}
}
+
+
/* Handle program arguments. */
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
@@ -203,11 +226,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
case 'i':
/* --interval */
- interval = atoi(arg);
- if (interval < MIN_INTERVAL) {
- interval = MIN_INTERVAL;
- syslog(LOG_WARNING, "you cannot specify a minimum interval less than %d, interval
adjusted.", MIN_INTERVAL);
- }
+ setInterval(arg);
break;
case 'v':
@@ -293,6 +312,7 @@ set_signal_handlers (void)
signal (SIGQUIT, termination_handler);
signal (SIGTERM, termination_handler);
signal (SIGPIPE, SIG_IGN);
+ signal (SIGHUP, SIGHUP_handler);
}
static void
@@ -302,6 +322,7 @@ unset_signal_handlers (void)
signal (SIGQUIT, SIG_DFL);
signal (SIGTERM, SIG_DFL);
signal (SIGPIPE, SIG_DFL);
+ signal (SIGHUP, SIG_DFL);
}
/* XXX: fix me up */
@@ -472,6 +493,93 @@ static int rhn_do_action(void)
return 0;
}
+
+
+static void setInterval(char *arg)
+{
+ interval = atoi(arg);
+ if (interval < MIN_INTERVAL) {
+ interval = MIN_INTERVAL;
+ syslog(LOG_WARNING, "you cannot specify a minimum interval less than %d,
interval adjusted.", MIN_INTERVAL);
+ }
+ syslog(LOG_NOTICE, "%s running with check_in interval set to %d seconds.",
doc, interval);
+}
+
+static int skipLine(char *line)
+{
+ if (line == NULL) {
+ return 1;
+ }
+ // Detect a Comment
+ if (line[0] == '#') {
+ return 1;
+ }
+ return 0;
+}
+
+/*
+ * Returns a key/value pair of a configuration item, or NULL.
+ * Expected format of config entries is:
+ * KEY=VALUE
+ */
+static config_param *parseLine(char *line)
+{
+ if (skipLine(line)) {
+ return NULL;
+ }
+
+ config_param *cp = malloc(sizeof(config_param));
+ char delim[] = "=";
+ char *dup = strdup(line);
+ cp->key = strsep(&dup, delim);
+ if (cp->key == NULL) {
+ free(dup);
+ return NULL;
+ }
+ int index;
+ // Cast all keys to lowercase
+ for (index = 0; index < strlen(cp->key); index++) {
+ cp->key[index] = tolower(cp->key[index]);
+ }
+
+ cp->data = strsep(&dup, delim);
+ if (cp->data == NULL) {
+ free(dup);
+ return NULL;
+ }
+ free(dup);
+ return cp;
+}
+
+static void read_configuration()
+{
+ FILE *config = fopen(RHNSD_CONFIG_FILE, "r");
+ if (config == NULL) {
+ syslog(LOG_ERR, "Error reading configuraton file, %s",
RHNSD_CONFIG_FILE);
+ syslog(LOG_ERR, "%s", strerror(errno));
+ return;
+ }
+ char line[LINE_MAX];
+ while (fgets(line, LINE_MAX, config) != NULL) {
+ config_param *cp = parseLine(line);
+ if (cp == NULL) {
+ continue;
+ }
+ if (strncmp(param_name_interval, cp->key, strlen(param_name_interval)) == 0)
{
+ setInterval(cp->data);
+ }
+ free(cp);
+ }
+ fclose(config);
+}
+
+static void SIGHUP_handler(int signum)
+{
+ read_configuration();
+}
+
+
+
#define MAX_CONFIG_LINE_SIZE (2*MAX_PATH_SIZE)
#define SYSTEMID_NMATCH 2
/* parse systemIdPath from the up2date configuration file */
diff --git a/client/rhel/rhnsd/rhnsd.init b/client/rhel/rhnsd/rhnsd.init
index 19dbc7d..31e6d3f 100644
--- a/client/rhel/rhnsd/rhnsd.init
+++ b/client/rhel/rhnsd/rhnsd.init
@@ -91,8 +91,10 @@ case "$1" in
fi
;;
reload)
+ echo -n $"Reloading Red Hat Network Daemon: "
killproc rhnsd -HUP
RETVAL=$?
+ echo
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"