~ubuntu-branches/ubuntu/vivid/logrotate/vivid

« back to all changes in this revision

Viewing changes to config.c

  • Committer: Bazaar Package Importer
  • Author(s): Bhavani Shankar
  • Date: 2009-08-16 12:40:24 UTC
  • mfrom: (4.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090816124024-zdaf837alkb789i5
Tags: 3.7.8-4ubuntu1
* Merge from debian unstable, remaining changes: LP: #414347
  - debian/control: Drop mailx to Suggests for Ubuntu; it's only used
    on request, and we don'c configure an MTA by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
237
237
 
238
238
static void freeLogInfo(struct logInfo *log)
239
239
{
240
 
    if (log->pattern)
241
240
        free(log->pattern);
242
 
    if (log->files)
243
241
        free_2d_array(log->files, log->numFiles);
244
 
    if (log->oldDir)
245
242
        free(log->oldDir);
246
 
    if (log->pre)
247
243
        free(log->pre);
248
 
    if (log->post)
249
244
        free(log->post);
250
 
    if (log->first)
251
245
        free(log->first);
252
 
    if (log->last)
253
246
        free(log->last);
254
 
    if (log->logAddress)
255
247
        free(log->logAddress);
256
 
    if (log->extension)
257
248
        free(log->extension);
258
 
    if (log->compress_prog)
259
249
        free(log->compress_prog);
260
 
    if (log->uncompress_prog)
261
250
        free(log->uncompress_prog);
262
 
    if (log->compress_ext)
263
251
        free(log->compress_ext);
264
 
    if (log->compress_options_list)
265
252
        free(log->compress_options_list);
266
253
        free(log->dateformat);
267
254
}
399
386
            freeLogInfo(&defConfigBackup);
400
387
        }
401
388
 
402
 
        fchdir(here);
 
389
        if (fchdir(here) < 0) {
 
390
                message(MESS_ERROR, "could not change directory to '.'");
 
391
        }
403
392
        close(here);
404
393
        free_2d_array(namelist, files_count);
405
394
    } else {
422
411
{
423
412
    int i, result = 0;
424
413
    const char **file;
425
 
    struct logInfo defConfig = { /* pattern */ NULL,
426
 
        /* files, numFiles */ NULL, 0,
427
 
        /* oldDir */ NULL,
428
 
        /* criterium */ ROT_SIZE,
429
 
        /* threshHold */ 1024 * 1024,
430
 
        /* minsize */ 0,
431
 
        /* rotateCount/Age */ 0, 0,
432
 
        /* log start */ -1,
433
 
        /* pre, post */ NULL, NULL,
434
 
        /* first, last */ NULL, NULL,
435
 
        /* logAddress */ NULL,
436
 
        /* extension */ NULL,
437
 
        /* compress_prog */ NULL,
438
 
        /* uncompress_prog */ NULL,
439
 
        /* compress_ext */ NULL,
440
 
        /* dateformat */ NULL,
441
 
        /* flags */ LOG_FLAG_IFEMPTY,
442
 
        /* shred_cycles */ 0,
443
 
        /* createMode/Uid/Gid */ NO_MODE, NO_UID, NO_GID,
444
 
        /* compress_options_list/count */ NULL, 0
 
414
    struct logInfo defConfig = {
 
415
                .pattern = NULL,
 
416
                .files = NULL,
 
417
                .numFiles = 0,
 
418
                .oldDir = NULL,
 
419
                .criterium = ROT_SIZE,
 
420
                .threshhold = 1024 * 1024,
 
421
                .minsize = 0,
 
422
                .rotateCount = 0,
 
423
                .rotateAge = 0,
 
424
                .logStart = -1,
 
425
                .pre = NULL,
 
426
                .post = NULL,
 
427
                .first = NULL,
 
428
                .last = NULL,
 
429
                .logAddress = NULL,
 
430
                .extension = NULL,
 
431
                .compress_prog = NULL,
 
432
                .uncompress_prog = NULL,
 
433
                .compress_ext = NULL,
 
434
                .dateformat = NULL,
 
435
                .flags = LOG_FLAG_IFEMPTY,
 
436
                .shred_cycles = 0,
 
437
                .createMode = NO_MODE,
 
438
                .createUid = NO_UID,
 
439
                .createGid = NO_GID,
 
440
                .compress_options_list = NULL,
 
441
                .compress_options_count = 0
445
442
    };
446
443
 
447
444
    tabooExts = malloc(sizeof(*tabooExts) * defTabooCount);
477
474
}
478
475
 
479
476
#define freeLogItem(what) \
480
 
    if (newlog->what) { \
481
 
        free(newlog->what); \
482
 
        newlog->what = NULL; \
483
 
    }
 
477
        do { \
 
478
                free(newlog->what); \
 
479
                newlog->what = NULL; \
 
480
        } while (0);
 
481
#define MAX_NESTING 16U
484
482
 
485
483
static int readConfigFile(const char *configFile, struct logInfo *defConfig)
486
484
{
507
505
    int argc, argNum;
508
506
    int logerror = 0;
509
507
    struct logInfo *log;
 
508
        static unsigned recursion_depth = 0U;
510
509
 
511
510
    /* FIXME: createOwner and createGroup probably shouldn't be fixed
512
511
       length arrays -- of course, if we aren't run setuid it doesn't
1095
1094
                    oldchar = *endtag, *endtag = '\0';
1096
1095
 
1097
1096
                    message(MESS_DEBUG, "including %s\n", start);
1098
 
 
1099
 
                    if (readConfigPath(start, defConfig))
1100
 
                        return 1;
 
1097
                        if (++recursion_depth > MAX_NESTING) {
 
1098
                                message(MESS_ERROR, "%s:%d include nesting too deep\n",
 
1099
                                                configFile, lineNum);
 
1100
                                --recursion_depth;
 
1101
                                return 1;
 
1102
                        }
 
1103
                    if (readConfigPath(start, defConfig)) {
 
1104
                                --recursion_depth;
 
1105
                                return 1;
 
1106
                        }
 
1107
                        --recursion_depth;
1101
1108
 
1102
1109
                    *endtag = oldchar, start = endtag;
1103
1110
                }