gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21948 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r21948 - gnunet/src/util
Date: Wed, 13 Jun 2012 10:58:42 +0200

Author: grothoff
Date: 2012-06-13 10:58:42 +0200 (Wed, 13 Jun 2012)
New Revision: 21948

Modified:
   gnunet/src/util/os_installation.c
   gnunet/src/util/os_priority.c
   gnunet/src/util/test_resolver_api.c
Log:
-fixes and cleanup

Modified: gnunet/src/util/os_installation.c
===================================================================
--- gnunet/src/util/os_installation.c   2012-06-13 08:38:15 UTC (rev 21947)
+++ gnunet/src/util/os_installation.c   2012-06-13 08:58:42 UTC (rev 21948)
@@ -56,8 +56,7 @@
   char *lgu;
 
   GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/maps", getpid ());
-  f = FOPEN (fn, "r");
-  if (f == NULL)
+  if (NULL == (f = FOPEN (fn, "r")))
     return NULL;
   while (NULL != fgets (line, sizeof (line), f))
   {
@@ -74,6 +73,7 @@
   return NULL;
 }
 
+
 /**
  * Try to determine path by reading /proc/PID/exe
  */
@@ -131,6 +131,7 @@
 #if DARWIN
 typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t * bufsize);
 
+
 static char *
 get_path_from_NSGetExecutablePath ()
 {
@@ -138,22 +139,19 @@
   char *path;
   size_t len;
   MyNSGetExecutablePathProto func;
-  int ret;
 
   path = NULL;
-  func =
-      (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, 
"_NSGetExecutablePath");
-  if (!func)
+  if (NULL == (func =
+              (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, 
"_NSGetExecutablePath")))
     return NULL;
   path = &zero;
   len = 0;
   /* get the path len, including the trailing \0 */
   func (path, &len);
-  if (len == 0)
+  if (0 == len)
     return NULL;
   path = GNUNET_malloc (len);
-  ret = func (path, &len);
-  if (ret != 0)
+  if (0 != func (path, &len))
   {
     GNUNET_free (path);
     return NULL;
@@ -165,11 +163,13 @@
   return path;
 }
 
+
 static char *
 get_path_from_dyld_image ()
 {
   const char *path;
-  char *p, *s;
+  char *p;
+  char *s;
   int i;
   int c;
 
@@ -180,11 +180,11 @@
     if (_dyld_get_image_header (i) == &_mh_dylib_header)
     {
       path = _dyld_get_image_name (i);
-      if (path != NULL && strlen (path) > 0)
+      if ( (NULL != path) && (strlen (path) > 0) )
       {
         p = GNUNET_strdup (path);
         s = p + strlen (p);
-        while ((s > p) && (*s != '/'))
+        while ((s > p) && ('/' != *s))
           s--;
         s++;
         *s = '\0';
@@ -196,6 +196,7 @@
 }
 #endif
 
+
 /**
  * Return the actual path to a file found in the current
  * PATH environment variable.
@@ -213,7 +214,7 @@
   const char *p;
 
   p = getenv ("PATH");
-  if (p == NULL)
+  if (NULL == p)
     return NULL;
   path = GNUNET_strdup (p);     /* because we write on it */
   buf = GNUNET_malloc (strlen (path) + 20);
@@ -232,7 +233,7 @@
     pos = end + 1;
   }
   sprintf (buf, "%s/%s", pos, binary);
-  if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
+  if (GNUNET_YES == GNUNET_DISK_file_test (buf))
   {
     pos = GNUNET_strdup (pos);
     GNUNET_free (buf);
@@ -244,17 +245,18 @@
   return NULL;
 }
 
+
 static char *
 get_path_from_GNUNET_PREFIX ()
 {
   const char *p;
 
-  p = getenv ("GNUNET_PREFIX");
-  if (p != NULL)
+  if (NULL != (p = getenv ("GNUNET_PREFIX")))
     return GNUNET_strdup (p);
   return NULL;
 }
 
+
 /**
  * @brief get the path to GNUnet bin/ or lib/, prefering the lib/ path
  * @author Milan
@@ -266,32 +268,25 @@
 {
   char *ret;
 
-  ret = get_path_from_GNUNET_PREFIX ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_GNUNET_PREFIX ()))
     return ret;
 #if LINUX
-  ret = get_path_from_proc_maps ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_proc_maps ()))
     return ret;
-  ret = get_path_from_proc_exe ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_proc_exe ()))
     return ret;
 #endif
 #if WINDOWS
-  ret = get_path_from_module_filename ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_module_filename ()))
     return ret;
 #endif
 #if DARWIN
-  ret = get_path_from_dyld_image ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_dyld_image ()))
     return ret;
-  ret = get_path_from_NSGetExecutablePath ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
     return ret;
 #endif
-  ret = get_path_from_PATH ("gnunet-arm");
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_PATH ("gnunet-arm")))
     return ret;
   /* other attempts here */
   LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -312,24 +307,20 @@
 {
   char *ret;
 
-  ret = NULL;
 #if LINUX
-  ret = get_path_from_proc_exe ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_proc_exe ()))
     return ret;
 #endif
 #if WINDOWS
-  ret = get_path_from_module_filename ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_module_filename ()))
     return ret;
 #endif
 #if DARWIN
