[sane-devel] [PATCH v2] saned: reorganize flags, remove run_mode SANED_RUN_DEBUG

2017-09-18 Thread luizluca
From: Luiz Angelo Daros de Luca 

Flags like -a, -d and -s have many overlap effects. This patch restricts
the effect of flags to a simple action.

New -u (user) flag replaces -a optional argument for running saned as a 
different user.
The code that retrieve the user info and drop privileges migrated to 
runas_user().
As a side effect, PID file can be created even if getting user info fails.

New -l (listen) flag sets run_mode to standalone.
New -D (daemonize) flag daemonizes saned after bind.
New -o (once) make saned exit after the first client disconnects.
Flag -s (syslog) is gone. Previous behavior can be reproduced with '-a -d level 
-o -f'.
New -e (stderr) flag for redirecting output to stderr, instead of syslog.

Flag -d (debug) now only sets the debug level and argument is required. 
Previous behavior
can be reproduced with '-a -d level -o -f -e'.

The run_mode SANED_RUN_DEBUG and SANED_RUN_ALONE shared most of its code
path. With the new flags dealing with their difference, SANED_RUN_DEBUG is gone.

Flag '-a' still works as before but it can be replaced by '-l -D -u user'.

Current uses of -d (debug) or -s (syslog) will break.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 NEWS |   8 ++
 doc/saned.man|  72 +--
 frontend/saned.c | 272 +--
 3 files changed, 197 insertions(+), 155 deletions(-)

diff --git a/NEWS b/NEWS
index 9ff64bf2..7d186ad5 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,12 @@
 -*-Mode: outline-*-
+New with the development version, not yet released:
+
+* Saned options where reorganized (See "man 8 saned" for details):
+ o New: -l (listen), -D (daemonize), -o (once), -e (stderr), -u (user).
+ o Removed: -s (syslog). Use '-a -d level -o -f' for the old behavior.
+ o Changed: -d (debug). Use '-a -d level -o -f -e' for the old behavior.
+
+
 New with 1.0.27 (see Note 1), released 2017-05-22:
 
 * Significant enhancements to canon_dr, epjitsu, epsonds, fujitsu,
diff --git a/doc/saned.man b/doc/saned.man
index b716122d..98a5d5e6 100644
--- a/doc/saned.man
+++ b/doc/saned.man
@@ -6,15 +6,21 @@ saned \- SANE network daemon
 .B saned
 .B [ \-a
 .I [ username ]
+.B ]
+.B [ \-u
+.I username
+.B ]
 .B [ \-b
 .I address
 .B ]
-.B | \-d
-.I [ n ]
-.B | \-s
-.I [ n ]
-.B | \-h
+.B [ \-l ]
+.B [ \-D ]
+.B [ \-o ]
+.B [ \-d
+.I n
 .B ]
+.B [ \-e ]
+.B [ \-h ]
 .SH DESCRIPTION
 .B saned
 is the SANE (Scanner Access Now Easy) daemon that allows remote clients
@@ -22,51 +28,59 @@ to access image acquisition devices available on the local 
host.
 .SH OPTIONS
 .PP
 The
-.B \-a
+.B \-l
 flag requests that
 .B saned
 run in standalone daemon mode. In this mode,
 .B saned
-will detach from the console and run in the background, listening for incoming
-client connections;
+will listening for incoming client connections;
 .B inetd
 is not required for
 .B saned
-operations in this mode. If the optional
-.B username
-is given after
+operations in this mode. The
+.B \-b
+flag can control which address
+.B saned
+will bind. The
+.B \-u
+.I username
+flag requests that
+.B saned
+drop root privileges and run as this user (and group) after bind.
+The
+.B \-D
+flag will request
+.B saned
+to detach from the console and run in the background.
+The flag
 .B \-a
-,
+is equals to
+.B \-l \-B \-u
+.I username
+.
+.PP
+The
+.B \-e
+flag will request that 
 .B saned
-will drop root privileges and run as this user (and group).
+output to stderr instead of syslog.
 .PP
 The
 .B \-d
-and
-.B \-s
-flags request that
-.B saned
-run in debug mode (as opposed to
-.BR inetd (8)
-daemon mode).  In this mode,
+flag sets the debug level of
 .B saned
-explicitly waits for a connection request.  When compiled with
-debugging enabled, these flags may be followed by a number to request
+. When compiled with debugging enabled, these flags may be followed by a 
number to request
 debug info. The larger the number, the more verbose the debug output.
 E.g.,
 .B \-d128
 will request printing of all debug info. Debug level 0 means no debug output
