Author: grothoff Date: 2006-07-26 02:13:36 -0700 (Wed, 26 Jul 2006) New Revision: 3140
Modified: GNUnet/src/server/gnunetd.c GNUnet/src/server/startup.c GNUnet/src/server/startup.h Log: s Modified: GNUnet/src/server/gnunetd.c =================================================================== --- GNUnet/src/server/gnunetd.c 2006-07-26 04:58:54 UTC (rev 3139) +++ GNUnet/src/server/gnunetd.c 2006-07-26 09:13:36 UTC (rev 3140) @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2004, 2005, 2006 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -28,6 +28,8 @@ */ #include "gnunet_util.h" +#include "gnunet_util_config_impl.h" +#include "gnunet_util_error_loggers.h" #include "gnunet_core.h" #include "core.h" #include "connection.h" @@ -36,18 +38,7 @@ #include "startup.h" #include "version.h" -void gnunet_main(); - -#ifdef MINGW /** - * Main method of the windows service - */ -void WINAPI ServiceMain(DWORD argc, LPSTR *argv) { - win_service_main(gnunet_main); -} -#endif - -/** * The main method of gnunetd. And here is how it works: * <ol> * <li>detach from tty, initialize all coresystems @@ -80,9 +71,10 @@ if (NO == debug_flag()) detachFromTerminal(filedes); - LOG(LOG_MESSAGE, - _("`%s' starting\n"), - "gnunetd"); + GE_LOG(ectx, + GE_INFO | GE_USER | GE_REQUEST, + _("`%s' starting\n"), + "gnunetd"); initCore(); initConnection(); /* requires core, starts transports! */ @@ -102,15 +94,17 @@ a SIGUSR1 which will wake us up from the sleep */ initSignalHandlers(); - LOG(LOG_MESSAGE, - _("`%s' startup complete.\n"), - "gnunetd"); - + GE_LOG(ectx, + GE_INFO | GE_USER | GE_REQUEST, + _("`%s' startup complete.\n"), + "gnunetd"); + waitForSignalHandler(); - LOG(LOG_MESSAGE, - _("`%s' is shutting down.\n"), - "gnunetd"); - + GE_LOG(ectx, + GE_INFO | GE_USER | GE_REQUEST, + _("`%s' is shutting down.\n"), + "gnunetd"); + /* init 5: shutdown */ disableCoreProcessing(); /* calls on applications! */ stopCron(); /* avoid concurrency! */ @@ -123,18 +117,54 @@ /* init 6: goodbye */ deletePIDFile(); doneSignalHandlers(); - doneUtil(); } +#ifdef MINGW /** + * Main method of the windows service + */ +void WINAPI ServiceMain(DWORD argc, LPSTR *argv) { + win_service_main(gnunet_main); +} +#endif + +/** * Initialize util (parse command line, options) and * call the main routine. */ -int main(int argc, char * argv[]) { - checkCompiler(); +int main(int argc, + char * argv[]) { + int ret; + struct GC_Configuration * cfg; + struct GE_Context * ectx; + + if ( (4 != sizeof(MESSAGE_HEADER)) || + (600 != sizeof(P2P_hello_MESSAGE)) ) { + fprintf(stderr, + "Sorry, your C compiler did not properly align the C structs. Aborting.\n"); + return -1; + } + + ectx = GE_create_context_stderr(NO, + GE_WARNING | GE_ERROR | GE_FATAL | + GE_USER | GE_ADMIN | GE_DEVELOPER | + GE_IMMEDIATE | GE_BULK); + GE_setDefaultContext(ectx); + cfg = GC_create_C_impl(); + GE_ASSERT(ectx, cfg != NULL); /* init 1: get options and basic services up */ - if (SYSERR == initUtil(argc, argv, &parseGnunetdCommandLine)) - return 0; /* parse error, --help, etc. */ + ret = gnunet_parse_options("gnunetd", + ectx, + cfg, + &gnunetdOptions, + (unsigned int) argc, + argv); + if (ret == -1) { + GC_free(cfg); + GE_free_context(ectx); + return -1; + } + /* now: patch up default context according to config! */ #ifdef MINGW if (win_service()) { @@ -146,7 +176,7 @@ } else #endif gnunet_main(); - + return 0; } Modified: GNUnet/src/server/startup.c =================================================================== --- GNUnet/src/server/startup.c 2006-07-26 04:58:54 UTC (rev 3139) +++ GNUnet/src/server/startup.c 2006-07-26 09:13:36 UTC (rev 3140) @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2004, 2005, 2006 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -38,9 +38,9 @@ #include "tcpserver.h" #include "core.h" +#include "startup.h" - /** * This flag is set if gnunetd is not (to be) detached from the * console. @@ -72,7 +72,7 @@ /** * This flag is set if gnunetd is shutting down. */ -static Semaphore * doShutdown; +static struct SEMAPHORE * doShutdown; /* ************* SIGNAL HANDLING *********** */ @@ -218,7 +218,7 @@ struct sigaction oldsig; #endif - doShutdown = SEMAPHORE_NEW(0); + doShutdown = SEMAPHORE_CREATE(0); #ifndef MINGW sig.sa_handler = &shutdown_gnunetd; @@ -240,7 +240,7 @@ if (SYSERR == registerCSHandler(CS_PROTO_SHUTDOWN_REQUEST, &shutdownHandler)) - GNUNET_ASSERT(0); + GE_ASSERT(ectx, 0); } void doneSignalHandlers() { @@ -261,7 +261,8 @@ #else SetConsoleCtrlHandler(&win_shutdown_gnunetd, TRUE); #endif - SEMAPHORE_FREE(doShutdown); + SEMAPHORE_DESTROY(doShutdown); + doShutdown = NULL; } /** @@ -306,18 +307,6 @@ } -/* *********** SYSTEM CHECKS ON STARTUP ************ */ - -/** - * Check if the compiler did a decent job aligning the structs... - */ -void checkCompiler() { - GNUNET_ASSERT(sizeof(P2P_hello_MESSAGE) == 600); - GNUNET_ASSERT(sizeof(P2P_MESSAGE_HEADER) == 4); -} - -/* *********** PID file handling *************** */ - static char * getPIDFile() { return getFileName("GNUNETD", "PIDFILE", Modified: GNUnet/src/server/startup.h =================================================================== --- GNUnet/src/server/startup.h 2006-07-26 04:58:54 UTC (rev 3139) +++ GNUnet/src/server/startup.h 2006-07-26 09:13:36 UTC (rev 3140) @@ -1,6 +1,8 @@ /* This file is part of GNUnet + (C) 2001, 2002, 2004, 2005, 2006 Christian Grothoff (and other contributing authors) + GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your @@ -34,29 +36,18 @@ #include "gnunet_util.h" #include "platform.h" -int debug_flag(); +int debug_flag(void); -int win_service(); +int win_service(void); /** - * Check if the compiler did a decent job. - **/ -void checkCompiler(); - -/** - * Perform option parsing from the command line. - **/ -int parseGnunetdCommandLine(int argc, - char * argv[]); - -/** * Initialize signal handlers **/ -void initSignalHandlers(); +void initSignalHandlers(void); -void doneSignalHandlers(); +void doneSignalHandlers(void); -void waitForSignalHandler(); +void waitForSignalHandler(void); /** * Fork and start a new session to go into the background @@ -76,17 +67,17 @@ /** * Write our process ID to the pid file. **/ -void writePIDFile(); +void writePIDFile(void); /** * Delete the pid file. **/ -void deletePIDFile(); +void deletePIDFile(void); /** * Load all of the user-specified application modules. */ -void loadApplicationModules(); +void loadApplicationModules(void); #ifndef MINGW /** _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn