Skip to content

Commit

Permalink
Merge branch 'freebsd:main' into patch-4
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamperrin authored Jan 5, 2025
2 parents e7da823 + e59b844 commit b3008c9
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 165 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes from 1.21.99.6 to 1.21.99.6
- ignore OSVERSION if set but ABI is not set

Changes from 1.21.99.4 to 1.21.99.5
- the pkg target ABI is now dynamically detected, pkg can be used to cross
install packages among OS.
Expand Down
2 changes: 1 addition & 1 deletion auto.def
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cc cc-lib cc-shared pkg-config
set maj_ver 1
set med_ver 21
set min_ver 99
set dev_ver 3
set dev_ver 6
define PKG_API [expr {$maj_ver * 1000000 + $med_ver * 1000 + $min_ver}]
define VERSION $maj_ver.$med_ver.$min_ver[expr {$dev_ver ? ".$dev_ver" : ""}]

Expand Down
2 changes: 1 addition & 1 deletion libpkg/Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,6 @@ install: all pkg.h lib$(LIB)$(LIBSOEXT) lib$(LIB)_flat.a
ln -sf lib$(LIB)$(LIBSOEXT) $(DESTDIR)$(libdir)/lib$(LIB)$(SH_SOEXT)
install -m 644 lib$(LIB)_flat.a $(DESTDIR)$(libdir)/lib$(LIB).a
install -m 644 pkg.h $(DESTDIR)$(includedir)/
install -m 644 pkgvec.h $(DESTDIR)$(includedir)/
install -m 644 $(top_srcdir)/libpkg/pkg/vec.h $(DESTDIR)$(includedir)/pkg
install -m 644 $(top_srcdir)/libpkg/pkg/audit.h $(DESTDIR)$(includedir)/pkg
install -m 644 pkg.pc $(DESTDIR)$(pkgconfigdir)/
4 changes: 2 additions & 2 deletions libpkg/pkg.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern "C" {
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <pkgvec.h>
#include <pkg/vec.h>

/* The expected name of the pkg(8) binary executable. */
#ifndef PKG_EXEC_NAME
Expand Down Expand Up @@ -136,7 +136,7 @@ struct pkg_kv {
char *value;
};

typedef pkgvec_t(struct pkg_kv *) pkg_kvl_t;
typedef vec_t(struct pkg_kv *) pkg_kvl_t;

/**
* The system-wide pkg(8) status: ie. is it a) installed or otherwise
Expand Down
26 changes: 13 additions & 13 deletions libpkg/pkgvec.h → libpkg/pkg/vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@
#include <stdlib.h>
#include <stddef.h>

#define pkgvec_t(Type) \
#define vec_t(Type) \
struct { Type *d; size_t len, cap; }

#define pkgvec_init(v) \
#define vec_init(v) \
memset((v), 0, sizeof(*(v)))

#define pkgvec_free(v) \
#define vec_free(v) \
do { \
free((v)->d); \
(v)->d == NULL; \
memset((v), 0, sizeof(*(v))); \
} while (0)

#define pkgvec_free_and_free(v, free_func) \
#define vec_free_and_free(v, free_func) \
do { \
for (size_t _i=0; _i < (v)->len ; _i++) { \
free_func((v)->d[_i]); \
(v)->d[_i] = NULL; \
} \
pkgvec_free((v)); \
vec_free((v)); \
} while(0)

#define pkgvec_first(v) \
#define vec_first(v) \
(v)->d[0]

#define pkgvec_last(v) \
#define vec_last(v) \
(v)->d[(v)->len -1]

#define pkgvec_clear(v) \
#define vec_clear(v) \
(v)->len = 0

#define pkgvec_clear_and_free(v, free_func) \
#define vec_clear_and_free(v, free_func) \
do { \
for (size_t _i=0; _i < (v)->len ; _i++) { \
free_func((v)->d[_i]); \
Expand All @@ -50,7 +50,7 @@
(v)->len = 0; \
} while (0)

#define pkgvec_push(v, _d) \
#define vec_push(v, _d) \
do { \
if ((v)->len + 1 > (v)->cap) { \
if ((v)->cap == 0) \
Expand All @@ -64,8 +64,8 @@
(v)->d[(v)->len++] = (_d); \
} while (0) \

#define pkgvec_pop(v) \
#define vec_pop(v) \
(v)->d[--(v)->len]

typedef pkgvec_t(char *) charv_t;
typedef pkgvec_t(const char *) c_charv_t;
typedef vec_t(char *) charv_t;
typedef vec_t(const char *) c_charv_t;
32 changes: 16 additions & 16 deletions libpkg/pkg_add.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ get_tempdir(int rootfd, const char *path, tempdirs_t *tempdirs, c_charv_t *symli

tmpdir = open_tempdir(rootfd, path, symlinks_allowed);
if (tmpdir != NULL)
pkgvec_push(tempdirs, tmpdir);
vec_push(tempdirs, tmpdir);

return (tmpdir);
}
Expand Down Expand Up @@ -1089,7 +1089,7 @@ pkg_extract_finalize(struct pkg *pkg, tempdirs_t *tempdirs)
return (EPKG_FATAL);
}
if (tempdirs != NULL)
pkgvec_free(tempdirs);
vec_free(tempdirs);

return (EPKG_OK);
}
Expand Down Expand Up @@ -1361,8 +1361,8 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,

assert(path != NULL);

pkgvec_init(&tempdirs);
pkgvec_init(&symlinks_allowed);
vec_init(&tempdirs);
vec_init(&symlinks_allowed);

/*
* Open the package archive file, read all the meta files and set the
Expand Down Expand Up @@ -1465,7 +1465,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
*/
if (extract) {
pkg_register_cleanup_callback(pkg_rollback_cb, pkg);
pkgvec_push(&symlinks_allowed, pkg->prefix);
vec_push(&symlinks_allowed, pkg->prefix);
retcode = do_extract(a, ae, nfiles, pkg, local, &tempdirs, &symlinks_allowed);
pkg_unregister_cleanup_callback(pkg_rollback_cb, pkg);
if (retcode != EPKG_OK) {
Expand Down Expand Up @@ -1564,7 +1564,7 @@ pkg_add_common(struct pkgdb *db, const char *path, unsigned flags,
}

cleanup:
pkgvec_free(&symlinks_allowed);
vec_free(&symlinks_allowed);

if (openxact)
pkgdb_register_finale(db, retcode, NULL);
Expand Down Expand Up @@ -1665,10 +1665,10 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
tempdirs_t tempdirs;
c_charv_t symlinks_allowed;

pkgvec_init(&symlinks_allowed);
pkgvec_push(&symlinks_allowed, pkg->prefix);
pkgvec_init(&hardlinks);
pkgvec_init(&tempdirs);
vec_init(&symlinks_allowed);
vec_push(&symlinks_allowed, pkg->prefix);
vec_init(&hardlinks);
vec_init(&tempdirs);
install_as_user = (getenv("INSTALL_AS_USER") != NULL);

fromfd = open(src, O_DIRECTORY);
Expand Down Expand Up @@ -1736,7 +1736,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
continue;
if (fstatat(fromfd, RELATIVE_PATH(f->path), &st,
AT_SYMLINK_NOFOLLOW) == -1) {
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);
close(fromfd);
pkg_fatal_errno("%s%s", src, f->path);
}
Expand Down Expand Up @@ -1789,7 +1789,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
if ((link_len = readlinkat(fromfd,
RELATIVE_PATH(f->path), target,
sizeof(target))) == -1) {
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);
close(fromfd);
pkg_fatal_errno("Impossible to read symlinks "
"'%s'", f->path);
Expand All @@ -1802,7 +1802,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
} else if (S_ISREG(st.st_mode)) {
if ((fd = openat(fromfd, RELATIVE_PATH(f->path),
O_RDONLY)) == -1) {
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);
close(fromfd);
pkg_fatal_errno("Impossible to open source file"
" '%s'", RELATIVE_PATH(f->path));
Expand Down Expand Up @@ -1832,7 +1832,7 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
h->ino = st.st_ino;
h->dev = st.st_dev;
h->path = f->path;
pkgvec_push(&hardlinks, h);
vec_push(&hardlinks, h);
}
close(fd);
} else {
Expand All @@ -1845,8 +1845,8 @@ pkg_add_fromdir(struct pkg *pkg, const char *src)
retcode = pkg_extract_finalize(pkg, &tempdirs);

cleanup:
pkgvec_free(&symlinks_allowed);
pkgvec_free_and_free(&hardlinks, free);
vec_free(&symlinks_allowed);
vec_free_and_free(&hardlinks, free);
close(fromfd);
return (retcode);
}
Expand Down
15 changes: 8 additions & 7 deletions libpkg/pkg_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ pkg_external_libs_version(void)
{
pkg_kvl_t *kvl = xcalloc(1, sizeof(*kvl));

pkgvec_push(kvl, pkg_kv_new("libcurl", curl_version()));
pkgvec_push(kvl, pkg_kv_new("libarchive", archive_version_string()));
pkgvec_push(kvl, pkg_kv_new("sqlite", sqlite3_libversion()));
pkgvec_push(kvl, pkg_kv_new("openssl", OpenSSL_version(OPENSSL_VERSION)));
vec_push(kvl, pkg_kv_new("libcurl", curl_version()));
vec_push(kvl, pkg_kv_new("libarchive", archive_version_string()));
vec_push(kvl, pkg_kv_new("sqlite", sqlite3_libversion()));
vec_push(kvl, pkg_kv_new("openssl", OpenSSL_version(OPENSSL_VERSION)));

return (kvl);
}
Expand Down Expand Up @@ -1066,10 +1066,11 @@ config_init_abi(struct pkg_abi *abi)
pkg_os_to_string(abi->os));
}
}
} else if (env_osversion_string != NULL) {
pkg_emit_error("Setting OSVERSION requires setting ABI as well");
return (EPKG_FATAL);
} else {
if (env_osversion_string != NULL) {
dbg(1, "Setting OSVERSION requires setting ABI as well (ignoring)");
unsetenv("OSVERSION");
}
if (pkg_abi_from_file(abi) != EPKG_OK) {
return (false);
}
Expand Down
10 changes: 5 additions & 5 deletions libpkg/pkg_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
ucl_object_t *obj;
hardlinks_t hardlinks;

pkgvec_init(&hardlinks);
vec_init(&hardlinks);
if (pkg_is_valid(pkg) != EPKG_OK) {
pkg_emit_error("the package is not valid");
return (EPKG_FATAL);
Expand All @@ -96,13 +96,13 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,

if (lstat(fpath, &st) == -1) {
pkg_emit_error("file '%s' is missing", fpath);
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);
return (EPKG_FATAL);
}

if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) {
pkg_emit_error("file '%s' is not a regular file or symlink", fpath);
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);
return (EPKG_FATAL);
}

