Re: [Nagios-devel] Errors while testing Nagios

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

Re: [Nagios-devel] Errors while testing Nagios

Post by Guest »

On 10/25/2010 12:00 PM, Andreas Ericsson wrote:
> On 10/25/2010 11:00 AM, Ton Voon wrote:
>> I had an idea to try a different technique (include the
>> source, but override some specific functions), but I couldn't redefine
>> functions in C without the compiler complaining.
> There's no sane way to do that. The un-sane way is to sed out the funct=
ions
> you want to replace and then source the sed'ed source-file.

Well, if you want only *mild* insanity, look no further than at the
preprocessor. ;-)



> $ cat main.c
> main()
> {
> speak();
> }


> $ cat normal.c
> #include
>=20
> #ifndef DEBUGGABLE
> #define DEBUGGABLE(x) x
> #endif
>=20
> void DEBUGGABLE(speak) ()
> {
> printf("Business as usual\n");
> }


> $ cat debug.c
> #define DEBUGGABLE(x) debugged_ ## x
>=20
> #include "normal.c"
>=20
> void speak()
> {
> printf("This is the debug version\n");
> debugged_speak();
> }


> $ gcc -c -o normal.o normal.c
> $ gcc -o main main.c normal.o
> $ ./main
> Business as usual


> $ gcc -c -o debug.o debug.c
> $ gcc -o main main.c debug.o
> $ ./main
> This is the debug version
> Business as usual


> $ nm normal.o
> U puts
> 00000000 T speak

> $ nm debug.o
> 00000000 T debugged_speak
> U puts
> 00000014 T speak


Kind regards,
J. Bern
--=20
Jochen Bern, Systemingenieur --- LINworks GmbH
Postfach 100121, 64201 Darmstadt | Robert-Koch-Str. 9, 64331 Weiterstadt
PGP (1024D/4096g) FP =3D D18B 41B1 16C0 11BA 7F8C DCF7 E1D5 FAF4 444E 1C2=
7
Tel. +49 6151 9067-231, Zentr. -0, Fax -299 - Amtsg. Darmstadt HRB 85202
Unternehmenssitz Weiterstadt, Gesch=E4ftsf=FChrer Metin Dogan, Oliver Mic=
hel





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked