File: common.c

package info (click to toggle)
upsd 1.0-5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 132 kB
  • ctags: 55
  • sloc: ansic: 532; makefile: 68; sh: 51
file content (100 lines) | stat: -rw-r--r-- 3,340 bytes parent folder | download | duplicates (3)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/********************************************************************

    File:       common.c

    Purpose:    Utility functions for upsd.

                Copyright 1996, Bob Hauck
                
                This program is free software; you can redistribute it
                and/or modify it under the terms of the GNU General Public
                License as published by the Free Software Foundation;
                either version 2 of the License, or (at your option) any
                later version.

                This program is distributed in the hope that it will be
                useful, but WITHOUT ANY WARRANTY; without even the implied
                warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
                PURPOSE.  See the GNU General Public License for more details.

                You should have received a copy of the GNU General Public
                License along with this program; if not, write to the Free
                Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
                USA.

    Language:   GCC 2.7.0

    Author:     Bob Hauck

    $Log: common.c,v $
    Revision 1.1  1996/11/23 16:45:12  bobh
    Initial revision

**********************************************************************/
#include <stdio.h>
#include <syslog.h>
#include "common.h"

static char *Version = "v1.0";

char *ProgName;   /*  Program name  */
int   Status;     /*  UPS Status (S_* codes)  */
int   IsDaemon;   /*  0 = not daemon, 1 = daemon, 2 = daemon with
                   *  log file open.  */


/*-------------------------------------------------------------------*
     LogError

     Log error messages to stderr or to syslog, depending on whether
     we are running as a daemon.

     Parameters:  Module - Module that is reporting the error.
                  Error  - Error message

     Returns:     Nothing.
 *-------------------------------------------------------------------*/
void LogError (char *Module, char *Error)
    {
    if (IsDaemon)
        {
        if (IsDaemon == 1)
            {
            openlog (ProgName, LOG_CONS, LOG_DAEMON);
            ++IsDaemon;
            }
        syslog (LOG_WARNING, "%s: %s", Module, Error);
        }
    else
        {
        printf ("%s: %s: %s\n", ProgName, Module, Error);
        }
    }


/*-------------------------------------------------------------------*
     Usage

     Print help & usage information.

     Parameters:  None

     Returns:     Nothing.
 *-------------------------------------------------------------------*/
void Usage (void)
    {
    printf ("Usage:\n");
    printf ("    %s [options] device | host\n", ProgName);
    printf ("Options:\n");
    printf (" -c count  Wait 'count' polls before shutdown (default 2).\n");
    printf (" -h        Print this help.\n");
    printf (" -i time   Set poll interval to 'time' seconds (default 10).\n");
    printf (" -k        Kill power now.\n");
    printf (" -l        Don't shut down until low battery.\n");
    printf (" -m        Disable master mode.\n");
    printf (" -p port   Use 'port' for remote status (default 401).\n");
    printf (" -s        Slave to host instead of device.\n");
    printf (" -t        Test mode, don't become daemon.\n");
    printf ("\n");
    printf ("Version ID = %s\n", Version);
    }