Expand All @@ -117,13 +117,13 @@ pkg_create_from_dir(struct pkg *pkg, const char *root,
file->sum = pkg_checksum_generate_file(fpath,
PKG_HASH_TYPE_SHA256_HEX);
if (file->sum == NULL) {
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);
return (EPKG_FATAL);
}

counter_count();
}
pkgvec_free_and_free(&hardlinks, free);
vec_free_and_free(&hardlinks, free);

counter_end();

Expand Down
5 changes: 2 additions & 3 deletions libpkg/pkg_jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "pkgvec.h"
#ifdef HAVE_CONFIG_H
#include "pkg_config.h"
#endif
Expand Down Expand Up @@ -121,9 +120,9 @@ int
pkg_jobs_set_repository(struct pkg_jobs *j, const char *ident)
{
c_charv_t idents;
pkgvec_init(&idents);
vec_init(&idents);
if (ident != NULL)
pkgvec_push(&idents, ident);
vec_push(&idents, ident);
return (pkg_jobs_set_repositories(j, &idents));
}

Expand Down
4 changes: 2 additions & 2 deletions libpkg/pkg_ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ plist_new(struct pkg *pkg, const char *stage)
p->post_install_buf = xstring_new();
p->pre_deinstall_buf = xstring_new();
p->post_deinstall_buf = xstring_new();
pkgvec_init(&p->hardlinks);
vec_init(&p->hardlinks);

populate_keywords(p);

Expand All @@ -1072,7 +1072,7 @@ plist_free(struct plist *p)

free(p->uname);
free(p->gname);
pkgvec_free_and_free(&p->hardlinks, free);
vec_free_and_free(&p->hardlinks, free);

xstring_free(p->post_deinstall_buf);
xstring_free(p->post_install_buf);
Expand Down
8 changes: 4 additions & 4 deletions libpkg/pkgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#include "private/utils.h"
#include "private/pkg_deps.h"
#include "tllist.h"
#include "pkgvec.h"
#include "pkg/vec.h"

#include "private/db_upgrades.h"

Expand Down Expand Up @@ -987,12 +987,12 @@ pkgdb_open_all(struct pkgdb **db_p, pkgdb_t type, const char *reponame)
c_charv_t r;
int ret;

pkgvec_init(&r);
vec_init(&r);
if (reponame != NULL)
pkgvec_push(&r, reponame);
vec_push(&r, reponame);

ret = pkgdb_open_all2(db_p, type, &r);
pkgvec_free(&r);
vec_free(&r);
return (ret);
}
int
Expand Down
Loading

0 comments on commit b3008c9

Please sign in to comment.