From dc0ce6f158ec9d9bd74144f78fc0b955bb00a7f1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Mar 2003 13:42:38 +0000 Subject: Convert to popt. (This used to be commit 18d52ce914715d188966be95f9e4466666a04f74) --- source3/nsswitch/winbindd.c | 84 ++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 58 deletions(-) (limited to 'source3/nsswitch') diff --git a/source3/nsswitch/winbindd.c b/source3/nsswitch/winbindd.c index 4033952a6e..c9d6808316 100644 --- a/source3/nsswitch/winbindd.c +++ b/source3/nsswitch/winbindd.c @@ -5,6 +5,7 @@ Copyright (C) by Tim Potter 2000-2002 Copyright (C) Andrew Tridgell 2002 + Copyright (C) Jelmer Vernooij 2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,7 +32,6 @@ BOOL opt_dual_daemon = False; static BOOL reload_services_file(BOOL test) { BOOL ret; - pstring logfile; if (lp_loaded()) { pstring fname; @@ -806,27 +806,26 @@ BOOL winbind_setup_common(void) struct winbindd_state server_state; /* Server state information */ - -static void usage(void) -{ - printf("Usage: winbindd [options]\n"); - printf("\t-F daemon in foreground mode\n"); - printf("\t-S log to stdout\n"); - printf("\t-i interactive mode\n"); - printf("\t-B dual daemon mode\n"); - printf("\t-n disable cacheing\n"); - printf("\t-d level set debug level\n"); - printf("\t-s configfile choose smb.conf location\n"); - printf("\t-h show this help message\n"); -} - - int main(int argc, char **argv) +int main(int argc, char **argv) { - extern BOOL AllowDebugChange; pstring logfile; - BOOL interactive = False; - BOOL Fork = True; - BOOL log_stdout = False; + static BOOL interactive = False; + static BOOL Fork = True; + static BOOL log_stdout = False; + struct poptOption long_options[] = { + POPT_AUTOHELP + POPT_COMMON_SAMBA + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, + { "stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, + { "foreground", 'F', POPT_ARG_VAL, &Fork, False, "Daemon in foreground mode" }, + { "interactive", 'i', POPT_ARG_NONE, NULL, 'i', "Interactive mode" }, + { "dual-daemon", 'B', POPT_ARG_VAL, &opt_dual_daemon, True, "Dual daemon mode" }, + { "no-caching", 'n', POPT_ARG_VAL, &opt_nocache, False, "Disable caching" }, + + { 0, 0, 0, 0 } + }; + poptContext pc; int opt; /* glibc (?) likes to print "User defined signal 1" and exit if a @@ -850,56 +849,24 @@ static void usage(void) /* Initialise samba/rpc client stuff */ - while ((opt = getopt(argc, argv, "FSid:s:nhB")) != EOF) { - switch (opt) { + pc = poptGetContext("winbindd", argc, (const char **)argv, long_options, + POPT_CONTEXT_KEEP_FIRST); - case 'F': - Fork = False; - break; - case 'S': - log_stdout = True; - break; + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { /* Don't become a daemon */ case 'i': interactive = True; log_stdout = True; Fork = False; break; - - /* dual daemon system */ - case 'B': - opt_dual_daemon = True; - break; - - /* disable cacheing */ - case 'n': - opt_nocache = True; - break; - - /* Run with specified debug level */ - case 'd': - DEBUGLEVEL = atoi(optarg); - AllowDebugChange = False; - break; - - /* Load a different smb.conf file */ - case 's': - pstrcpy(dyn_CONFIGFILE,optarg); - break; - - case 'h': - usage(); - exit(0); - - default: - printf("Unknown option %c\n", (char)opt); - exit(1); } } + if (log_stdout && Fork) { printf("Can't log to stdout (-S) unless daemon is in foreground +(-F) or interactive (-i)\n"); - usage(); + poptPrintUsage(pc, stderr, 0); exit(1); } @@ -950,6 +917,7 @@ static void usage(void) DEBUG(0, ("unable to initialise messaging system\n")); exit(1); } + poptFreeContext(pc); register_msg_pool_usage(); message_register(MSG_REQ_TALLOC_USAGE, return_all_talloc_info); -- cgit