[6517] in Athena Bugs

home help back first fref pref prev next nref lref last post

Improvements for "install"

daemon@ATHENA.MIT.EDU (daemon@ATHENA.MIT.EDU)
Mon Dec 3 14:02:29 1990

Date: Mon, 3 Dec 90 14:02:11 -0500
To: bugs@ATHENA.MIT.EDU
From: Richard Basch <probe@MIT.EDU>


The following addes two features:

1) Default characteristics can be specified in the INSTOPT environment
   variable.

2) Using the "-t" option preserves times on installation.

In addition, a bug has been fixed where specifying "-s" on a non-binary
file would create a zero-length file and then bomb out.  Now it just
prints a warning and completes the copy.

-Richard


*** /tmp/,RCSt1010716	Mon Dec  3 13:59:52 1990
--- install.c	Mon Dec  3 13:59:41 1990
***************
*** 25,33 ****
--- 25,35 ----
  static char sccsid[] = "@(#)install.c	5.12 (Berkeley) 7/6/88";
  #endif /* not lint */
  
+ #include <sys/types.h>
  #include <sys/param.h>
  #include <sys/stat.h>
  #include <sys/file.h>
+ #include <sys/time.h>
  #include <a.out.h>
  #include <grp.h>
  #include <pwd.h>
***************
*** 43,56 ****
  	perror(msg); \
  }
  
  static uid_t uid;
  static gid_t gid;
! static int	docopy, dostrip, domove,
  		mode = 0755;
! int multiple = NO;
  static char	*group, *owner,
  		pathbuf[MAXPATHLEN];
  
  main(argc, argv)
  	int argc;
  	char **argv;
--- 45,68 ----
  	perror(msg); \
  }
  
+ #define MAXARGS	256
+ 
  static uid_t uid;
  static gid_t gid;
! 
! static int	docopy = NO,
! 		dostrip = NO,
! 		domove = NO,
! 		dotime = NO,
! 		multiple = NO,
  		mode = 0755;
! 
  static char	*group, *owner,
  		pathbuf[MAXPATHLEN];
  
+ char *strdup();
+ extern char *getenv();
+ 
  main(argc, argv)
  	int argc;
  	char **argv;
***************
*** 63,77 ****
  	struct passwd *pp;
  	struct group *gp;
  
! 	while ((ch = getopt(argc, argv, "cdg:m:o:s")) != EOF)
  		switch((char)ch) {
  		case 'c':
!                         if (domove == YES)
                                  multiple = YES;
  			docopy = YES;
  			break;
                  case 'd':
!                         if (docopy == YES)
                                  multiple = YES;
                          domove = YES;
                          break;
--- 75,117 ----
  	struct passwd *pp;
  	struct group *gp;
  
! 	int argc_extend = 1, argc_extra;
! 	char *argv_extend[MAXARGS];
! 	char *inst_env;
! 
! 	if ((inst_env = getenv("INSTOPT")) == NULL)
! 		inst_env = "";
! 	else
! 		inst_env = strdup(inst_env);
! 
! 	while (*inst_env) {
! 		argv_extend[argc_extend++] = inst_env;
! 		while (*++inst_env && *inst_env != ' ' && *inst_env != '\t');
! 		if (*inst_env)
! 			*inst_env++ = '\0';
! 	}
! 	
! 	argc_extra = argc_extend;
! 	argv_extend[0] = *argv++;
! 	while (--argc)
! 		argv_extend[argc_extend++] = *argv++;
! 
! 	argc = argc_extend;
! 	argv = argv_extend;
! 	
! 	while ((ch = getopt(argc, argv, "cdstg:m:o:")) != EOF)
  		switch((char)ch) {
  		case 'c':
!                         if (domove == YES && optind < argc_extra)
! 				domove = NO;
! 			else
                                  multiple = YES;
  			docopy = YES;
  			break;
                  case 'd':
!                         if (docopy == YES && optind < argc_extra)
! 				docopy = NO;
! 			else
                                  multiple = YES;
                          domove = YES;
                          break;
***************
*** 87,92 ****
--- 127,135 ----
  		case 's':
  			dostrip = YES;
  			break;
+ 		case 't':
+ 			dotime = YES;
+ 			break;
  		case '?':
  		default:
  			usage();
***************
*** 183,190 ****
  	int isdir;
  {
  	struct stat from_sb;
  	int devnull, from_fd, to_fd;
! 	char *C, *rindex();
  
  	/* if try to install "/dev/null" to a directory, fails */
  	if (isdir || strcmp(from_name, "/dev/null")) {
--- 226,234 ----
  	int isdir;
  {
  	struct stat from_sb;
+ 	struct timeval timep[2];
  	int devnull, from_fd, to_fd;
! 	char *C;
  
  	/* if try to install "/dev/null" to a directory, fails */
  	if (isdir || strcmp(from_name, "/dev/null")) {
***************
*** 238,243 ****
--- 282,296 ----
  	    bad();
  	}
  	(void)close(to_fd);
+ 	if (dotime) {
+ 		timep[0].tv_sec = from_sb.st_atime;
+ 		timep[1].tv_sec = from_sb.st_mtime;
+ 		timep[0].tv_usec = timep[1].tv_usec = 0;
+ 		if (utimes(to_name, timep)) {
+ 			PERROR("install: utimes: ", to_name);
+ 			bad();
+ 		}
+ 	}
  }
  
  /*
***************
*** 258,264 ****
  
  	if (read(from_fd, (char *)&head, sizeof(head)) < 0 || N_BADMAG(head)) {
  		fprintf(stderr, "install: %s not in a.out format.\n", from_name);
! 		bad();
  	}
  	if (head.a_syms || head.a_trsize || head.a_drsize) {
  		size = (long)head.a_text + head.a_data;
--- 311,319 ----
  
  	if (read(from_fd, (char *)&head, sizeof(head)) < 0 || N_BADMAG(head)) {
  		fprintf(stderr, "install: %s not in a.out format.\n", from_name);
! 		(void)lseek(from_fd, 0L, L_SET);
! 		copy(from_fd, from_name, to_fd, to_name);
! 		return;
  	}
  	if (head.a_syms || head.a_trsize || head.a_drsize) {
  		size = (long)head.a_text + head.a_data;
***************
*** 313,318 ****
--- 368,387 ----
  		PERROR("install: read: ", from_name);
  		bad();
  	}
+ }
+ 
+ /*
+  * strdup --
+  * 	Duplicate a string
+  */
+ char *strdup(string)
+     char *string;
+ {
+     char *temp;
+ 
+     if (temp = (char *)malloc(strlen(string)+1))
+         strcpy(temp,string);
+     return(temp);
  }
  
  /*

home help back first fref pref prev next nref lref last post