2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-31 14:25:39 +00:00

Added -p/--pid-file option to write a PID file for the daemon and

-d/--debug option to allow unwanted information to be more easily
suppressed. Kicked version to 0.5.0. -- merlin@merlin.org


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@1024 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Merlin Hughes
2001-02-11 18:51:24 +00:00
parent 0f1417afc7
commit 1d1859040b
7 changed files with 89 additions and 41 deletions

View File

@@ -3,7 +3,7 @@
*
* A daemon that periodically logs sensor information to syslog.
*
* Copyright (c) 1999-2000 Merlin Hughes <merlin@merlin.org>
* Copyright (c) 1999-2001 Merlin Hughes <merlin@merlin.org>
*
* 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
@@ -33,11 +33,13 @@
int isDaemon = 0;
const char *sensorsCfgFile = "sensors.conf";
const char *pidFile = "/var/run/sensord.pid";
int scanTime = 60;
int logTime = 30 * 60;
int syslogFacility = LOG_LOCAL4;
int doScan = 0;
int doSet = 0;
int debug = 0;
sensors_chip_name chipNames[MAX_CHIP_NAMES];
int numChipNames = 0;
@@ -92,6 +94,8 @@ static const char *daemonSyntax =
" -l, --log-interval <time> -- interval between logging sensors (default 30m)\n"
" -f, --syslog-facility <f> -- syslog facility to use (default local4)\n"
" -c, --config-file <file> -- configuration file (default sensors.conf)\n"
" -p, --pid-file <file> -- PID file (default /var/run/sensord.pid)\n"
" -d, --debug -- display some debug information\n"
" -v, --version -- display version and exit\n"
" -h, --help -- display help and exit\n"
"\n"
@@ -107,6 +111,7 @@ static const char *appSyntax =
" -a, --alarm-scan -- only scan for alarms\n"
" -s, --set -- execute set statements too (root only)\n"
" -c, --config-file <file> -- configuration file (default sensors.conf)\n"
" -d, --debug -- display some debug information\n"
" -v, --version -- display version and exit\n"
" -h, --help -- display help and exit\n"
"\n"
@@ -115,24 +120,27 @@ static const char *appSyntax =
"\n"
"If no chips are specified, all chip info will be printed.\n";
static const char *daemonShortOptions = "i:l:f:c:vh";
static const char *daemonShortOptions = "i:l:f:c:p:dvh";
static const struct option daemonLongOptions[] = {
{ "interval", required_argument, NULL, 'i' },
{ "log-interval", required_argument, NULL, 'l' },
{ "syslog-facility", required_argument, NULL, 'f' },
{ "config-file", required_argument, NULL, 'c' },
{ "pid-file", required_argument, NULL, 'p' },
{ "debug", no_argument, NULL, 'd' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
};
static const char *appShortOptions = "asc:vh";
static const char *appShortOptions = "asc:dvh";
static const struct option appLongOptions[] = {
{ "alarm-scan", no_argument, NULL, 'a' },
{ "set", no_argument, NULL, 's' },
{ "config-file", required_argument, NULL, 'c' },
{ "debug", no_argument, NULL, 'd' },
{ "version", no_argument, NULL, 'v' },
{ "help", no_argument, NULL, 'h' },
{ NULL, 0, NULL, 0 }
@@ -173,6 +181,13 @@ parseArgs
if ((sensorsCfgFile = strdup (optarg)) == NULL)
return -1;
break;
case 'p':
if ((pidFile = strdup (optarg)) == NULL)
return -1;
break;
case 'd':
debug = 1;
break;
case 'v':
printf ("sensord version %s\n", version);
exit (EXIT_SUCCESS);

View File

@@ -3,7 +3,7 @@
*
* A daemon that periodically logs sensor information to syslog.
*
* Copyright (c) 1999-2000 Merlin Hughes <merlin@merlin.org>
* Copyright (c) 1999-2001 Merlin Hughes <merlin@merlin.org>
*
* 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

View File

@@ -3,7 +3,7 @@
*
* A daemon that periodically logs sensor information to syslog.
*
* Copyright (c) 1999-2000 Merlin Hughes <merlin@merlin.org>
* Copyright (c) 1999-2001 Merlin Hughes <merlin@merlin.org>
*
* 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

View File

@@ -3,7 +3,7 @@
*
* A daemon that periodically logs sensor information to syslog.
*
* Copyright (c) 1999-2000 Merlin Hughes <merlin@merlin.org>
* Copyright (c) 1999-2001 Merlin Hughes <merlin@merlin.org>
*
* 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
@@ -214,6 +214,7 @@ doChips
(int action) {
const sensors_chip_name *chip;
int i = 0, j, ret = 0;
while ((ret == 0) && ((chip = sensors_get_detected_chips (&i)) != NULL)) {
for (j = 0; j < numChipNames; ++ j) {
if (sensors_match_chip (*chip, chipNames[j])) {
@@ -222,6 +223,8 @@ doChips
}
}
}
return ret;
}
int
@@ -241,9 +244,9 @@ scanChips
(void) {
int ret = 0;
sensorLog (LOG_DEBUG, "sensor scan started");
sensorLog (LOG_DEBUG, "sensor sweeep started");
ret = doChips (DO_SCAN);
sensorLog (LOG_DEBUG, "sensor scan finished");
sensorLog (LOG_DEBUG, "sensor sweep finished");
return ret;
}

View File

@@ -1,4 +1,4 @@
.\" Copyright 1999-2000 Merlin Hughes <merlin@merlin.org>
.\" Copyright 1999-2001 Merlin Hughes <merlin@merlin.org>
.\" sensord is distributed under the GPL
.\"
.\" Permission is granted to make and distribute verbatim copies of this
@@ -21,7 +21,7 @@
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.TH sensord 8 "July 7, 2000" "Version 0.4.0" "Linux System Administration"
.TH sensord 8 "February 11, 2001" "Version 0.5.0" "Linux System Administration"
.SH NAME
sensord \- Sensor information logging daemon.
.SH SYNOPSIS
@@ -42,7 +42,7 @@ fan fails, a temperature limit is exceeded, etc.
.B Sensord
knows about certain chips, and outputs nicely formatted readings for them; but
it can also display the information of unknown chips, as long as
.BR libsensors
.BR libsensors (3)
knows about them.
.SH OPTIONS
.IP "-i, --interval time"
@@ -78,13 +78,19 @@ or
.IR user .
.IP "-c, --config-file file"
Specify a
.BR libsensors
.BR libsensors (3)
configuration file. If no file is specified, the name `sensors.conf'
is used.
If the sensors configuration name does not contain a directory separator,
the following paths are searched for the file:
`/etc', `/usr/lib/sensors', `/usr/local/lib/sensors', `/usr/lib', `/usr/local/lib'.
.IP "-p, --pid-file file"
Specify what PID file to write; the default is to write the file
`/var/run/sensord.pid'. You should always specify an absolute path
here. The file is removed when the daemon exits.
.IP "-d, --debug"
Prints a small amount of additional debugging information.
.IP "-h, --help"
Prints a help message and exits.
.IP "-v, --version"
@@ -116,7 +122,8 @@ Alarms are logged at the level
.IR alert .
Inconsequential status messages are logged at
the minimum level,
.IR debug .
.IR debug ,
when debugging is enabled.
You can use an appropriate `/etc/syslog.conf'
file to direct these messages in a useful manner. See
@@ -126,7 +133,7 @@ for full details, however the following is a sample configuration:
.nf
# Sample syslog.conf entries
*.info;...;local4.none;local4.warn /var/log/messages
local4.debug -/var/log/sensors
local4.info -/var/log/sensors
local4.alert /dev/console
local4.alert *
.fi
@@ -173,10 +180,10 @@ Typically, an alarm will only be signaled once,
even if the critical condition persists. This means that it is very
easy to miss an alarm!
In other cases, however,
uninteresting alarms (e.g., chassis intrusion detection) will be
repeated continuously. You can configure
.BR libsensors
In other cases, however, uninteresting alarms (e.g., chassis
intrusion detection) will be repeated continuously. You can
configure
.BR libsensors (3)
to ignore unwanted sensor reading such as these by placing an
`ignore' entry in the appropriate chip-specific section of the
.BR sensors.conf (5)
@@ -201,28 +208,26 @@ your system is configured to issue an audio warning from the
motherboard if an alarm is signalled on that sensor.
.SH MODULES
It is expected that all required sensor modules are loaded prior to
this daemon being started. Typically, this is achieved with an entry
in `/etc/rc.d/...' containing
this daemon being started. This can either be achieved with a system
specific module loading scheme (e.g., listing the required modules
in the file `/etc/modules' under Debian) or with explicit
.BR modprobe (1)
commands to load the required modules before starting the daemon.
commands in an init script before loading the daemon.
For example, on my box I have a `sensord' initialization script
containing (among others) the following commands:
For example, a `sensord' initialization script might
contain (among others) the following commands:
.IP
.nf
# Sample /etc/rc.d/init.d scriptlet
# Sample init.d scriptlet
echo -n "Loading AMD756 module: "
modprobe i2c-amd756 || { failure ; echo ; exit 1 ; }
echo_success
echo
modprobe i2c-amd756 || { echo Fail. ; exit 1 ; }
echo OK.
echo -n "Loading W83781D module: "
modprobe w83781d || { failure ; echo ; exit 1 ; }
echo_success
echo
modprobe w83781d || { echo Fail. ; exit 1 ; }
echo OK.
echo -n "Starting sensord: "
daemon sensord
RETVAL=$?
echo
...
.fi
.PP
Ignore the platform-specific shell functions; the general idea
@@ -240,7 +245,7 @@ chips.
.I /etc/sensors.conf
.RS
The system-wide
.BR libsensors
.BR libsensors (3)
configuration file. See
.BR sensors.conf (5)
for further details.

View File

@@ -3,7 +3,7 @@
*
* A daemon that periodically logs sensor information to syslog.
*
* Copyright (c) 1999-2000 Merlin Hughes <merlin@merlin.org>
* Copyright (c) 1999-2001 Merlin Hughes <merlin@merlin.org>
*
* 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
@@ -22,9 +22,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <signal.h>
#include <syslog.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "sensord.h"
@@ -45,11 +49,13 @@ sensorLog
vsnprintf (buffer, LOG_BUFFER, fmt, ap);
buffer[LOG_BUFFER] = '\0';
va_end (ap);
if (logOpened) {
syslog (priority, "%s", buffer);
} else if (priority != LOG_DEBUG) {
fprintf (stderr, "%s\n", buffer);
fflush (stderr);
if (debug || (priority < LOG_DEBUG)) {
if (logOpened) {
syslog (priority, "%s", buffer);
} else {
fprintf (stderr, "%s\n", buffer);
fflush (stderr);
}
}
}
@@ -108,6 +114,8 @@ static void
daemonize
(void) {
int pid;
struct stat fileStat;
FILE *file;
openlog ("sensord", 0, syslogFacility);
@@ -117,6 +125,17 @@ daemonize
perror ("chdir()");
exit (EXIT_FAILURE);
}
if (!(stat (pidFile, &fileStat)) &&
((!S_ISREG (fileStat.st_mode)) || (fileStat.st_size > 11))) {
fprintf (stderr, "Error: PID file `%s' already exists and looks suspicious.\n", pidFile);
exit (EXIT_FAILURE);
}
if (!(file = fopen (pidFile, "w"))) {
fprintf (stderr, "fopen(\"%s\"): %s\n", pidFile, strerror (errno));
exit (EXIT_FAILURE);
}
/* I should use sigaction but... */
if (signal (SIGTERM, signalHandler) == SIG_ERR) {
@@ -128,6 +147,8 @@ daemonize
perror ("fork()");
exit (EXIT_FAILURE);
} else if (pid != 0) {
fprintf (file, "%d\n", pid);
fclose (file);
exit (EXIT_SUCCESS);
}
@@ -136,6 +157,7 @@ daemonize
exit (EXIT_FAILURE);
}
fclose (file);
close (STDIN_FILENO);
close (STDOUT_FILENO);
close (STDERR_FILENO);
@@ -144,6 +166,7 @@ daemonize
static void
undaemonize
(void) {
unlink (pidFile);
closelog ();
}

View File

@@ -3,7 +3,7 @@
*
* A daemon that periodically logs sensor information to syslog.
*
* Copyright (c) 1999-2000 Merlin Hughes <merlin@merlin.org>
* Copyright (c) 1999-2001 Merlin Hughes <merlin@merlin.org>
*
* 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
@@ -20,7 +20,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define version "0.4.0"
#define version "0.5.0"
#include "lib/sensors.h"
@@ -30,11 +30,13 @@ extern void sensorLog (int priority, const char *fmt, ...);
extern int isDaemon;
extern const char *sensorsCfgFile;
extern const char *pidFile;
extern int scanTime;
extern int logTime;
extern int syslogFacility;
extern int doScan;
extern int doSet;
extern int debug;
extern sensors_chip_name chipNames[];
extern int numChipNames;