1103149Ssobomax/* 2103149Ssobomax * FreeBSD install - a package for the installation and maintenance 3103149Ssobomax * of non-core utilities. 4103149Ssobomax * 5103149Ssobomax * Redistribution and use in source and binary forms, with or without 6103149Ssobomax * modification, are permitted provided that the following conditions 7103149Ssobomax * are met: 8103149Ssobomax * 1. Redistributions of source code must retain the above copyright 9103149Ssobomax * notice, this list of conditions and the following disclaimer. 10103149Ssobomax * 2. Redistributions in binary form must reproduce the above copyright 11103149Ssobomax * notice, this list of conditions and the following disclaimer in the 12103149Ssobomax * documentation and/or other materials provided with the distribution. 13103149Ssobomax * 14103149Ssobomax * Maxim Sobolev 15103149Ssobomax * 8 September 2002 16103149Ssobomax * 17103149Ssobomax */ 18103149Ssobomax 19103149Ssobomax#include <sys/cdefs.h> 20103149Ssobomax__FBSDID("$FreeBSD$"); 21103149Ssobomax 22103149Ssobomax#include "lib.h" 23103149Ssobomax#include <ctype.h> 24103149Ssobomax#include <stdio.h> 25103149Ssobomax#include <stdlib.h> 26103149Ssobomax#include <unistd.h> 27103149Ssobomax 28103149Ssobomax#undef main 29103149Ssobomax 30103149Ssobomax#define SEPARATORS " \t" 31103149Ssobomax 32103149Ssobomaxextern char **environ; 33103149Ssobomax 34103149Ssobomaxint 35103149Ssobomaxmain(int argc, char **argv) 36103149Ssobomax{ 37103149Ssobomax FILE *f; 38103149Ssobomax char buffer[FILENAME_MAX], *cp, *verstr; 39103149Ssobomax int len; 40103149Ssobomax 41103149Ssobomax if (getenv("PKG_NOWRAP") != NULL) 42103149Ssobomax goto nowrap; 43103149Ssobomax f = fopen(PKG_WRAPCONF_FNAME, "r"); 44103149Ssobomax if (f == NULL) 45103149Ssobomax goto nowrap; 46103149Ssobomax cp = fgets(buffer, 256, f); 47103149Ssobomax fclose(f); 48103149Ssobomax if (cp == NULL) 49103149Ssobomax goto nowrap; 50103149Ssobomax len = strlen(cp); 51103149Ssobomax if (cp[len - 1] == '\n') 52103149Ssobomax cp[len - 1] = '\0'; 53103149Ssobomax while (strchr(SEPARATORS, *cp) != NULL) 54103149Ssobomax cp++; 55103149Ssobomax verstr = cp; 56103149Ssobomax cp = strpbrk(cp, SEPARATORS); 57103149Ssobomax if (cp == NULL) 58103149Ssobomax goto nowrap; 59103149Ssobomax *cp = '\0'; 60103149Ssobomax for (cp = verstr; *cp != '\0'; cp++) 61103149Ssobomax if (isdigit(*cp) == 0) 62103149Ssobomax goto nowrap; 63103149Ssobomax if (atoi(verstr) < PKG_INSTALL_VERSION) 64103149Ssobomax goto nowrap; 65103149Ssobomax cp++; 66103149Ssobomax while (*cp != '\0' && strchr(SEPARATORS, *cp) != NULL) 67103149Ssobomax cp++; 68103149Ssobomax if (*cp == '\0') 69103149Ssobomax goto nowrap; 70103149Ssobomax bcopy(cp, buffer, strlen(cp) + 1); 71103149Ssobomax cp = strpbrk(buffer, SEPARATORS); 72103149Ssobomax if (cp != NULL) 73103149Ssobomax *cp = '\0'; 74103149Ssobomax if (!isdir(buffer)) 75103149Ssobomax goto nowrap; 76103149Ssobomax cp = strrchr(argv[0], '/'); 77103149Ssobomax if (cp == NULL) 78103149Ssobomax cp = argv[0]; 79103149Ssobomax else 80103149Ssobomax cp++; 81103149Ssobomax strlcat(buffer, "/", sizeof(buffer)); 82103149Ssobomax strlcat(buffer, cp, sizeof(buffer)); 83103149Ssobomax setenv("PKG_NOWRAP", "1", 1); 84103149Ssobomax execve(buffer, argv, environ); 85103149Ssobomax 86103149Ssobomaxnowrap: 87103149Ssobomax unsetenv("PKG_NOWRAP"); 88103149Ssobomax return(real_main(argc, argv)); 89103149Ssobomax} 90