[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sensorsd(8) patch



On 4/3/06, Ted Unangst <ted_(_dot_)_unangst_(_at_)_gmail_(_dot_)_com> wrote:
> i think it should continue if the file is missing on reload after
> logging a warning.  if it's running as a daemon, you won't see the
> err() output, and now the program is just gone.
I pulled the specific error messages out of parse_config and instead
now have it return -2 when there is a file error. If parse_config
return -2 when the program is loading err(1, configfile) is executed
if it returns -2 after the daemon has been loaded then it continues
running but logs the fact it couldn't open the config file with
syslog.

Index: sensorsd.c
===================================================================
RCS file: /cvs/src/usr.sbin/sensorsd/sensorsd.c,v
retrieving revision 1.22
diff -u -r1.22 sensorsd.c
--- sensorsd.c  2006/04/01 20:09:13     1.22
+++ sensorsd.c  2006/04/04 01:33:21
@@ -73,7 +73,7 @@
 usage(void)
 {
        extern char *__progname;
-       fprintf(stderr, "usage: %s [-d]\n", __progname);
+       fprintf(stderr, "usage: %s [-d] [-f file]\n", __progname);
        exit(1);
 }

@@ -86,11 +86,14 @@
        time_t           next_report, last_report = 0, next_check;
        int              mib[3], i, sleeptime, sensor_cnt, watch_cnt, ch;

-       while ((ch = getopt(argc, argv, "d")) != -1) {
+       while ((ch = getopt(argc, argv, "df:")) != -1) {
                switch (ch) {
                case 'd':
                        debug = 1;
                        break;
+               case 'f':
+                       configfile = optarg;
+                       break;
                default:
                        usage();
                }
@@ -128,6 +131,9 @@
                        err(1, "out of memory");
        if ((watch_cnt = parse_config(configfile)) == -1)
                errx(1, "error in config file");
+
+       if (watch_cnt == -2)
+               err(1, configfile);

        if (watch_cnt == 0)
                errx(1, "no watches defined");
@@ -145,7 +151,10 @@

        for (;;) {
                if (reload) {
-                       if ((watch_cnt = parse_config(configfile)) == -1)
+                       if ((watch_cnt = parse_config(configfile)) == -2)
+                               syslog(LOG_CRIT, "config file %s not found",
+                                   configfile);
+                       else if (watch_cnt == -1)
                                syslog(LOG_CRIT, "error in config file %s",
                                    configfile);
                        else
@@ -347,9 +356,11 @@
        for (p = TAILQ_FIRST(&limits); p != NULL; p = next) {
                next = TAILQ_NEXT(p, entries);
                snprintf(node, sizeof(node), "hw.sensors.%d", p->num);
-               if (cgetent(&buf, cfa, node) != 0)
-                       p->watch = 0;
-               else {
+               switch (cgetent(&buf, cfa, node)) {
+               case -2:
+                       free(cfa);
+                       return (-2);
+               case 0:
                        p->watch = 1;
                        watch_cnt++;
                        if (cgetstr(buf, "low", &ebuf) < 0)
@@ -364,6 +375,10 @@
                                asprintf(&(p->command), "%s", ebuf);
                        free(buf);
                        buf = NULL;
+                       break;
+               default:
+                       p->watch = 0;
+                       break;
                }
        }
        free(cfa);



Visit your host, monkey.org