bug-gnulib
[Top][All Lists]
Advanced

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

progreloc.c


From: Charles Wilson
Subject: progreloc.c
Date: Mon, 06 Nov 2006 21:32:53 -0500
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)

The file lib/progreloc.c has no module, and carries an embedded GPL license. However, the intent for this file is that it is LGPL, according to the check-in message for revision 1.5, here:

http://cvs.savannah.gnu.org/viewcvs/gnulib/gnulib/lib/progreloc.c?rev=1.10&view=log
"Change copyright notice to GPL. The file is still under LGPL 2.0; this will be formalized when a modules/relocatable file is added."

Unfortunately, there are a few issues with progreloc.c that extend back to revision 1.1:

---------------------
#include "progname.h"
...
#include "xreadlink.h"
#include "canonicalize.h"
#include "relocatable.h"

#ifdef NO_XMALLOC
# define xmalloc malloc
# define xstrdup strdup
#else
# include "xalloc.h"
#endif
---------------------

(1) uses progname module, which is GPL

(2) uses xreadlink module, which is GPL

(3) until recently, one had to assume it used the canonicalize module, which is GPL. However, now we can assume instead that the eventual module file will depend on canonicalize-lgpl.

(4) unless NO_XMALLOC, it will depend on xalloc (GPL). But that's precisely why the NO_XMALLOC symbol is there: so that end-users can arrange things so that compiling this .c file will succeed in an LGPL environment where xalloc is not present.

So, (3) and (4) are non-issues. The attached patch fixes (2) by implementing a local static wrapper around readlink() that is not derived from xreadlink. However, to compile cleanly on mingw I also needed a slight change to m4/readlink.m4 -- so that's included below, as well.


Unfortunately, (1) can only be "fixed" by a license change on the progname module. I'm going to propose that to RMS, but I'd like for there to be only ONE issue with progreloc.c instead of 2(or 3 or 4).

--
Chuck

2006-11-06  Charles Wilson  <...>

        * lib/progreloc.c: don't include xreadlink. Declare readlink()
        if needed.
        (local_readlink): new wrapper function for readlink().
        (find_executable)[__linux__]: use local_readlink() instead of
        xreadlink().

        * m4/readlink.m4: use *_ONCE macros. Check for declaration as
        well as function.


Index: lib/progreloc.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/progreloc.c,v
retrieving revision 1.10
diff -u -r1.10 progreloc.c
--- lib/progreloc.c     14 Sep 2006 14:18:36 -0000      1.10
+++ lib/progreloc.c     7 Nov 2006 01:42:01 -0000
@@ -46,7 +46,12 @@
 # include <windows.h>
 #endif
 
-#include "xreadlink.h"
+#include "pathmax.h"
+
+#ifndef HAVE_DECL_READLINK
+int readlink(const char *path, char *buf, size_t bufsize);
+#endif
+
 #include "canonicalize.h"
 #include "relocatable.h"
 
@@ -88,6 +93,29 @@
 static int executable_fd = -1;
 #endif
 
+static char*
+local_readlink(char const* file)
+{
+  char* rVal = NULL;
+  char buf[PATH_MAX + 2]; /* from pathmax.h LGPL */
+  int c = readlink(file, buf, PATH_MAX + 1);
+  if ((c > 0) && (c <= PATH_MAX))
+  {
+    buf[c] = '\0';
+    rVal = (char*)xmalloc( sizeof(char) * (c+1) );
+#if NO_XMALLOC
+    if (rVal)
+    {
+#endif
+      strncpy(rVal, buf, c+1);
+#if NO_XMALLOC
+    }
+#endif
+  }
+  /* else: return NULL because error, or too long and we truncated */
+  return rVal;
+}
+
 /* Tests whether a given pathname may belong to the executable.  */
 static bool
 maybe_executable (const char *filename)
@@ -169,7 +197,7 @@
   {
     char *link;
 
-    link = xreadlink ("/proc/self/exe");
+    link = local_readlink ("/proc/self/exe");
     if (link != NULL && link[0] != '[')
       return link;
     if (executable_fd < 0)
@@ -178,7 +206,7 @@
     {
       char buf[6+10+5];
       sprintf (buf, "/proc/%d/exe", getpid ());
-      link = xreadlink (buf);
+      link = local_readlink (buf);
       if (link != NULL && link[0] != '[')
        return link;
       if (executable_fd < 0)
Index: m4/readlink.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/readlink.m4,v
retrieving revision 1.3
diff -u -r1.3 readlink.m4
--- m4/readlink.m4      18 Jan 2005 13:07:56 -0000      1.3
+++ m4/readlink.m4      7 Nov 2006 01:42:01 -0000
@@ -6,7 +6,8 @@
 
 AC_DEFUN([gl_FUNC_READLINK],
 [
-  AC_CHECK_FUNCS(readlink)
+  AC_CHECK_DECLS_ONCE(readlink)
+  AC_CHECK_FUNCS_ONCE(readlink)
   if test $ac_cv_func_readlink = no; then
     AC_LIBOBJ(readlink)
     gl_PREREQ_READLINK

reply via email to

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