[PATCH] fix option_index

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[PATCH] fix option_index

Post by Guest »

------=_20130911140732_91621
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Ok, i got an initial partial start, and i was interested if you feel i wa=
s
going in the right direction:

i noticed that there were external symbols on both the primary main confi=
g
file and the config directory. i kept that, so that it wouldn't break
other stuff.

the plan is to use config_files instead of config_file to read the object=
s
file below that.

then also the real part needs to read the config_files and also, i'll nee=
d
to review what happens when someone reloads the nagios daemon.

PS: i added a patch to presumably fix the optind issue
------=_20130911140732_91621
Content-Type: text/x-patch; name="start_multiple_config_files.patch"
Content-Disposition: attachment; filename="start_multiple_config_files.patch"
Content-Transfer-Encoding: quoted-printable

diff --git a/base/nagios.c b/base/nagios.c
index 4f78ffe..453442e 100644
--- a/base/nagios.c
+++ b/base/nagios.c
@@ -348,7 +348,7 @@ int main(int argc, char **argv) {
/* if there are no command line options (or if we encountered an =
error), print usage */
if(error =3D=3D TRUE || display_help =3D=3D TRUE) {

- printf("Usage: %s [options] \n", argv[0=
]);
+ printf("Usage: %s [options] [] ...\n", argv[0]);
printf("\n");
printf("Options:\n");
printf("\n");
@@ -370,17 +370,24 @@ int main(int argc, char **argv) {
exit(ERROR);
}

-
- /*
- * config file is last argument specified.
- * Make sure it uses an absolute path
- */
- config_file =3D nspath_absolute(argv[option_index], NULL);
- if(config_file =3D=3D NULL) {
- printf("Error allocating memory.\n");
- exit(ERROR);
+ /* get all config files */
+ config_files =3D malloc(sizeof(*config_files) * (argc - option_in=
dex));
+ i =3D 0;
+ while (option_index + i < argc) {
+ /* Make sure it uses an absolute path */
+ config_files =3D nspath_absolute(argv[option_index + i=
], NULL);
+ if(config_file =3D=3D NULL) {
+ printf("Error allocating memory.\n");
+ exit(ERROR);
+ }
+ i++;
}
+ config_files =3D NULL;
+
+ /* The main config file is first of the config files. */
+ config_file =3D config_files[0];

+ /* Also initialize the main config directory */
config_file_dir =3D nspath_absolute_dirname(config_file, NULL);

/*
@@ -417,6 +424,21 @@ int main(int argc, char **argv) {
if(verify_config)
printf(" Read main config file okay...\n");

+ /* read extra config files */
+ i =3D 1;
+
+ if(verify_config && config_files !=3D NULL)
+ printf(" Reading extra config files...\n");
+
+ while (config_files !=3D NULL) {
+ result =3D read_main_config_file(config_files)=
;
+ if(result !=3D OK) {
+ printf(" Error processing extra config =
file!\n\n");
+ exit(EXIT_FAILURE);
+ }
+ i++;
+ }
+
/* drop privileges */
if((result =3D drop_privileges(nagios_user, nagios_group)=
) =3D=3D ERROR) {
printf(" Failed to drop privileges. Aborting."=
);
@@ -520,6 +542,7 @@ int main(int argc, char **argv) {
/* make valgrind shut up about still reachable memory */
neb_free_module_list();
free(config_file_dir);
+ free(config_files);
free(config_file);

exit(result);
diff --git a/include/nagios.h b/include/nagios.h
index 62b33cb..fa503db 100644
--- a/include/nagios.h
+++ b/include/nagios.h
@@ -37,6 +37,7 @@
*/
extern char *nagios_binary_path;
extern char *config_file;
+extern char **config_files;
extern char *command_file;
extern char *temp_file;
extern char *temp_path;
------=_20130911140732_91621
Content-Type: text/x-patch; name="fix-option_

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: alien@mageia.org
Locked