This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A symlink patch for glibc 2.0.7


> 
> On Mon, 20 Jul 1998 08:42:51 -0700 (PDT), H.J. Lu wrote:
> >> 
> >> I think he's talking about this program.  Basically the perl script
> >> needs to get rewritten in C (and if you find any bugs in the C part,
> >> please fix them too :)
> >> 
> >
> >I have a simple solution. I will send in a patch very soon.
> 
> Please note I have a patch on ice that will fix the problem in 2.1. 
> Unfortunately it depends on my other makefile patches, which Ulrich still
> hasn't taken :(  (and reworking it not to do so would be impossibly ugly).
> 

Here is my version. Please give it a try. Ulrich, I'd like to see glibc
2.0.7 released ASAP.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
----
Mon Jul 20 08:18:45 1998  H.J. Lu  <hjl@gnu.org>

	* elf/sln.c: New file.

	* elf/Makefile (extra-objs): Add sln.o.
	(install-rootsbin): Add sln.
	($(objpfx)sln): New target.

	* Makerules (symbolic-link-prog, symbolic-link-list): New
	macros.
	(install-clean-symbolic-link-list): New target.
	(install): Depend on install-clean-symbolic-link-list.
	(make-shlib-link): Changed to generate $(symbolic-link-list).

	* Makefile (install-symblolic-link): New target.
	(install): Depend on install-symblolic-link.

Index: elf/Makefile
===================================================================
RCS file: /home/work/cvs/gnu/glibc-2.0/elf/Makefile,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 Makefile
--- elf/Makefile	1998/07/15 00:14:39	1.1.1.3
+++ elf/Makefile	1998/07/20 15:36:12
@@ -56,9 +56,19 @@
 install-bin	= ldd
 endif
 
+extra-objs	+= sln.o
+install-rootsbin = sln
+
+$(objpfx)sln: $(objpfx)sln.o
+	$(CC) -nostdlib -nostartfiles -o $@ $(sysdep-LDFLAGS) -static	      \
+	      $(addprefix $(csu-objpfx),start.o) $(+preinit)		      \
+	      $(filter-out $(addprefix $(csu-objpfx),start.o) $(+preinit)     \
+		$(link-extra-libs) $(common-objpfx)libc% $(+postinit),$^)     \
+	      $(link-extra-libs) $(common-objpfx)libc.a $(gnulib) $(+postinit)
+
 ifeq (yes,$(has-ldconfig))
 extra-objs	+= ldconfig.o
-install-rootsbin = ldconfig
+install-rootsbin += ldconfig
 
 $(objpfx)ldconfig: $(objpfx)ldconfig.o
 	$(CC) -nostdlib -nostartfiles -o $@ $(sysdep-LDFLAGS) -static	      \
Index: Makerules
===================================================================
RCS file: /home/work/cvs/gnu/glibc-2.0/Makerules,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 Makerules
--- Makerules	1998/05/20 21:50:19	1.1.1.7
+++ Makerules	1998/07/20 17:02:51
@@ -597,6 +597,13 @@
 	    $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
 endef
 
+# We need to clean the symbolic link list first.
+symbolic-link-prog := $(common-objpfx)elf/sln
+symbolic-link-list := $(common-objpfx)elf/symlink.list
+install: install-clean-symbolic-link-list
+install-clean-symbolic-link-list:
+	rm -f $(symbolic-link-list)
+
 # Any directory (parent or subdir) that has any object files to build
 # should install libc.a; this way "make install" in a subdir is guaranteed
 # to install everything it changes.
@@ -648,17 +655,9 @@
 endef
 endif
 
-# XXX The following will have to be changed when `ldconfig' is available.
-ifneq (yes,$(cross-compiling))
-ifeq (yes,$(has-ldconfig))
-define make-shlib-link
-@:
-endef
-endif
-endif
 ifndef make-shlib-link
 define make-shlib-link
-$(make-link)
+echo $(<F) $@ >> $(symbolic-link-list)
 endef
 endif
 
Index: Makefile
===================================================================
RCS file: /home/work/cvs/gnu/glibc-2.0/Makefile,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 Makefile
--- Makefile	1998/05/20 21:50:17	1.1.1.7
+++ Makefile	1998/07/20 16:29:39
@@ -113,6 +113,12 @@
 # Install from subdirectories too.
 install: subdir_install
 
+ifeq (yes,$(build-shared))
+install: install-symblolic-link
+install-symblolic-link:
+	$(symbolic-link-prog) $(symbolic-link-list)
+endif
+
 # Create linkfs for shared libraries using the `ldconfig' program is possible.
 # Ignore the error if we cannot update /etc/ld.so.cache.
 ifeq (no,$(cross-compiling))
