[PATCH] sensorsd - Command line switch for alternative configuration file

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH] sensorsd - Command line switch for alternative configuration file

Silamael
Hi there,

I wrote some patch allowing to specify the path of the configuration
file of sensorsd like it's done for other daemons.

Greetings,
Matthias

Index: sensorsd.8
===================================================================
RCS file: /usr/src/usr.sbin/sensorsd/sensorsd.8,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 sensorsd.8
--- sensorsd.8 27 Jul 2015 17:28:40 -0000 1.22
+++ sensorsd.8 14 Mar 2017 06:32:55 -0000
@@ -26,6 +26,7 @@
 .Nm sensorsd
 .Op Fl d
 .Op Fl c Ar check
+.Op Fl f Ar file
 .Sh DESCRIPTION
 The
 .Nm
@@ -63,6 +64,11 @@ seconds.
 The shortest reporting period for state changes
 will be three times this value.
 The default is 20.
+.It Fl f Ar file
+Read configuration from
+.Ar file
+instead of the default configuration file
+.Pa /etc/sensorsd.conf .
 .It Fl d
 Do not daemonize.
 If this option is specified,
Index: sensorsd.c
===================================================================
RCS file: /usr/src/usr.sbin/sensorsd/sensorsd.c,v
retrieving revision 1.59
diff -u -p -u -p -r1.59 sensorsd.c
--- sensorsd.c 12 Dec 2015 20:04:23 -0000 1.59
+++ sensorsd.c 14 Mar 2017 06:31:45 -0000
@@ -101,7 +101,8 @@ void
 usage(void)
 {
  extern char *__progname;
- fprintf(stderr, "usage: %s [-d] [-c check]\n", __progname);
+ fprintf(stderr, "usage: %s [-d] [-c check] [-f file]\n",
+    __progname);
  exit(1);
 }

@@ -115,7 +116,7 @@ main(int argc, char *argv[])
  if (pledge("stdio rpath proc exec", NULL) == -1)
  err(1, "pledge");

- while ((ch = getopt(argc, argv, "c:d")) != -1) {
+ while ((ch = getopt(argc, argv, "c:df:")) != -1) {
  switch (ch) {
  case 'c':
  check_period = strtonum(optarg, 1, 600, &errstr);
@@ -124,6 +125,12 @@ main(int argc, char *argv[])
  break;
  case 'd':
  debug = 1;
+ break;
+ case 'f':
+ configfile = optarg;
+ if (access(configfile, R_OK) != 0)
+    err(1, "Cannot access configuration file %s",
+ configfile);
  break;
  default:
  usage();

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] sensorsd - Command line switch for alternative configuration file

Alexander Bluhm
On Tue, Mar 14, 2017 at 10:45:43AM +0100, Silamael wrote:

> @@ -63,6 +64,11 @@ seconds.
>  The shortest reporting period for state changes
>  will be three times this value.
>  The default is 20.
> +.It Fl f Ar file
> +Read configuration from
> +.Ar file
> +instead of the default configuration file
> +.Pa /etc/sensorsd.conf .
>  .It Fl d
>  Do not daemonize.
>  If this option is specified,

The -f must be documented after -d.

> @@ -124,6 +125,12 @@ main(int argc, char *argv[])
>   break;
>   case 'd':
>   debug = 1;
> + break;
> + case 'f':
> + configfile = optarg;
> + if (access(configfile, R_OK) != 0)
> +    err(1, "Cannot access configuration file %s",
> + configfile);
>   break;
>   default:
>   usage();

All other error messages are lower case.  I would write "err(1,
"access configuration file %s", configfile)" as err(3) privides a
reason anyway.

apart from that OK bluhm@

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] sensorsd - Command line switch for alternative configuration file

Silamael
On 14.03.2017 12:55, Alexander Bluhm wrote:
> All other error messages are lower case.  I would write "err(1,
> "access configuration file %s", configfile)" as err(3) privides a
> reason anyway.
>
> apart from that OK bluhm@
>

Upated diff.

-- Matthias

Index: sensorsd.8
===================================================================
RCS file: /mount/cvsdev/cvs/openbsd/src/usr.sbin/sensorsd/sensorsd.8,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 sensorsd.8
--- sensorsd.8 27 Jul 2015 17:28:40 -0000 1.22
+++ sensorsd.8 15 Mar 2017 07:45:39 -0000
@@ -26,6 +26,7 @@
 .Nm sensorsd
 .Op Fl d
 .Op Fl c Ar check
+.Op Fl f Ar file
 .Sh DESCRIPTION
 The
 .Nm
@@ -68,6 +69,11 @@ Do not daemonize.
 If this option is specified,
 .Nm
 will run in the foreground.
+.It Fl f Ar file
+Read configuration from
+.Ar file
+instead of the default configuration file
+.Pa /etc/sensorsd.conf .
 .El
 .Sh FILES
 .Bl -tag -width "/etc/sensorsd.conf"
Index: sensorsd.c
===================================================================
RCS file: /mount/cvsdev/cvs/openbsd/src/usr.sbin/sensorsd/sensorsd.c,v
retrieving revision 1.59
diff -u -p -u -p -r1.59 sensorsd.c
--- sensorsd.c 12 Dec 2015 20:04:23 -0000 1.59
+++ sensorsd.c 15 Mar 2017 07:46:02 -0000
@@ -101,7 +101,8 @@ void
 usage(void)
 {
  extern char *__progname;
- fprintf(stderr, "usage: %s [-d] [-c check]\n", __progname);
+ fprintf(stderr, "usage: %s [-d] [-c check] [-f file]\n",
+    __progname);
  exit(1);
 }

@@ -115,7 +116,7 @@ main(int argc, char *argv[])
  if (pledge("stdio rpath proc exec", NULL) == -1)
  err(1, "pledge");

- while ((ch = getopt(argc, argv, "c:d")) != -1) {
+ while ((ch = getopt(argc, argv, "c:df:")) != -1) {
  switch (ch) {
  case 'c':
  check_period = strtonum(optarg, 1, 600, &errstr);
@@ -124,6 +125,12 @@ main(int argc, char *argv[])
  break;
  case 'd':
  debug = 1;
+ break;
+ case 'f':
+ configfile = optarg;
+ if (access(configfile, R_OK) != 0)
+    err(1, "access configuration file %s",
+ configfile);
  break;
  default:
  usage();

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH] sensorsd - Command line switch for alternative configuration file

Alexander Bluhm
On Wed, Mar 15, 2017 at 08:49:17AM +0100, Silamael wrote:
> On 14.03.2017 12:55, Alexander Bluhm wrote:
> > All other error messages are lower case.  I would write "err(1,
> > "access configuration file %s", configfile)" as err(3) privides a
> > reason anyway.
> >
> > apart from that OK bluhm@
> >
>
> Upated diff.

commited, thanks

bluhm

Loading...