/* * revdep - reverse dependency checker for rawnix * * Copyright (c) 2025 zorz@gmx.com * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * Concept based on revdep by James Buren for CRUX Linux. */ #ifndef REVDEP_H #define REVDEP_H #include #include #define VERSION "1.3.0" /* default paths */ #define PKG_DB_PATH "/var/lib/pkg/db" #define REVDEP_DIR "/etc/revdep.d" /* * System library path, as musl's dynamic linker has it: the file * /etc/ld-musl-x86_64.path if it exists, otherwise musl's built-in * default. */ #define MUSL_PATH_FILE "/etc/ld-musl-x86_64.path" #define MUSL_SYS_PATH "/lib:/usr/local/lib:/usr/lib" /* verbosity levels */ enum { V_QUIET = 0, /* package names only */ V_NORMAL = 1, /* formatted status per package */ V_FILES = 2, /* include broken files */ V_DETAIL = 3, /* include missing library names */ V_DEBUG = 4 /* trace everything */ }; /* dynamic string array */ typedef struct { char **items; size_t count; size_t capacity; } strvec_t; /* package */ typedef struct { char *name; char *version; strvec_t files; strvec_t dirs; /* extra lib search dirs from /etc/revdep.d */ bool ignore; } pkg_t; /* package array */ typedef struct { pkg_t **items; size_t count; size_t capacity; } pkgvec_t; /* ELF info */ typedef struct { char *path; strvec_t needed; strvec_t rpath; strvec_t runpath; bool valid; } elfinfo_t; /* --- strvec --------------------------------------------------------- */ void strvec_init(strvec_t *v); void strvec_free(strvec_t *v); bool strvec_push(strvec_t *v, const char *s); bool strvec_contains(const strvec_t *v, const char *s); /* --- pkg ------------------------------------------------------------- */ pkg_t *pkg_new(const char *name, const char *version); void pkg_free(pkg_t *p); /* --- pkgvec ---------------------------------------------------------- */ void pkgvec_init(pkgvec_t *v); void pkgvec_free(pkgvec_t *v); bool pkgvec_push(pkgvec_t *v, pkg_t *p); pkg_t *pkgvec_find(const pkgvec_t *v, const char *name); /* --- pkg database ---------------------------------------------------- */ bool db_read(const char *path, pkgvec_t *pkgs); bool db_read_dirs(const char *path, pkgvec_t *pkgs); /* --- elf ------------------------------------------------------------- */ elfinfo_t *elf_inspect(const char *path); void elf_free(elfinfo_t *e); /* --- elf cache ------------------------------------------------------- */ elfinfo_t *cache_lookup(const char *path); void cache_clear(void); /* --- library resolution ---------------------------------------------- */ bool lib_find(const elfinfo_t *elf, const pkg_t *pkg, const char *lib, const strvec_t *sys_dirs); /* --- python path checker --------------------------------------------- */ char *py_installed_version(const pkgvec_t *pkgs); bool py_check_package(const pkg_t *pkg, const char *installed); /* --- perl path checker ---------------------------------------------- */ char *perl_installed_version(const pkgvec_t *pkgs); bool perl_check_package(const pkg_t *pkg, const char *installed); /* --- package versions ----------------------------------------------- */ char *pkg_upstream_version(const char *dbversion); /* --- utility --------------------------------------------------------- */ char *xstrdup(const char *s); char *xpathjoin(const char *dir, const char *file); bool is_regfile(const char *path); char *realpath_safe(const char *path); void strsplit(const char *s, char delim, strvec_t *v); /* --- logging --------------------------------------------------------- */ extern int verbosity; void msg(int level, const char *fmt, ...); #endif