--- /dev/null	Tue May  5 13:32:27 1998
+++ elf/sln.c	Mon Jul 20 10:35:51 1998
@@ -0,0 +1,190 @@
+/* `sln' program to create symboblic links between files.
+   Copyright (C) 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+#include <limits.h>
+
+#if !defined(S_ISDIR) && defined(S_IFDIR)
+#define	S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
+#endif
+
+static int makesymlink __P ((const char *src, const char *dest));
+static int makesymlinks __P ((const char *file));
+
+int
+main (argc, argv)
+     int argc;
+     char **argv;
+{
+  switch (argc)
+    {
+    case 2:
+      return makesymlinks (argv [1]) == 0 ? 0 : 1;
+      break;
+
+    case 3:
+      return makesymlink (argv [1], argv [2]) == 0 ? 0 : 1;
+      break;
+
+    default:
+      printf ("Usage: %s src dest|file\n", argv [0]);
+      return 1;
+      break;
+    }
+}
+
+static int
+makesymlinks (file)
+     const char *file;
+{
+#ifndef PATH_MAX
+#define PATH_MAX 4095
+#endif
+  char buffer [PATH_MAX * 4];
+  int i, ret, len;
+  int lineno;
+  const char *src;
+  const char *dest;
+  const char *error;
+  FILE *fp;
+
+  fp = fopen (file, "r");
+  if (fp == NULL)
+    {
+      error = strerror (errno);
+      fprintf (stderr, "%s: file open error: %s\n", file, error);
+      return -1;
+    }
+
+  ret = 0;
+  lineno = 0;
+  while (fgets (buffer, sizeof (buffer) - 1, fp))
+    {
+      lineno++;
+      src = dest = NULL;
+      buffer [sizeof (buffer) - 1] = '\0';
+      len = strlen (buffer);
+      for (i = 0; i < len && isspace (buffer [i]); i++);
+      if (i >= len)
+        {
+	  fprintf (stderr, "Fail to parse line %d: \"%s\"\n", lineno,
+	  	   buffer);
+	  ret--;
+	  continue;
+	}
+
+      src = &buffer [i];
+      for (; i < len && !isspace (buffer [i]); i++);
+      if (i < len)
+	{
+	  buffer [i++] = '\0';
+	  for (; i < len && isspace (buffer [i]); i++);
+	  if (i >= len)
+	    {
+	      fprintf (stderr, "No target in line %d: \"%s\"\n", lineno,
+	      	       buffer);
+	      ret--;
+	      continue;
+	    }
+	  dest = &buffer [i];
+	  for (; i < len && !isspace (buffer [i]); i++);
+	  buffer [i] = '\0';
+	}
+      else
+        {
+	  fprintf (stderr, "No target in line %d: \"%s\"\n", lineno,
+	  	   buffer);
+	  ret--;
+	  continue;
+	}
+
+      if (makesymlink (src, dest))
+        {
+	  fprintf (stderr, "Failed to make link from \"%s\" to \"%s\" in line %d\n",
+	  	   src, dest, lineno);
+	  ret--;
+	}
+    }
+  fclose (fp);
+
+  return ret;
+}
+
+static int
+makesymlink (src, dest)
+     const char *src;
+     const char *dest;
+{
+  struct stat stats;
+  const char *error;
+
+  /* Destination must not be a directory. */
+  if (lstat (dest, &stats) == 0)
+    {
+      if (S_ISDIR (stats.st_mode))
+	{
+	  fprintf (stderr, "%s: destination must not be a directory\n",
+	  	   dest);
+	  return -1;
+	}
+      else if (unlink (dest) && errno != ENOENT)
+	{
+	  fprintf (stderr, "%s: failed to remove the old destination\n",
+	  	   dest);
+	  return -1;
+	}
+    }
+  else if (errno != ENOENT)
+    {
+      error = strerror (errno);
+      fprintf (stderr, "%s: invalid destination: %s\n", dest, error);
+      return -1;
+    }
+       
+#ifdef S_ISLNK
+  if (symlink (src, dest) == 0)
+#else
+  if (link (src, dest) == 0)
+#endif
+    {
+      /* Destination must exist by now. */
+      if (access (dest, F_OK))
+        {
+	  error = strerror (errno);
+	  unlink (dest);
+	  fprintf (stderr, "Invalid link from \"%s\" to \"%s\": %s\n",
+	  	   src, dest, error);
+	  return -1;
+	}
+      return 0;
+    }
+  else
+    {
+      error = strerror (errno);
+      fprintf (stderr, "Invalid link from \"%s\" to \"%s\": %s\n",
+      	       src, dest, error);
+      return -1;
+    }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]