Author: durner Date: 2006-07-31 12:20:32 -0700 (Mon, 31 Jul 2006) New Revision: 3204
Added: GNUnet/src/util/os/init.c Removed: GNUnet/src/util/initialize.c Modified: GNUnet/configure.ac GNUnet/src/include/gnunet_util_os.h GNUnet/src/server/gnunetd.c GNUnet/src/util/Makefile.am GNUnet/src/util/getopt/getopt.c GNUnet/src/util/os/Makefile.am GNUnet/src/util/os/semaphore.c GNUnet/src/util/threads/pthread.c GNUnet/src/util/threads/shutdown.c GNUnet/src/util/threads/signal.c GNUnet/src/util/win/winproc.c Log: towards fixing MinGW Modified: GNUnet/configure.ac =================================================================== --- GNUnet/configure.ac 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/configure.ac 2006-07-31 19:20:32 UTC (rev 3204) @@ -164,6 +164,8 @@ AC_CHECK_MEMBER(pthread_t.p, AC_DEFINE(HAVE_NEW_PTHREAD_T, 1, [Define if you have a post 11/2004 pthread library]), , [#include <pthread.h>]) +AC_CHECK_FUNCS(pthread_equal) + # libgcrypt gcrypt=0 AC_MSG_CHECKING(for libgcrypt) Modified: GNUnet/src/include/gnunet_util_os.h =================================================================== --- GNUnet/src/include/gnunet_util_os.h 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/include/gnunet_util_os.h 2006-07-31 19:20:32 UTC (rev 3204) @@ -307,7 +307,18 @@ int * filedes, int success); +/** + * @brief Perform OS specific initalization + * @param ectx logging context, NULL means stderr + * @returns OK on success, SYSERR otherwise + */ +int os_init(struct GE_Context *ectx); +/** + * @brief Perform OS specific cleanup + */ +void os_done(); + #if 0 /* keep Emacsens' auto-indent happy */ { #endif Modified: GNUnet/src/server/gnunetd.c =================================================================== --- GNUnet/src/server/gnunetd.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/server/gnunetd.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -191,6 +191,7 @@ GE_setDefaultContext(ectx); cfg = GC_create_C_impl(); GE_ASSERT(ectx, cfg != NULL); + os_init(); if (-1 == gnunet_parse_options("gnunetd", ectx, cfg, @@ -218,6 +219,7 @@ } ret = gnunet_main(ectx); GC_free(cfg); + os_done(); GE_free_context(ectx); if (ret != OK) return 1; Modified: GNUnet/src/util/Makefile.am =================================================================== --- GNUnet/src/util/Makefile.am 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/Makefile.am 2006-07-31 19:20:32 UTC (rev 3204) @@ -57,6 +57,3 @@ -export-dynamic $(LIBLTDL) $(LIBGCRYPT_LIBS) $(SOLFLAGS) $(WINFLAGS) $(LIBS) -lgmp $(DLFLAG) \ -version-info 1:0:0 -libgnunetutil_la_SOURCES = \ - initialize.c - Modified: GNUnet/src/util/getopt/getopt.c =================================================================== --- GNUnet/src/util/getopt/getopt.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/getopt/getopt.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -67,11 +67,6 @@ # endif #endif -/** - * 32-bit timer value. - */ -typedef unsigned int TIME_T; - /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct GNoption' terminated by an element containing a name which is Deleted: GNUnet/src/util/initialize.c =================================================================== --- GNUnet/src/util/initialize.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/initialize.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -1,45 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2001, 2002, 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 - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file util/initialize.c - * @brief functions to initializing libgnunetutil in the proper order. - * @author Christian Grothoff - */ - -#include "platform.h" -#include "gnunet_util.h" - -#ifdef MINGW -/** - * Initialize the util library. - */ -int __attribute__ ((constructor)) gnunet_util_init() { - if (InitWinEnv() != ERROR_SUCCESS) - return SYSERR; - return OK; -} - -void __attribute__ ((destructor)) gnunet_util_fini() { - ShutdownWinEnv(); -} -#endif - -/* end of initialize.c */ Modified: GNUnet/src/util/os/Makefile.am =================================================================== --- GNUnet/src/util/os/Makefile.am 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/os/Makefile.am 2006-07-31 19:20:32 UTC (rev 3204) @@ -10,6 +10,7 @@ cpustatus.c \ daemon.c \ dso.c \ + init.c \ osconfig.c \ priority.c \ semaphore.c \ Added: GNUnet/src/util/os/init.c =================================================================== --- GNUnet/src/util/os/init.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/os/init.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -0,0 +1,55 @@ +/* + This file is part of GNUnet. + (C) 2001, 2002, 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 + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file util/os/init.c + * @brief functions to initialize os specifics + * @author Christian Grothoff + */ + +#include "platform.h" +#include "gnunet_util.h" + +/** + * @brief Perform OS specific initalization + * @param ectx logging context, NULL means stderr + * @returns OK on success, SYSERR otherwise + */ +int os_init(struct GE_Context *ectx) +{ +#ifdef MINGW + if (InitWinEnv(ectx) != ERROR_SUCCESS) + return SYSERR; + else +#endif + return OK; +} + +/** + * @brief Perform OS specific cleanup + */ +void os_done() +{ +#ifdef MINGW + ShutdownWinEnv(); +#endif +} + +/* end of init.c */ Modified: GNUnet/src/util/os/semaphore.c =================================================================== --- GNUnet/src/util/os/semaphore.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/os/semaphore.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -209,7 +209,7 @@ } if (! ret->internal) { GE_LOG(ectx, - GE_FAILURE | GE_USER | GE_DEVELOPER | GE_BULK, + GE_FATAL | GE_USER | GE_DEVELOPER | GE_BULK, _("Can't create semaphore: %i"), dwErr); DIE_STRERROR_FILE(ectx, Modified: GNUnet/src/util/threads/pthread.c =================================================================== --- GNUnet/src/util/threads/pthread.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/threads/pthread.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -51,7 +51,7 @@ */ int PTHREAD_TEST_SELF(PThread * handle) { GE_ASSERT(NULL, handle != NULL); -#if pthread_equal +#if HAVE_PTHREAD_EQUAL if (pthread_equal(pthread_self(), handle->pt)) #else #if HAVE_NEW_PTHREAD_T Modified: GNUnet/src/util/threads/shutdown.c =================================================================== --- GNUnet/src/util/threads/shutdown.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/threads/shutdown.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -64,21 +64,49 @@ } /** + * Stop the application under Windows. + * @param signum is ignored + */ +#ifdef MINGW +BOOL WINAPI run_shutdown_win(DWORD dwCtrlType) +{ + switch(dwCtrlType) + { + case CTRL_C_EVENT: + case CTRL_CLOSE_EVENT: + case CTRL_SHUTDOWN_EVENT: + case CTRL_LOGOFF_EVENT: + run_shutdown(); + } + + return TRUE; +} +#endif + +/** * Initialize the signal handlers, etc. */ void __attribute__ ((constructor)) shutdown_handlers_ltdl_init() { GE_ASSERT(NULL, shutdown_signal == NULL); GE_ASSERT(NULL, shutdown_active == NO); shutdown_signal = SEMAPHORE_CREATE(0); +#ifndef MINGW shc_int = signal_handler_install(SIGINT, &run_shutdown); shc_term = signal_handler_install(SIGTERM, &run_shutdown); shc_quit = signal_handler_install(SIGQUIT, &run_shutdown); +#else + SetConsoleCtrlHandler(&run_shutdown_win, TRUE); +#endif } void __attribute__ ((destructor)) shutdown_handlers_ltdl_fini() { +#ifndef MINGW signal_handler_uninstall(SIGINT, &run_shutdown, shc_int); signal_handler_uninstall(SIGTERM, &run_shutdown, shc_term); signal_handler_uninstall(SIGQUIT, &run_shutdown, shc_quit); +#else + SetConsoleCtrlHandler(&run_shutdown_win, FALSE); +#endif SEMAPHORE_DESTROY(shutdown_signal); shutdown_signal = NULL; shc_int = NULL; Modified: GNUnet/src/util/threads/signal.c =================================================================== --- GNUnet/src/util/threads/signal.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/threads/signal.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -28,14 +28,13 @@ #include "gnunet_util_string.h" #include "platform.h" +#ifndef MINGW typedef struct SignalHandlerContext { int sig; SignalHandler method; -#ifndef MINGW struct sigaction oldsig; -#endif } SignalHandlerContext; struct SignalHandlerContext * signal_handler_install(int signal, @@ -46,7 +45,7 @@ ret = MALLOC(sizeof(struct SignalHandlerContext)); ret->sig = signal; ret->method = handler; -#ifndef MINGW + sig.sa_handler = (void*) handler; sigemptyset(&sig.sa_mask); #ifdef SA_INTERRUPT @@ -55,23 +54,16 @@ sig.sa_flags = SA_RESTART; #endif sigaction(signal, &sig, &ret->oldsig); -#else - /* FIXME: mingw! */ -#endif return ret; } void signal_handler_uninstall(int signal, SignalHandler handler, struct SignalHandlerContext * ctx) { -#ifndef MINGW struct sigaction sig; GE_ASSERT(NULL, (ctx->sig == signal) && (ctx->method == handler)); sigemptyset(&sig.sa_mask); sigaction(signal, &ctx->oldsig, &sig); -#else - /* FIXME: mingw! */ -#endif } - +#endif Modified: GNUnet/src/util/win/winproc.c =================================================================== --- GNUnet/src/util/win/winproc.c 2006-07-31 16:44:20 UTC (rev 3203) +++ GNUnet/src/util/win/winproc.c 2006-07-31 19:20:32 UTC (rev 3204) @@ -32,6 +32,8 @@ #ifdef MINGW static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi; +static struct GE_Context *pEctx = NULL; + TNtQuerySystemInformation GNNtQuerySystemInformation; TGetIfEntry GNGetIfEntry; TGetIpAddrTable GNGetIpAddrTable; @@ -68,17 +70,25 @@ /** * Log (panic) messages from PlibC */ -void plibc_panic(int err, char *msg) { - LOG((err = INT_MAX) ? LOG_DEBUG : LOG_FAILURE, "%s", msg); +void plibc_panic(int err, char *msg) +{ + if (!pEctx) + fprintf(stderr, "%s", msg); + else + GE_LOG(pEctx, ((err == INT_MAX) ? GE_DEBUG : GE_FATAL) | GE_USER | GE_ADMIN | + GE_IMMEDIATE, "%s", msg); } /** - * Initialize PlibC and set up Windows environment + * @brief Initialize PlibC and set up Windows environment + * @param logging context, NULL means stderr * @return Error code from winerror.h, ERROR_SUCCESS on success */ -int InitWinEnv() +int InitWinEnv(struct GE_Context *ectx) { int ret; + + pEctx = ectx; plibc_set_panic_proc(plibc_panic); ret = plibc_init("GNU", PACKAGE); @@ -234,6 +244,8 @@ FreeLibrary(hNetapi); CoUninitialize(); + + pEctx = NULL; } #endif /* MINGW */ _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn