[6519] in Athena Bugs

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

install: more patches

daemon@ATHENA.MIT.EDU (daemon@ATHENA.MIT.EDU)
Mon Dec 3 20:00:36 1990

Date: Mon, 3 Dec 90 16:54:49 -0500
To: bugs@ATHENA.MIT.EDU
From: Richard Basch <probe@MIT.EDU>


Here is a new version...  one bug in the previous patch was fixed...
In addition, this now supports MIPS, and can easily be extended to
support other COFF architectures.

-Richard


*** /tmp/,RCSt1010990	Mon Dec  3 16:53:47 1990
--- install.c	Mon Dec  3 16:51:19 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>
***************
*** 35,42 ****
  #include <strings.h>
  #include <ctype.h>
  
- #define	YES	1			/* yes/true */
  #define	NO	0			/* no/false */
  
  #define	PERROR(head, msg) { \
  	fputs(head, stderr); \
--- 37,44 ----
  #include <strings.h>
  #include <ctype.h>
  
  #define	NO	0			/* no/false */
+ #define	YES	1			/* yes/true */
  
  #define	PERROR(head, msg) { \
  	fputs(head, stderr); \
***************
*** 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,69 ****
  	struct passwd *pp;
  	struct group *gp;
  
! 	while ((ch = getopt(argc, argv, "cdg:m:o:s")) != EOF)
  		switch((char)ch) {
  		case 'c':
                          if (domove == YES)
--- 75,105 ----
  	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)
***************
*** 87,92 ****
--- 123,131 ----
  		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")) {
--- 222,230 ----
  	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")) {
***************
*** 233,243 ****
  		PERROR("install: fchmod: ", to_name);
  		bad();
  	}
! 	if (fchown(to_fd, uid, gid)) {
  	    PERROR("install: fchown: ", to_name);
  	    bad();
  	}
  	(void)close(to_fd);
  }
  
  /*
--- 273,292 ----
  		PERROR("install: fchmod: ", to_name);
  		bad();
  	}
! 	if ((uid != -1 || gid != -1) && fchown(to_fd, uid, gid)) {
  	    PERROR("install: fchown: ", to_name);
  	    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();
+ 		}
+ 	}
  }
  
  /*
***************
*** 249,264 ****
  	register int from_fd, to_fd;
  	char *from_name, *to_name;
  {
  	typedef struct exec EXEC;
  	register long size;
  	register int n;
- 	EXEC head;
  	char buf[MAXBSIZE];
  	off_t lseek();
  
  	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;
--- 298,344 ----
  	register int from_fd, to_fd;
  	char *from_name, *to_name;
  {
+ #if defined(ibm032) || defined(vax)
  	typedef struct exec EXEC;
+ 	EXEC head;
+ #else
+ 	int swapheader = 0;
+ 	FILHDR head;
+ 	typedef FILHDR EXEC;
+ #endif
  	register long size;
  	register int n;
  	char buf[MAXBSIZE];
  	off_t lseek();
  
+ #if defined(mips)
+ 	if (read(from_fd, (char *)&head, sizeof(head)) < 0 ||
+ 	    (head.f_magic != MIPSEBMAGIC && head.f_magic != MIPSELMAGIC &&
+ 	     head.f_magic != SMIPSEBMAGIC && head.f_magic != SMIPSELMAGIC)) {
+ 		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.f_magic == SMIPSEBMAGIC || head.f_magic == SMIPSELMAGIC)
+ 		swapheader = 1;
+ 	if (swapheader) swap_filehdr(&head, gethostsex());
+ 	if (head.f_symptr) {
+ 		size = head.f_symptr - sizeof(EXEC);
+ 		head.f_symptr = head.f_nsyms = 0;
+ 	} else {
+ 		(void)lseek(from_fd, 0L, L_SET);
+ 		copy(from_fd, from_name, to_fd, to_name);
+ 		return;
+ 	}
+ 	if (swapheader) swap_filehdr(&head, gethostsex());
+ #endif
+ #if defined(vax) || defined(ibm032)
  	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;
***************
*** 265,295 ****
  		head.a_syms = head.a_trsize = head.a_drsize = 0;
  		if ((head.a_magic == ZMAGIC) || (head.a_magic == Z0MAGIC))
  			size += getpagesize() - sizeof(EXEC);
- 		if (write(to_fd, (char *)&head, sizeof(EXEC)) != sizeof(EXEC)) {
- 			PERROR("install: write: ", to_name);
- 			bad();
- 		}
- 		for (; size; size -= n)
- 			/* sizeof(buf) guaranteed to fit in an int */
- 			if ((n = read(from_fd, buf, (int)MIN(size, sizeof(buf)))) <= 0)
- 				break;
- 			else if (write(to_fd, buf, n) != n) {
- 				PERROR("install: write: ", to_name);
- 				bad();
- 			}
- 		if (size) {
- 			fprintf(stderr, "install: read: %s: premature EOF.\n", from_name);
- 			bad();
- 		}
- 		if (n == -1) {
- 			PERROR("install: read: ", from_name);
- 			bad();
- 		}
  	}
  	else {
  		(void)lseek(from_fd, 0L, L_SET);
  		copy(from_fd, from_name, to_fd, to_name);
  	}
  }
  
  /*
--- 345,378 ----
  		head.a_syms = head.a_trsize = head.a_drsize = 0;
  		if ((head.a_magic == ZMAGIC) || (head.a_magic == Z0MAGIC))
  			size += getpagesize() - sizeof(EXEC);
  	}
  	else {
  		(void)lseek(from_fd, 0L, L_SET);
  		copy(from_fd, from_name, to_fd, to_name);
+ 		return;
  	}
+ #endif
+ 
+ 	if (write(to_fd, (char *)&head, sizeof(EXEC)) != sizeof(EXEC)) {
+ 		PERROR("install: write: ", to_name);
+ 		bad();
+ 	}
+ 	for (; size; size -= n)
+ 		/* sizeof(buf) guaranteed to fit in an int */
+ 		if ((n = read(from_fd, buf, (int)MIN(size, sizeof(buf)))) <= 0)
+ 			break;
+ 		else if (write(to_fd, buf, n) != n) {
+ 			PERROR("install: write: ", to_name);
+ 			bad();
+ 		}
+ 	if (size) {
+ 		fprintf(stderr, "install: read: %s: premature EOF.\n", from_name);
+ 		bad();
+ 	}
+ 	if (n == -1) {
+ 		PERROR("install: read: ", from_name);
+ 		bad();
+ 	}
  }
  
  /*
***************
*** 313,318 ****
--- 396,415 ----
  		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