File: options1.cc

package info (click to toggle)
ssh-cron 2.00.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 840 kB
  • sloc: cpp: 1,372; fortran: 200; makefile: 99; sh: 36; ansic: 10
file content (76 lines) | stat: -rw-r--r-- 1,993 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#define XERR "options"
#include "options.ih"

    // by instance.cc

Options::Options()
:
    d_arg(ArgConfig::instance()),
    d_msg(&d_multiBuf)
{
    // --help and --version already handled by versionHelp, but if nothing
    // is requested on the command line help is also provided.
    if (
        d_arg.nArgs() == 0 && d_arg.nOptions() == 0 && 
        d_arg.nLongOptions() == 0
    )
    {
        d_arg.help();
        throw 1;
    }

    d_foreground = d_arg.option(0, "foreground");

    if ((d_list = d_arg.option('l')))
        d_udsReq = LIST;

    if ((d_reload = d_arg.option('r')))
        d_udsReq = RELOAD;

    if ((d_terminate = d_arg.option('t')))
        d_udsReq = TERMINATE;

    if (d_arg.option('s'))
    {
        if (d_foreground)
            d_multiBuf.insert(cout);
        else
            wmsg << "--stdout ignored: " << d_arg.basename() << 
                    " runs as a daemon process" << endl;
    }

    loadConfigFile();

    if (not d_arg.option(&d_agent, "agent"))
        d_agent = s_defaultAgent;

    if (not d_arg.option(&d_uds, 'u'))
        d_uds = User().homedir() + s_defaultUDS;

    checkAction();                      // check for incompatible options

    string logName;
    if (d_arg.option(&logName, 'L'))
    {
        d_log.open(logName);
        if (not d_log)
            fmsg << "could not open " << logName << endl;

        d_multiBuf.insert(d_log);
    }

    if (not d_arg.option(&d_mailer, 'm'))   // empty argument: no mail
        d_mailer = s_defaultMailer;         // (cf. cron/definerun.cc)

    bool useSyslog = setSyslog();

    if (not d_arg.option('V'))              // verbose messages appear in the
        imsg.off();                         // logs
    else if (useSyslog || not logName.empty())
        imsg.reset(d_msg);
    else
        wmsg << "--verbose ignored: --syslog or --log not specified" << endl;

    if (d_arg.nArgs() > 0)
        d_cronFile = FileSystem{ d_arg[0] }.canonical().string();
}