First steps for libapk
parent
60b537e356
commit
3ec82a5a42
|
@ -2,3 +2,4 @@ apk
|
|||
*.o
|
||||
*.d
|
||||
*.cmd
|
||||
*.so
|
||||
|
|
22
Make.rules
22
Make.rules
|
@ -70,7 +70,7 @@ INSTALL := install
|
|||
INSTALLDIR := $(INSTALL) -d
|
||||
|
||||
CFLAGS ?= -g -O2
|
||||
CFLAGS_ALL := -Werror -Wall -Wstrict-prototypes -D_GNU_SOURCE -std=gnu99
|
||||
CFLAGS_ALL := -Werror -Wall -Wstrict-prototypes -D_GNU_SOURCE -std=gnu99 -fPIC
|
||||
CFLAGS_ALL += $(CFLAGS)
|
||||
|
||||
LDFLAGS ?= -g
|
||||
|
@ -196,6 +196,24 @@ $(obj)/%.o: override local-target-prereqs=%
|
|||
$(obj)/%.o: $(src)/%.c FORCE
|
||||
$(call if_changed_rule,cc_o_c)
|
||||
|
||||
#####
|
||||
# Link shared libraries
|
||||
#
|
||||
__shlibs := $(addprefix $(obj)/,$(sort $(shlibs-y)))
|
||||
shobjs := $(addprefix $(obj)/,$(sort $(foreach m,$(shlibs-y),$($(m)-objs))))
|
||||
|
||||
# link shared library
|
||||
quiet_cmd_shlib = LD -shared $@
|
||||
cmd_shlib = $(CC) $(ld_flags) -shared -o $@ \
|
||||
$(addprefix $(obj)/,$($(@F)-objs)) \
|
||||
$(LIBS) $(LIBS_$(@F))
|
||||
|
||||
$(__shlibs): override local-target-prereqs=$(addprefix $(obj)/,$($(*F)-objs))
|
||||
|
||||
$(__shlibs): $(obj)/%: $(shobjs) FORCE
|
||||
$(call if_changed,shlib)
|
||||
|
||||
targets += $(__shlibs) $(shobjs)
|
||||
#####
|
||||
# Link programs
|
||||
|
||||
|
@ -256,7 +274,7 @@ ifeq ($(toplevelrun),yes)
|
|||
\( -name '*.[oas]' -o -name '.*.cmd' -o -name '.*.d' \) \
|
||||
-type f -print | xargs rm -f
|
||||
endif
|
||||
$(Q)rm -rf $(addprefix $(obj)/,$(sort $(progs-y) $(progs-n) $(progs-)))
|
||||
$(Q)rm -rf $(addprefix $(obj)/,$(sort $(progs-y) $(progs-n) $(progs-) $(shlibs-y) $(shlibs-n) $(shlibs-)))
|
||||
|
||||
ifeq ($(origin VERSION),command line)
|
||||
DIST_VERSION=$(VERSION)
|
||||
|
|
3
Makefile
3
Makefile
|
@ -9,11 +9,12 @@ VERSION := 2.0.3
|
|||
|
||||
DESTDIR :=
|
||||
SBINDIR := /sbin
|
||||
LIBDIR := /lib
|
||||
CONFDIR := /etc/apk
|
||||
MANDIR := /usr/share/man
|
||||
DOCDIR := /usr/share/doc/apk
|
||||
|
||||
export DESTDIR SBINDIR CONFDIR MANDIR DOCDIR
|
||||
export DESTDIR SBINDIR LIBDIR CONFDIR MANDIR DOCDIR
|
||||
|
||||
##
|
||||
# Top-level rules and targets
|
||||
|
|
24
src/Makefile
24
src/Makefile
|
@ -4,24 +4,34 @@ ifeq ($(shell pkg-config --print-errors --exists $(PKGDEPS) || echo fail),fail)
|
|||
$(error Build dependencies are not met)
|
||||
endif
|
||||
|
||||
shlibs-y += libapk.so
|
||||
libapk.so-objs := common.o state.o database.o package.o archive.o \
|
||||
version.o io.o url.o gunzip.o blob.o hash.o print.o
|
||||
|
||||
progs-y += apk
|
||||
apk-objs := common.o state.o database.o package.o archive.o \
|
||||
version.o io.o url.o gunzip.o blob.o hash.o apk.o \
|
||||
add.o del.o fix.o update.o info.o search.o upgrade.o \
|
||||
cache.o ver.o index.o fetch.o audit.o verify.o
|
||||
apk-objs := apk.o add.o del.o fix.o update.o info.o \
|
||||
search.o upgrade.o cache.o ver.o index.o fetch.o \
|
||||
audit.o verify.o
|
||||
|
||||
CFLAGS += -D_ATFILE_SOURCE
|
||||
CFLAGS_apk.o := -DAPK_VERSION=\"$(FULL_VERSION)\"
|
||||
LIBS_apk := -lapk
|
||||
|
||||
progs-$(STATIC) += apk.static
|
||||
apk.static-objs := $(apk-objs)
|
||||
LDFLAGS_apk.static := -static
|
||||
LDFLAGS_apk += -nopie
|
||||
LDFLAGS_apk += -nopie -L$(obj)
|
||||
|
||||
CFLAGS += $(shell pkg-config --cflags $(PKGDEPS))
|
||||
LIBS := -Wl,--as-needed \
|
||||
$(shell pkg-config --libs $(PKGDEPS)) \
|
||||
-Wl,--no-as-needed
|
||||
|
||||
install:
|
||||
$(INSTALLDIR) $(DESTDIR)$(SBINDIR)
|
||||
|
||||
$(obj)/apk: $(obj)/libapk.so
|
||||
|
||||
install: $(obj)/apk $(obj)/libapk.so
|
||||
$(INSTALLDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR)
|
||||
$(INSTALL) $(obj)/apk $(DESTDIR)$(SBINDIR)
|
||||
$(INSTALL) $(obj)/libapk.so $(DESTDIR)$(LIBDIR)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
struct add_ctx {
|
||||
const char *virtpkg;
|
||||
|
|
60
src/apk.c
60
src/apk.c
|
@ -24,9 +24,7 @@
|
|||
#include "apk_database.h"
|
||||
#include "apk_applet.h"
|
||||
#include "apk_blob.h"
|
||||
|
||||
int apk_verbosity = 1, apk_wait;
|
||||
unsigned int apk_flags = 0;
|
||||
#include "apk_print.h"
|
||||
|
||||
static struct apk_option generic_options[] = {
|
||||
{ 'h', "help", "Show generic help or applet specific help" },
|
||||
|
@ -60,64 +58,12 @@ static struct apk_option generic_options[] = {
|
|||
{ 0x111, "overlay-from-stdin", "Read list of overlay files from stdin" },
|
||||
};
|
||||
|
||||
const char *apk_error_str(int error)
|
||||
{
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
switch (error) {
|
||||
case ENOKEY:
|
||||
return "UNTRUSTED signature";
|
||||
case EKEYREJECTED:
|
||||
return "BAD signature";
|
||||
case EIO:
|
||||
return "IO ERROR";
|
||||
case EBADMSG:
|
||||
return "BAD archive";
|
||||
case ENOMSG:
|
||||
return "archive does not contain expected data";
|
||||
default:
|
||||
return strerror(error);
|
||||
}
|
||||
}
|
||||
|
||||
void apk_log(const char *prefix, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
if (prefix != NULL)
|
||||
fprintf(stderr, "%s", prefix);
|
||||
va_start(va, format);
|
||||
vfprintf(stderr, format, va);
|
||||
va_end(va);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
static int version(void)
|
||||
{
|
||||
printf("apk-tools " APK_VERSION "\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
|
||||
{
|
||||
static const int wrap_length = 80;
|
||||
|
||||
if (i->x + blob.len + 1 >= wrap_length) {
|
||||
i->x = i->indent;
|
||||
printf("\n%*s", i->indent - 1, "");
|
||||
} else if (i->x+1 < i->indent) {
|
||||
printf("%*s", i->indent - i->x - 1, "");
|
||||
}
|
||||
i->x += printf(" %.*s", blob.len, blob.ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void apk_print_indented_words(struct apk_indent *i, const char *text)
|
||||
{
|
||||
apk_blob_for_each_segment(APK_BLOB_STR(text), " ",
|
||||
(apk_blob_cb) apk_print_indented, i);
|
||||
}
|
||||
|
||||
static int format_option(char *buf, size_t len, struct apk_option *o,
|
||||
const char *separator)
|
||||
{
|
||||
|
@ -289,7 +235,7 @@ int main(int argc, char **argv)
|
|||
struct apk_applet *applet;
|
||||
char short_options[256], *sopt;
|
||||
struct option *opt, *all_options;
|
||||
int r, optindex, num_options;
|
||||
int r, optindex, num_options, apk_wait = 0;
|
||||
void *ctx = NULL;
|
||||
struct apk_repository_list *repo = NULL;
|
||||
struct apk_database db;
|
||||
|
@ -410,7 +356,7 @@ int main(int argc, char **argv)
|
|||
argv++;
|
||||
}
|
||||
|
||||
r = apk_db_open(&db, &dbopts);
|
||||
r = apk_db_open(&db, &dbopts, apk_wait);
|
||||
if (r != 0) {
|
||||
apk_error("Failed to open apk database: %s",
|
||||
apk_error_str(r));
|
||||
|
|
|
@ -155,7 +155,7 @@ struct apk_db_file *apk_db_file_query(struct apk_database *db,
|
|||
APK_OPENF_NO_SCRIPTS | \
|
||||
APK_OPENF_NO_WORLD)
|
||||
|
||||
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts);
|
||||
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts, int apk_wait);
|
||||
void apk_db_close(struct apk_database *db);
|
||||
int apk_db_write_config(struct apk_database *db);
|
||||
int apk_db_run_triggers(struct apk_database *db);
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
#endif
|
||||
|
||||
extern int apk_verbosity, apk_wait;
|
||||
extern int apk_verbosity;
|
||||
extern unsigned int apk_flags;
|
||||
|
||||
#define APK_FORCE 0x0001
|
||||
|
@ -65,13 +65,6 @@ extern unsigned int apk_flags;
|
|||
#define APK_NO_NETWORK 0x1000
|
||||
#define APK_OVERLAY_FROM_STDIN 0x2000
|
||||
|
||||
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
|
||||
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
|
||||
#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
|
||||
|
||||
void apk_log(const char *prefix, const char *format, ...);
|
||||
const char *apk_error_str(int error);
|
||||
|
||||
static inline size_t apk_calc_installed_size(size_t size)
|
||||
{
|
||||
const size_t bsize = 4 * 1024;
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/* apk_state.h - Alpine Package Keeper (APK)
|
||||
*
|
||||
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
|
||||
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation. See http://www.gnu.org/ for details.
|
||||
*/
|
||||
|
||||
#ifndef APK_PRINT_H
|
||||
#define APK_PRINT_H
|
||||
|
||||
#include "apk_blob.h"
|
||||
|
||||
#define apk_error(args...) do { apk_log("ERROR: ", args); } while (0)
|
||||
#define apk_warning(args...) do { if (apk_verbosity > 0) { apk_log("WARNING: ", args); } } while (0)
|
||||
#define apk_message(args...) do { if (apk_verbosity > 0) { apk_log(NULL, args); } } while (0)
|
||||
|
||||
void apk_log(const char *prefix, const char *format, ...);
|
||||
const char *apk_error_str(int error);
|
||||
|
||||
int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
|
||||
void apk_print_indented_words(struct apk_indent *i, const char *text);
|
||||
|
||||
#endif
|
|
@ -43,4 +43,7 @@ int apk_state_lock_name(struct apk_state *state,
|
|||
struct apk_name *name,
|
||||
struct apk_package *newpkg);
|
||||
|
||||
int apk_print_indented(struct apk_indent *i, apk_blob_t blob);
|
||||
void apk_print_indented_words(struct apk_indent *i, const char *text);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "apk_defines.h"
|
||||
#include "apk_print.h"
|
||||
#include "apk_archive.h"
|
||||
|
||||
struct tar_header {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_package.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
#define CACHE_CLEAN BIT(0)
|
||||
#define CACHE_DOWNLOAD BIT(1)
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
#include "apk_state.h"
|
||||
#include "apk_applet.h"
|
||||
#include "apk_archive.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
int apk_verbosity = 1;
|
||||
unsigned int apk_flags = 0;
|
||||
|
||||
const char * const apkindex_tar_gz = "APKINDEX.tar.gz";
|
||||
const char * const apk_index_gz = "APK_INDEX.gz";
|
||||
|
@ -1021,7 +1025,8 @@ static void handle_alarm(int sig)
|
|||
{
|
||||
}
|
||||
|
||||
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts)
|
||||
int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts,
|
||||
int apk_wait)
|
||||
{
|
||||
const char *msg = NULL;
|
||||
struct apk_repository_list *repo = NULL;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "apk_applet.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
static int del_parse(void *ctx, struct apk_db_options *db,
|
||||
int optch, int optindex, const char *optarg)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_io.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
#define FETCH_RECURSIVE 1
|
||||
#define FETCH_STDOUT 2
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
struct fix_ctx {
|
||||
unsigned int reinstall : 1;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
#define INDEX_OLD_FORMAT 0x10000
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "apk_package.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
struct info_ctx {
|
||||
int (*action)(struct info_ctx *ctx, struct apk_database *db,
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "apk_package.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
void apk_pkg_format_plain(struct apk_package *pkg, apk_blob_t to)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/* state.c - Alpine Package Keeper (APK)
|
||||
*
|
||||
* Copyright (C) 2005-2008 Natanael Copa <n@tanael.org>
|
||||
* Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi>
|
||||
* All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 as published
|
||||
* by the Free Software Foundation. See http://www.gnu.org/ for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "apk_defines.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
int apk_print_indented(struct apk_indent *i, apk_blob_t blob)
|
||||
{
|
||||
static const int wrap_length = 80;
|
||||
|
||||
if (i->x + blob.len + 1 >= wrap_length) {
|
||||
i->x = i->indent;
|
||||
printf("\n%*s", i->indent - 1, "");
|
||||
}
|
||||
i->x += printf(" %.*s", blob.len, blob.ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void apk_print_indented_words(struct apk_indent *i, const char *text)
|
||||
{
|
||||
apk_blob_for_each_segment(APK_BLOB_STR(text), " ",
|
||||
(apk_blob_cb) apk_print_indented, i);
|
||||
}
|
||||
|
||||
const char *apk_error_str(int error)
|
||||
{
|
||||
if (error < 0)
|
||||
error = -error;
|
||||
switch (error) {
|
||||
case ENOKEY:
|
||||
return "UNTRUSTED signature";
|
||||
case EKEYREJECTED:
|
||||
return "BAD signature";
|
||||
case EIO:
|
||||
return "IO ERROR";
|
||||
case EBADMSG:
|
||||
return "BAD archive";
|
||||
case ENOMSG:
|
||||
return "archive does not contain expected data";
|
||||
default:
|
||||
return strerror(error);
|
||||
}
|
||||
}
|
||||
|
||||
void apk_log(const char *prefix, const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
if (prefix != NULL)
|
||||
fprintf(stderr, "%s", prefix);
|
||||
va_start(va, format);
|
||||
vfprintf(stderr, format, va);
|
||||
va_end(va);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "apk_state.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
struct apk_name_choices {
|
||||
unsigned short refs, num;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_version.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
static int update_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_state.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
static int upgrade_parse(void *ctx, struct apk_db_options *dbopts,
|
||||
int optch, int optindex, const char *optarg)
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_version.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
struct ver_ctx {
|
||||
int (*action)(struct apk_database *db, int argc, char **argv);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "apk_applet.h"
|
||||
#include "apk_database.h"
|
||||
#include "apk_print.h"
|
||||
|
||||
static int verify_main(void *ctx, struct apk_database *db, int argc, char **argv)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue