pkgwrap.c revision 285830
1/* 2 * FreeBSD install - a package for the installation and maintenance 3 * of non-core utilities. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * Maxim Sobolev 15 * 8 September 2002 16 * 17 */ 18 19#include <sys/cdefs.h> 20__FBSDID("$FreeBSD: releng/10.2/usr.sbin/pkg_install/lib/pkgwrap.c 103149 2002-09-09 19:43:30Z sobomax $"); 21 22#include "lib.h" 23#include <ctype.h> 24#include <stdio.h> 25#include <stdlib.h> 26#include <unistd.h> 27 28#undef main 29 30#define SEPARATORS " \t" 31 32extern char **environ; 33 34int 35main(int argc, char **argv) 36{ 37 FILE *f; 38 char buffer[FILENAME_MAX], *cp, *verstr; 39 int len; 40 41 if (getenv("PKG_NOWRAP") != NULL) 42 goto nowrap; 43 f = fopen(PKG_WRAPCONF_FNAME, "r"); 44 if (f == NULL) 45 goto nowrap; 46 cp = fgets(buffer, 256, f); 47 fclose(f); 48 if (cp == NULL) 49 goto nowrap; 50 len = strlen(cp); 51 if (cp[len - 1] == '\n') 52 cp[len - 1] = '\0'; 53 while (strchr(SEPARATORS, *cp) != NULL) 54 cp++; 55 verstr = cp; 56 cp = strpbrk(cp, SEPARATORS); 57 if (cp == NULL) 58 goto nowrap; 59 *cp = '\0'; 60 for (cp = verstr; *cp != '\0'; cp++) 61 if (isdigit(*cp) == 0) 62 goto nowrap; 63 if (atoi(verstr) < PKG_INSTALL_VERSION) 64 goto nowrap; 65 cp++; 66 while (*cp != '\0' && strchr(SEPARATORS, *cp) != NULL) 67 cp++; 68 if (*cp == '\0') 69 goto nowrap; 70 bcopy(cp, buffer, strlen(cp) + 1); 71 cp = strpbrk(buffer, SEPARATORS); 72 if (cp != NULL) 73 *cp = '\0'; 74 if (!isdir(buffer)) 75 goto nowrap; 76 cp = strrchr(argv[0], '/'); 77 if (cp == NULL) 78 cp = argv[0]; 79 else 80 cp++; 81 strlcat(buffer, "/", sizeof(buffer)); 82 strlcat(buffer, cp, sizeof(buffer)); 83 setenv("PKG_NOWRAP", "1", 1); 84 execve(buffer, argv, environ); 85 86nowrap: 87 unsetenv("PKG_NOWRAP"); 88 return(real_main(argc, argv)); 89} 90