This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add --foreground option for nscd


On Wednesday, May 09, 2012 17:24:10 Pedro Alves wrote:
> On 05/09/2012 03:33 PM, Andreas Jaeger wrote:
> >  int disabled_group;
> > 
> > -int go_background = 1;
> > +
> > +enum
> > +{
> > +  /* Running in foreground but otherwise behave like a daemon,
> > +     i.e., detach from terminal and use syslog.  */
> > +  RUN_FOREGROUND,
> > +  /* Running in background as daemon.  */
> > +  RUN_DAEMONIZE,
> > +  /* Run in foreground in debug mode.  */
> > +  RUN_DEBUG
> > +};
> > +static int run_mode = RUN_DAEMONIZE;
> 
> Since you have an enum, why not make the variable have enum type too?
> If you don't want to give the enum a name/tag, there's always:
> 
> static enum
>  {
>    ...
>  } run_mode = RUN_DAEMONIZE;
> 
> As principle, making the type an enum makes the code easier to debug,
> as "(gdb) print run_mode" then outputs the enum value (RUN_DAEMONIZE,
> etc.) instead of the underlying integer (0, 1, etc.).
> 
> > -  /* Behave like a daemon.  */
> > -  if (go_background)
> > +  if ((run_mode == RUN_DAEMONIZE) || (run_mode == RUN_FOREGROUND))
> 
> GNU style is against such redundant parenthesis.

I'm adding these changes as obvious, tested on Linux/x86-64,

Andreas

2012-05-09  Andreas Jaeger  <aj@suse.de>

	* nscd/nscd.c (run_mode): Use enum.
	(main): Cleanup coding style issue.

diff --git a/nscd/nscd.c b/nscd/nscd.c
index 38a1421..e22d8e8 100644
--- a/nscd/nscd.c
+++ b/nscd/nscd.c
@@ -72,7 +72,7 @@ int do_shutdown;
 int disabled_passwd;
 int disabled_group;
 
-enum
+static enum
 {
   /* Running in foreground but otherwise behave like a daemon,
      i.e., detach from terminal and use syslog.  This allows
@@ -82,8 +82,7 @@ enum
   RUN_DAEMONIZE,
   /* Run in foreground in debug mode.  */
   RUN_DEBUG
-};
-static int run_mode = RUN_DAEMONIZE;
+} run_mode = RUN_DAEMONIZE;
 
 static const char *conffile = _PATH_NSCDCONF;
 
@@ -187,7 +186,7 @@ main (int argc, char **argv)
   /* Determine page size.  */
   pagesize_m1 = getpagesize () - 1;
 
-  if ((run_mode == RUN_DAEMONIZE) || (run_mode == RUN_FOREGROUND))
+  if (run_mode == RUN_DAEMONIZE || run_mode == RUN_FOREGROUND)
     {
       int i;
       pid_t pid;

-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]