-  ret = get_path_from_NSGetExecutablePath ();
-  if (ret != NULL)
+  if (NULL != (ret = get_path_from_NSGetExecutablePath ()))
     return ret;
 #endif
   /* other attempts here */
-  return ret;
+  return NULL;
 }
 
 
@@ -355,21 +346,21 @@
 
   /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some
    * guess for the current app */
-  if (execpath == NULL)
+  if (NULL == execpath)
     execpath = os_get_gnunet_path ();
 
-  if (execpath == NULL)
+  if (NULL == execpath)
     return NULL;
 
   n = strlen (execpath);
-  if (n == 0)
+  if (0 == n)
   {
     /* should never happen, but better safe than sorry */
     GNUNET_free (execpath);
     return NULL;
   }
   /* remove filename itself */
-  while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR))
+  while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1]))
     execpath[--n] = '\0';
 
   isbasedir = 1;
@@ -377,7 +368,7 @@
       ((0 == strcasecmp (&execpath[n - 5], "lib32")) ||
        (0 == strcasecmp (&execpath[n - 5], "lib64"))))
   {
-    if (dirkind != GNUNET_OS_IPK_LIBDIR)
+    if (GNUNET_OS_IPK_LIBDIR != dirkind)
     {
       /* strip '/lib32' or '/lib64' */
       execpath[n - 5] = '\0';
@@ -458,30 +449,39 @@
   struct stat statbuf;
   char *p;
   char *pf;
-
 #ifdef MINGW
   SOCKET rawsock;
   char *binaryexe;
 
   GNUNET_asprintf (&binaryexe, "%s.exe", binary);
-  p = get_path_from_PATH (binaryexe);
-  if (p != NULL)
+  if (DIR_SEPARATOR == binary[0])
+    p = GNUNET_strdup (binary);
+  else
   {
-    GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
-    GNUNET_free (p);
-    p = pf;
+    p = get_path_from_PATH (binaryexe);
+    if (NULL != p)
+    {
+      GNUNET_asprintf (&pf, "%s/%s", p, binaryexe);
+      GNUNET_free (p);
+      p = pf;
+    }
   }
   GNUNET_free (binaryexe);
 #else
-  p = get_path_from_PATH (binary);
-  if (p != NULL)
+  if (DIR_SEPARATOR == binary[0])
+    p = GNUNET_strdup (binary);
+  else
   {
-    GNUNET_asprintf (&pf, "%s/%s", p, binary);
-    GNUNET_free (p);
-    p = pf;
+    p = get_path_from_PATH (binary);
+    if (NULL != p)
+    {
+      GNUNET_asprintf (&pf, "%s/%s", p, binary);
+      GNUNET_free (p);
+      p = pf;
+    }
   }
 #endif
-  if (p == NULL)
+  if (NULL == p)
   {
     LOG (GNUNET_ERROR_TYPE_INFO, _("Could not find binary `%s' in PATH!\n"),
          binary);

Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c       2012-06-13 08:38:15 UTC (rev 21947)
+++ gnunet/src/util/os_priority.c       2012-06-13 08:58:42 UTC (rev 21948)
@@ -781,7 +781,7 @@
   pid_t ret;
   char lpid[16];
   char fds[16];
-  struct GNUNET_OS_Process *gnunet_proc = NULL;
+  struct GNUNET_OS_Process *gnunet_proc;
   char *childpipename = NULL;
   int i;
   int j;
@@ -918,7 +918,7 @@
   LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
   _exit (1);
 #else
-  struct GNUNET_DISK_FileHandle *control_pipe = NULL;
+  struct GNUNET_DISK_FileHandle *control_pipe;
   char *childpipename = NULL;
   char **arg;
   char **non_const_argv;
@@ -928,7 +928,7 @@
   STARTUPINFOW start;
   PROCESS_INFORMATION proc;
   int argcount = 0;
-  struct GNUNET_OS_Process *gnunet_proc = NULL;
+  struct GNUNET_OS_Process *gnunet_proc;
   char path[MAX_PATH + 1];
   char *our_env[5] = { NULL, NULL, NULL, NULL, NULL };
   char *env_block = NULL;

Modified: gnunet/src/util/test_resolver_api.c
===================================================================
--- gnunet/src/util/test_resolver_api.c 2012-06-13 08:38:15 UTC (rev 21947)
+++ gnunet/src/util/test_resolver_api.c 2012-06-13 08:58:42 UTC (rev 21948)
@@ -30,7 +30,6 @@
 #include "gnunet_resolver_service.h"
 #include "resolver.h"
 
-#define VERBOSE GNUNET_NO
 
 /**
  * Using DNS root servers to check gnunet's resolver service
@@ -40,12 +39,13 @@
 #define ROOTSERVER_NAME "a.root-servers.net"
 #define ROOTSERVER_IP  "198.41.0.4"
 
+
 static void
 check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen)
 {
   int *ok = cls;
 
-  if (salen == 0)
+  if (0 == salen)
   {
     (*ok) &= ~8;
     return;
@@ -82,7 +82,7 @@
 {
   int *ok = cls;
 
-  if (hostname == NULL)
+  if (NULL == hostname)
     return;
   if (0 == strcmp (hostname, "localhost"))
   {
@@ -98,13 +98,14 @@
   }
 }
 
+
 static void
 check_127 (void *cls, const struct sockaddr *sa, socklen_t salen)
 {
   int *ok = cls;
   const struct sockaddr_in *sai = (const struct sockaddr_in *) sa;
 
-  if (sa == NULL)
+  if (NULL == sa)
     return;
   GNUNET_assert (sizeof (struct sockaddr_in) == salen);
   if (sai->sin_addr.s_addr == htonl (INADDR_LOOPBACK))
@@ -122,6 +123,7 @@
   }
 }
 
+
 static void
 check_local_fqdn (void *cls, const char *gnunet_fqdn)
 {
@@ -159,14 +161,13 @@
 }
 
 
-
 static void
 check_rootserver_ip (void *cls, const struct sockaddr *sa, socklen_t salen)
 {
   int *ok = cls;
   const struct sockaddr_in *sai = (const struct sockaddr_in *) sa;
 
-  if (sa == NULL)
+  if (NULL == sa)
     return;
   GNUNET_assert (sizeof (struct sockaddr_in) == salen);
 
@@ -184,12 +185,13 @@
   }
 }
 
+
 static void
 check_rootserver_name (void *cls, const char *hostname)
 {
   int *ok = cls;
 
-  if (hostname == NULL)
+  if (NULL == hostname)
     return;
 
   if (0 == strcmp (hostname, ROOTSERVER_NAME))
@@ -206,6 +208,7 @@
   }
 }
 
+
 static void
 run (void *cls, char *const *args, const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -347,36 +350,33 @@
 
 }
 
-static int
-check ()
+
+int
+main (int argc, char *argv[])
 {
   int ok = 1 + 2 + 4 + 8;
   char *fn;
   char *pfx;
   struct GNUNET_OS_Process *proc;
-
-  char *const argv[] =
-      { "test-resolver-api", "-c", "test_resolver_api_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
-    NULL
+  char *const argvx[] = { 
+    "test-resolver-api", "-c", "test_resolver_api_data.conf", NULL
   };
   struct GNUNET_GETOPT_CommandLineOption options[] =
       { GNUNET_GETOPT_OPTION_END };
+
+  GNUNET_log_setup ("test-resolver-api",
+                    "WARNING",
+                    NULL);
   pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
   GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR);
   GNUNET_free (pfx);
   proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, 
"gnunet-service-resolver",
-#if VERBOSE
-                                  "-L", "DEBUG",
-#endif
                                   "-c", "test_resolver_api_data.conf", NULL);
   GNUNET_assert (NULL != proc);
   GNUNET_free (fn);
   GNUNET_assert (GNUNET_OK ==
-                 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-                                     argv, "test-resolver-api", "nohelp",
+                 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
+                                     argvx, "test-resolver-api", "nohelp",
                                      options, &run, &ok));
   if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
   {
@@ -386,26 +386,10 @@
   GNUNET_OS_process_wait (proc);
   GNUNET_OS_process_destroy (proc);
   proc = NULL;
-  if (ok != 0)
+  if (0 != ok)
     FPRINTF (stderr, "Missed some resolutions: %u\n", ok);
   return ok;
 }
 
-int
-main (int argc, char *argv[])
-{
-  int ret;
 
-  GNUNET_log_setup ("test-resolver-api",
-#if VERBOSE
-                    "DEBUG",
-#else
-                    "WARNING",
-#endif
-                    NULL);
-  ret = check ();
-
-  return ret;
-}
-
 /* end of test_resolver_api.c */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]