-at all. The default value is 2. If flag
-.B \-d
-is used, the debug messages will be printed to stderr while
-.B \-s
-requests using syslog.
+at all. The default value is 2.
 .PP
 The
-.B \-b
+.B \-o
 flag requests that
 .B saned
-bind to a specific address.
+exits after the first client disconnects. Useful for debugging.
 .PP
 If
 .B saned
diff --git a/frontend/saned.c b/frontend/saned.c
index da965421..ed9fec7c 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -251,6 +251,8 @@ static Wire wire;
 static int num_handles;
 static int debug;
 static int run_mode;
+static int run_foreground;
+static int run_once;
 static int data_connect_timeout = 4000;
 static Handle *handle;
 static char *bind_addr;
@@ -299,9 +301,7 @@ static SANE_Bool log_to_syslog = SANE_TRUE;
 static int process_request (Wire * w);
 
 #define SANED_RUN_INETD  0
-#define SANED_RUN_DEBUG  1
-#define 

[sane-devel] [PATCH 3/3] saned: reorganize flags, remove run_mode SANED_RUN_DEBUG

2017-07-22 Thread luizluca
From: Luiz Angelo Daros de Luca 

Flags like -a, -d and -s have many overlap effects. This patch restricts
the effect of flags to a simple action.

New -u (user) flag replaces -a optional argument for running saned as a 
different user.
The code that retrieve the user info and drop privileges migrated to 
runas_user().
As a side effect, PID file can be created even if getting user info fails.

New -l (listen) flag sets run_mode to standalone. It can be cancelled with -i.
New -i (inetd, default) flag sets run_mode to inetd. It is useful only to 
cancel -l.

New -D (daemonize) flag daemonizes saned after bind. Requires -l and it can be 
cancelled
by -f.
New -f (foreground) flag for running saned in foreground (useful for procd).
It can be cancelled using new -D flag.

New -o (once) make saned exit after the first client disconnects.

Flag -s (syslog) now only forces output to syslog and does not accept 
arguments. It can be
cancelled using -e. Previous behavior can be reproduced with '-a -d level -o -f 
-s'.
New -e (stderr) flag for redirecting output to stderr, instead of syslog. It 
can be
cancelled using -s.

Flag -d (debug) now only sets the debug level and argument is required. 
Previous behavior
can be reproduced with '-a -d level -o -f'.

The run_mode SANED_RUN_DEBUG and SANED_RUN_ALONE shared most of its code
path. With the new flags dealing with their difference, SANED_RUN_DEBUG is gone.

Flag '-a' still works as before but it can be replaced by '-l -D -u user'.

Current uses of -d (debug) or -s (syslog) will break.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 doc/saned.man|  78 --
 frontend/saned.c | 306 +++
 2 files changed, 220 insertions(+), 164 deletions(-)

diff --git a/doc/saned.man b/doc/saned.man
index 8542d254..0bddc58d 100644
--- a/doc/saned.man
+++ b/doc/saned.man
@@ -6,15 +6,21 @@ saned \- SANE network daemon
 .B saned
 .B [ \-a
 .I [ username ]
+.B ]
+.B [ \-u
+.I username
+.B ]
 .B [ \-b
 .I address
 .B ]
-.B | \-d
-.I [ n ]
-.B | \-s
-.I [ n ]
-.B | \-h
+.B [ \-l | \-i ]
+.B [ \-D | \-f ]
+.B [ \-o ]
+.B [ \-d
+.I n
 .B ]
+.B [ \-s | \-e ]
+.B [ \-h ]
 .SH DESCRIPTION
 .B saned
 is the SANE (Scanner Access Now Easy) daemon that allows remote clients
@@ -22,51 +28,63 @@ to access image acquisition devices available on the local 
host.
 .SH OPTIONS
 .PP
 The
-.B \-a
+.B \-l
 flag requests that
 .B saned
 run in standalone daemon mode. In this mode,
 .B saned
-will detach from the console and run in the background, listening for incoming
-client connections;
+will listening for incoming client connections;
 .B inetd
 is not required for
 .B saned
-operations in this mode. If the optional
-.B username
-is given after
-.B \-a
-,
+operations in this mode. The
+.B \-b
+flag can control which address
 .B saned
