[CFR] OpenBSD install(1) fixes: atomic install, etc.

2001-04-20 Thread Ruslan Ermilov

Hi!

The attached patch incorporates most of OpenBSD fixes to install(1).
It does not include manpage update.  Most significant changes are:

o All TODOs are acted upon.

o New flags: -b and -B

: -bBackup any existing files before overwriting them by
:   renaming them to file.old.  See -B for specifying a
:   different backup suffix.
: 
: -B suffix
:   Use suffix as the backup suffix if -b is given.

o New flag: -S (atomic install)

: -SSafe copy.  Normally, install unlinks an existing target before
:   installing the new file.  With the -S flag a temporary file is
:   used and then renamed to be the target.  The reason this is safer
:   is that if the copy or rename fails, the existing target is left
:   untouched.

o The -c flag is now the default, and only provided for backwards
  compatibility.  We now never remove the original file.

o Flags -v and -D were withdrawn.

o strip(1) failure is not considered fatal.

Please review.


Thanks,
-- 
Ruslan Ermilov  Oracle Developer/DBA,
[EMAIL PROTECTED]   Sunbay Software AG,
[EMAIL PROTECTED]  FreeBSD committer,
+380.652.512.251Simferopol, Ukraine

http://www.FreeBSD.org  The Power To Serve
http://www.oracle.com   Enabling The Information Age


Index: xinstall.c
===
RCS file: /home/ncvs/src/usr.bin/xinstall/xinstall.c,v
retrieving revision 1.40
diff -u -p -r1.40 xinstall.c
--- xinstall.c  2000/10/08 09:17:56 1.40
+++ xinstall.c  2001/04/20 15:42:20
@@ -45,21 +45,6 @@ static const char rcsid[] =
   "$FreeBSD: src/usr.bin/xinstall/xinstall.c,v 1.40 2000/10/08 09:17:56 bde Exp $";
 #endif /* not lint */
 
-/*-
- * Todo:
- * o for -C, compare original files except in -s case.
- * o for -C, don't change anything if nothing needs be changed.  In
- *   particular, don't toggle the immutable flags just to allow null
- *   attribute changes and don't clear the dump flag.  (I think inode
- *   ctimes are not updated for null attribute changes, but this is a
- *   bug.)
- * o independent of -C, if a copy must be made, then copy to a tmpfile,
- *   set all attributes except the immutable flags, then rename, then
- *   set the immutable flags.  It's annoying that the immutable flags
- *   defeat the atomicicity of rename - it seems that there must be
- *   a window where the target is not immutable.
- */
-
 #include sys/param.h
 #include sys/wait.h
 #include sys/mman.h
@@ -82,45 +67,29 @@ static const char rcsid[] =
 
 #include "pathnames.h"
 
-/* Bootstrap aid - this doesn't exist in most older releases */
-#ifndef MAP_FAILED
-#define MAP_FAILED ((void *)-1)/* from sys/mman.h */
-#endif
-
-int debug, docompare, docopy, dodir, dopreserve, dostrip, nommap, verbose;
-int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
-char *group, *owner, pathbuf[MAXPATHLEN];
-char pathbuf2[MAXPATHLEN];
-
 #defineDIRECTORY   0x01/* Tell install it's a directory. */
 #defineSETFLAGS0x02/* Tell install to set flags. */
 #defineNOCHANGEBITS(UF_IMMUTABLE | UF_APPEND | SF_IMMUTABLE | SF_APPEND)
+#defineBACKUP_SUFFIX   ".old"
 
+struct passwd *pp;
+struct group *gp;
+int dobackup, docompare, dodir, dopreserve, dostrip, nommap, safecopy;
+int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
+char pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN];
+char *suffix = BACKUP_SUFFIX;
+uid_t uid;
+gid_t gid;
+
 void   copy __P((int, char *, int, char *, off_t));
-intcompare __P((int, const char *, int, const char *, 
-const struct stat *, const struct stat *));
+intcompare __P((int, const char *, size_t, int, const char *, size_t));
+intcreate_newfile __P((char *, struct stat *));
+intcreate_tempfile __P((char *, char *, size_t));
 void   install __P((char *, char *, u_long, u_int));
 void   install_dir __P((char *));
 void   strip __P((char *));
-void   usage __P((void));
 inttrymmap __P((int));
-
-#define ALLOW_NUMERIC_IDS 1
-#ifdef ALLOW_NUMERIC_IDS
-
-uid_t   uid = -1;
-gid_t   gid = -1;
-
-uid_t  resolve_uid __P((char *));
-gid_t  resolve_gid __P((char *));
-u_long numeric_id __P((char *, char *));
-
-#else
-
-struct passwd *pp;
-struct group *gp;
-
-#endif /* ALLOW_NUMERIC_IDS */
+void   usage __P((void));
 
 int
 main(argc, argv)
@@ -132,20 +101,23 @@ main(argc, argv)
u_long fset;
u_int iflags;
int ch, no_target;
-   char *flags, *to_name;
+   char *flags, *to_name, *group = NULL, *owner = NULL;
 
