View Issue Details

IDProjectCategoryView StatusLast Update
0002240GNUnetutil librarypublic2012-11-05 18:34
ReporterChristian Grothoff Assigned ToChristian Grothoff  
PrioritylowSeveritytweakReproducibilityalways
Status closedResolutionfixed 
Product VersionGit master 
Target Version0.9.4Fixed in Version0.9.4 
Summary0002240: duplicate code in os_priority.c for starting processes
DescriptionCurrently, the code for starting processes is duplicated in os_priority. There are subtle differences between the two versions, but it should be possible in principle to abstract out one common version. The fact that the code is full of #ifdef's for handling W32 vs. POSIX makes this task a bit more tricky.
Steps To ReproduceWe get this report from CPD/PMD, but it only scratches the surface:
=====================================================================
Found a 22 line (145 tokens) duplication in the following files:
Starting at line 887 of /home/pmdcpd/gnunet/src/util/os_priority.c
Starting at line 1257 of /home/pmdcpd/gnunet/src/util/os_priority.c

  cmdlen = strlen (filename);
  if (cmdlen < 5 || strcmp (&filename[cmdlen - 4], ".exe") != 0)
    GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
  else
    GNUNET_asprintf (&non_const_filename, "%s", filename);

  /* Check that this is the full path. If it isn't, search. */
  if (non_const_filename[1] == ':')
    snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
  else if (!SearchPathA
           (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
            path, NULL))
  {
    SetErrnoFromWinError (GetLastError ());
    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
                       non_const_filename);
    GNUNET_free (non_const_filename);
    GNUNET_free (pathbuf);
    return NULL;
  }
  GNUNET_free (pathbuf);
  GNUNET_free (non_const_filename);


=====================================================================
Found a 24 line (120 tokens) duplication in the following files:
Starting at line 861 of /home/pmdcpd/gnunet/src/util/os_priority.c
Starting at line 1226 of /home/pmdcpd/gnunet/src/util/os_priority.c

  wchar_t wpath[MAX_PATH + 1], wcmd[32768];

  /* Search in prefix dir (hopefully - the directory from which
   * the current module was loaded), bindir and libdir, then in PATH
   */
  self_prefix = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_SELF_PREFIX);
  bindir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
  libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);

  pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);

  alloc_len =
      pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
      strlen (libdir);

  pathbuf = GNUNET_malloc (alloc_len * sizeof (char));

  ptr = pathbuf;
  ptr += sprintf (pathbuf, "%s;%s;%s;", self_prefix, bindir, libdir);
  GNUNET_free (self_prefix);
  GNUNET_free (bindir);
  GNUNET_free (libdir);

  alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
TagsNo tags attached.

Activities

Christian Grothoff

2012-06-13 10:35

manager   ~0006057

Deduplicated in SVN 21946.

Issue History

Date Modified Username Field Change
2012-03-24 16:01 Christian Grothoff New Issue
2012-03-24 16:04 Christian Grothoff Steps to Reproduce Updated
2012-03-24 16:05 Christian Grothoff Status new => confirmed
2012-06-03 01:16 Christian Grothoff Target Version => 0.9.4
2012-06-13 10:29 Christian Grothoff Assigned To => Christian Grothoff
2012-06-13 10:29 Christian Grothoff Status confirmed => assigned
2012-06-13 10:35 Christian Grothoff Note Added: 0006057
2012-06-13 10:35 Christian Grothoff Status assigned => resolved
2012-06-13 10:35 Christian Grothoff Fixed in Version => 0.9.4
2012-06-13 10:35 Christian Grothoff Resolution open => fixed
2012-11-05 18:34 Christian Grothoff Status resolved => closed