diff --git a/prog/sensord/Module.mk b/prog/sensord/Module.mk index d2a6bddb..7556b66a 100644 --- a/prog/sensord/Module.mk +++ b/prog/sensord/Module.mk @@ -27,7 +27,7 @@ PROGSENSORDMAN1FILES := $(MODULE_DIR)/sensord.8 # Regrettably, even 'simply expanded variables' will not put their currently # defined value verbatim into the command-list of rules... PROGSENSORDTARGETS := $(MODULE_DIR)/sensord -PROGSENSORDSOURCES := $(MODULE_DIR)/sensord.c $(MODULE_DIR)/chips.c +PROGSENSORDSOURCES := $(MODULE_DIR)/args.c $(MODULE_DIR)/chips.c $(MODULE_DIR)/lib.c $(MODULE_DIR)/sense.c $(MODULE_DIR)/sensord.c # Include all dependency files. We use '.rd' to indicate this will create # executables. diff --git a/prog/sensord/args.c b/prog/sensord/args.c new file mode 100644 index 00000000..32b96c45 --- /dev/null +++ b/prog/sensord/args.c @@ -0,0 +1,211 @@ +/* + * sensord + * + * A daemon that periodically logs sensor information to syslog. + * + * Copyright (c) 1999-2000 Merlin Hughes + * + * 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. + */ + +#include +#include +#include +#include +#include + +#include "sensord.h" +#include "lib/error.h" + +#define MAX_CHIP_NAMES 32 + +int isDaemon = 0; +const char *sensorsCfgFile = "sensors.conf"; +int sleepTime = 5 * 60; +int logTime = 30 * 60; +int syslogFacility = LOG_LOCAL4; +int doSet = 0; +sensors_chip_name chipNames[MAX_CHIP_NAMES]; +int numChipNames = 0; + +static int +parseTime +(char *arg) { + char *end; + int value = strtoul (arg, &end, 10); + if ((end > arg) && (*end == 's')) { + ++ end; + } else if ((end > arg) && (*end == 'm')) { + value *= 60; + ++ end; + } else if ((end > arg) && (*end == 'h')) { + value *= 60 * 60; + ++ end; + } + if ((end == arg) || *end) { + fprintf (stderr, "Error parsing time value `%s'.\n", arg); + return -1; + } + return value; +} + +static struct { + const char *name; + int id; +} facilities[] = { + { "local0", LOG_LOCAL0 }, { "local1", LOG_LOCAL1 }, + { "local2", LOG_LOCAL2 }, { "local3", LOG_LOCAL3 }, + { "local4", LOG_LOCAL4 }, { "local5", LOG_LOCAL5 }, + { "local6", LOG_LOCAL6 }, { "local7", LOG_LOCAL7 }, + { "daemon", LOG_DAEMON }, { "user", LOG_USER }, + { NULL } +}; + +static int +parseFacility +(char *arg) { + int i = 0; + while (facilities[i].name && strcasecmp (arg, facilities[i].name)) + ++ i; + if (!facilities[i].name) { + fprintf (stderr, "Error parsing facility value `%s'.\n", arg); + return -1; + } + return facilities[i].id; +} + +/* TODO: -s, --set */ + +static const char *daemonSyntax = + " -i, --interval