[PATCH] prevent install(1) from overwritting symlinks

Aryeh M. Friedman aryeh.friedman at gmail.com
Thu Nov 1 21:24:05 PDT 2007


The below patch is designed to keep install(1) from overwriting symbolic
links.   The motivation is if cups is installed some programs still
expect lpr to be in /usr/bin thus when I install cups I backlink the
/usr/local/bin versions of lp* to /usr/bin.   When a build/installworld
is done these links are overwritten and the sym links have to be
performed again.   This patch prevents the overwrite.

This is my very first patch (of any kind [not just for FreeBSD]) so can
people please tell me what I did right and what I did wrong in making
it.   Also tell me what improvements (if any) can be made to the patched
code.

--- src/usr.bin/xinstall/xinstall.c.orig        2007-11-01
18:46:45.000000000 -0400
+++ src/usr.bin/xinstall/xinstall.c     2007-11-01 19:44:43.000000000 -0400
@@ -268,7 +268,7 @@
 void
 install(const char *from_name, const char *to_name, u_long fset, u_int
flags)
 {
-       struct stat from_sb, temp_sb, to_sb;
+       struct stat from_sb, temp_sb, to_sb, to_lsb;
        struct timeval tvb[2];
        int devnull, files_match, from_fd, serrno, target;
        int tempcopy, temp_fd, to_fd;
@@ -299,6 +299,13 @@
        }
 
        target = stat(to_name, &to_sb) == 0;
+       target = lstat(to_name, &to_lsb) == 0;
+
+       if(S_ISLNK(to_lsb.st_mode)) {
+               printf("%s is a symbolic link not modified\n",to_name);
+               errno = EFTYPE;
+               return;
+       }
 
        /* Only install to regular files. */
        if (target && !S_ISREG(to_sb.st_mode)) {



More information about the freebsd-current mailing list