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 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.

-- 
Pedro Alves


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