Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 10 commits
  • 10 files changed
  • 0 commit comments
  • 2 contributors
Commits on May 27, 2012
@infracaninophile Fix comments 8c0936c
@bapt bapt Document in FAQ: Undefined symbol "pkg_event_register" b26f5c8
@bapt bapt Fix keeping automatic flags on install/upgrade 45777b5
Commits on May 28, 2012
@bapt bapt Fix hardlinks detection 86303b1
@bapt bapt Factorise a bit pkgdb_it_next 26fab9e
@bapt bapt Remove some printf debug 2a31741
@infracaninophile Merge remote-tracking branch 'upstream/master'
Tracking upstream.
acdae9d
@bapt bapt pkg remove is an alias to pkg delete 23fc528
@infracaninophile Add the beginnings of ARCH_INDEP package support.
Initially, this modifies pkg register to allow automatically detecting
and marking as architecture independent packages that do not install
any ELF object files.  This should be correct in the vast majority of
cases, if not all.  Any cases where this isn't sufficient probably
aren't going to be dectable heuristically and packagers should
probably set an arch for the pkg explicitly.

Add ARCH_INDEP: yes to pkg.conf to enable this processing: defaults to
no change from existing behaviour.

Sets the arch field in the packages table of local.sqlite to (eg.)
freebsd:9:arch-indep for such packages.
c27cf88
@infracaninophile Merge remote-tracking branch 'upstream/master' 8d2ebfb
Showing with 183 additions and 116 deletions.
  1. +10 −0 FAQ.md
  2. +9 −2 libpkg/pkg.c
  3. +9 −0 libpkg/pkg.h
  4. +6 −0 libpkg/pkg_config.c
  5. +81 −42 libpkg/pkg_elf.c
  6. +27 −50 libpkg/pkgdb.c
  7. +11 −11 libpkg/utils.c
  8. +3 −0 pkg/main.c
  9. +5 −0 pkg/pkg.conf.5
  10. +22 −11 pkg/register.c