iflags = 0;
-   while ((ch = getopt(argc, argv, "CcdDf:g:m:Mo:psv")) != -1)
+   while ((ch = getopt(argc, argv, "BbCcdf:g:Mm:o:pSs")) != -1)
switch((char)ch) {
+   case 'B':
+   suffix = optarg;
+   /* FALLTHROUGH */
+   case 'b':
+   dobackup = 1;
+   break;
case 'C':
- 

Re: [CFR] OpenBSD install(1) fixes: atomic install, etc.

2001-04-20 Thread Konstantin Chuguev

Hi,

Ruslan Ermilov wrote:

 The attached patch incorporates most of OpenBSD fixes to install(1).
 It does not include manpage update.  Most significant changes are:

 o New flag: -S (atomic install)

 : -SSafe copy.  Normally, install unlinks an existing target before
 :   installing the new file.  With the -S flag a temporary file is
 :   used and then renamed to be the target.  The reason this is safer
 :   is that if the copy or rename fails, the existing target is left
 :   untouched.


Just curious: why not make this way of doing install default (i.e. always use
it)?

Regards,
Konstantin.

--
  * *Konstantin Chuguev - Application Engineer
   *  *  Francis House, 112 Hills Road
 *   Cambridge CB2 1PQ, United Kingdom
 D  A  N  T  E   WWW:http://www.dante.net




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: [CFR] OpenBSD install(1) fixes: atomic install, etc.

2001-04-20 Thread Maxim Sobolev

Konstantin Chuguev wrote:

 Hi,

 Ruslan Ermilov wrote:

  The attached patch incorporates most of OpenBSD fixes to install(1).
  It does not include manpage update.  Most significant changes are:
 
  o New flag: -S (atomic install)
 
  : -SSafe copy.  Normally, install unlinks an existing target before
  :   installing the new file.  With the -S flag a temporary file is
  :   used and then renamed to be the target.  The reason this is safer
  :   is that if the copy or rename fails, the existing target is left
  :   untouched.
 

 Just curious: why not make this way of doing install default (i.e. always use
 it)?

It may effectively doubles disk space requirements during copy (when destination
file is not on a sofdep-enabled partition and is not open at the moment when
install(8) unlinks it). For small files it doesn't matter, but for a big ones it
could lead to a problem.

-Maxim


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: [CFR] OpenBSD install(1) fixes: atomic install, etc.

2001-04-20 Thread Ruslan Ermilov

On Fri, Apr 20, 2001 at 07:41:36PM +0300, Maxim Sobolev wrote:
 Konstantin Chuguev wrote:
 
  Hi,
 
  Ruslan Ermilov wrote:
 
   The attached patch incorporates most of OpenBSD fixes to install(1).
   It does not include manpage update.  Most significant changes are:
  
   o New flag: -S (atomic install)
  
   : -SSafe copy.  Normally, install unlinks an existing target before
   :   installing the new file.  With the -S flag a temporary file is
   :   used and then renamed to be the target.  The reason this is safer
   :   is that if the copy or rename fails, the existing target is left
   :   untouched.
  
 
  Just curious: why not make this way of doing install default (i.e. always use
  it)?
 
 It may effectively doubles disk space requirements during copy (when destination
 file is not on a sofdep-enabled partition and is not open at the moment when
 install(8) unlinks it). For small files it doesn't matter, but for a big ones it
 could lead to a problem.
 
I think -S should be made the default for `installworld' (this was the main
reason that triggered this work).  But I don't think this should be turned
`on' by default in install(1).

BTW, this binary just completed the `installworld' test on -STABLE.


Cheers,
-- 
Ruslan Ermilov  Oracle Developer/DBA,
[EMAIL PROTECTED]   Sunbay Software AG,
[EMAIL PROTECTED]  FreeBSD committer,
+380.652.512.251Simferopol, Ukraine

http://www.FreeBSD.org  The Power To Serve
http://www.oracle.com   Enabling The Information Age

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message



Re: [CFR] OpenBSD install(1) fixes: atomic install, etc.

2001-04-20 Thread Ruslan Ermilov

On Fri, Apr 20, 2001 at 08:03:20PM +0300, Ruslan Ermilov wrote:
 On Fri, Apr 20, 2001 at 07:41:36PM +0300, Maxim Sobolev wrote:
  Konstantin Chuguev wrote:
  
   Hi,
  
   Ruslan Ermilov wrote:
  
The attached patch incorporates most of OpenBSD fixes to install(1).
It does not include manpage update.  Most significant changes are:
   
o New flag: -S (atomic install)
   
: -SSafe copy.  Normally, install unlinks an existing target before
:   installing the new file.  With the -S flag a temporary file is
:   used and then renamed to be the target.  The reason this is safer
:   is that if the copy or rename fails, the existing target is left
:   untouched.
   
  
   Just curious: why not make this way of doing install default (i.e. always use
   it)?
  
  It may effectively doubles disk space requirements during copy (when destination
  file is not on a sofdep-enabled partition and is not open at the moment when
  install(8) unlinks it). For small files it doesn't matter, but for a big ones it
  could lead to a problem.
  
 I think -S should be made the default for `installworld' (this was the main
 reason that triggered this work).  But I don't think this should be turned
 `on' by default in install(1).
 
 BTW, this binary just completed the `installworld' test on -STABLE.
 
Just tried -j32 installworld with modified install(1) binary for which
-S is the default, and it still choked on lib/libncurses.  The problem
is in bsd.man.mk: we should separate installing of manpages and their
MLINKS, otherwise links could be attempted before their originals are
installed.

Continuing with -DNOMAN now...


Cheers,
-- 
Ruslan Ermilov  Oracle Developer/DBA,
[EMAIL PROTECTED]   Sunbay Software AG,
[EMAIL PROTECTED]  FreeBSD committer,
+380.652.512.251Simferopol, Ukraine

http://www.FreeBSD.org  The Power To Serve
http://www.oracle.com   Enabling The Information Age

To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message