summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib
diff options
context:
space:
mode:
authorflz <flz@FreeBSD.org>2010-04-01 14:27:29 +0000
committerflz <flz@FreeBSD.org>2010-04-01 14:27:29 +0000
commit348853b7ae1be0b9abbde8c1b0ad8dcb786a2cb7 (patch)
tree1486f9eaf9804cb93c84a7078a8ff619081a81d8 /usr.sbin/pkg_install/lib
parent45fc1063dc09f04be77d5f45e0f6dac1fe29025e (diff)
downloadFreeBSD-src-348853b7ae1be0b9abbde8c1b0ad8dcb786a2cb7.zip
FreeBSD-src-348853b7ae1be0b9abbde8c1b0ad8dcb786a2cb7.tar.gz
Various fixes.
- Replace hardcoded INDEX version. [1] - Fix a buffer overlap. [2] - Remove empty package when fetching fails and -K is used. [3] - Remove useless chmod2() after mkdtemp(3). [4] - Replace mkdir(1) call with mkdir(2). [5] - Get rid of some vsystem() calls. - Switch from lstat(2) to open(2) in fexists(). - Try rename(2) in move_file() first. - Bump PKG_INSTALL_VERSION to 20100401. PR: bin/145101 [1], bin/139492 [2], bin/144919 [3] bin/144920 [4], bin/144921 [5] Submitted by: gcooper [1,2,3,4,5]
Diffstat (limited to 'usr.sbin/pkg_install/lib')
-rw-r--r--usr.sbin/pkg_install/lib/file.c31
-rw-r--r--usr.sbin/pkg_install/lib/lib.h20
-rw-r--r--usr.sbin/pkg_install/lib/match.c2
-rw-r--r--usr.sbin/pkg_install/lib/pen.c4
-rw-r--r--usr.sbin/pkg_install/lib/url.c4
5 files changed, 32 insertions, 29 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 0b74ddf..c7ab9d6 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -31,10 +31,13 @@ __FBSDID("$FreeBSD$");
Boolean
fexists(const char *fname)
{
- struct stat dummy;
- if (!lstat(fname, &dummy))
- return TRUE;
- return FALSE;
+ int fd;
+
+ if ((fd = open(fname, O_RDONLY)) == -1)
+ return FALSE;
+
+ close(fd);
+ return TRUE;
}
/* Quick check to see if something is a directory or symlink to a directory */
@@ -279,17 +282,23 @@ copy_file(const char *dir, const char *fname, const char *to)
}
void
-move_file(const char *dir, const char *fname, const char *to)
+move_file(const char *dir, const char *fname, const char *tdir)
{
- char cmd[FILENAME_MAX];
+ char from[FILENAME_MAX];
+ char to[FILENAME_MAX];
if (fname[0] == '/')
- snprintf(cmd, FILENAME_MAX, "/bin/mv %s %s", fname, to);
+ strncpy(from, fname, FILENAME_MAX);
else
- snprintf(cmd, FILENAME_MAX, "/bin/mv %s/%s %s", dir, fname, to);
- if (vsystem(cmd)) {
- cleanup(0);
- errx(2, "%s: could not perform '%s'", __func__, cmd);
+ snprintf(from, FILENAME_MAX, "%s/%s", dir, fname);
+
+ snprintf(to, FILENAME_MAX, "%s/%s", tdir, fname);
+
+ if (rename(from, to) == -1) {
+ if (vsystem("/bin/mv %s %s", from, to)) {
+ cleanup(0);
+ errx(2, "%s: could not move '%s' to '%s'", __func__, from, to);
+ }
}
}
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index 4a6c625..21c2e75 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -28,6 +28,7 @@
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/queue.h>
+#include <sys/utsname.h>
#include <ctype.h>
#include <dirent.h>
#include <stdarg.h>
@@ -51,6 +52,11 @@
#define YES 2
#define NO 1
+/* Some more stat macros. */
+#define S_IRALL 0000444
+#define S_IWALL 0000222
+#define S_IXALL 0000111
+
/* Usually "rm", but often "echo" during debugging! */
#define REMOVE_CMD "/bin/rm"
@@ -84,18 +90,6 @@
#define DISPLAY_FNAME "+DISPLAY"
#define MTREE_FNAME "+MTREE_DIRS"
-#if defined(__FreeBSD_version) && __FreeBSD_version >= 900000
-#define INDEX_FNAME "INDEX-9"
-#elif defined(__FreeBSD_version) && __FreeBSD_version >= 800000
-#define INDEX_FNAME "INDEX-8"
-#elif defined(__FreeBSD_version) && __FreeBSD_version >= 700000
-#define INDEX_FNAME "INDEX-7"
-#elif defined(__FreeBSD_version) && __FreeBSD_version >= 600000
-#define INDEX_FNAME "INDEX-6"
-#else
-#define INDEX_FNAME "INDEX"
-#endif
-
#define CMD_CHAR '@' /* prefix for extended PLIST cmd */
/* The name of the "prefix" environment variable given to scripts */
@@ -105,7 +99,7 @@
* Version of the package tools - increase whenever you make a change
* in the code that is not cosmetic only.
*/
-#define PKG_INSTALL_VERSION 20100122
+#define PKG_INSTALL_VERSION 20100401
#define PKG_WRAPCONF_FNAME "/var/db/pkg_install.conf"
#define main(argc, argv) real_main(argc, argv)
diff --git a/usr.sbin/pkg_install/lib/match.c b/usr.sbin/pkg_install/lib/match.c
index 1f8b02a..6c1b2bf 100644
--- a/usr.sbin/pkg_install/lib/match.c
+++ b/usr.sbin/pkg_install/lib/match.c
@@ -267,7 +267,7 @@ matchallbyorigin(const char **origins, int *retval)
*/
if (isemptydir(tmp))
continue;
- snprintf(tmp, PATH_MAX, "%s/%s", tmp, CONTENTS_FNAME);
+ strncat(tmp, "/" CONTENTS_FNAME, PATH_MAX);
fp = fopen(tmp, "r");
if (fp == NULL) {
warnx("the package info for package '%s' is corrupt", installed[i]);
diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c
index 2f7e917..2b405a3 100644
--- a/usr.sbin/pkg_install/lib/pen.c
+++ b/usr.sbin/pkg_install/lib/pen.c
@@ -113,10 +113,6 @@ make_playpen(char *pen, off_t sz)
cleanup(0);
errx(2, "%s: can't mktemp '%s'", __func__, pen);
}
- if (chmod(pen, 0700) == FAIL) {
- cleanup(0);
- errx(2, "%s: can't mkdir '%s'", __func__, pen);
- }
if (Verbose) {
if (sz) {
diff --git a/usr.sbin/pkg_install/lib/url.c b/usr.sbin/pkg_install/lib/url.c
index b598c60..8c55347 100644
--- a/usr.sbin/pkg_install/lib/url.c
+++ b/usr.sbin/pkg_install/lib/url.c
@@ -108,6 +108,10 @@ fileGetURL(const char *base, const char *spec, int keep_package)
if ((ftp = fetchGetURL(fname, Verbose ? "v" : NULL)) == NULL) {
printf("Error: Unable to get %s: %s\n",
fname, fetchLastErrString);
+ /* If the fetch fails, yank the package. */
+ if (keep_package && unlink(pkg) < 0 && Verbose) {
+ warnx("failed to remove partially fetched package: %s", pkg);
+ }
return NULL;
}
OpenPOWER on IntegriCloud