-will drop root privileges and run as this user (and group).
+will bind. The
+.B \-u
+.I username
+flag requests that
+.B saned
+drop root privileges and run as this user (and group) after bind.
+The
+.B \-B
+flag will request
+.B saned
+to detach from the console and run in the background, while 
+.B \-f
+flag will keep it attached to the console and running foreground.
+The flag
+.B \-a
+is equals to
+.B \-l \-B \-u
+.I username
+.
+.PP
+The
+.B \-e
+flag will request that 
+.B saned
+output to stderr while the
+.B \-s
+flag forces the output to syslog.
 .PP
 The
 .B \-d
-and
-.B \-s
-flags request that
+flag sets the debug level of
 .B saned
-run in debug mode (as opposed to
-.BR inetd (8)
-daemon mode).  In this mode,
-.B saned
-explicitly waits for a connection request.  When compiled with
-debugging enabled, these flags may be followed by a number to request
+. When compiled with debugging enabled, these flags may be followed by a 
number to request
 debug info. The larger the number, the more verbose the debug output.
 E.g.,
 .B \-d128
 will request printing of all debug info. Debug level 0 means no debug output
-at all. The default value is 2. If flag
-.B \-d
-is used, the debug messages will be printed to stderr while
-.B \-s
-requests using syslog.
+at all. The default value is 2.
 .PP
 The
-.B \-b
+.B \-o
 flag requests that
 .B saned
-bind to a specific address.
+exits after the first client disconnects. Useful for debugging.
 .PP
 If
 .B saned
diff --git a/frontend/saned.c b/frontend/saned.c
index 6b97e914..93afd612 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -251,6 +251,8 @@ static Wire wire;
 static int num_handles;
 static int debug;
 static int run_mode;
+static int run_foreground;
+static int run_once;
 static Handle *handle;
 static char *bind_addr;
 static union
@@ -298,9 +300,10 @@ static SANE_Bool log_to_syslog = SANE_TRUE;
 static int process_request (Wire * w);
 
 #define SANED_RUN_INETD  0
-#define SANED_RUN_DEBUG  1
-#define SANED_RUN_ALONE  2
+#define SANED_RUN_ALONE  1
 
+#define SANED_EXEC_FOREGROUND 0
+#define SANED_EXEC_BACKGROUND 1
 

[sane-devel] [PATCH 2/3] saned: update man for option -b

2017-07-22 Thread luizluca
From: Luiz Angelo Daros de Luca 

---
 doc/saned.man | 9 +
 1 file changed, 9 insertions(+)

diff --git a/doc/saned.man b/doc/saned.man
index 34764f1f..8542d254 100644
--- a/doc/saned.man
+++ b/doc/saned.man
@@ -6,6 +6,9 @@ saned \- SANE network daemon
 .B saned
 .B [ \-a
 .I [ username ]
+.B [ \-b
+.I address
+.B ]
 .B | \-d
 .I [ n ]
 .B | \-s
@@ -59,6 +62,12 @@ is used, the debug messages will be printed to stderr while
 .B \-s
 requests using syslog.
 .PP
+The
+.B \-b
+flag requests that
+.B saned
+bind to a specific address.
+.PP
 If
 .B saned
 is run from inetd, xinetd or systemd, no option can be given.
-- 
2.11.0


-- 
sane-devel mailing list: sane-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
 to sane-devel-requ...@lists.alioth.debian.org


[sane-devel] [PATCH 1/3] saned: fix --debug help message (output is stderr)

2017-07-22 Thread luizluca
From: Luiz Angelo Daros de Luca 

Man page was correct.

Signed-off-by: Luiz Angelo Daros de Luca 
---
 frontend/saned.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/frontend/saned.c b/frontend/saned.c
index 2fc33216..6b97e914 100644
--- a/frontend/saned.c
+++ b/frontend/saned.c
@@ -3300,7 +3300,7 @@ static void usage(char *me, int err)
"Usage: %s [OPTIONS]\n\n"
" Options:\n\n"
"  -a, --alone[=user]   run standalone and fork in background as 
`user'\n"
-   "  -d, --debug[=level]  run foreground with output to stdout\n"
+   "  -d, --debug[=level]  run foreground with output to stderr\n"
"   and debug level `level' (default is 2)\n"
"  -s, --syslog[=level] run foreground with output to syslog\n"
"   and debug level `level' (default is 2)\n"
-- 
2.11.0


-- 
sane-devel mailing list: sane-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
 to sane-devel-requ...@lists.alioth.debian.org