Changeset 3628 in MondoRescue for branches/3.3/mondo/src/lib/mr_msg.c


Ignore:
Timestamp:
Dec 21, 2016, 3:18:07 PM (7 years ago)
Author:
Bruno Cornec
Message:

Change mr_msg_init interface definition to include argc and argv, which allows to detect the presence of the -K option and setup the log level accordingly as early as possible

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mondo/src/lib/mr_msg.c

    r3509 r3628  
    1313#define _GNU_SOURCE
    1414#endif
     15
    1516#include <stdio.h>
    1617#include <stdarg.h>
    1718#include <stdlib.h>
     19#include <unistd.h>
     20#include <string.h>
    1821
    1922static int mr_loglevel = 0;
     
    4851
    4952/* Initialization function for messages */
    50 void mr_msg_init(const char *logfile, int loglevel) {
     53void mr_msg_init(const char *logfile, int loglevel, int argc, char *argv[]) {
     54
     55    int i=1;
     56
    5157    if (asprintf(&mr_logfile, "%s", logfile) == -1) {
    5258        fprintf(stderr,"Unable to alloc memory\n");
     
    6773            fprintf(stderr,"Logging desactivated\n");
    6874            mr_msg_close();
     75        }
     76    }
     77    while (i < argc) {
     78        if (strcmp(argv[i],"-K") == 0) {
     79            i++;
     80            if (argv[i]) {
     81                loglevel = atoi(argv[i]);
     82            } else {
     83                fprintf(stderr,"-K option requires a loglevel\n");
     84                mr_msg_close();
     85                exit(-1);
     86            }
    6987        }
    7088    }
Note: See TracChangeset for help on using the changeset viewer.