~ubuntu-branches/ubuntu/karmic/rsyslog/karmic-200908151517

« back to all changes in this revision

Viewing changes to plugins/imklog/ksym.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-07-23 02:22:32 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080723022232-496osxty0v9vvw9g
Tags: 3.18.1-1
* New upstream release. Closes: #490445
  - List Debian in doc/rsyslog_packages.html. Closes: #488870
  - Fix compilation of imklog module on GNU/kFreeBSD. Closes: #491193
* debian/rsyslog-doc.install
  - Install the example config file. Closes: #488860
* debian/rules
  - Enable mail output plugin.
  - Make sure all directories are created by calling dh_installdirs for both
    binary-arch and binary-indep. Closes: #491459
* debian/rsyslog.install
  - Install mail output plugin (ommail.so).
* debian/control
  - Add Suggests www-browser to rsyslog-doc as the package contains mostly
    html documents.
  - Update feature list.
  - Adjust priorities, set rsyslog priority to important.

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
 
139
139
 
140
140
/* Function prototypes. */
141
 
static char * FindSymbolFile(void);
 
141
static char *FindSymbolFile(void);
142
142
static int AddSymbol(unsigned long, char*);
143
143
static void FreeSymbols(void);
144
144
static int CheckVersion(char *);
173
173
 
174
174
        auto FILE *sym_file;
175
175
 
 
176
        BEGINfunc
176
177
 
177
178
        /* Check and make sure that we are starting with a clean slate. */
178
179
        if ( num_syms > 0 )
179
180
                FreeSymbols();
180
181
 
181
182
 
182
 
        /*
183
 
         * Search for and open the file containing the kernel symbols.
184
 
         */
185
 
        if ( mapfile != (char *) 0 ) {
186
 
                if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 )
 
183
        /* Search for and open the file containing the kernel symbols. */
 