View
10 FAQ.md
@@ -21,6 +21,7 @@ Table of Contents
* [When will pkgng be the default package manager?](#14)
* [How can I use pkgng with portmaster?](#15)
* [How can I use pkgng with portupgrade?](#16)
+* [pkgng does not work it says: /usr/local/sbin/pkg: Undefined symbol "pkg_event_register"](#17)
<a name="0"></a>
### Q: How can I start using pkgng?
@@ -144,3 +145,12 @@ Currently only **ports-mgmt/portupgrade-devel** supports pkgng.
# pkg2ng
More information can be found in the portupgrade [NEWS](https://github.com/pkgtools/pkgtools/blob/master/NEWS.md) file.
+
+<a name="17"></a>
+### Q: pkgng does not work it says: /usr/local/sbin/pkg: Undefined symbol "pkg_event_register"
+
+You should have forgotten make delete-old-libs when you upgraded your system.
+
+during 9-CURRENT life the pkg_install tools has been splitted to provide a
+shared library: libpkg.so.0 and this has been reverted, this error message means
+that this library is still on your system, please check /usr/lib/libpkg.so.0
View
11 libpkg/pkg.c
@@ -176,6 +176,15 @@ pkg_is_valid(struct pkg *pkg)
return (EPKG_OK);
}
+int
+pkg_is_arch_indep(struct pkg *pkg)
+{
+ if (pkg->flags & PKG_CONTAINS_ARCH_DEP)
+ return EPKG_FATAL;
+ else
+ return EPKG_OK;
+}
+
static int
pkg_vget(struct pkg const *const pkg, va_list ap)
{
@@ -1085,14 +1094,12 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
while (pkg_dirs(pkg, &dir) == EPKG_OK) {
snprintf(spath, sizeof(spath), "%s%s", src, pkg_dir_path(dir));
snprintf(dpath, sizeof(dpath), "%s%s", dest, pkg_dir_path(dir));
- printf("%s -> %s\n", spath, dpath);
packing_append_file(pack, spath, dpath);
}
while (pkg_files(pkg, &file) == EPKG_OK) {
snprintf(spath, sizeof(spath), "%s%s", src, pkg_file_get(file, PKG_FILE_PATH));
snprintf(dpath, sizeof(dpath), "%s%s", dest, pkg_file_get(file, PKG_FILE_PATH));
- printf("%s -> %s\n", spath, dpath);
packing_append_file(pack, spath, dpath);
}
View
9 libpkg/pkg.h
@@ -258,6 +258,7 @@ typedef enum _pkg_config_key {
PKG_CONFIG_SIGNED_REPOS = 13,
PKG_CONFIG_ABI = 14,
PKG_CONFIG_DEVELOPER_MODE = 15,
+ PKG_CONFIG_ARCH_INDEP = 16,
} pkg_config_key;
typedef enum {
@@ -324,6 +325,11 @@ void pkg_free(struct pkg *);
int pkg_is_valid(struct pkg *);
/**
+ * Check if a package is marked architecture independent
+ */
+int pkg_is_arch_indep(struct pkg *);
+
+/**
* Open a package file archive and retrive informations.
* @param p A pointer to pkg allocated by pkg_new(), or if it points to a
* NULL pointer, the function allocate a new pkg using pkg_new().
@@ -433,6 +439,8 @@ int pkg_shlibs(struct pkg *pkg, struct pkg_shlib **shlib);
* @return An error code
*/
+#define PKG_CONTAINS_ARCH_DEP (1<<24) /* Don't conflict with PKG_LOAD_* q.v. */
+
int pkg_analyse_files(struct pkgdb *, struct pkg *);
/**
* Generic setter for simple attributes.
@@ -917,6 +925,7 @@ void pkg_test_filesum(struct pkg *);
int64_t pkg_recompute_flatsize(struct pkg *);
int pkg_get_myarch(char *pkgarch, size_t sz);
+int pkg_get_myarch_indep(char *pkgarch, size_t sz);
void pkgdb_cmd(int argc, char **argv);
#endif
View
6 libpkg/pkg_config.c
@@ -157,6 +157,12 @@ static struct config_entry c[] = {
"DEVELOPER_MODE",
"NO",
{ NULL }
+ },
+ [PKG_CONFIG_ARCH_INDEP] = {
+ BOOL,
+ "ARCH_INDEP",
+ "NO",
+ { NULL }
}
};
View
123 libpkg/pkg_elf.c
@@ -130,6 +130,14 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
size_t dynidx;
const char *osname;
+ bool shlibs = false;
+ bool autodeps = false;
+ bool arch_indep = false;
+
+ pkg_config_bool(PKG_CONFIG_AUTODEPS, &autodeps);
+ pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
+ pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &arch_indep);
+
int fd;
if ((fd = open(fpath, O_RDONLY, 0)) < 0) {
@@ -154,6 +162,14 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
return (EPKG_END); /* Not an elf file: no results */
}
+ if (arch_indep)
+ pkg->flags |= PKG_CONTAINS_ARCH_DEP;
+
+ if (!autodeps && !shlibs) {
+ ret = EPKG_OK;
+ goto cleanup;
+ }
+
if (gelf_getehdr(e, &elfhdr) == NULL) {
ret = EPKG_FATAL;
pkg_emit_error("getehdr() failed: %s.", elf_errmsg(-1));
@@ -181,15 +197,14 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
}
/*
- * note == NULL means no freebsd
+ * note == NULL usually means a shared object for use with dlopen(3)
* dynamic == NULL means not a dynamic linked elf
*/
if (dynamic == NULL) {
ret = EPKG_END;
goto cleanup; /* not a dynamically linked elf: no results */
}
- /* some freebsd binaries don't have notes like some perl modules */
if (note != NULL) {
data = elf_getdata(note, NULL);
osname = (const char *) data->d_buf + sizeof(Elf_Note);
@@ -234,16 +249,21 @@ pkg_analyse_files(struct pkgdb *db, struct pkg *pkg)
int ret = EPKG_OK;
bool shlibs = false;
bool autodeps = false;
+ bool arch_indep = false;
pkg_config_bool(PKG_CONFIG_SHLIBS, &shlibs);
pkg_config_bool(PKG_CONFIG_AUTODEPS, &autodeps);
+ pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &arch_indep);
- if (!autodeps && !shlibs)
+ if (!autodeps && !shlibs && !arch_indep)
return (EPKG_OK);
if (elf_version(EV_CURRENT) == EV_NONE)
return (EPKG_FATAL);
+ if (arch_indep)
+ pkg->flags &= ~PKG_CONTAINS_ARCH_DEP; /* Assume no architecture dependence, for contradiction */
+
while (pkg_files(pkg, &file) == EPKG_OK)
analyse_elf(db, pkg, pkg_file_get(file, PKG_FILE_PATH));
@@ -263,8 +283,8 @@ elf_corres_to_string(struct _elf_corres* m, int e)
}
-int
-pkg_get_myarch(char *dest, size_t sz)
+static int
+get_myarch(char *dest, size_t sz, bool arch_indep)
{
Elf *elf = NULL;
GElf_Ehdr elfhdr;
@@ -339,44 +359,51 @@ pkg_get_myarch(char *dest, size_t sz)
for (i = 0; osname[i] != '\0'; i++)
osname[i] = (char)tolower(osname[i]);
- snprintf(dest, sz, "%s:%d:%s:%s",
- osname,
- version / 100000,
- elf_corres_to_string(mach_corres, (int) elfhdr.e_machine),
- elf_corres_to_string(wordsize_corres, (int)elfhdr.e_ident[EI_CLASS]));
-
- switch (elfhdr.e_machine) {
- case EM_ARM:
- snprintf(dest + strlen(dest), sz - strlen(dest), ":%s:%s:%s",
- elf_corres_to_string(endian_corres, (int) elfhdr.e_ident[EI_DATA]),
- (elfhdr.e_flags & EF_ARM_NEW_ABI) > 0 ? "eabi" : "oabi",
- (elfhdr.e_flags & EF_ARM_VFP_FLOAT) > 0 ? "softfp" : "vfp");
- break;
- case EM_MIPS:
- /*
- * this is taken from binutils sources:
- * include/elf/mips.h
- * mapping is figured out from binutils:
- * gas/config/tc-mips.c
- */
- switch (elfhdr.e_flags & EF_MIPS_ABI) {
- case E_MIPS_ABI_O32:
- abi = "o32";
- break;
- case E_MIPS_ABI_N32:
- abi = "n32";
- break;
- default:
- if (elfhdr.e_ident[EI_DATA] == ELFCLASS32)
+ if (arch_indep) {
+ snprintf(dest, sz, "%s:%d:%s",
+ osname,
+ version / 100000,
+ "arch-indep");
+ } else {
+ snprintf(dest, sz, "%s:%d:%s:%s",
+ osname,
+ version / 100000,
+ elf_corres_to_string(mach_corres, (int) elfhdr.e_machine),
+ elf_corres_to_string(wordsize_corres, (int)elfhdr.e_ident[EI_CLASS]));
+
+ switch (elfhdr.e_machine) {
+ case EM_ARM:
+ snprintf(dest + strlen(dest), sz - strlen(dest), ":%s:%s:%s",
+ elf_corres_to_string(endian_corres, (int) elfhdr.e_ident[EI_DATA]),
+ (elfhdr.e_flags & EF_ARM_NEW_ABI) > 0 ? "eabi" : "oabi",
+ (elfhdr.e_flags & EF_ARM_VFP_FLOAT) > 0 ? "softfp" : "vfp");
+ break;
+ case EM_MIPS:
+ /*
+ * this is taken from binutils sources:
+ * include/elf/mips.h
+ * mapping is figured out from binutils:
+ * gas/config/tc-mips.c
+ */
+ switch (elfhdr.e_flags & EF_MIPS_ABI) {
+ case E_MIPS_ABI_O32:
abi = "o32";
- else if (elfhdr.e_ident[EI_DATA] == ELFCLASS64)
- abi = "n64";
- break;
- }
- snprintf(dest + strlen(dest), sz - strlen(dest), ":%s:%s",
- elf_corres_to_string(endian_corres, (int) elfhdr.e_ident[EI_DATA]),
- abi);
- break;
+ break;
+ case E_MIPS_ABI_N32:
+ abi = "n32";
+ break;
+ default:
+ if (elfhdr.e_ident[EI_DATA] == ELFCLASS32)
+ abi = "o32";
+ else if (elfhdr.e_ident[EI_DATA] == ELFCLASS64)
+ abi = "n64";
+ break;
+ }
+ snprintf(dest + strlen(dest), sz - strlen(dest), ":%s:%s",
+ elf_corres_to_string(endian_corres, (int) elfhdr.e_ident[EI_DATA]),
+ abi);
+ break;
+ }
}
cleanup:
@@ -386,3 +413,15 @@ pkg_get_myarch(char *dest, size_t sz)
close(fd);
return (ret);
}
+
+int
+pkg_get_myarch(char *dest, size_t sz)
+{
+ return (get_myarch(dest, sz, false));
+}
+
+int
+pkg_get_myarch_indep(char *dest, size_t sz)
+{
+ return (get_myarch(dest, sz, true));
+}
View
77 libpkg/pkgdb.c
@@ -760,11 +760,30 @@ pkgdb_it_new(struct pkgdb *db, sqlite3_stmt *s, int type)
return (it);
}
+static struct load_on_flag {
+ int flag;
+ int (*load)(struct pkgdb *db, struct pkg *p);
+} load_on_flag[] = {
+ { PKG_LOAD_DEPS, pkgdb_load_deps },
+ { PKG_LOAD_RDEPS, pkgdb_load_rdeps },
+ { PKG_LOAD_FILES, pkgdb_load_files },
+ { PKG_LOAD_DIRS, pkgdb_load_dirs },
+ { PKG_LOAD_SCRIPTS, pkgdb_load_scripts },
+ { PKG_LOAD_OPTIONS, pkgdb_load_options },
+ { PKG_LOAD_MTREE, pkgdb_load_mtree },
+ { PKG_LOAD_CATEGORIES, pkgdb_load_category },
+ { PKG_LOAD_LICENSES, pkgdb_load_license },
+ { PKG_LOAD_USERS, pkgdb_load_user },
+ { PKG_LOAD_GROUPS, pkgdb_load_group },
+ { PKG_LOAD_SHLIBS, pkgdb_load_shlib },
+ { -1, NULL }
+};
int
pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
{
struct pkg *pkg;
+ int i;
int ret;
assert(it != NULL);
@@ -779,53 +798,11 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
populate_pkg(it->stmt, pkg);
- if (flags & PKG_LOAD_DEPS)
- if ((ret = pkgdb_load_deps(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_RDEPS)
- if ((ret = pkgdb_load_rdeps(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_FILES)
- if ((ret = pkgdb_load_files(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_DIRS)
- if ((ret = pkgdb_load_dirs(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_SCRIPTS)
- if ((ret = pkgdb_load_scripts(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_OPTIONS)
- if ((ret = pkgdb_load_options(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_MTREE)
- if ((ret = pkgdb_load_mtree(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_CATEGORIES)
- if ((ret = pkgdb_load_category(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_LICENSES)
- if ((ret = pkgdb_load_license(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_USERS)
- if ((ret = pkgdb_load_user(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_GROUPS)
- if ((ret = pkgdb_load_group(it->db, pkg)) != EPKG_OK)
- return (ret);
-
- if (flags & PKG_LOAD_SHLIBS)
- if ((ret = pkgdb_load_shlib(it->db, pkg)) != EPKG_OK)
- return (ret);
+ for (i = 0; load_on_flag[i].load != NULL; i++) {
+ if (flags & load_on_flag[i].flag)
+ if ((ret = load_on_flag[i].load(it->db, pkg)) != EPKG_OK)
+ return (ret);
+ }
return (EPKG_OK);
case SQLITE_DONE:
@@ -2441,7 +2418,7 @@ pkgdb_query_installs(struct pkgdb *db, match_t match, int nbpkgs, char **pkgs, c
"cksum, repopath, automatic) "
"SELECT l.id, l.origin, l.name, l.version, l.comment, l.desc, l.message, l.arch, "
"l.maintainer, l.www, l.prefix, l.flatsize, r.version AS newversion, "
- "r.flatsize AS newflatsize, r.pkgsize, r.cksum, r.repopath, r.automatic "
+ "r.flatsize AS newflatsize, r.pkgsize, r.cksum, r.repopath, l.automatic "
"FROM main.packages AS l, pkgjobs AS r WHERE l.origin = r.origin ");
sbuf_reset(sql);
@@ -2514,7 +2491,7 @@ pkgdb_query_upgrades(struct pkgdb *db, const char *repo, bool all)
"cksum, repopath, automatic) "
"SELECT l.id, l.origin, l.name, l.version, l.comment, l.desc, l.message, l.arch, "
"l.maintainer, l.www, l.prefix, l.flatsize, r.version AS newversion, "
- "r.flatsize AS newflatsize, r.pkgsize, r.cksum, r.repopath, r.automatic "
+ "r.flatsize AS newflatsize, r.pkgsize, r.cksum, r.repopath, l.automatic "
"FROM main.packages AS l, pkgjobs AS r WHERE l.origin = r.origin "
"AND (PKGLT(l.version, r.version) OR (l.name != r.name))";
} else {
@@ -2523,7 +2500,7 @@ pkgdb_query_upgrades(struct pkgdb *db, const char *repo, bool all)
"cksum, repopath, automatic) "
"SELECT l.id, l.origin, l.name, l.version, l.comment, l.desc, l.message, l.arch, "
"l.maintainer, l.www, l.prefix, l.flatsize, r.version AS newversion, "
- "r.flatsize AS newflatsize, r.pkgsize, r.cksum, r.repopath, r.automatic "
+ "r.flatsize AS newflatsize, r.pkgsize, r.cksum, r.repopath, l.automatic "
"FROM main.packages AS l, pkgjobs AS r WHERE l.origin = r.origin";
}
View
22 libpkg/utils.c
@@ -370,16 +370,16 @@ bool is_hardlink(struct hardlinks *hl, struct stat *st)
size_t i;
for (i = 0; i < hl->len; i++) {
- if (hl->inodes[i] == st->st_ino) {
- if (hl->cap <= hl->len) {
- hl->cap |= 1;
- hl->cap *= 2;
- hl->inodes = reallocf(hl->inodes,
- hl->cap * sizeof(ino_t));
- }
- hl->inodes[hl->len++] = st->st_ino;
- return false;
- }
+ if (hl->inodes[i] == st->st_ino)
+ return (false);
}
- return true;
+ if (hl->cap <= hl->len) {
+ hl->cap |= 1;
+ hl->cap *= 2;
+ hl->inodes = reallocf(hl->inodes,
+ hl->cap * sizeof(ino_t));
+ }
+ hl->inodes[hl->len++] = st->st_ino;
+
+ return (true);
}
View
3 pkg/main.c
@@ -75,6 +75,7 @@ static struct commands {
{ "search", "Performs a search in remote package repositories", exec_search, usage_search},
{ "set", "Modify local database informations", exec_set, usage_set},
{ "register", "Registers a package into the local package database", exec_register, usage_register},
+ { "remove", "Deletes packages from the database and the system", exec_delete, usage_delete},
{ "repo", "Creates a package database repository", exec_repo, usage_repo},
{ "rquery", "Query information from the remote repository", exec_rquery, usage_rquery},
{ "shell", "Open a debug shell", exec_shell, usage_shell},
@@ -265,6 +266,8 @@ main(int argc, char **argv)
printf("Custom keywords directory: %s\n", buf ? buf : "none");
pkg_config_bool(PKG_CONFIG_DEVELOPER_MODE, &b);
printf("Developer mode: %s\n", b ? "yes" : "no");
+ pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &b);
+ printf("Detect achitecture independence: %s\n", b ? "yes" : "no");
}
pkg_config_bool(PKG_CONFIG_MULTIREPOS, &b);
if (b) {
View
5 pkg/pkg.conf.5
@@ -114,6 +114,11 @@ All the remote repositories should be signed.
default: off
.It Cm ABI: string
the abi of the package you want to install, by default the /bin/sh abi is used
+.It Cm ARCH_INDEP: boolean
+Analyse package contents to detect when it consists entirely of
+architecture independent files (ie. no ELF objects are contained
+within it)
+default: off
.El
.Sh ENVIRONMENT
An environment variable with the same name as the option in the configuration
View
33 pkg/register.c
@@ -93,6 +93,7 @@ exec_register(int argc, char **argv)
size_t size;
bool legacy = false;
+ bool arch_indep = false;
int i;
int ret = EPKG_OK, retcode = EPKG_OK;
@@ -138,17 +139,7 @@ exec_register(int argc, char **argv)
if (plist == NULL)
errx(EX_USAGE, "missing -f flag");
- if (arch == NULL) {
- /*
- * do not take the one from configuration on purpose
- * but the real abi of the package
- */
- pkg_get_myarch(myarch, BUFSIZ);
- pkg_set(pkg, PKG_ARCH, myarch);
- } else {
- pkg_set(pkg, PKG_ARCH, arch);
- free(arch);
- }
+ pkg_config_bool(PKG_CONFIG_ARCH_INDEP, &arch_indep);
if (mdir == NULL)
errx(EX_USAGE, "missing -m flag");
@@ -208,6 +199,26 @@ exec_register(int argc, char **argv)
pkg_analyse_files(db, pkg);
+ if (arch == NULL) {
+ /*
+ * do not take the one from configuration on purpose
+ * but the real abi of the package.
+ *
+ * Don't label any package as arch-indep unless arch_indep
+ * is set: default to treating everything as
+ * architecture dependent.
+ */
+ if (arch_indep && pkg_is_arch_indep(pkg) == EPKG_OK)
+ pkg_get_myarch_indep(myarch, BUFSIZ);
+ else
+ pkg_get_myarch(myarch, BUFSIZ);
+
+ pkg_set(pkg, PKG_ARCH, myarch);
+ } else {
+ pkg_set(pkg, PKG_ARCH, arch);
+ free(arch);
+ }
+
if (input_path != NULL) {
pkg_copy_tree(pkg, input_path, "/");
free(input_path);

No commit comments for this range

Something went wrong with that request. Please try again.