From 10cb56ae4e463e404d4d3ba2147340809d608ed8 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 13 Jun 2012 08:38:15 +0000 Subject: [PATCH] -minor optimization --- src/util/os_installation.c | 26 ++++++++++++++++++-------- src/util/os_priority.c | 5 +++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/util/os_installation.c b/src/util/os_installation.c index e790ce10e..2e1acac64 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c @@ -520,16 +520,26 @@ GNUNET_OS_check_helper_binary (const char *binary) return GNUNET_NO; #else GNUNET_free (p); - rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); - if (INVALID_SOCKET == rawsock) { - DWORD err = GetLastError (); + static int once; /* remember result from previous runs... */ - LOG (GNUNET_ERROR_TYPE_INFO, - "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); - return GNUNET_NO; /* not running as administrator */ - } - closesocket (rawsock); + if (0 == once) + { + rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); + if (INVALID_SOCKET == rawsock) + { + DWORD err = GetLastError (); + + LOG (GNUNET_ERROR_TYPE_INFO, + "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); + once = -1; + return GNUNET_NO; /* not running as administrator */ + } + once = 1; + closesocket (rawsock); + } + if (-1 == once) + return GNUNET_NO; return GNUNET_YES; #endif } diff --git a/src/util/os_priority.c b/src/util/os_priority.c index cafb1504c..e53dbfa2d 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -795,6 +795,8 @@ start_process (int pipe_control, int fd_stdin_read; int fd_stdin_write; + if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename)) + return NULL; /* not executable */ if ( (GNUNET_YES == pipe_control) && (GNUNET_OK != npipe_setup (&childpipename)) ) return NULL; @@ -952,6 +954,9 @@ start_process (int pipe_control, long lRet; HANDLE stdin_handle; HANDLE stdout_handle; + + if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename)) + return NULL; /* not executable */ /* Search in prefix dir (hopefully - the directory from which * the current module was loaded), bindir and libdir, then in PATH -- 2.25.1