/* * sensord * * A daemon that periodically logs sensor information to syslog. * * Copyright (c) 1999-2002 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., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA. */ #include #include #include #include #include #include "args.h" #include "sensord.h" #include "lib/error.h" #include "version.h" struct sensord_arguments sensord_args = { .pidFile = "/var/run/sensord.pid", .scanTime = 60, .logTime = 30 * 60, .rrdTime = 5 * 60, .syslogFacility = LOG_DAEMON, }; 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, 0 } }; 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; } static const char *daemonSyntax = " -i, --interval