184
        if ( mapfile != NULL ) {
 
185
                if ( (sym_file = fopen(mapfile, "r")) == NULL )
187
186
                {
188
 
                        Syslog(LOG_WARNING, "Cannot open map file: %s.", mapfile);
 
187
                        imklogLogIntMsg(LOG_WARNING, "Cannot open map file: %s.", mapfile);
189
188
                        return(0);
190
189
                }
191
190
        } else {
192
 
                if ( (mapfile = FindSymbolFile()) == (char *) 0 ) {
193
 
                        Syslog(LOG_WARNING, "Cannot find map file.");
 
191
                if ( (mapfile = FindSymbolFile()) == NULL ) {
 
192
                        imklogLogIntMsg(LOG_WARNING, "Cannot find map file.");
194
193
                        dbgprintf("Cannot find map file.\n");
195
194
                        return(0);
196
195
                }
197
196
                
198
 
                if ( (sym_file = fopen(mapfile, "r")) == (FILE *) 0 ) {
199
 
                        Syslog(LOG_WARNING, "Cannot open map file.");
 
197
                if ( (sym_file = fopen(mapfile, "r")) == NULL ) {
 
198
                        imklogLogIntMsg(LOG_WARNING, "Cannot open map file.");
200
199
                        dbgprintf("Cannot open map file.\n");
201
200
                        return(0);
202
201
                }
203
202
        }
204
203
        
205
204
 
206
 
        /*
207
 
         * Read the kernel symbol table file and add entries for each
 
205
        /* Read the kernel symbol table file and add entries for each
208
206
         * line.  I suspect that the use of fscanf is not really in vogue
209
207
         * but it was quick and dirty and IMHO suitable for fixed format
210
208
         * data such as this.  If anybody doesn't agree with this please
213
211
         */
214
212
        while ( !feof(sym_file) ) {
215
213
                if ( fscanf(sym_file, "%lx %c %s\n", &address, &type, sym) != 3 ) {
216
 
                        Syslog(LOG_ERR, "Error in symbol table input (#1).");
 
214
                        imklogLogIntMsg(LOG_ERR, "Error in symbol table input (#1).");
217
215
                        fclose(sym_file);
218
216
                        return(0);
219
217
                }
221
219
                        dbgprintf("Address: %lx, Type: %c, Symbol: %s\n", address, type, sym);
222
220
 
223
221
                if ( AddSymbol(address, sym) == 0 ) {
224
 
                        Syslog(LOG_ERR, "Error adding symbol - %s.", sym);
 
222
                        imklogLogIntMsg(LOG_ERR, "Error adding symbol - %s.", sym);
225
223
                        fclose(sym_file);
226
224
                        return(0);
227
225
                }
231
229
        }
232
230
        
233
231
 
234
 
        Syslog(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
 
232
        imklogLogIntMsg(LOG_INFO, "Loaded %d symbols from %s.", num_syms, mapfile);
235
233
        switch(version) {
236
234
            case -1:
237
 
                Syslog(LOG_WARNING, "Symbols do not match kernel version.");
 
235
                imklogLogIntMsg(LOG_WARNING, "Symbols do not match kernel version.");
238
236
                num_syms = 0;
239
237
                break;
240
238
 
241
239
            case 0:
242
 
                Syslog(LOG_WARNING, "Cannot verify that symbols match kernel version.");
 
240
                imklogLogIntMsg(LOG_WARNING, "Cannot verify that symbols match kernel version.");
243
241
                break;
244
242
                
245
243
            case 1:
246
 
                Syslog(LOG_INFO, "Symbols match kernel version %s.", vstring);
 
244
                imklogLogIntMsg(LOG_INFO, "Symbols match kernel version %s.", vstring);
247
245
                break;
248
246
        }
249
247
                
250
248
        fclose(sym_file);
 
249
        ENDfunc
251
250
        return(1);
252
251
}
253
252
 
292
291
 **************************************************************************/
293
292
static char *FindSymbolFile(void)
294
293
{
295
 
        auto char       *file = (char *) 0,
 
294
        auto char       *file = NULL,
296
295
                        **mf = system_maps;
297
 
 
298
296
        auto struct utsname utsname;
299
 
        static char symfile[100];
300
 
 
301
 
        auto FILE *sym_file = (FILE *) 0;
302
 
 
303
 
        if ( uname(&utsname) < 0 ) {
304
 
                Syslog(LOG_ERR, "Cannot get kernel version information.");
 
297
        static char mysymfile[100];
 
298
        auto FILE *sym_file = NULL;
 
299
        BEGINfunc
 
300
 
 
301
        if(uname(&utsname) < 0) {
 
302
                imklogLogIntMsg(LOG_ERR, "Cannot get kernel version information.");
305
303
                return(0);
306
304
        }
307
305
 
308
306
        dbgprintf("Searching for symbol map.\n");
309
307
        
310
 
        for(mf = system_maps; *mf != (char *) 0 && file == (char *) 0; ++mf) {
311
 
 
312
 
                snprintf(symfile, sizeof(symfile), "%s-%s", *mf, utsname.release);
313
 
                dbgprintf("Trying %s.\n", symfile);
314
 
                if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) {
315
 
                        if (CheckMapVersion(symfile) == 1)
316
 
                                file = symfile;
 
308
        for(mf = system_maps; *mf != NULL && file == NULL; ++mf) {
 
309
                snprintf(mysymfile, sizeof(mysymfile), "%s-%s", *mf, utsname.release);
 
310
                dbgprintf("Trying %s.\n", mysymfile);
 
311
                if((sym_file = fopen(mysymfile, "r")) != NULL) {
 
312
                        if(CheckMapVersion(mysymfile) == 1)
 
313
                                file = mysymfile;
317
314
                        fclose(sym_file);
318
315
                }
319
 
                if (sym_file == (FILE *) 0 || file == (char *) 0) {
320
 
                        sprintf (symfile, "%s", *mf);
321
 
                        dbgprintf("Trying %s.\n", symfile);
322
 
                        if ( (sym_file = fopen(symfile, "r")) != (FILE *) 0 ) {
323
 
                                if (CheckMapVersion(symfile) == 1)
324
 
                                        file = symfile;
 
316
                if(sym_file == NULL || file == NULL) {
 
317
                        sprintf (mysymfile, "%s", *mf);
 
318
                        dbgprintf("Trying %s.\n", mysymfile);
 
319
                        if((sym_file = fopen(mysymfile, "r")) != NULL ) {
 
320
                                if (CheckMapVersion(mysymfile) == 1)
 
321
                                        file = mysymfile;
325
322
                                fclose(sym_file);
326
323
                        }
327
324
                }
328
 
 
329
325
        }
330
326
 
331
327
        /* At this stage of the game we are at the end of the symbol tables.  */
332
328
        dbgprintf("End of search list encountered.\n");
 
329
        ENDfunc
333
330
        return(file);
334
331
}
335
332
 
410
407
         * version level.
411
408
         */
412
409
        if ( uname(&utsname) < 0 ) {
413
 
                Syslog(LOG_ERR, "Cannot get kernel version information.");
 
410
                imklogLogIntMsg(LOG_ERR, "Cannot get kernel version information.");
414
411
                return(0);
415
412
        }
416
413
        dbgprintf("Comparing kernel %s with symbol table %s.\n", utsname.release, vstring);
417
414
 
418
415
        if ( sscanf (utsname.release, "%d.%d.%d", &major, &minor, &patch) < 3 ) {
419
 
                Syslog(LOG_ERR, "Kernel send bogus release string `%s'.", utsname.release);
 
416
                imklogLogIntMsg(LOG_ERR, "Kernel send bogus release string `%s'.", utsname.release);
420
417
                return(0);
421
418
        }
422
419
 
464
461
        auto char       type,
465
462
                        sym[512];
466
463
 
467
 
        if ( (sym_file = fopen(fname, "r")) != (FILE *) 0 ) {
 
464
        if ( (sym_file = fopen(fname, "r")) != NULL ) {
468
465
                /*
469
466
                 * At this point a map file was successfully opened.  We
470
467
                 * now need to search this file and look for version
471
468
                 * information.
472
469
                 */
473
 
                Syslog(LOG_INFO, "Inspecting %s", fname);
 
470
                imklogLogIntMsg(LOG_INFO, "Inspecting %s", fname);
474
471
 
475
472
                version = 0;
476
473
                while ( !feof(sym_file) && (version == 0) ) {
477
474
                        if ( fscanf(sym_file, "%lx %c %s\n", &address, &type, sym) != 3 ) {
478
 
                                Syslog(LOG_ERR, "Error in symbol table input (#2).");
 
475
                                imklogLogIntMsg(LOG_ERR, "Error in symbol table input (#2).");
479
476
                                fclose(sym_file);
480
477
                                return(0);
481
478
                        }
487
484
 
488
485
                switch ( version ) {
489
486
                    case -1:
490
 
                        Syslog(LOG_ERR, "Symbol table has incorrect version number.\n");
 
487
                        imklogLogIntMsg(LOG_ERR, "Symbol table has incorrect version number.\n");
491
488
                        break;
492
489
                    case 0:
493
490
                        dbgprintf("No version information found.\n");
527
524
 
528
525
        /* Then the space for the symbol. */
529
526
        sym_array[num_syms].name = (char *) malloc(strlen(symbol)*sizeof(char) + 1);
530
 
        if ( sym_array[num_syms].name == (char *) 0 )
 
527
        if ( sym_array[num_syms].name == NULL )
531
528
                return(0);
532
529
        
533
530
        sym_array[num_syms].value = address;
566
563
        struct symbol ksym, msym;
567
564
 
568
565
        if (!sym_array)
569
 
                return((char *) 0);
 
566
                return(NULL);
570
567
 
571
568
        last = sym_array[0].name;
572
569
        ksym.offset = 0;
573
570
        ksym.size = 0;
574
571
        if ( value < sym_array[0].value )
575
 
                return((char *) 0);
 
572
                return(NULL);
576
573
 
577
574
        for(lp = 0; lp <= num_syms; ++lp) {
578
575
                if ( sym_array[lp].value > value ) {
587
584
        name = LookupModuleSymbol(value, &msym);
588
585
 
589
586
        if ( ksym.offset == 0 && msym.offset == 0 ) {
590
 
                return((char *) 0);
 
587
                return(NULL);
591
588
        }
592
589
 
593
590
        if ( ksym.offset == 0 || msym.offset < 0 ||
602
599
        }
603
600
 
604
601
 
605
 
        return((char *) 0);
 
602
        return(NULL);
606
603
}
607
604
 
608
605
/**************************************************************************
683
680
         * open for patches.
684
681
         */
685
682
        if ( i_am_paranoid &&
686
 
             (strstr(line, "Oops:") != (char *) 0) && !InitMsyms() )
687
 
                Syslog(LOG_WARNING, "Cannot load kernel module symbols.\n");
 
683
             (strstr(line, "Oops:") != NULL) && !InitMsyms() )
 
684
                imklogLogIntMsg(LOG_WARNING, "Cannot load kernel module symbols.\n");
688
685
        
689
686
 
690
687
        /*
692
689
         * messages in this line.
693
690
         */
694
691
        if ( (num_syms == 0) ||
695
 
             (kp = strstr(line, "[<")) == (char *) 0 ) {
 
692
             (kp = strstr(line, "[<")) == NULL ) {
696
693
#ifdef __sparc__
697
694
                if (num_syms) {
698
695
                        /* On SPARC, register dumps do not have the [< >] characters in it.
780
777
                        *elp++ = *sl++;
781
778
 
782
779
                /* Now poised at a kernel delimiter. */
783
 
                if ( (kp = strstr(sl, ">]")) == (char *) 0 ) {
 
780
                if ( (kp = strstr(sl, ">]")) == NULL ) {
784
781
                        strcpy(el, sl);
785
782
                        return(el);
786
783
                }
788
785
                strncpy(num,sl+1,kp-sl-1);
789
786
                num[kp-sl-1] = '\0';
790
787
                value = strtoul(num, (char **) 0, 16);
791
 
                if ( (symbol = LookupSymbol(value, &sym)) == (char *) 0 )
 
788
                if ( (symbol = LookupSymbol(value, &sym)) == NULL )
792
789
                        symbol = sl;
793
790
                        
794
791
                strcat(elp, symbol);
805
802
                strncat(elp, kp, value);
806
803
                elp += value;
807
804
                sl = kp + value;
808
 
                if ( (kp = strstr(sl, "[<")) == (char *) 0 )
 
805
                if ( (kp = strstr(sl, "[<")) == NULL )
809
806
                        strcat(elp, sl);
810
807
        }
811
 
        while ( kp != (char *) 0);
 
808
        while ( kp != NULL);
812
809
                
813
810
        dbgprintf("Expanded line: %s\n", el);
814
811
        return(el);