2 * FreeBSD install - a package for the installation and maintenance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
19 #include <sys/cdefs.h>
20 __FBSDID("$FreeBSD$");
28 extern char **environ;
31 pkg_wrap(long curver, char **argv)
34 char ver[9]; /* Format is: 'YYYYMMDD\0' */
35 char buffer[FILENAME_MAX+10]; /* Format is: 'YYYYMMDD <path>' */
36 char cmd[FILENAME_MAX+5]; /* Format is: '<path> -PPq' */
40 if (getenv("PKG_NOWRAP") != NULL)
43 setenv("PKG_NOWRAP", "1", 1);
45 /* Get alternative location for package tools. */
46 if ((f = fopen(PKG_WRAPCONF_FNAME, "r")) == NULL) {
49 if (get_string(buffer, FILENAME_MAX+9, f) == NULL) {
52 if ((path = strrchr(buffer, ' ')) == NULL) {
60 if ((cp = strrchr(argv[0], '/')) == NULL) {
66 /* Get version of the other pkg_install and libpkg */
67 snprintf(cmd, FILENAME_MAX+10, "%s/%s -PPq", path, cp);
68 if ((f = popen(cmd, "r")) == NULL) {
72 if (get_string(ver, 9, f) == NULL)
75 ptver = strtol(ver, NULL, 10);
76 if (get_string(ver, 9, f) == NULL)
79 lpver = strtol(ver, NULL, 10);
83 if ((lpver >= LIBPKG_VERSION) && (ptver > curver)) {
84 snprintf(cmd, FILENAME_MAX, "%s/%s", path, cp);
85 execve(cmd, argv, environ);
89 unsetenv("PKG_NOWRAP");