From: graham.gower Date: Wed, 9 Dec 2009 01:20:03 +0000 (+0000) Subject: Merge commit 'grg' into HEAD X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2fdb3fc0b67757afd6fe7a244b6e14d2a546af0e;p=oweals%2Fopkg-lede.git Merge commit 'grg' into HEAD git-svn-id: http://opkg.googlecode.com/svn/trunk@471 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- diff --git a/libbb/Makefile.am b/libbb/Makefile.am index 2da2dfd..1cc82df 100644 --- a/libbb/Makefile.am +++ b/libbb/Makefile.am @@ -11,12 +11,9 @@ libbb_la_SOURCES = gz_open.c \ unarchive.c \ copy_file.c \ copy_file_chunk.c \ - error_msg.c error_msg_and_die.c \ - perror_msg.c perror_msg_and_die.c \ xreadlink.c \ concat_path_file.c \ - verror_msg.c vperror_msg.c \ - xfuncs.c messages.c \ + xfuncs.c \ last_char_is.c \ make_directory.c \ safe_strncpy.c \ diff --git a/libbb/error_msg.c b/libbb/error_msg.c deleted file mode 100644 index 58308b6..0000000 --- a/libbb/error_msg.c +++ /dev/null @@ -1,46 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include "libbb.h" - -extern void error_msg(const char *s, ...) -{ - va_list p; - - va_start(p, s); - verror_msg(s, p); - va_end(p); - putc('\n', stderr); -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/error_msg_and_die.c b/libbb/error_msg_and_die.c deleted file mode 100644 index 67a79c3..0000000 --- a/libbb/error_msg_and_die.c +++ /dev/null @@ -1,47 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include "libbb.h" - -extern void error_msg_and_die(const char *s, ...) -{ - va_list p; - - va_start(p, s); - verror_msg(s, p); - va_end(p); - putc('\n', stderr); - exit(EXIT_FAILURE); -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/gz_open.c b/libbb/gz_open.c index 3d07b58..7c7c722 100644 --- a/libbb/gz_open.c +++ b/libbb/gz_open.c @@ -35,11 +35,11 @@ gz_open(FILE *compressed_file, int *pid) int unzip_pipe[2]; if (pipe(unzip_pipe)!=0) { - perror_msg("%s: pipe", __FUNCTION__); + perror_msg("pipe"); return(NULL); } if ((*pid = fork()) == -1) { - perror_msg("%s: fork", __FUNCTION__); + perror_msg("fork"); return(NULL); } if (*pid==0) { @@ -62,26 +62,26 @@ gz_close(int gunzip_pid) int ret; if (waitpid(gunzip_pid, &status, 0) == -1) { - perror_msg("%s: waitpid", __FUNCTION__); + perror_msg("waitpid"); return -1; } if (WIFSIGNALED(status)) { - error_msg("%s: unzip process killed by signal %d\n", - __FUNCTION__, WTERMSIG(status)); + error_msg("Unzip process killed by signal %d.\n", + WTERMSIG(status)); return -1; } if (!WIFEXITED(status)) { /* shouldn't happen */ - error_msg("%s: Your system is broken: got status %d from waitpid\n", - __FUNCTION__, status); + error_msg("Your system is broken: got status %d from waitpid.\n", + status); return -1; } if ((ret = WEXITSTATUS(status))) { - error_msg("%s: unzip process failed with return code %d.\n", - __FUNCTION__, ret); + error_msg("Unzip process failed with return code %d.\n", + ret); return -1; } diff --git a/libbb/libbb.h b/libbb/libbb.h index 619b400..4e1fafc 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h @@ -24,10 +24,10 @@ #include #include #include - +#include #include -#include +#include "../libopkg/opkg_message.h" #ifndef FALSE #define FALSE ((int) 0) @@ -37,15 +37,20 @@ #define TRUE ((int) 1) #endif -extern void error_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); -extern void error_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); -extern void perror_msg(const char *s, ...); -extern void perror_msg_and_die(const char *s, ...) __attribute__ ((noreturn)); -extern void archive_xread_all(int fd, char *buf, size_t count); +#define error_msg(fmt, args...) opkg_msg(ERROR, fmt"\n", ##args) +#define perror_msg(fmt, args...) opkg_perror(ERROR, fmt, ##args) +#define error_msg_and_die(fmt, args...) \ + do { \ + error_msg(fmt, ##args); \ + exit(EXIT_FAILURE); \ + } while (0) +#define perror_msg_and_die(fmt, args...) \ + do { \ + perror_msg(fmt, ##args); \ + exit(EXIT_FAILURE); \ + } while (0) -/* These two are used internally -- you shouldn't need to use them */ -extern void verror_msg(const char *s, va_list p); -extern void vperror_msg(const char *s, va_list p); +extern void archive_xread_all(int fd, char *buf, size_t count); const char *mode_string(int mode); const char *time_string(time_t timeVal); @@ -115,7 +120,4 @@ enum { FILEUTILS_FORCE = 8, }; -extern const char *applet_name; -extern const char * const memory_exhausted; - #endif /* __LIBBB_H__ */ diff --git a/libbb/messages.c b/libbb/messages.c deleted file mode 100644 index b9334c4..0000000 --- a/libbb/messages.c +++ /dev/null @@ -1,24 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "libbb.h" - -const char * const memory_exhausted = "memory exhausted"; diff --git a/libbb/perror_msg.c b/libbb/perror_msg.c deleted file mode 100644 index 8c57b0d..0000000 --- a/libbb/perror_msg.c +++ /dev/null @@ -1,45 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include "libbb.h" - -extern void perror_msg(const char *s, ...) -{ - va_list p; - - va_start(p, s); - vperror_msg(s, p); - va_end(p); -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/perror_msg_and_die.c b/libbb/perror_msg_and_die.c deleted file mode 100644 index 9004925..0000000 --- a/libbb/perror_msg_and_die.c +++ /dev/null @@ -1,46 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include "libbb.h" - -extern void perror_msg_and_die(const char *s, ...) -{ - va_list p; - - va_start(p, s); - vperror_msg(s, p); - va_end(p); - exit(EXIT_FAILURE); -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/unarchive.c b/libbb/unarchive.c index 31c76d2..03a63bd 100644 --- a/libbb/unarchive.c +++ b/libbb/unarchive.c @@ -185,7 +185,7 @@ extract_archive(FILE *src_stream, FILE *out_stream, goto cleanup; } archive_offset += file_entry->size; - copy_file_chunk(src_stream, dst_stream, file_entry->size); + *err = copy_file_chunk(src_stream, dst_stream, file_entry->size); fclose(dst_stream); } break; @@ -194,7 +194,7 @@ extract_archive(FILE *src_stream, FILE *out_stream, if (mkdir(full_name, file_entry->mode) < 0) { if ((function & extract_quiet) != extract_quiet) { *err = -1; - perror_msg("%s: %s", __FUNCTION__, full_name); + perror_msg("Cannot make dir %s", full_name); } } } @@ -641,7 +641,8 @@ deb_extract(const char *package_filename, FILE *out_stream, else if (extract_function & extract_data_tar_gz) { ared_file = "data.tar.gz"; } else { - fprintf(stderr, "no file specified to extract -- extract_function=%x\n", extract_function); + opkg_msg(ERROR, "Internal error: extract_function=%x\n", + extract_function); *err = -1; goto cleanup; } @@ -668,7 +669,6 @@ deb_extract(const char *package_filename, FILE *out_stream, /* open a stream of decompressed data */ uncompressed_stream = gz_open(deb_stream, &gunzip_pid); if (uncompressed_stream == NULL) { - printf("%s: %d\n", __FUNCTION__, __LINE__); *err = -1; goto cleanup; } diff --git a/libbb/unzip.c b/libbb/unzip.c index 7ff07a5..e0a2388 100644 --- a/libbb/unzip.c +++ b/libbb/unzip.c @@ -57,9 +57,6 @@ static unsigned long *crc_table = NULL; static unsigned long crc; /* shift register contents */ -/* Return codes from gzip */ -static const int ERROR = 1; - /* * window size--must be a power of two, and * at least 32K for zip's deflate method @@ -100,7 +97,7 @@ static const unsigned short mask_bits[] = { static void abort_gzip() { error_msg("gzip aborted\n"); - _exit(ERROR); + _exit(-1); } static void make_crc_table() @@ -975,8 +972,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) } if (method < 0) { - printf("it failed\n"); - return(exit_code); /* error message already emitted */ + return(exit_code); } make_crc_table(); @@ -987,7 +983,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) int res = inflate(); if (res == 3) { - error_msg(memory_exhausted); + perror_msg("inflate"); exit_code = 1; } else if (res != 0) { error_msg("invalid compressed data--format violated"); diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c deleted file mode 100644 index 21cde20..0000000 --- a/libbb/verror_msg.c +++ /dev/null @@ -1,43 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include "libbb.h" - -extern void verror_msg(const char *s, va_list p) -{ - fflush(stdout); - fprintf(stderr, "%s: ", applet_name); - vfprintf(stderr, s, p); -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/vperror_msg.c b/libbb/vperror_msg.c deleted file mode 100644 index 7da5bae..0000000 --- a/libbb/vperror_msg.c +++ /dev/null @@ -1,45 +0,0 @@ -/* vi: set sw=4 ts=4: */ -/* - * Utility routines. - * - * Copyright (C) 1999,2000,2001 by Erik Andersen - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include -#include -#include "libbb.h" - -extern void vperror_msg(const char *s, va_list p) -{ - int err=errno; - if(s == 0) s = ""; - verror_msg(s, p); - if (*s) s = ": "; - fprintf(stderr, "%s%s\n", s, strerror(err)); -} - - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/ diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index c12b282..4374048 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c @@ -30,7 +30,7 @@ extern void *xmalloc(size_t size) { void *ptr = malloc(size); if (ptr == NULL && size != 0) - error_msg_and_die(memory_exhausted); + perror_msg_and_die("malloc"); return ptr; } @@ -38,7 +38,7 @@ extern void *xrealloc(void *ptr, size_t size) { ptr = realloc(ptr, size); if (ptr == NULL && size != 0) - error_msg_and_die(memory_exhausted); + perror_msg_and_die("realloc"); return ptr; } @@ -46,7 +46,7 @@ extern void *xcalloc(size_t nmemb, size_t size) { void *ptr = calloc(nmemb, size); if (ptr == NULL && nmemb != 0 && size != 0) - error_msg_and_die(memory_exhausted); + perror_msg_and_die("calloc"); return ptr; } @@ -59,7 +59,7 @@ extern char * xstrdup (const char *s) { t = strdup (s); if (t == NULL) - error_msg_and_die(memory_exhausted); + perror_msg_and_die("strdup"); return t; } diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 932e487..5b0504c 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c @@ -24,7 +24,7 @@ extern char *xreadlink(const char *path) buf = xrealloc(buf, bufsize += GROWBY); readsize = readlink(path, buf, bufsize); /* 1st try */ if (readsize == -1) { - perror_msg("%s:%s", applet_name, path); + perror_msg("%s", path); return NULL; } } diff --git a/libopkg/Makefile.am b/libopkg/Makefile.am index d860be7..13d4960 100644 --- a/libopkg/Makefile.am +++ b/libopkg/Makefile.am @@ -6,9 +6,9 @@ libopkg_include_HEADERS= opkg.h opkg_libcore_sources = args.c args.h libopkg.c libopkg.h\ - user.c user.h \ - opkg.c opkg.h includes.h \ - opkg_error.h opkg_defines.h + includes.h \ + opkg.c opkg.h \ + opkg_defines.h opkg_cmd_sources = opkg_cmd.c opkg_cmd.h \ opkg_configure.c opkg_configure.h \ opkg_download.c opkg_download.h \ diff --git a/libopkg/active_list.c b/libopkg/active_list.c index 6b177c6..ffc6db0 100644 --- a/libopkg/active_list.c +++ b/libopkg/active_list.c @@ -34,7 +34,7 @@ void active_list_init(struct active_list *ptr) { struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) { struct active_list *next=NULL; if ( !head ) { - fprintf(stderr, "active_list_next head = %p, ptr = %p invalid value!!\n", head, ptr); + opkg_msg(ERROR, "Internal error: head=%p, ptr=%p\n", head, ptr); return NULL; } if ( !ptr ) @@ -56,7 +56,7 @@ struct active_list * active_list_next(struct active_list *head, struct active_li struct active_list * active_list_prev(struct active_list *head, struct active_list *ptr) { struct active_list *prev=NULL; if ( !head ) { - fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr); + opkg_msg(ERROR, "Internal error: head=%p, ptr=%p\n", head, ptr); return NULL; } if ( !ptr ) @@ -119,7 +119,7 @@ void active_list_add(struct active_list *head, struct active_list *node) { node->depended = head; } -struct active_list * active_list_head_new() { +struct active_list * active_list_head_new(void) { struct active_list * head = xcalloc(1, sizeof(struct active_list)); active_list_init(head); return head; diff --git a/libopkg/active_list.h b/libopkg/active_list.h index 70d2af8..c9d90c0 100644 --- a/libopkg/active_list.h +++ b/libopkg/active_list.h @@ -27,7 +27,7 @@ struct active_list { }; -struct active_list * active_list_head_new(); +struct active_list * active_list_head_new(void); void active_list_head_delete(struct active_list *); void active_list_init(struct active_list *ptr); void active_list_clear(struct active_list *head); diff --git a/libopkg/args.c b/libopkg/args.c index d5e379c..bc2fb61 100644 --- a/libopkg/args.c +++ b/libopkg/args.c @@ -26,13 +26,13 @@ #include "args.h" #include "sprintf_alloc.h" #include "libbb/libbb.h" +#include "opkg_conf.h" static void print_version(void); enum long_args_opt { - ARGS_OPT_FORCE_DEFAULTS = 129, - ARGS_OPT_FORCE_MAINTAINER, + ARGS_OPT_FORCE_MAINTAINER = 129, ARGS_OPT_FORCE_DEPENDS, ARGS_OPT_FORCE_OVERWRITE, ARGS_OPT_FORCE_DOWNGRADE, @@ -42,7 +42,6 @@ enum long_args_opt ARGS_OPT_FORCE_SPACE, ARGS_OPT_NOACTION, ARGS_OPT_NODEPS, - ARGS_OPT_MULTIPLE_PROVIDERS, ARGS_OPT_AUTOREMOVE, ARGS_OPT_CACHE, }; @@ -55,38 +54,12 @@ void args_init(args_t *args) sprintf_alloc(&args->conf_file, "%s/%s", OPKGETCDIR, ARGS_DEFAULT_CONF_FILE_NAME); - - args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS; - args->force_maintainer = ARGS_DEFAULT_FORCE_MAINTAINER; - args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS; - args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE; - args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE; - args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL; - args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES; - args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES; - args->autoremove = ARGS_DEFAULT_AUTOREMOVE; - args->noaction = ARGS_DEFAULT_NOACTION; - args->nodeps = ARGS_DEFAULT_NODEPS; - args->verbosity = ARGS_DEFAULT_VERBOSITY; - args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT; - args->offline_root_path = ARGS_DEFAULT_OFFLINE_ROOT_PATH; - args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD; - args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD; - args->multiple_providers = 0; - args->nocheckfordirorfile = 0; - args->noreadfeedsfile = 0; + conf->verbosity = ARGS_DEFAULT_VERBOSITY; } void args_deinit(args_t *args) { - free (args->offline_root); - free (args->offline_root_path); - free (args->offline_root_pre_script_cmd); - free (args->offline_root_post_script_cmd); - free (args->dest); - free (args->tmp_dir); - free (args->cache); free(args->conf_file); args->conf_file = NULL; } @@ -103,10 +76,8 @@ int args_parse(args_t *args, int argc, char *argv[]) {"conf-file", 1, 0, 'f'}, {"conf", 1, 0, 'f'}, {"dest", 1, 0, 'd'}, - {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS}, - {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS}, - {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, - {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, + {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, + {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, @@ -127,14 +98,10 @@ int args_parse(args_t *args, int argc, char *argv[]) ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, {"force_removal_of_essential_packages", 0, 0, ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, - {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS}, - {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS}, {"noaction", 0, 0, ARGS_OPT_NOACTION}, {"nodeps", 0, 0, ARGS_OPT_NODEPS}, {"offline", 1, 0, 'o'}, {"offline-root", 1, 0, 'o'}, - {"offline-path", 1, 0, 'p'}, - {"offline-root-path", 1, 0, 'p'}, {"test", 0, 0, ARGS_OPT_NOACTION}, {"tmp-dir", 1, 0, 't'}, {"tmp_dir", 1, 0, 't'}, @@ -150,7 +117,7 @@ int args_parse(args_t *args, int argc, char *argv[]) switch (c) { case 'A': - args->query_all = 1; + conf->query_all = 1; break; case 'd': args->dest = xstrdup(optarg); @@ -160,68 +127,59 @@ int args_parse(args_t *args, int argc, char *argv[]) args->conf_file = xstrdup(optarg); break; case 'o': - args->offline_root = xstrdup(optarg); - break; - case 'p': - args->offline_root_path = xstrdup(optarg); + conf->offline_root = xstrdup(optarg); break; case 't': - args->tmp_dir = xstrdup(optarg); + conf->tmp_dir = xstrdup(optarg); break; case 'v': print_version(); exit(0); case 'V': - args->verbosity = atoi(optarg); + conf->verbosity = atoi(optarg); break; case ARGS_OPT_AUTOREMOVE: - args->autoremove = 1; + conf->autoremove = 1; break; case ARGS_OPT_CACHE: - free(args->cache); - args->cache = xstrdup(optarg); - break; - case ARGS_OPT_FORCE_DEFAULTS: - args->force_defaults = 1; + free(conf->cache); + conf->cache = xstrdup(optarg); break; case ARGS_OPT_FORCE_MAINTAINER: - args->force_maintainer = 1; + conf->force_maintainer = 1; break; case ARGS_OPT_FORCE_DEPENDS: - args->force_depends = 1; + conf->force_depends = 1; break; case ARGS_OPT_FORCE_OVERWRITE: - args->force_overwrite = 1; + conf->force_overwrite = 1; break; case ARGS_OPT_FORCE_DOWNGRADE: - args->force_downgrade = 1; + conf->force_downgrade = 1; break; case ARGS_OPT_FORCE_REINSTALL: - args->force_reinstall = 1; + conf->force_reinstall = 1; break; case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES: - args->force_removal_of_essential_packages = 1; + conf->force_removal_of_essential_packages = 1; break; case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES: - args->force_removal_of_dependent_packages = 1; + conf->force_removal_of_dependent_packages = 1; break; case ARGS_OPT_FORCE_SPACE: - args->force_space = 1; - break; - case ARGS_OPT_MULTIPLE_PROVIDERS: - args->multiple_providers = 1; + conf->force_space = 1; break; case ARGS_OPT_NODEPS: - args->nodeps = 1; + conf->nodeps = 1; break; case ARGS_OPT_NOACTION: - args->noaction = 1; + conf->noaction = 1; break; case ':': - parse_err++; + parse_err = -1; break; case '?': - parse_err++; + parse_err = -1; break; default: printf("Confusion: getopt_long returned %d\n", c); @@ -229,13 +187,13 @@ int args_parse(args_t *args, int argc, char *argv[]) } if (parse_err) { - return -parse_err; + return parse_err; } else { return optind; } } -void args_usage(char *complaint) +void args_usage(const char *complaint) { if (complaint) { printf("opkg: %s\n", complaint); @@ -291,11 +249,10 @@ void args_usage(char *complaint) printf(" directory name in a pinch).\n"); printf("\t-o Use as the root directory for\n"); printf("\t--offline-root offline installation of packages.\n"); - printf("\t--offline-path $PATH for postinsts scripts in offline mode\n"); printf("\nForce Options:\n"); printf("\t--force-depends Install/remove despite failed dependences\n"); - printf("\t--force-defaults Use default options for questions asked by opkg\n"); + printf("\t--force-maintainer Overwrite preexisting config files\n"); printf("\t--force-reinstall Reinstall package(s)\n"); printf("\t--force-overwrite Overwrite files from other package(s)\n"); printf("\t--force-downgrade Allow opkg to downgrade packages\n"); diff --git a/libopkg/args.h b/libopkg/args.h index 7992844..176d354 100644 --- a/libopkg/args.h +++ b/libopkg/args.h @@ -22,57 +22,20 @@ struct args { char *conf_file; char *dest; - char *tmp_dir; - int force_defaults; - int force_maintainer; - int force_depends; - int force_overwrite; - int force_downgrade; - int force_reinstall; - int force_removal_of_essential_packages; - int force_removal_of_dependent_packages; - int force_space; - int noaction; - int nodeps; - int multiple_providers; - int query_all; - int verbosity; + int nocheckfordirorfile; int noreadfeedsfile; - int autoremove; - char *offline_root; - char *offline_root_path; - char *offline_root_pre_script_cmd; - char *offline_root_post_script_cmd; - char *cache; }; typedef struct args args_t; #define ARGS_DEFAULT_CONF_FILE_DIR OPKGETCDIR"/opkg" #define ARGS_DEFAULT_CONF_FILE_NAME "opkg.conf" #define ARGS_DEFAULT_DEST NULL -#define ARGS_DEFAULT_FORCE_DEFAULTS 0 -#define ARGS_DEFAULT_FORCE_MAINTAINER 0 -#define ARGS_DEFAULT_FORCE_DEPENDS 0 -#define ARGS_DEFAULT_FORCE_OVERWRITE 0 -#define ARGS_DEFAULT_FORCE_DOWNGRADE 0 -#define ARGS_DEFAULT_FORCE_REINSTALL 0 -#define ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES 0 -#define ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES 0 -#define ARGS_DEFAULT_FORCE_SPACE 0 -#define ARGS_DEFAULT_OFFLINE_ROOT NULL -#define ARGS_DEFAULT_OFFLINE_ROOT_PATH NULL -#define ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD NULL -#define ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD NULL -#define ARGS_DEFAULT_NOACTION 0 -#define ARGS_DEFAULT_NODEPS 0 -#define ARGS_DEFAULT_VERBOSE_WGET 0 #define ARGS_DEFAULT_VERBOSITY 1 -#define ARGS_DEFAULT_AUTOREMOVE 0 void args_init(args_t *args); void args_deinit(args_t *args); int args_parse(args_t *args, int argc, char *argv[]); -void args_usage(char *complaint); +void args_usage(const char *complaint); #endif diff --git a/libopkg/conffile.c b/libopkg/conffile.c index 4bedf73..984a191 100644 --- a/libopkg/conffile.c +++ b/libopkg/conffile.c @@ -35,7 +35,7 @@ void conffile_deinit(conffile_t *conffile) nv_pair_deinit(conffile); } -int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile) +int conffile_has_been_modified(conffile_t *conffile) { char *md5sum; char *filename = conffile->name; @@ -43,17 +43,17 @@ int conffile_has_been_modified(opkg_conf_t *conf, conffile_t *conffile) int ret = 1; if (conffile->value == NULL) { - opkg_message(conf, OPKG_NOTICE, "%s: conffile %s has no md5sum\n", __FUNCTION__, conffile->name); + opkg_msg(NOTICE, "Conffile %s has no md5sum.\n", conffile->name); return 1; } - root_filename = root_filename_alloc(conf, filename); + root_filename = root_filename_alloc(filename); md5sum = file_md5sum_alloc(root_filename); if (md5sum && (ret = strcmp(md5sum, conffile->value))) { - opkg_message(conf, OPKG_INFO, "%s: conffile %s: \t\nold md5=%s \t\nnew md5=%s\n", __FUNCTION__, - conffile->name, md5sum, conffile->value); + opkg_msg(INFO, "Conffile %s:\n\told md5=%s\n\tnew md5=%s\n", + conffile->name, md5sum, conffile->value); } free(root_filename); diff --git a/libopkg/conffile.h b/libopkg/conffile.h index 68ba3dc..5031835 100644 --- a/libopkg/conffile.h +++ b/libopkg/conffile.h @@ -25,7 +25,7 @@ typedef struct nv_pair conffile_t; int conffile_init(conffile_t *conffile, const char *file_name, const char *md5sum); void conffile_deinit(conffile_t *conffile); -int conffile_has_been_modified(struct opkg_conf *conf, conffile_t *conffile); +int conffile_has_been_modified(conffile_t *conffile); #endif diff --git a/libopkg/file_util.c b/libopkg/file_util.c index e625984..f5519c8 100644 --- a/libopkg/file_util.c +++ b/libopkg/file_util.c @@ -63,9 +63,9 @@ char * file_read_line_alloc(FILE *fp) { char buf[BUFSIZ]; - int buf_len; + unsigned int buf_len; char *line = NULL; - int line_size = 0; + unsigned int line_size = 0; int got_nl = 0; buf[0] = '\0'; @@ -105,8 +105,8 @@ file_move(const char *src, const char *dest) if (err == 0) unlink(src); } else { - fprintf(stderr, "%s: rename(%s, %s): %s\n", - __FUNCTION__, src, dest, strerror(errno)); + opkg_perror(ERROR, "Failed to rename %s to %s", + src, dest); } } @@ -120,8 +120,8 @@ file_copy(const char *src, const char *dest) err = copy_file(src, dest, FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); if (err) - fprintf(stderr, "%s: copy_file(%s, %s)\n", - __FUNCTION__, src, dest); + opkg_msg(ERROR, "Failed to copy file %s to %s.\n", + src, dest); return err; } @@ -153,16 +153,14 @@ char *file_md5sum_alloc(const char *file_name) file = fopen(file_name, "r"); if (file == NULL) { - fprintf(stderr, "%s: Failed to open file %s: %s\n", - __FUNCTION__, file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open file %s", file_name); free(md5sum_hex); return NULL; } err = md5_stream(file, md5sum_bin); if (err) { - fprintf(stderr, "%s: ERROR computing md5sum for %s: %s\n", - __FUNCTION__, file_name, strerror(err)); + opkg_msg(ERROR, "Could't compute md5sum for %s.\n", file_name); fclose(file); free(md5sum_hex); return NULL; @@ -202,16 +200,14 @@ char *file_sha256sum_alloc(const char *file_name) file = fopen(file_name, "r"); if (file == NULL) { - fprintf(stderr, "%s: Failed to open file %s: %s\n", - __FUNCTION__, file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open file %s", file_name); free(sha256sum_hex); return NULL; } err = sha256_stream(file, sha256sum_bin); if (err) { - fprintf(stderr, "%s: ERROR computing sha256sum for %s: %s\n", - __FUNCTION__, file_name, strerror(err)); + opkg_msg(ERROR, "Could't compute sha256sum for %s.\n", file_name); fclose(file); free(sha256sum_hex); return NULL; @@ -241,12 +237,12 @@ rm_r(const char *path) dir = opendir(path); if (dir == NULL) { - perror_msg("%s: opendir(%s)", __FUNCTION__, path); + opkg_perror(ERROR, "Failed to open dir %s", path); return -1; } if (fchdir(dirfd(dir)) == -1) { - perror_msg("%s: fchdir(%s)", __FUNCTION__, path); + opkg_perror(ERROR, "Failed to change to dir %s", path); closedir(dir); return -1; } @@ -255,8 +251,8 @@ rm_r(const char *path) errno = 0; if ((dent = readdir(dir)) == NULL) { if (errno) { - perror_msg("%s: readdir(%s)", - __FUNCTION__, path); + opkg_perror(ERROR, "Failed to read dir %s", + path); ret = -1; } break; @@ -275,8 +271,8 @@ rm_r(const char *path) { struct stat st; if ((ret = lstat(dent->d_name, &st)) == -1) { - perror_msg("%s: lstat(%s)", - __FUNCTION__, dent->d_name); + opkg_perror(ERROR, "Failed to lstat %s", + dent->d_name); break; } if (S_ISDIR(st.st_mode)) { @@ -287,25 +283,24 @@ rm_r(const char *path) } if ((ret = unlink(dent->d_name)) == -1) { - perror_msg("%s: unlink(%s)", - __FUNCTION__, dent->d_name); + opkg_perror(ERROR, "Failed to unlink %s", dent->d_name); break; } } if (chdir("..") == -1) { ret = -1; - perror_msg("%s: chdir(%s/..)", __FUNCTION__, path); + opkg_perror(ERROR, "Failed to change to dir %s/..", path); } if (rmdir(path) == -1 ) { ret = -1; - perror_msg("%s: rmdir(%s)", __FUNCTION__, path); + opkg_perror(ERROR, "Failed to remove dir %s", path); } if (closedir(dir) == -1) { ret = -1; - perror_msg("%s: closedir(%s)", __FUNCTION__, path); + opkg_perror(ERROR, "Failed to close dir %s", path); } return ret; diff --git a/libopkg/hash_table.c b/libopkg/hash_table.c index 2d42d91..f3705ea 100644 --- a/libopkg/hash_table.c +++ b/libopkg/hash_table.c @@ -46,8 +46,7 @@ void hash_table_init(const char *name, hash_table_t *hash, int len) { if (hash->entries != NULL) { - fprintf(stderr, "ERROR: %s called on a non empty hash table\n", - __FUNCTION__); + opkg_msg(ERROR, "Internal error: non empty hash table.\n"); return; } @@ -114,7 +113,6 @@ void *hash_table_get(hash_table_t *hash, const char *key) if (hash_entry->key) { if (strcmp(key, hash_entry->key) == 0) { - // opkg_message(NULL, OPKG_DEBUG, "Function: %s. Key found for '%s' \n", __FUNCTION__, key); hash->n_hits++; return hash_entry->data; } diff --git a/libopkg/libopkg.c b/libopkg/libopkg.c index 3121984..f6fc251 100644 --- a/libopkg/libopkg.c +++ b/libopkg/libopkg.c @@ -24,39 +24,32 @@ #include "file_util.h" #include "opkg_message.h" -#include "opkg_error.h" /* This is used for backward compatibility */ int opkg_op (int argc, char *argv[]) { - int err, optind; + int err, opts; args_t args; char *cmd_name; opkg_cmd_t *cmd; - opkg_conf_t opkg_conf; args_init (&args); - optind = args_parse (&args, argc, argv); - if (optind == argc || optind < 0) + opts = args_parse (&args, argc, argv); + if (opts == argc || opts < 0) { args_usage ("opkg must have one sub-command argument"); } - cmd_name = argv[optind++]; -/* Pigi: added a flag to disable the checking of structures if the command does not need to - read anything from there. -*/ + cmd_name = argv[opts++]; + if ( !strcmp(cmd_name,"print-architecture") || !strcmp(cmd_name,"print_architecture") || !strcmp(cmd_name,"print-installation-architecture") || !strcmp(cmd_name,"print_installation_architecture") ) args.nocheckfordirorfile = 1; -/* Pigi: added a flag to disable the reading of feed files if the command does not need to - read anything from there. -*/ if ( !strcmp(cmd_name,"flag") || !strcmp(cmd_name,"configure") || !strcmp(cmd_name,"remove") || @@ -69,8 +62,17 @@ opkg_op (int argc, char *argv[]) !strcmp(cmd_name,"status") ) args.noreadfeedsfile = 1; + cmd = opkg_cmd_find (cmd_name); + if (cmd == NULL) + { + fprintf (stderr, "%s: unknown sub-command %s\n", argv[0], + cmd_name); + args_usage (NULL); + } - err = opkg_conf_init (&opkg_conf, &args); + conf->pfm = cmd->pfm; + + err = opkg_conf_init (&args); args_deinit (&args); if (err) { @@ -79,28 +81,20 @@ opkg_op (int argc, char *argv[]) return err; } - cmd = opkg_cmd_find (cmd_name); - if (cmd == NULL) - { - fprintf (stderr, "%s: unknown sub-command %s\n", argv[0], - cmd_name); - args_usage (NULL); - } - - if (cmd->requires_args && optind == argc) + if (cmd->requires_args && opts == argc) { fprintf (stderr, "%s: the ``%s'' command requires at least one argument\n", - __FUNCTION__, cmd_name); + argv[0], cmd_name); args_usage (NULL); } - err = opkg_cmd_exec (cmd, &opkg_conf, argc - optind, (const char **) (argv + optind), NULL); + err = opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts)); #ifdef HAVE_CURL opkg_curl_cleanup(); #endif - opkg_conf_deinit (&opkg_conf); + opkg_conf_deinit (); return err; } diff --git a/libopkg/libopkg.h b/libopkg/libopkg.h index 72d3640..01ce6f0 100644 --- a/libopkg/libopkg.h +++ b/libopkg/libopkg.h @@ -28,7 +28,6 @@ #include "args.h" #include "pkg.h" -#include "user.h" extern int opkg_op(int argc, char *argv[]); /* opkglib.c */ diff --git a/libopkg/opkg.c b/libopkg/opkg.c index 51989f7..24469ba 100644 --- a/libopkg/opkg.c +++ b/libopkg/opkg.c @@ -27,26 +27,19 @@ #include "opkg_download.h" #include "opkg_remove.h" #include "opkg_upgrade.h" -#include "opkg_error.h" #include "sprintf_alloc.h" #include "file_util.h" #include -struct _opkg_t -{ - args_t *args; - opkg_conf_t *conf; - opkg_option_t *options; -}; +args_t *args; #define opkg_assert(expr) if (!(expr)) { \ printf ("opkg: file %s: line %d (%s): Assertation '%s' failed",\ __FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); } -#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data); -#define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0 +#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (&d, user_data); /** Private Functions ***/ @@ -67,16 +60,15 @@ pkg_t_to_opkg_package_t (pkg_t *old) new->repository = xstrdup(old->src->name); new->description = xstrdup(old->description); new->tags = xstrdup(old->tags); - new->url = xstrdup(old->url); - new->size = (old->size) ? atoi (old->size) : 0; + new->size = old->size; new->installed = (old->state_status == SS_INSTALLED); return new; } static int -opkg_configure_packages(opkg_conf_t *conf, char *pkg_name) +opkg_configure_packages(char *pkg_name) { pkg_vec_t *all; int i; @@ -84,7 +76,7 @@ opkg_configure_packages(opkg_conf_t *conf, char *pkg_name) int r, err = 0; all = pkg_vec_alloc (); - pkg_hash_fetch_available (&conf->pkg_hash, all); + pkg_hash_fetch_available (all); for (i = 0; i < all->len; i++) { @@ -95,7 +87,7 @@ opkg_configure_packages(opkg_conf_t *conf, char *pkg_name) if (pkg->state_status == SS_UNPACKED) { - r = opkg_configure (conf, pkg); + r = opkg_configure (pkg); if (r == 0) { pkg->state_status = SS_INSTALLED; @@ -118,7 +110,6 @@ struct _curl_cb_data { opkg_progress_callback_t cb; opkg_progress_data_t *progress_data; - opkg_t *opkg; void *user_data; int start_range; int finish_range; @@ -146,8 +137,7 @@ curl_progress_cb (struct _curl_cb_data *cb_data, progress = cb_data->start_range + (d / t * ((cb_data->finish_range - cb_data->start_range))); cb_data->progress_data->percentage = progress; - (cb_data->cb)(cb_data->opkg, - cb_data->progress_data, + (cb_data->cb)(cb_data->progress_data, cb_data->user_data); return 0; @@ -175,127 +165,56 @@ opkg_package_free (opkg_package_t *p) free (p->architecture); free (p->description); free (p->tags); - free (p->url); free (p->repository); free (p); } -opkg_t * +int opkg_new () { - opkg_t *opkg; int err; - opkg = xcalloc(1, sizeof (opkg_t)); - - opkg->args = xcalloc(1, sizeof (args_t)); - args_init (opkg->args); + args = xcalloc(1, sizeof (args_t)); + args_init (args); - opkg->conf = xcalloc(1, sizeof (opkg_conf_t)); - err = opkg_conf_init (opkg->conf, opkg->args); + err = opkg_conf_init (args); if (err) { - free (opkg->conf); - free (opkg->args); - free (opkg); - return NULL; + args_deinit (args); + free (args); + return -1; } - opkg_init_options_array (opkg->conf, &opkg->options); - return opkg; + return 0; } void -opkg_free (opkg_t *opkg) +opkg_free (void) { - opkg_assert (opkg != NULL); - #ifdef HAVE_CURL opkg_curl_cleanup(); #endif - opkg_conf_deinit (opkg->conf); - args_deinit (opkg->args); - free (opkg->options); - free (opkg->args); - free (opkg->conf); - free (opkg); + opkg_conf_deinit (); + args_deinit (args); + free (args); } int -opkg_re_read_config_files (opkg_t *opkg) +opkg_re_read_config_files (void) { - args_t *a; - opkg_conf_t *c; - - opkg_assert (opkg != NULL); - - a = opkg->args; - c = opkg->conf; - - /* Unfortunatly, the easiest way to re-read the config files right now is to - * throw away opkg->conf and start again */ - - /* copy the settings we need to keep */ - a->autoremove = c->autoremove; - a->force_depends = c->force_depends; - a->force_defaults = c->force_defaults; - a->force_maintainer = c->force_maintainer; - a->force_overwrite = c->force_overwrite; - a->force_downgrade = c->force_downgrade; - a->force_reinstall = c->force_reinstall; - a->force_removal_of_dependent_packages = c->force_removal_of_dependent_packages; - a->force_removal_of_essential_packages = c->force_removal_of_essential_packages; - a->nodeps = c->nodeps; - a->noaction = c->noaction; - a->query_all = c->query_all; - a->verbosity = c->verbosity; - - if (c->offline_root) - { - if (a->offline_root) free (a->offline_root); - a->offline_root = xstrdup(c->offline_root); - } - - if (c->offline_root_pre_script_cmd) - { - if (a->offline_root_pre_script_cmd) free (a->offline_root_pre_script_cmd); - a->offline_root_pre_script_cmd = xstrdup(c->offline_root_pre_script_cmd); - } - - if (c->offline_root_post_script_cmd) - { - if (a->offline_root_post_script_cmd) free (a->offline_root_post_script_cmd); - a->offline_root_post_script_cmd = xstrdup(c->offline_root_post_script_cmd); - } - - if (c->cache) { - if (a->cache) - free (a->cache); - a->cache = xstrdup(c->cache); - } - - /* throw away old opkg_conf and start again */ - opkg_conf_deinit (opkg->conf); - opkg_conf_init (opkg->conf, opkg->args); - - free (opkg->options); - opkg_init_options_array (opkg->conf, &opkg->options); - - return 0; + /* Unfortunately, the easiest way to re-read the config files right now is to + * throw away conf and start again */ + opkg_free(); + memset(conf, '\0', sizeof(opkg_conf_t)); + return opkg_new(); } void -opkg_get_option (opkg_t *opkg, char *option, void **value) +opkg_get_option (char *option, void **value) { int i = 0; - opkg_option_t *options; - - opkg_assert (opkg != NULL); - opkg_assert (option != NULL); - opkg_assert (value != NULL); - - options = opkg->options; + extern opkg_option_t options[]; /* look up the option * TODO: this would be much better as a hash table @@ -328,17 +247,14 @@ opkg_get_option (opkg_t *opkg, char *option, void **value) } void -opkg_set_option (opkg_t *opkg, char *option, void *value) +opkg_set_option (char *option, void *value) { int i = 0, found = 0; - opkg_option_t *options; + extern opkg_option_t options[]; - opkg_assert (opkg != NULL); opkg_assert (option != NULL); opkg_assert (value != NULL); - options = opkg->options; - /* look up the option * TODO: this would be much better as a hash table */ @@ -381,12 +297,11 @@ opkg_set_option (opkg_t *opkg, char *option, void *value) /** * @brief libopkg API: Install package - * @param opkg Then opkg handler * @param package_name The name of package in which is going to install * @param progress_callback The callback function that report the status to caller. */ int -opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data) +opkg_install_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data) { int err; char *stripped_filename; @@ -396,22 +311,21 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call int i, ndepends; char **unresolved = NULL; - opkg_assert (opkg != NULL); opkg_assert (package_name != NULL); /* ... */ - pkg_info_preinstall_check (opkg->conf); + pkg_info_preinstall_check (); /* check to ensure package is not already installed */ - old = pkg_hash_fetch_installed_by_name(&opkg->conf->pkg_hash, package_name); + old = pkg_hash_fetch_installed_by_name(package_name); if (old) { /* XXX: Error: Package is already installed. */ return OPKG_PACKAGE_ALREADY_INSTALLED; } - new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, package_name); + new = pkg_hash_fetch_best_installation_candidate_by_name(package_name); if (!new) { /* XXX: Error: Could not find package to install */ @@ -428,7 +342,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call /* find dependancies and download them */ deps = pkg_vec_alloc (); /* this function does not return the original package, so we insert it later */ - ndepends = pkg_hash_fetch_unsatisfied_dependencies (opkg->conf, new, deps, &unresolved); + ndepends = pkg_hash_fetch_unsatisfied_dependencies (new, deps, &unresolved); if (unresolved) { /* XXX: Error: Could not satisfy dependencies */ @@ -467,17 +381,16 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call if ( ! stripped_filename ) stripped_filename = pkg->filename; - sprintf_alloc(&pkg->local_filename, "%s/%s", opkg->conf->tmp_dir, stripped_filename); + sprintf_alloc(&pkg->local_filename, "%s/%s", conf->tmp_dir, stripped_filename); cb_data.cb = progress_callback; cb_data.progress_data = &pdata; - cb_data.opkg = opkg; cb_data.user_data = user_data; /* 75% of "install" progress is for downloading */ cb_data.start_range = 75 * i / deps->len; cb_data.finish_range = 75 * (i + 1) / deps->len; - err = opkg_download(opkg->conf, url, pkg->local_filename, + err = opkg_download(url, pkg->local_filename, (curl_progress_func) curl_progress_cb, &cb_data); free(url); @@ -493,7 +406,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */ all = pkg_vec_alloc (); - pkg_hash_fetch_available (&opkg->conf->pkg_hash, all); + pkg_hash_fetch_available (all); for (i = 0; i < all->len; i++) { all->pkgs[i]->parent->dependencies_checked = 0; @@ -508,7 +421,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call progress (pdata, 75); /* unpack the package */ - err = opkg_install_pkg(opkg->conf, new, 0); + err = opkg_install_pkg(new, 0); if (err) { @@ -519,7 +432,7 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call progress (pdata, 75); /* run configure scripts, etc. */ - err = opkg_configure_packages (opkg->conf, NULL); + err = opkg_configure_packages (NULL); if (err) { opkg_package_free (pdata.package); @@ -527,8 +440,8 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call } /* write out status files and file lists */ - opkg_conf_write_status_files (opkg->conf); - pkg_write_changed_filelists (opkg->conf); + opkg_conf_write_status_files (); + pkg_write_changed_filelists (); progress (pdata, 100); opkg_package_free (pdata.package); @@ -536,19 +449,18 @@ opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_call } int -opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data) +opkg_remove_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data) { int err; pkg_t *pkg = NULL; pkg_t *pkg_to_remove; opkg_progress_data_t pdata; - opkg_assert (opkg != NULL); opkg_assert (package_name != NULL); - pkg_info_preinstall_check (opkg->conf); + pkg_info_preinstall_check (); - pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, package_name); + pkg = pkg_hash_fetch_installed_by_name (package_name); if (pkg == NULL) { @@ -569,25 +481,24 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb } progress (pdata, 25); - if (opkg->conf->restrict_to_default_dest) + if (conf->restrict_to_default_dest) { - pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash, - pkg->name, - opkg->conf->default_dest); + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest (pkg->name, + conf->default_dest); } else { - pkg_to_remove = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, pkg->name ); + pkg_to_remove = pkg_hash_fetch_installed_by_name (pkg->name); } progress (pdata, 75); - err = opkg_remove_pkg (opkg->conf, pkg_to_remove, 0); + err = opkg_remove_pkg (pkg_to_remove, 0); /* write out status files and file lists */ - opkg_conf_write_status_files (opkg->conf); - pkg_write_changed_filelists (opkg->conf); + opkg_conf_write_status_files (); + pkg_write_changed_filelists (); progress (pdata, 100); @@ -596,24 +507,20 @@ opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callb } int -opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data) +opkg_upgrade_package (const char *package_name, opkg_progress_callback_t progress_callback, void *user_data) { int err; pkg_t *pkg; opkg_progress_data_t pdata; - - - opkg_assert (opkg != NULL); opkg_assert (package_name != NULL); - pkg_info_preinstall_check (opkg->conf); + pkg_info_preinstall_check (); - if (opkg->conf->restrict_to_default_dest) + if (conf->restrict_to_default_dest) { - pkg = pkg_hash_fetch_installed_by_name_dest (&opkg->conf->pkg_hash, - package_name, - opkg->conf->default_dest); + pkg = pkg_hash_fetch_installed_by_name_dest (package_name, + conf->default_dest); if (pkg == NULL) { /* XXX: Error: Package not installed in default_dest */ @@ -622,8 +529,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call } else { - pkg = pkg_hash_fetch_installed_by_name (&opkg->conf->pkg_hash, - package_name); + pkg = pkg_hash_fetch_installed_by_name (package_name); } if (!pkg) @@ -636,7 +542,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call pdata.package = pkg_t_to_opkg_package_t (pkg); progress (pdata, 0); - err = opkg_upgrade_pkg (opkg->conf, pkg); + err = opkg_upgrade_pkg (pkg); /* opkg_upgrade_pkg returns the error codes of opkg_install_pkg */ if (err) { @@ -645,15 +551,15 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call } progress (pdata, 75); - err = opkg_configure_packages (opkg->conf, NULL); + err = opkg_configure_packages (NULL); if (err) { opkg_package_free (pdata.package); return OPKG_UNKNOWN_ERROR; } /* write out status files and file lists */ - opkg_conf_write_status_files (opkg->conf); - pkg_write_changed_filelists (opkg->conf); + opkg_conf_write_status_files (); + pkg_write_changed_filelists (); progress (pdata, 100); opkg_package_free (pdata.package); @@ -661,7 +567,7 @@ opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_call } int -opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data) +opkg_upgrade_all (opkg_progress_callback_t progress_callback, void *user_data) { pkg_vec_t *installed; int err = 0; @@ -672,13 +578,12 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void pdata.action = OPKG_INSTALL; pdata.package = NULL; - opkg_assert (opkg != NULL); progress (pdata, 0); installed = pkg_vec_alloc (); - pkg_info_preinstall_check (opkg->conf); + pkg_info_preinstall_check (); - pkg_hash_fetch_all_installed (&opkg->conf->pkg_hash, installed); + pkg_hash_fetch_all_installed (installed); for (i = 0; i < installed->len; i++) { pkg = installed->pkgs[i]; @@ -687,14 +592,14 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void progress (pdata, 99 * i / installed->len); opkg_package_free (pdata.package); - err += opkg_upgrade_pkg (opkg->conf, pkg); + err += opkg_upgrade_pkg (pkg); } pkg_vec_free (installed); if (err) return 1; - err = opkg_configure_packages (opkg->conf, NULL); + err = opkg_configure_packages (NULL); if (err) return 1; @@ -704,7 +609,7 @@ opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void } int -opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data) +opkg_update_package_lists (opkg_progress_callback_t progress_callback, void *user_data) { char *tmp; int err, result = 0; @@ -714,16 +619,14 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb int sources_list_count, sources_done; opkg_progress_data_t pdata; - opkg_assert (opkg != NULL); - pdata.action = OPKG_DOWNLOAD; pdata.package = NULL; progress (pdata, 0); sprintf_alloc (&lists_dir, "%s", - (opkg->conf->restrict_to_default_dest) - ? opkg->conf->default_dest->lists_dir - : opkg->conf->lists_dir); + (conf->restrict_to_default_dest) + ? conf->default_dest->lists_dir + : conf->lists_dir); if (!file_is_dir (lists_dir)) { @@ -743,7 +646,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb } } - sprintf_alloc(&tmp, "%s/update-XXXXXX", opkg->conf->tmp_dir); + sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir); if (mkdtemp (tmp) == NULL) { /* XXX: Error: could not create temporary file name */ free (lists_dir); @@ -754,12 +657,12 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb /* count the number of sources so we can give some progress updates */ sources_list_count = 0; sources_done = 0; - list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node) + list_for_each_entry(iter, &conf->pkg_src_list.head, node) { sources_list_count++; } - list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node) + list_for_each_entry(iter, &conf->pkg_src_list.head, node) { char *url, *list_file_name = NULL; @@ -784,12 +687,11 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb cb_data.cb = progress_callback; cb_data.progress_data = &pdata; - cb_data.opkg = opkg; cb_data.user_data = user_data; cb_data.start_range = 100 * sources_done / sources_list_count; cb_data.finish_range = 100 * (sources_done + 1) / sources_list_count; - err = opkg_download (opkg->conf, url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data); + err = opkg_download (url, tmp_file_name, (curl_progress_func) curl_progress_cb, &cb_data); if (err == 0) { @@ -809,7 +711,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb free (tmp_file_name); } else - err = opkg_download (opkg->conf, url, list_file_name, NULL, NULL); + err = opkg_download (url, list_file_name, NULL, NULL); if (err) { @@ -819,7 +721,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb free (url); #if defined(HAVE_GPGME) || defined(HAVE_OPENSSL) - if ( opkg->conf->check_signature ) { + if ( conf->check_signature ) { char *sig_file_name; /* download detached signitures to verify the package lists */ /* get the url for the sig file */ @@ -835,7 +737,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb /* make sure there is no existing signature file */ unlink (sig_file_name); - err = opkg_download (opkg->conf, url, sig_file_name, NULL, NULL); + err = opkg_download (url, sig_file_name, NULL, NULL); if (err) { /* XXX: Warning: Download failed */ @@ -843,7 +745,7 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb else { int err; - err = opkg_verify_file (opkg->conf, list_file_name, sig_file_name); + err = opkg_verify_file (list_file_name, sig_file_name); if (err == 0) { /* XXX: Notice: Signature check passed */ @@ -872,23 +774,22 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb free (lists_dir); /* Now re-read the package lists to update package hash tables. */ - opkg_re_read_config_files (opkg); + opkg_re_read_config_files (); return result; } int -opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data) +opkg_list_packages (opkg_package_callback_t callback, void *user_data) { pkg_vec_t *all; int i; - opkg_assert (opkg); opkg_assert (callback); all = pkg_vec_alloc (); - pkg_hash_fetch_available (&opkg->conf->pkg_hash, all); + pkg_hash_fetch_available (all); for (i = 0; i < all->len; i++) { pkg_t *pkg; @@ -897,7 +798,7 @@ opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_d pkg = all->pkgs[i]; package = pkg_t_to_opkg_package_t (pkg); - callback (opkg, package, user_data); + callback (package, user_data); opkg_package_free (package); } @@ -907,28 +808,26 @@ opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_d } int -opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data) +opkg_list_upgradable_packages (opkg_package_callback_t callback, void *user_data) { struct active_list *head; struct active_list *node; pkg_t *old=NULL, *new = NULL; static opkg_package_t* package=NULL; - - opkg_assert (opkg); opkg_assert (callback); /* ensure all data is valid */ - pkg_info_preinstall_check (opkg->conf); + pkg_info_preinstall_check (); - head = prepare_upgrade_list(opkg->conf); + head = prepare_upgrade_list(); for (node=active_list_next(head, head); node; active_list_next(head,node)) { old = list_entry(node, pkg_t, list); - new = pkg_hash_fetch_best_installation_candidate_by_name(opkg->conf, old->name); + new = pkg_hash_fetch_best_installation_candidate_by_name(old->name); if (new == NULL) continue; package = pkg_t_to_opkg_package_t (new); - callback (opkg, package, user_data); + callback (package, user_data); opkg_package_free (package); } active_list_head_delete(head); @@ -936,17 +835,15 @@ opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, v } opkg_package_t* -opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *arch, const char *repo) +opkg_find_package (const char *name, const char *ver, const char *arch, const char *repo) { pkg_vec_t *all; opkg_package_t *package = NULL; int i; #define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0 - opkg_assert (opkg); - all = pkg_vec_alloc (); - pkg_hash_fetch_available (&opkg->conf->pkg_hash, all); + pkg_hash_fetch_available (all); for (i = 0; i < all->len; i++) { pkg_t *pkg; @@ -996,10 +893,9 @@ opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char * #endif /** * @brief Check the accessibility of repositories. It will try to access the repository to check if the respository is accessible throught current network status. - * @param opkg The opkg_t * @return return how many repositories cannot access. 0 means all okay. */ -int opkg_repository_accessibility_check(opkg_t *opkg) +int opkg_repository_accessibility_check(void) { pkg_src_list_elt_t *iter; str_list_elt_t *iter1; @@ -1009,11 +905,10 @@ int opkg_repository_accessibility_check(opkg_t *opkg) int err; char *repo_ptr; char *stmp; - opkg_assert(opkg != NULL); src = str_list_alloc(); - list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node) + list_for_each_entry(iter, &conf->pkg_src_list.head, node) { if (strstr(((pkg_src_t *)iter->data)->value, "://") && index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/')) @@ -1043,7 +938,7 @@ int opkg_repository_accessibility_check(opkg_t *opkg) iter1 = str_list_pop(src); repositories--; - err = opkg_download(opkg->conf, iter1->data, "/dev/null", NULL, NULL); + err = opkg_download(iter1->data, "/dev/null", NULL, NULL); #ifdef HAVE_CURL if (!(err == CURLE_OK || err == CURLE_HTTP_RETURNED_ERROR || diff --git a/libopkg/opkg.h b/libopkg/opkg.h index 4c34c32..7444faf 100644 --- a/libopkg/opkg.h +++ b/libopkg/opkg.h @@ -18,12 +18,11 @@ #ifndef OPKG_H #define OPKG_H -typedef struct _opkg_t opkg_t; typedef struct _opkg_package_t opkg_package_t; typedef struct _opkg_progress_data_t opkg_progress_data_t; -typedef void (*opkg_progress_callback_t) (opkg_t *opkg, const opkg_progress_data_t *progress, void *user_data); -typedef void (*opkg_package_callback_t) (opkg_t *opkg, opkg_package_t *package, void *user_data); +typedef void (*opkg_progress_callback_t) (const opkg_progress_data_t *progress, void *user_data); +typedef void (*opkg_package_callback_t) (opkg_package_t *package, void *user_data); enum _opkg_action_t { @@ -55,7 +54,6 @@ struct _opkg_package_t char *repository; char *description; char *tags; - char *url; int size; int installed; }; @@ -70,22 +68,22 @@ struct _opkg_progress_data_t opkg_package_t* opkg_package_new (); void opkg_package_free (opkg_package_t *package); -opkg_t* opkg_new (); -void opkg_free (opkg_t *opkg); -void opkg_get_option (opkg_t *opkg, char *option, void **value); -void opkg_set_option (opkg_t *opkg, char *option, void *value); -int opkg_re_read_config_files (opkg_t *opkg); +int opkg_new (void); +void opkg_free (void); +int opkg_re_read_config_files (void); +void opkg_get_option (char *option, void **value); +void opkg_set_option (char *option, void *value); -int opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data); -int opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data); -int opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data); -int opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data); -int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data); +int opkg_install_package (const char *package_name, opkg_progress_callback_t callback, void *user_data); +int opkg_remove_package (const char *package_name, opkg_progress_callback_t callback, void *user_data); +int opkg_upgrade_package (const char *package_name, opkg_progress_callback_t callback, void *user_data); +int opkg_upgrade_all (opkg_progress_callback_t callback, void *user_data); +int opkg_update_package_lists (opkg_progress_callback_t callback, void *user_data); -int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data); -int opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data); -opkg_package_t* opkg_find_package (opkg_t *opkg, const char *name, const char *version, const char *architecture, const char *repository); +int opkg_list_packages (opkg_package_callback_t callback, void *user_data); +int opkg_list_upgradable_packages (opkg_package_callback_t callback, void *user_data); +opkg_package_t* opkg_find_package (const char *name, const char *version, const char *architecture, const char *repository); -int opkg_repository_accessibility_check(opkg_t *opkg); +int opkg_repository_accessibility_check(void); #endif /* OPKG_H */ diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index ca9d9c9..30d3126 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -38,72 +38,11 @@ #include "opkg_upgrade.h" #include "opkg_remove.h" #include "opkg_configure.h" -#include "opkg_message.h" #include "libopkg.h" #include "xsystem.h" -static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_info_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatdepends_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatdepends_recursively_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatsuggests_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatrecommends_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatprovides_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatconflicts_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_whatreplaces_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv); -static int opkg_configure_cmd(opkg_conf_t *conf, int argc, char **argv); -static int pkg_mark_provides(pkg_t *pkg); - -/* XXX: CLEANUP: The usage strings should be incorporated into this - array for easier maintenance */ -static opkg_cmd_t cmds[] = { - {"update", 0, (opkg_cmd_fun_t)opkg_update_cmd}, - {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd}, - {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd}, - {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd}, - {"list-installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd}, - {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd}, - {"list-upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd}, - {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd}, - {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd}, - {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd}, - {"install", 1, (opkg_cmd_fun_t)opkg_install_cmd}, - {"remove", 1, (opkg_cmd_fun_t)opkg_remove_cmd}, - {"configure", 0, (opkg_cmd_fun_t)opkg_configure_cmd}, - {"files", 1, (opkg_cmd_fun_t)opkg_files_cmd}, - {"search", 1, (opkg_cmd_fun_t)opkg_search_cmd}, - {"download", 1, (opkg_cmd_fun_t)opkg_download_cmd}, - {"compare_versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd}, - {"compare-versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd}, - {"print-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd}, - {"print_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd}, - {"print-installation-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd}, - {"print_installation_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd}, - {"depends", 1, (opkg_cmd_fun_t)opkg_depends_cmd}, - {"whatdepends", 1, (opkg_cmd_fun_t)opkg_whatdepends_cmd}, - {"whatdependsrec", 1, (opkg_cmd_fun_t)opkg_whatdepends_recursively_cmd}, - {"whatrecommends", 1, (opkg_cmd_fun_t)opkg_whatrecommends_cmd}, - {"whatsuggests", 1, (opkg_cmd_fun_t)opkg_whatsuggests_cmd}, - {"whatprovides", 1, (opkg_cmd_fun_t)opkg_whatprovides_cmd}, - {"whatreplaces", 1, (opkg_cmd_fun_t)opkg_whatreplaces_cmd}, - {"whatconflicts", 1, (opkg_cmd_fun_t)opkg_whatconflicts_cmd}, -}; - -static void print_pkg(pkg_t *pkg) +static void +print_pkg(pkg_t *pkg) { char *version = pkg_version_str_alloc(pkg); if (pkg->description) @@ -114,49 +53,30 @@ static void print_pkg(pkg_t *pkg) } int opkg_state_changed; -static void write_status_files_if_changed(opkg_conf_t *conf) + +static void +write_status_files_if_changed(void) { if (opkg_state_changed && !conf->noaction) { - opkg_message(conf, OPKG_INFO, - " writing status file\n"); - opkg_conf_write_status_files(conf); - pkg_write_changed_filelists(conf); + opkg_msg(INFO, "Writing status file.\n"); + opkg_conf_write_status_files(); + pkg_write_changed_filelists(); } else { - opkg_message(conf, OPKG_DEBUG, "Nothing to be done\n"); - } -} - - -static int num_cmds = sizeof(cmds) / sizeof(opkg_cmd_t); - -opkg_cmd_t *opkg_cmd_find(const char *name) -{ - int i; - opkg_cmd_t *cmd; - - for (i=0; i < num_cmds; i++) { - cmd = &cmds[i]; - if (strcmp(name, cmd->name) == 0) { - return cmd; - } + opkg_msg(DEBUG, "Nothing to be done.\n"); } - - return NULL; } -int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, const char **argv, void *userdata) +static void +sigint_handler(int sig) { - int result; - - result = (cmd->fun)(conf, argc, argv); - - print_error_list(); - free_error_list(); - - return result; + signal(sig, SIG_DFL); + opkg_msg(NOTICE, "Interrupted. Writing out status database.\n"); + write_status_files_if_changed(); + exit(128 + sig); } -static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_update_cmd(int argc, char **argv) { char *tmp; int err; @@ -170,17 +90,13 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) if (! file_is_dir(lists_dir)) { if (file_exists(lists_dir)) { - opkg_message(conf, OPKG_ERROR, - "%s: ERROR: %s exists, but is not a directory\n", - __FUNCTION__, lists_dir); + opkg_msg(ERROR, "%s exists, but is not a directory.\n", + lists_dir); free(lists_dir); return -1; } err = file_mkdir_hier(lists_dir, 0755); if (err) { - opkg_message(conf, OPKG_ERROR, - "%s: ERROR: failed to make directory %s: %s\n", - __FUNCTION__, lists_dir, strerror(errno)); free(lists_dir); return -1; } @@ -190,7 +106,7 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) sprintf_alloc(&tmp, "%s/update-XXXXXX", conf->tmp_dir); if (mkdtemp (tmp) == NULL) { - perror ("mkdtemp"); + opkg_perror(ERROR, "Failed to make temp dir %s", conf->tmp_dir); return -1; } @@ -212,9 +128,9 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) FILE *in, *out; sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name); - err = opkg_download(conf, url, tmp_file_name, NULL, NULL); + err = opkg_download(url, tmp_file_name, NULL, NULL); if (err == 0) { - opkg_message (conf, OPKG_NOTICE, "Inflating %s\n", url); + opkg_msg(NOTICE, "Inflating %s.\n", url); in = fopen (tmp_file_name, "r"); out = fopen (list_file_name, "w"); if (in && out) @@ -229,12 +145,11 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) } free(tmp_file_name); } else - err = opkg_download(conf, url, list_file_name, NULL, NULL); + err = opkg_download(url, list_file_name, NULL, NULL); if (err) { failures++; } else { - opkg_message(conf, OPKG_NOTICE, - "Updated list of available packages in %s\n", + opkg_msg(NOTICE, "Updated list of available packages in %s.\n", list_file_name); } free(url); @@ -254,17 +169,16 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv) /* Put the signature in the right place */ sprintf_alloc (&tmp_file_name, "%s/%s.sig", lists_dir, src->name); - err = opkg_download(conf, url, tmp_file_name, NULL, NULL); + err = opkg_download(url, tmp_file_name, NULL, NULL); if (err) { failures++; - opkg_message (conf, OPKG_NOTICE, "Signature check failed\n"); + opkg_msg(NOTICE, "Signature check failed.\n"); } else { - int err; - err = opkg_verify_file (conf, list_file_name, tmp_file_name); + err = opkg_verify_file (list_file_name, tmp_file_name); if (err == 0) - opkg_message (conf, OPKG_NOTICE, "Signature check passed\n"); + opkg_msg(NOTICE, "Signature check passed.\n"); else - opkg_message (conf, OPKG_NOTICE, "Signature check failed\n"); + opkg_msg(NOTICE, "Signature check failed.\n"); } /* We shouldn't unlink the signature ! */ // unlink (tmp_file_name); @@ -292,7 +206,8 @@ struct opkg_intercept typedef struct opkg_intercept *opkg_intercept_t; -static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf) +static opkg_intercept_t +opkg_prep_intercepts(void) { opkg_intercept_t ctx; char *newpath; @@ -303,7 +218,7 @@ static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf) sprintf_alloc(&ctx->statedir, "%s/opkg-intercept-XXXXXX", conf->tmp_dir); if (mkdtemp(ctx->statedir) == NULL) { - fprintf(stderr, "%s: mkdtemp: %s\n", __FUNCTION__, strerror(errno)); + opkg_perror(ERROR,"Failed to make temp dir %s", ctx->statedir); free(ctx->oldpath); free(ctx->statedir); free(newpath); @@ -318,7 +233,8 @@ static opkg_intercept_t opkg_prep_intercepts(opkg_conf_t *conf) return ctx; } -static int opkg_finalize_intercepts(opkg_intercept_t ctx) +static int +opkg_finalize_intercepts(opkg_intercept_t ctx) { DIR *dir; int err = 0; @@ -344,7 +260,7 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx) } closedir(dir); } else - perror (ctx->statedir); + opkg_perror(ERROR, "Failed to open dir %s", ctx->statedir); rm_r(ctx->statedir); free (ctx->statedir); @@ -361,7 +277,8 @@ static int opkg_finalize_intercepts(opkg_intercept_t ctx) used to end recursion and avoid an infinite loop on graph cycles. pkg_vec ordered will finally contain the ordered set of packages. */ -static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *all, +static int +opkg_recurse_pkgs_in_order(pkg_t *pkg, pkg_vec_t *all, pkg_vec_t *visited, pkg_vec_t *ordered) { int j,k,l,m; @@ -385,8 +302,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t * /* If the package has already been visited (by this function), skip it */ for(j = 0; j < visited->len; j++) if ( ! strcmp(visited->pkgs[j]->name, pkg->name)) { - opkg_message(conf, OPKG_INFO, - " pkg: %s already visited\n", pkg->name); + opkg_msg(INFO, "pkg %s already visited, skipping.\n", pkg->name); return 0; } @@ -395,8 +311,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t * count = pkg->pre_depends_count + pkg->depends_count + \ pkg->recommends_count + pkg->suggests_count; - opkg_message(conf, OPKG_INFO, - " pkg: %s\n", pkg->name); + opkg_msg(INFO, "pkg %s.\n", pkg->name); /* Iterate over all the dependencies of pkg. For each one, find a package that is either installed or unpacked and satisfies this dependency. @@ -411,8 +326,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t * l = 0; if (dependents != NULL) while (l < abpkg->provided_by->len && dependents[l] != NULL) { - opkg_message(conf, OPKG_INFO, - " Descending on pkg: %s\n", + opkg_msg(INFO, "Descending on pkg %s.\n", dependents [l]->name); /* find whether dependent l is installed or unpacked, @@ -421,7 +335,7 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t * dep = all->pkgs[m]; if ( dep->state_status != SS_NOT_INSTALLED) if ( ! strcmp(dep->name, dependents[l]->name)) { - opkg_recurse_pkgs_in_order(conf, dep, all, + opkg_recurse_pkgs_in_order(dep, all, visited, ordered); /* Stop the outer loop */ l = abpkg->provided_by->len; @@ -443,7 +357,8 @@ static int opkg_recurse_pkgs_in_order(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t * } -static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name) +static int +opkg_configure_packages(char *pkg_name) { pkg_vec_t *all, *ordered, *visited; int i; @@ -451,26 +366,23 @@ static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name) opkg_intercept_t ic; int r, err = 0; - opkg_message(conf, OPKG_INFO, - "Configuring unpacked packages\n"); - fflush( stdout ); + opkg_msg(INFO, "Configuring unpacked packages.\n"); all = pkg_vec_alloc(); - pkg_hash_fetch_available(&conf->pkg_hash, all); + pkg_hash_fetch_available(all); /* Reorder pkgs in order to be configured according to the Depends: tag order */ - opkg_message(conf, OPKG_INFO, - "Reordering packages before configuring them...\n"); + opkg_msg(INFO, "Reordering packages before configuring them...\n"); ordered = pkg_vec_alloc(); visited = pkg_vec_alloc(); for(i = 0; i < all->len; i++) { pkg = all->pkgs[i]; - opkg_recurse_pkgs_in_order(conf, pkg, all, visited, ordered); + opkg_recurse_pkgs_in_order(pkg, all, visited, ordered); } - ic = opkg_prep_intercepts (conf); + ic = opkg_prep_intercepts(); if (ic == NULL) { err = -1; goto error; @@ -483,10 +395,8 @@ static int opkg_configure_packages(opkg_conf_t *conf, char *pkg_name) continue; if (pkg->state_status == SS_UNPACKED) { - opkg_message(conf, OPKG_NOTICE, - "Configuring %s\n", pkg->name); - fflush( stdout ); - r = opkg_configure(conf, pkg); + opkg_msg(NOTICE, "Configuring %s.\n", pkg->name); + r = opkg_configure(pkg); if (r == 0) { pkg->state_status = SS_INSTALLED; pkg->parent->state_status = SS_INSTALLED; @@ -510,24 +420,13 @@ error: return err; } -static opkg_conf_t *global_conf; - -static void sigint_handler(int sig) -{ - signal(sig, SIG_DFL); - opkg_message(NULL, OPKG_NOTICE, - "opkg: interrupted. writing out status database\n"); - write_status_files_if_changed(global_conf); - exit(128 + sig); -} - -static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_install_cmd(int argc, char **argv) { int i; char *arg; int err=0; - global_conf = conf; signal(SIGINT, sigint_handler); /* @@ -536,116 +435,109 @@ static int opkg_install_cmd(opkg_conf_t *conf, int argc, char **argv) for (i=0; i < argc; i++) { arg = argv[i]; - opkg_message(conf, OPKG_DEBUG2, "Debug install_cmd: %s \n",arg ); - err = opkg_prepare_url_for_install(conf, arg, &argv[i]); + opkg_msg(DEBUG2, "%s\n", arg); + err = opkg_prepare_url_for_install(arg, &argv[i]); if (err) return err; } - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); for (i=0; i < argc; i++) { arg = argv[i]; - err = opkg_install_by_name(conf, arg); + err = opkg_install_by_name(arg); if (err) { - opkg_message(conf, OPKG_ERROR, "Cannot find package %s.\n", arg); + opkg_msg(ERROR, "Cannot install package %s.\n", arg); } } - opkg_configure_packages(conf, NULL); + opkg_configure_packages(NULL); - write_status_files_if_changed(conf); + write_status_files_if_changed(); return err; } -static int opkg_upgrade_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_upgrade_cmd(int argc, char **argv) { int i; pkg_t *pkg; int err; - global_conf = conf; signal(SIGINT, sigint_handler); if (argc) { for (i=0; i < argc; i++) { char *arg = argv[i]; - err = opkg_prepare_url_for_install(conf, arg, &arg); + err = opkg_prepare_url_for_install(arg, &arg); if (err) return err; } - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); for (i=0; i < argc; i++) { char *arg = argv[i]; if (conf->restrict_to_default_dest) { - pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, - argv[i], - conf->default_dest); + pkg = pkg_hash_fetch_installed_by_name_dest(argv[i], + conf->default_dest); if (pkg == NULL) { - opkg_message(conf, OPKG_NOTICE, - "Package %s not installed in %s\n", + opkg_msg(NOTICE, "Package %s not installed in %s.\n", argv[i], conf->default_dest->name); continue; } } else { - pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, - argv[i]); + pkg = pkg_hash_fetch_installed_by_name(argv[i]); } if (pkg) - opkg_upgrade_pkg(conf, pkg); + opkg_upgrade_pkg(pkg); else { - opkg_install_by_name(conf, arg); + opkg_install_by_name(arg); } } } else { pkg_vec_t *installed = pkg_vec_alloc(); - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); - pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); + pkg_hash_fetch_all_installed(installed); for (i = 0; i < installed->len; i++) { pkg = installed->pkgs[i]; - opkg_upgrade_pkg(conf, pkg); + opkg_upgrade_pkg(pkg); } pkg_vec_free(installed); } - opkg_configure_packages(conf, NULL); + opkg_configure_packages(NULL); - write_status_files_if_changed(conf); + write_status_files_if_changed(); return 0; } -static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_download_cmd(int argc, char **argv) { int i, err; char *arg; pkg_t *pkg; - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); for (i = 0; i < argc; i++) { arg = argv[i]; - pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, arg); + pkg = pkg_hash_fetch_best_installation_candidate_by_name(arg); if (pkg == NULL) { - opkg_message(conf, OPKG_ERROR, - "Cannot find package %s.\n" - "Check the spelling or perhaps run 'opkg update'\n", - arg); + opkg_msg(ERROR, "Cannot find package %s.\n", arg); continue; } - err = opkg_download_pkg(conf, pkg, "."); + err = opkg_download_pkg(pkg, "."); if (err) { - opkg_message(conf, OPKG_ERROR, - "Failed to download %s\n", pkg->name); + opkg_msg(ERROR, "Failed to download %s.\n", pkg->name); } else { - opkg_message(conf, OPKG_NOTICE, - "Downloaded %s as %s\n", + opkg_msg(NOTICE, "Downloaded %s as %s.\n", pkg->name, pkg->local_filename); } } @@ -654,7 +546,8 @@ static int opkg_download_cmd(opkg_conf_t *conf, int argc, char **argv) } -static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_list_cmd(int argc, char **argv) { int i; pkg_vec_t *available; @@ -665,7 +558,7 @@ static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv) pkg_name = argv[0]; } available = pkg_vec_alloc(); - pkg_hash_fetch_available(&conf->pkg_hash, available); + pkg_hash_fetch_available(available); pkg_vec_sort(available, pkg_compare_names); for (i=0; i < available->len; i++) { pkg = available->pkgs[i]; @@ -680,7 +573,8 @@ static int opkg_list_cmd(opkg_conf_t *conf, int argc, char **argv) } -static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_list_installed_cmd(int argc, char **argv) { int i ; pkg_vec_t *available; @@ -691,7 +585,7 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv) pkg_name = argv[0]; } available = pkg_vec_alloc(); - pkg_hash_fetch_all_installed(&conf->pkg_hash, available); + pkg_hash_fetch_all_installed(available); pkg_vec_sort(available, pkg_compare_names); for (i=0; i < available->len; i++) { pkg = available->pkgs[i]; @@ -706,15 +600,16 @@ static int opkg_list_installed_cmd(opkg_conf_t *conf, int argc, char **argv) return 0; } -static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_list_upgradable_cmd(int argc, char **argv) { - struct active_list *head = prepare_upgrade_list(conf); + struct active_list *head = prepare_upgrade_list(); struct active_list *node=NULL; pkg_t *_old_pkg, *_new_pkg; char *old_v, *new_v; for (node = active_list_next(head, head); node;node = active_list_next(head,node)) { _old_pkg = list_entry(node, pkg_t, list); - _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(conf, _old_pkg->name); + _new_pkg = pkg_hash_fetch_best_installation_candidate_by_name(_old_pkg->name); if (_new_pkg == NULL) continue; old_v = pkg_version_str_alloc(_old_pkg); @@ -727,7 +622,8 @@ static int opkg_list_upgradable_cmd(opkg_conf_t *conf, int argc, char **argv) return 0; } -static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int installed_only) +static int +opkg_info_status_cmd(int argc, char **argv, int installed_only) { int i; pkg_vec_t *available; @@ -740,9 +636,9 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in available = pkg_vec_alloc(); if (installed_only) - pkg_hash_fetch_all_installed(&conf->pkg_hash, available); + pkg_hash_fetch_all_installed(available); else - pkg_hash_fetch_available(&conf->pkg_hash, available); + pkg_hash_fetch_available(available); for (i=0; i < available->len; i++) { pkg = available->pkgs[i]; @@ -752,14 +648,13 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in pkg_formatted_info(stdout, pkg); - if (conf->verbosity >= OPKG_NOTICE) { + if (conf->verbosity >= NOTICE) { conffile_list_elt_t *iter; for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) { conffile_t *cf = (conffile_t *)iter->data; - int modified = conffile_has_been_modified(conf, cf); + int modified = conffile_has_been_modified(cf); if (cf->value) - opkg_message(conf, OPKG_INFO, - "conffile=%s md5sum=%s modified=%d\n", + opkg_msg(INFO, "conffile=%s md5sum=%s modified=%d.\n", cf->name, cf->value, modified); } } @@ -769,52 +664,50 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in return 0; } -static int opkg_info_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_info_cmd(int argc, char **argv) { - return opkg_info_status_cmd(conf, argc, argv, 0); + return opkg_info_status_cmd(argc, argv, 0); } -static int opkg_status_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_status_cmd(int argc, char **argv) { - return opkg_info_status_cmd(conf, argc, argv, 1); + return opkg_info_status_cmd(argc, argv, 1); } -static int opkg_configure_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_configure_cmd(int argc, char **argv) { - - int err; - if (argc > 0) { - char *pkg_name = NULL; + int err; + char *pkg_name = NULL; - pkg_name = argv[0]; + if (argc > 0) + pkg_name = argv[0]; - err = opkg_configure_packages (conf, pkg_name); - - } else { - err = opkg_configure_packages (conf, NULL); - } + err = opkg_configure_packages(pkg_name); - write_status_files_if_changed(conf); + write_status_files_if_changed(); - return err; + return err; } -static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_remove_cmd(int argc, char **argv) { int i, a, done; pkg_t *pkg; pkg_t *pkg_to_remove; pkg_vec_t *available; - global_conf = conf; done = 0; signal(SIGINT, sigint_handler); - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); available = pkg_vec_alloc(); - pkg_hash_fetch_all_installed(&conf->pkg_hash, available); + pkg_hash_fetch_all_installed(available); for (i=0; ilen; a++) { @@ -823,22 +716,22 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv) continue; } if (conf->restrict_to_default_dest) { - pkg_to_remove = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, + pkg_to_remove = pkg_hash_fetch_installed_by_name_dest( pkg->name, conf->default_dest); } else { - pkg_to_remove = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name ); + pkg_to_remove = pkg_hash_fetch_installed_by_name(pkg->name); } if (pkg_to_remove == NULL) { - opkg_message(conf, OPKG_ERROR, "Package %s is not installed.\n", pkg->name); + opkg_msg(ERROR, "Package %s is not installed.\n", pkg->name); continue; } if (pkg->state_status == SS_NOT_INSTALLED) { // Added the control, so every already removed package could be skipped - opkg_message(conf, OPKG_ERROR, "Package seems to be %s not installed (STATUS = NOT_INSTALLED).\n", pkg->name); + opkg_msg(ERROR, "Package %s not installed.\n", pkg->name); continue; } - opkg_remove_pkg(conf, pkg_to_remove, 0); + opkg_remove_pkg(pkg_to_remove, 0); done = 1; } } @@ -846,33 +739,31 @@ static int opkg_remove_cmd(opkg_conf_t *conf, int argc, char **argv) pkg_vec_free(available); if (done == 0) - opkg_message(conf, OPKG_NOTICE, "No packages removed.\n"); + opkg_msg(NOTICE, "No packages removed.\n"); - write_status_files_if_changed(conf); + write_status_files_if_changed(); return 0; } -static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_flag_cmd(int argc, char **argv) { int i; pkg_t *pkg; const char *flags = argv[0]; - global_conf = conf; signal(SIGINT, sigint_handler); for (i=1; i < argc; i++) { if (conf->restrict_to_default_dest) { - pkg = pkg_hash_fetch_installed_by_name_dest(&conf->pkg_hash, - argv[i], + pkg = pkg_hash_fetch_installed_by_name_dest(argv[i], conf->default_dest); } else { - pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, argv[i]); + pkg = pkg_hash_fetch_installed_by_name(argv[i]); } if (pkg == NULL) { - opkg_message(conf, OPKG_ERROR, - "Package %s is not installed.\n", argv[i]); + opkg_msg(ERROR, "Package %s is not installed.\n", argv[i]); continue; } if (( strcmp(flags,"hold")==0)||( strcmp(flags,"noprune")==0)|| @@ -889,16 +780,16 @@ static int opkg_flag_cmd(opkg_conf_t *conf, int argc, char **argv) } opkg_state_changed++; - opkg_message(conf, OPKG_NOTICE, - "Setting flags for package %s to %s\n", + opkg_msg(NOTICE, "Setting flags for package %s to %s.\n", pkg->name, flags); } - write_status_files_if_changed(conf); + write_status_files_if_changed(); return 0; } -static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_files_cmd(int argc, char **argv) { pkg_t *pkg; str_list_t *files; @@ -906,18 +797,16 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv) char *pkg_version; if (argc < 1) { - return EINVAL; + return -1; } - pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, - argv[0]); + pkg = pkg_hash_fetch_installed_by_name(argv[0]); if (pkg == NULL) { - opkg_message(conf, OPKG_ERROR, - "Package %s not installed.\n", argv[0]); + opkg_msg(ERROR, "Package %s not installed.\n", argv[0]); return 0; } - files = pkg_get_installed_files(conf, pkg); + files = pkg_get_installed_files(pkg); pkg_version = pkg_version_str_alloc(pkg); printf("Package %s (%s) is installed on %s and has the following files:\n", @@ -932,7 +821,8 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv) return 0; } -static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_depends_cmd(int argc, char **argv) { int i, j, k; int depends_count; @@ -941,13 +831,13 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv) pkg_t *pkg; char *str; - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); available_pkgs = pkg_vec_alloc(); if (conf->query_all) - pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); + pkg_hash_fetch_available(available_pkgs); else - pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); + pkg_hash_fetch_all_installed(available_pkgs); for (i=0; ilen; j++) { @@ -961,8 +851,7 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv) pkg->recommends_count + pkg->suggests_count; - opkg_message(conf, OPKG_NOTICE, "%s depends on:\n", - pkg->name); + opkg_msg(NOTICE, "%s depends on:\n", pkg->name); for (k=0; kdepends[k]; @@ -971,7 +860,7 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv) continue; str = pkg_depend_str(pkg, k); - opkg_message(conf, OPKG_NOTICE, "\t%s\n", str); + opkg_msg(NOTICE, "\t%s\n", str); free(str); } @@ -982,6 +871,19 @@ static int opkg_depends_cmd(opkg_conf_t *conf, int argc, char **argv) return 0; } +static int +pkg_mark_provides(pkg_t *pkg) +{ + int provides_count = pkg->provides_count; + abstract_pkg_t **provides = pkg->provides; + int i; + pkg->parent->state_flag |= SF_MARKED; + for (i = 0; i < provides_count; i++) { + provides[i]->state_flag |= SF_MARKED; + } + return 0; +} + enum what_field_type { WHATDEPENDS, WHATCONFLICTS, @@ -991,7 +893,8 @@ enum what_field_type { WHATSUGGESTS }; -static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type what_field_type, int recursive, int argc, char **argv) +static int +opkg_what_depends_conflicts_cmd(enum depend_type what_field_type, int recursive, int argc, char **argv) { depend_t *possibility; compound_depend_t *cdep; @@ -1013,13 +916,13 @@ static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type w available_pkgs = pkg_vec_alloc(); if (conf->query_all) - pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); + pkg_hash_fetch_available(available_pkgs); else - pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); + pkg_hash_fetch_all_installed(available_pkgs); /* mark the root set */ pkg_vec_clear_marks(available_pkgs); - opkg_message(conf, OPKG_NOTICE, "Root set:\n"); + opkg_msg(NOTICE, "Root set:\n"); for (i = 0; i < argc; i++) pkg_vec_mark_if_matches(available_pkgs, argv[i]); @@ -1028,11 +931,11 @@ static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type w if (pkg->state_flag & SF_MARKED) { /* mark the parent (abstract) package */ pkg_mark_provides(pkg); - opkg_message(conf, OPKG_NOTICE, " %s\n", pkg->name); + opkg_msg(NOTICE, " %s\n", pkg->name); } } - opkg_message(conf, OPKG_NOTICE, "What %s root set\n", rel_str); + opkg_msg(NOTICE, "What %s root set\n", rel_str); do { changed = 0; @@ -1073,23 +976,21 @@ static int opkg_what_depends_conflicts_cmd(opkg_conf_t *conf, enum depend_type w changed++; ver = pkg_version_str_alloc(pkg); - opkg_message(conf, OPKG_NOTICE, - "\t%s %s\t%s %s", + opkg_msg(NOTICE, "\t%s %s\t%s %s", pkg->name, ver, rel_str, possibility->pkg->name); free(ver); if (possibility->version) { - opkg_message(conf, OPKG_NOTICE, - " (%s%s)", + opkg_msg(NOTICE, " (%s%s)", constraint_to_str(possibility->constraint), possibility->version); } - if (!pkg_dependence_satisfiable(conf, possibility)) - opkg_message(conf, OPKG_NOTICE, + if (!pkg_dependence_satisfiable(possibility)) + opkg_msg(NOTICE, " unsatisfiable"); - opkg_message(conf, OPKG_NOTICE, "\n"); + opkg_msg(NOTICE, "\n"); goto next_package; } } @@ -1103,43 +1004,38 @@ next_package: return 0; } -static int pkg_mark_provides(pkg_t *pkg) +static int +opkg_whatdepends_recursively_cmd(int argc, char **argv) { - int provides_count = pkg->provides_count; - abstract_pkg_t **provides = pkg->provides; - int i; - pkg->parent->state_flag |= SF_MARKED; - for (i = 0; i < provides_count; i++) { - provides[i]->state_flag |= SF_MARKED; - } - return 0; + return opkg_what_depends_conflicts_cmd(DEPEND, 1, argc, argv); } -static int opkg_whatdepends_recursively_cmd(opkg_conf_t *conf, int argc, char **argv) -{ - return opkg_what_depends_conflicts_cmd(conf, DEPEND, 1, argc, argv); -} -static int opkg_whatdepends_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_whatdepends_cmd(int argc, char **argv) { - return opkg_what_depends_conflicts_cmd(conf, DEPEND, 0, argc, argv); + return opkg_what_depends_conflicts_cmd(DEPEND, 0, argc, argv); } -static int opkg_whatsuggests_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_whatsuggests_cmd(int argc, char **argv) { - return opkg_what_depends_conflicts_cmd(conf, SUGGEST, 0, argc, argv); + return opkg_what_depends_conflicts_cmd(SUGGEST, 0, argc, argv); } -static int opkg_whatrecommends_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_whatrecommends_cmd(int argc, char **argv) { - return opkg_what_depends_conflicts_cmd(conf, RECOMMEND, 0, argc, argv); + return opkg_what_depends_conflicts_cmd(RECOMMEND, 0, argc, argv); } -static int opkg_whatconflicts_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_whatconflicts_cmd(int argc, char **argv) { - return opkg_what_depends_conflicts_cmd(conf, CONFLICTS, 0, argc, argv); + return opkg_what_depends_conflicts_cmd(CONFLICTS, 0, argc, argv); } -static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_type what_field_type, int argc, char **argv) +static int +opkg_what_provides_replaces_cmd(enum what_field_type what_field_type, int argc, char **argv) { if (argc > 0) { @@ -1147,17 +1043,17 @@ static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_ty const char *rel_str = (what_field_type == WHATPROVIDES ? "provides" : "replaces"); int i; - pkg_info_preinstall_check(conf); + pkg_info_preinstall_check(); if (conf->query_all) - pkg_hash_fetch_available(&conf->pkg_hash, available_pkgs); + pkg_hash_fetch_available(available_pkgs); else - pkg_hash_fetch_all_installed(&conf->pkg_hash, available_pkgs); + pkg_hash_fetch_all_installed(available_pkgs); for (i = 0; i < argc; i++) { const char *target = argv[i]; int j; - opkg_message(conf, OPKG_ERROR, "What %s %s\n", + opkg_msg(NOTICE, "What %s %s\n", rel_str, target); for (j = 0; j < available_pkgs->len; j++) { pkg_t *pkg = available_pkgs->pkgs[j]; @@ -1169,10 +1065,11 @@ static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_ty ? pkg->provides[k] : pkg->replaces[k]); if (fnmatch(target, apkg->name, 0) == 0) { - opkg_message(conf, OPKG_ERROR, " %s", pkg->name); + opkg_msg(NOTICE, " %s", pkg->name); if (strcmp(target, apkg->name) != 0) - opkg_message(conf, OPKG_ERROR, "\t%s %s\n", rel_str, apkg->name); - opkg_message(conf, OPKG_ERROR, "\n"); + opkg_msg(NOTICE, "\t%s %s\n", + rel_str, apkg->name); + opkg_msg(NOTICE, "\n"); } } } @@ -1182,17 +1079,20 @@ static int opkg_what_provides_replaces_cmd(opkg_conf_t *conf, enum what_field_ty return 0; } -static int opkg_whatprovides_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_whatprovides_cmd(int argc, char **argv) { - return opkg_what_provides_replaces_cmd(conf, WHATPROVIDES, argc, argv); + return opkg_what_provides_replaces_cmd(WHATPROVIDES, argc, argv); } -static int opkg_whatreplaces_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_whatreplaces_cmd(int argc, char **argv) { - return opkg_what_provides_replaces_cmd(conf, WHATREPLACES, argc, argv); + return opkg_what_provides_replaces_cmd(WHATREPLACES, argc, argv); } -static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_search_cmd(int argc, char **argv) { int i; @@ -1203,17 +1103,17 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv) char *installed_file; if (argc < 1) { - return EINVAL; + return -1; } installed = pkg_vec_alloc(); - pkg_hash_fetch_all_installed(&conf->pkg_hash, installed); + pkg_hash_fetch_all_installed(installed); pkg_vec_sort(installed, pkg_compare_names); for (i=0; i < installed->len; i++) { pkg = installed->pkgs[i]; - installed_files = pkg_get_installed_files(conf, pkg); + installed_files = pkg_get_installed_files(pkg); for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) { installed_file = (char *)iter->data; @@ -1229,7 +1129,8 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv) return 0; } -static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_compare_versions_cmd(int argc, char **argv) { if (argc == 3) { /* this is a bit gross */ @@ -1238,14 +1139,15 @@ static int opkg_compare_versions_cmd(opkg_conf_t *conf, int argc, char **argv) parse_version(&p2, argv[2]); return pkg_version_satisfied(&p1, &p2, argv[1]); } else { - opkg_message(conf, OPKG_ERROR, + opkg_msg(ERROR, "opkg compare_versions \n" " is one of <= >= << >> =\n"); return -1; } } -static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv) +static int +opkg_print_architecture_cmd(int argc, char **argv) { nv_pair_list_elt_t *l; @@ -1255,3 +1157,68 @@ static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv) } return 0; } + + +/* XXX: CLEANUP: The usage strings should be incorporated into this + array for easier maintenance */ +static opkg_cmd_t cmds[] = { + {"update", 0, (opkg_cmd_fun_t)opkg_update_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"upgrade", 0, (opkg_cmd_fun_t)opkg_upgrade_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"list", 0, (opkg_cmd_fun_t)opkg_list_cmd, PFM_SOURCE}, + {"list_installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd, PFM_SOURCE}, + {"list-installed", 0, (opkg_cmd_fun_t)opkg_list_installed_cmd, PFM_SOURCE}, + {"list_upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd, PFM_SOURCE}, + {"list-upgradable", 0, (opkg_cmd_fun_t)opkg_list_upgradable_cmd, PFM_SOURCE}, + {"info", 0, (opkg_cmd_fun_t)opkg_info_cmd, 0}, + {"flag", 1, (opkg_cmd_fun_t)opkg_flag_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"status", 0, (opkg_cmd_fun_t)opkg_status_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"install", 1, (opkg_cmd_fun_t)opkg_install_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"remove", 1, (opkg_cmd_fun_t)opkg_remove_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"configure", 0, (opkg_cmd_fun_t)opkg_configure_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"files", 1, (opkg_cmd_fun_t)opkg_files_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"search", 1, (opkg_cmd_fun_t)opkg_search_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"download", 1, (opkg_cmd_fun_t)opkg_download_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"compare_versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"compare-versions", 1, (opkg_cmd_fun_t)opkg_compare_versions_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"print-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"print_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"print-installation-architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"print_installation_architecture", 0, (opkg_cmd_fun_t)opkg_print_architecture_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"depends", 1, (opkg_cmd_fun_t)opkg_depends_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatdepends", 1, (opkg_cmd_fun_t)opkg_whatdepends_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatdependsrec", 1, (opkg_cmd_fun_t)opkg_whatdepends_recursively_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatrecommends", 1, (opkg_cmd_fun_t)opkg_whatrecommends_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatsuggests", 1, (opkg_cmd_fun_t)opkg_whatsuggests_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatprovides", 1, (opkg_cmd_fun_t)opkg_whatprovides_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatreplaces", 1, (opkg_cmd_fun_t)opkg_whatreplaces_cmd, PFM_DESCRIPTION|PFM_SOURCE}, + {"whatconflicts", 1, (opkg_cmd_fun_t)opkg_whatconflicts_cmd, PFM_DESCRIPTION|PFM_SOURCE}, +}; + +opkg_cmd_t * +opkg_cmd_find(const char *name) +{ + int i; + opkg_cmd_t *cmd; + int num_cmds = sizeof(cmds) / sizeof(opkg_cmd_t); + + for (i=0; i < num_cmds; i++) { + cmd = &cmds[i]; + if (strcmp(name, cmd->name) == 0) + return cmd; + } + + return NULL; +} + +int +opkg_cmd_exec(opkg_cmd_t *cmd, int argc, const char **argv) +{ + int result; + + result = (cmd->fun)(argc, argv); + + print_error_list(); + free_error_list(); + + return result; +} diff --git a/libopkg/opkg_cmd.h b/libopkg/opkg_cmd.h index 9c9dad2..6d2f1ad 100644 --- a/libopkg/opkg_cmd.h +++ b/libopkg/opkg_cmd.h @@ -18,19 +18,19 @@ #ifndef OPKG_CMD_H #define OPKG_CMD_H -typedef int (*opkg_cmd_fun_t)(opkg_conf_t *conf, int argc, const char **argv); +typedef int (*opkg_cmd_fun_t)(int argc, const char **argv); struct opkg_cmd { - char *name; + const char *name; int requires_args; opkg_cmd_fun_t fun; + uint pfm; /* package field mask */ }; typedef struct opkg_cmd opkg_cmd_t; opkg_cmd_t *opkg_cmd_find(const char *name); -int opkg_cmd_exec(opkg_cmd_t *cmd, opkg_conf_t *conf, int argc, - const char **argv, void *userdata); +int opkg_cmd_exec(opkg_cmd_t *cmd, int argc, const char **argv); extern int opkg_state_changed; #endif diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c index 7405b48..69b6935 100644 --- a/libopkg/opkg_conf.c +++ b/libopkg/opkg_conf.c @@ -17,7 +17,6 @@ #include "includes.h" #include "opkg_conf.h" -#include "opkg_error.h" #include "xregex.h" #include "sprintf_alloc.h" @@ -33,385 +32,59 @@ #include #include -static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, - pkg_src_list_t *pkg_src_list, - nv_pair_list_t *tmp_dest_nv_pair_list); -static int opkg_conf_set_option(const opkg_option_t *options, - const char *name, const char *value); -static int opkg_conf_set_default_dest(opkg_conf_t *conf, - const char *default_dest_name); -static int set_and_load_pkg_src_list(opkg_conf_t *conf, - pkg_src_list_t *nv_pair_list); -static int set_and_load_pkg_dest_list(opkg_conf_t *conf, - nv_pair_list_t *nv_pair_list); - -void opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options) -{ - opkg_option_t tmp[] = { - { "cache", OPKG_OPT_TYPE_STRING, &conf->cache}, - { "force_defaults", OPKG_OPT_TYPE_BOOL, &conf->force_defaults }, - { "force_maintainer", OPKG_OPT_TYPE_BOOL, &conf->force_maintainer }, - { "force_depends", OPKG_OPT_TYPE_BOOL, &conf->force_depends }, - { "force_overwrite", OPKG_OPT_TYPE_BOOL, &conf->force_overwrite }, - { "force_downgrade", OPKG_OPT_TYPE_BOOL, &conf->force_downgrade }, - { "force_reinstall", OPKG_OPT_TYPE_BOOL, &conf->force_reinstall }, - { "force_space", OPKG_OPT_TYPE_BOOL, &conf->force_space }, - { "check_signature", OPKG_OPT_TYPE_INT, &conf->check_signature }, - { "ftp_proxy", OPKG_OPT_TYPE_STRING, &conf->ftp_proxy }, - { "http_proxy", OPKG_OPT_TYPE_STRING, &conf->http_proxy }, - { "no_proxy", OPKG_OPT_TYPE_STRING, &conf->no_proxy }, - { "test", OPKG_OPT_TYPE_INT, &conf->noaction }, - { "noaction", OPKG_OPT_TYPE_INT, &conf->noaction }, - { "nodeps", OPKG_OPT_TYPE_BOOL, &conf->nodeps }, - { "offline_root", OPKG_OPT_TYPE_STRING, &conf->offline_root }, - { "offline_root_path", OPKG_OPT_TYPE_STRING, &conf->offline_root_path }, - { "offline_root_post_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_post_script_cmd }, - { "offline_root_pre_script_cmd", OPKG_OPT_TYPE_STRING, &conf->offline_root_pre_script_cmd }, - { "proxy_passwd", OPKG_OPT_TYPE_STRING, &conf->proxy_passwd }, - { "proxy_user", OPKG_OPT_TYPE_STRING, &conf->proxy_user }, - { "query-all", OPKG_OPT_TYPE_BOOL, &conf->query_all }, - { "tmp_dir", OPKG_OPT_TYPE_STRING, &conf->tmp_dir }, - { "verbosity", OPKG_OPT_TYPE_BOOL, &conf->verbosity }, +static int lock_fd; + +static opkg_conf_t _conf; +opkg_conf_t *conf = &_conf; + +/* + * Config file options + */ +opkg_option_t options[] = { + { "cache", OPKG_OPT_TYPE_STRING, &_conf.cache}, + { "force_defaults", OPKG_OPT_TYPE_BOOL, &_conf.force_defaults }, + { "force_maintainer", OPKG_OPT_TYPE_BOOL, &_conf.force_maintainer }, + { "force_depends", OPKG_OPT_TYPE_BOOL, &_conf.force_depends }, + { "force_overwrite", OPKG_OPT_TYPE_BOOL, &_conf.force_overwrite }, + { "force_downgrade", OPKG_OPT_TYPE_BOOL, &_conf.force_downgrade }, + { "force_reinstall", OPKG_OPT_TYPE_BOOL, &_conf.force_reinstall }, + { "force_space", OPKG_OPT_TYPE_BOOL, &_conf.force_space }, + { "check_signature", OPKG_OPT_TYPE_BOOL, &_conf.check_signature }, + { "ftp_proxy", OPKG_OPT_TYPE_STRING, &_conf.ftp_proxy }, + { "http_proxy", OPKG_OPT_TYPE_STRING, &_conf.http_proxy }, + { "no_proxy", OPKG_OPT_TYPE_STRING, &_conf.no_proxy }, + { "test", OPKG_OPT_TYPE_BOOL, &_conf.noaction }, + { "noaction", OPKG_OPT_TYPE_BOOL, &_conf.noaction }, + { "nodeps", OPKG_OPT_TYPE_BOOL, &_conf.nodeps }, + { "offline_root", OPKG_OPT_TYPE_STRING, &_conf.offline_root }, + { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd }, + { "proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user }, + { "query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all }, + { "tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir }, + { "verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity }, #if defined(HAVE_OPENSSL) - { "signature_ca_file", OPKG_OPT_TYPE_STRING, &conf->signature_ca_file }, - { "signature_ca_path", OPKG_OPT_TYPE_STRING, &conf->signature_ca_path }, + { "signature_ca_file", OPKG_OPT_TYPE_STRING, &_conf.signature_ca_file }, + { "signature_ca_path", OPKG_OPT_TYPE_STRING, &_conf.signature_ca_path }, #endif #if defined(HAVE_PATHFINDER) - { "check_x509_path", OPKG_OPT_TYPE_INT, &conf->check_x509_path }, + { "check_x509_path", OPKG_OPT_TYPE_BOOL, &_conf.check_x509_path }, #endif #if defined(HAVE_SSLCURL) && defined(HAVE_CURL) - { "ssl_engine", OPKG_OPT_TYPE_STRING, &conf->ssl_engine }, - { "ssl_cert", OPKG_OPT_TYPE_STRING, &conf->ssl_cert }, - { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &conf->ssl_cert_type }, - { "ssl_key", OPKG_OPT_TYPE_STRING, &conf->ssl_key }, - { "ssl_key_type", OPKG_OPT_TYPE_STRING, &conf->ssl_key_type }, - { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &conf->ssl_key_passwd }, - { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_file }, - { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &conf->ssl_ca_path }, - { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &conf->ssl_dont_verify_peer }, + { "ssl_engine", OPKG_OPT_TYPE_STRING, &_conf.ssl_engine }, + { "ssl_cert", OPKG_OPT_TYPE_STRING, &_conf.ssl_cert }, + { "ssl_cert_type", OPKG_OPT_TYPE_STRING, &_conf.ssl_cert_type }, + { "ssl_key", OPKG_OPT_TYPE_STRING, &_conf.ssl_key }, + { "ssl_key_type", OPKG_OPT_TYPE_STRING, &_conf.ssl_key_type }, + { "ssl_key_passwd", OPKG_OPT_TYPE_STRING, &_conf.ssl_key_passwd }, + { "ssl_ca_file", OPKG_OPT_TYPE_STRING, &_conf.ssl_ca_file }, + { "ssl_ca_path", OPKG_OPT_TYPE_STRING, &_conf.ssl_ca_path }, + { "ssl_dont_verify_peer", OPKG_OPT_TYPE_BOOL, &_conf.ssl_dont_verify_peer }, #endif - { NULL } - }; - - *options = xcalloc(1, sizeof(tmp)); - memcpy(*options, tmp, sizeof(tmp)); + { NULL, 0, NULL } }; -static void opkg_conf_override_string(char **conf_str, char *arg_str) -{ - if (arg_str) { - if (*conf_str) { - free(*conf_str); - } - *conf_str = xstrdup(arg_str); - } -} - -static void opkg_conf_free_string(char **conf_str) -{ - if (*conf_str) { - free(*conf_str); - *conf_str = NULL; - } -} - -int opkg_conf_init(opkg_conf_t *conf, const args_t *args) -{ - int err; - int errno_copy; - char *tmp_dir_base, *tmp2; - nv_pair_list_t tmp_dest_nv_pair_list; - char *lock_file = NULL; - glob_t globbuf; - char *etc_opkg_conf_pattern; - char *offline_root = NULL; - - memset(conf, 0, sizeof(opkg_conf_t)); - -#if defined(HAVE_PATHFINDER) - conf->check_x509_path = 1; -#endif - - pkg_src_list_init(&conf->pkg_src_list); - - nv_pair_list_init(&tmp_dest_nv_pair_list); - pkg_dest_list_init(&conf->pkg_dest_list); - - nv_pair_list_init(&conf->arch_list); - - conf->restrict_to_default_dest = 0; - conf->default_dest = NULL; - - if (args->conf_file) { - struct stat stat_buf; - err = stat(args->conf_file, &stat_buf); - if (err == 0) - if (opkg_conf_parse_file(conf, args->conf_file, - &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) { - /* Memory leakage from opkg_conf_parse-file */ - return -1; - } - } - - opkg_conf_override_string(&conf->offline_root, args->offline_root); - offline_root = conf->offline_root; - - if (conf->offline_root) - sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", conf->offline_root); - else { - char *conf_file_dir = getenv("OPKG_CONF_DIR"); - if (conf_file_dir == NULL) - conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR; - sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir); - } - memset(&globbuf, 0, sizeof(globbuf)); - err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf); - free (etc_opkg_conf_pattern); - if (!err) { - int i; - for (i = 0; i < globbuf.gl_pathc; i++) { - if (globbuf.gl_pathv[i]) - if (args->conf_file && - !strcmp(args->conf_file, globbuf.gl_pathv[i])) - continue; - if ( opkg_conf_parse_file(conf, globbuf.gl_pathv[i], - &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) { - /* Memory leakage from opkg_conf_parse-file */ - return -1; - } - if (offline_root != conf->offline_root) { - opkg_message(conf, OPKG_ERROR, - "Config file %s, within an offline " - "root contains option offline_root.\n", - globbuf.gl_pathv[i]); - return -1; - } - } - } - globfree(&globbuf); - - opkg_conf_override_string(&conf->offline_root_path, - args->offline_root_path); - opkg_conf_override_string(&conf->offline_root_pre_script_cmd, - args->offline_root_pre_script_cmd); - opkg_conf_override_string(&conf->offline_root_post_script_cmd, - args->offline_root_post_script_cmd); - - opkg_conf_override_string(&conf->cache, args->cache); - opkg_conf_override_string(&conf->tmp_dir, args->tmp_dir); - - /* check for lock file */ - if (conf->offline_root) - sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX); - else - sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX); - - err = conf->lock_fd = creat (lock_file, S_IRUSR | S_IWUSR | S_IRGRP); - if (err != -1) - err = lockf (conf->lock_fd, F_TLOCK, 0); - errno_copy = errno; - - if (err) { - opkg_message (conf, OPKG_ERROR, "Could not lock %s: %s\n", - lock_file, strerror(errno_copy)); - free(lock_file); - return -1; - } - free(lock_file); - - if (conf->tmp_dir) - tmp_dir_base = conf->tmp_dir; - else - tmp_dir_base = getenv("TMPDIR"); - sprintf_alloc(&tmp2, "%s/%s", - tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE, - OPKG_CONF_TMP_DIR_SUFFIX); - if (conf->tmp_dir) - free(conf->tmp_dir); - conf->tmp_dir = mkdtemp(tmp2); - if (conf->tmp_dir == NULL) { - opkg_message(conf, OPKG_ERROR, - "%s: Creating temp dir %s failed: %s\n", - __FUNCTION__, tmp2, strerror(errno)); - return -1; - } - - pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN); - hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN); - hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN/16); - - if (conf->lists_dir == NULL) - conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR); - - if (conf->offline_root) { - char *tmp; - sprintf_alloc(&tmp, "%s/%s", conf->offline_root, conf->lists_dir); - free(conf->lists_dir); - conf->lists_dir = tmp; - } - - /* if no architectures were defined, then default all, noarch, and host architecture */ - if (nv_pair_list_empty(&conf->arch_list)) { - nv_pair_list_append(&conf->arch_list, "all", "1"); - nv_pair_list_append(&conf->arch_list, "noarch", "1"); - nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10"); - } - - /* Even if there is no conf file, we'll need at least one dest. */ - if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) { - nv_pair_list_append(&tmp_dest_nv_pair_list, - OPKG_CONF_DEFAULT_DEST_NAME, - OPKG_CONF_DEFAULT_DEST_ROOT_DIR); - } - - /* After parsing the file, set options from command-line, (so that - command-line arguments take precedence) */ - /* XXX: CLEANUP: The interaction between args.c and opkg_conf.c - really needs to be cleaned up. There is so much duplication - right now it is ridiculous. Maybe opkg_conf_t should just save - a pointer to args_t (which could then not be freed), rather - than duplicating every field here? */ - if (args->autoremove) { - conf->autoremove = 1; - } - if (args->force_depends) { - conf->force_depends = 1; - } - if (args->force_defaults) { - conf->force_defaults = 1; - } - if (args->force_maintainer) { - conf->force_maintainer = 1; - } - if (args->force_overwrite) { - conf->force_overwrite = 1; - } - if (args->force_downgrade) { - conf->force_downgrade = 1; - } - if (args->force_space) { - conf->force_space = 1; - } - if (args->force_reinstall) { - conf->force_reinstall = 1; - } - if (args->force_removal_of_dependent_packages) { - conf->force_removal_of_dependent_packages = 1; - } - if (args->force_removal_of_essential_packages) { - conf->force_removal_of_essential_packages = 1; - } - if (args->nodeps) { - conf->nodeps = 1; - } - if (args->noaction) { - conf->noaction = 1; - } - if (args->query_all) { - conf->query_all = 1; - } - if (args->verbosity != conf->verbosity) { - conf->verbosity = args->verbosity; - } - -/* Pigi: added a flag to disable the checking of structures if the command does not need to - read anything from there. -*/ - if (!(args->nocheckfordirorfile)) { - - if (!(args->noreadfeedsfile)) { - if (set_and_load_pkg_src_list(conf, &conf->pkg_src_list)) { - nv_pair_list_deinit(&tmp_dest_nv_pair_list); - return -1; - } - } - - /* Now that we have resolved conf->offline_root, we can commit to - the directory names for the dests and load in all the package - lists. */ - if (set_and_load_pkg_dest_list(conf, &tmp_dest_nv_pair_list)) { - nv_pair_list_deinit(&tmp_dest_nv_pair_list); - return -1; - } - - if (args->dest) { - err = opkg_conf_set_default_dest(conf, args->dest); - if (err) { - nv_pair_list_deinit(&tmp_dest_nv_pair_list); - return -1; - } - } - } - nv_pair_list_deinit(&tmp_dest_nv_pair_list); - - return 0; -} - -void opkg_conf_deinit(opkg_conf_t *conf) -{ - rm_r(conf->tmp_dir); - - free(conf->tmp_dir); - free(conf->lists_dir); - - pkg_src_list_deinit(&conf->pkg_src_list); - pkg_dest_list_deinit(&conf->pkg_dest_list); - nv_pair_list_deinit(&conf->arch_list); - - opkg_conf_free_string(&conf->cache); - - opkg_conf_free_string(&conf->ftp_proxy); - opkg_conf_free_string(&conf->http_proxy); - opkg_conf_free_string(&conf->no_proxy); - - opkg_conf_free_string(&conf->offline_root); - opkg_conf_free_string(&conf->offline_root_path); - opkg_conf_free_string(&conf->offline_root_pre_script_cmd); - opkg_conf_free_string(&conf->offline_root_post_script_cmd); - - opkg_conf_free_string(&conf->proxy_passwd); - opkg_conf_free_string(&conf->proxy_user); - -#if defined(HAVE_OPENSSL) - opkg_conf_free_string(&conf->signature_ca_file); - opkg_conf_free_string(&conf->signature_ca_path); -#endif - -#if defined(HAVE_SSLCURL) - opkg_conf_free_string(&conf->ssl_engine); - opkg_conf_free_string(&conf->ssl_cert); - opkg_conf_free_string(&conf->ssl_cert_type); - opkg_conf_free_string(&conf->ssl_key); - opkg_conf_free_string(&conf->ssl_key_type); - opkg_conf_free_string(&conf->ssl_key_passwd); - opkg_conf_free_string(&conf->ssl_ca_file); - opkg_conf_free_string(&conf->ssl_ca_path); -#endif - - if (conf->verbosity >= OPKG_DEBUG) { - hash_print_stats(&conf->pkg_hash); - hash_print_stats(&conf->file_hash); - hash_print_stats(&conf->obs_file_hash); - } - - if (&conf->pkg_hash) - pkg_hash_deinit(&conf->pkg_hash); - if (&conf->file_hash) - hash_table_deinit(&conf->file_hash); - if (&conf->obs_file_hash) - hash_table_deinit(&conf->obs_file_hash); - - /* lockf maybe defined with warn_unused_result */ - if(lockf(conf->lock_fd, F_ULOCK, 0) != 0){ - opkg_message(conf, OPKG_DEBUG, "%s: unlock failed: %s\n", - __FUNCTION__, - strerror(errno)); - } - close(conf->lock_fd); -} - -static int opkg_conf_set_default_dest(opkg_conf_t *conf, - const char *default_dest_name) +static int +opkg_conf_set_default_dest(const char *default_dest_name) { pkg_dest_list_elt_t *iter; pkg_dest_t *dest; @@ -425,13 +98,13 @@ static int opkg_conf_set_default_dest(opkg_conf_t *conf, } } - fprintf(stderr, "ERROR: Unknown dest name: `%s'\n", default_dest_name); + opkg_msg(ERROR, "Unknown dest name: `%s'.\n", default_dest_name); return 1; } static int -set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list) +set_and_load_pkg_src_list(pkg_src_list_t *pkg_src_list) { pkg_src_list_elt_t *iter; pkg_src_t *src; @@ -448,7 +121,7 @@ set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list) src->name); if (file_exists(list_file)) { - if (pkg_hash_add_from_file(conf, list_file, src, NULL, 0)) { + if (pkg_hash_add_from_file(list_file, src, NULL, 0)) { free(list_file); return -1; } @@ -460,7 +133,7 @@ set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_list) } static int -set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list) +set_and_load_pkg_dest_list(nv_pair_list_t *nv_pair_list) { nv_pair_list_elt_t *iter; nv_pair_t *nv_pair; @@ -484,7 +157,7 @@ set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list) conf->default_dest = dest; } if (file_exists(dest->status_file_name)) { - if (pkg_hash_add_from_file(conf, dest->status_file_name, + if (pkg_hash_add_from_file(dest->status_file_name, NULL, dest, 1)) return -1; } @@ -493,38 +166,87 @@ set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list) return 0; } -static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, +static int +opkg_conf_set_option(const char *name, const char *value) +{ + int i = 0; + while (options[i].name) { + if (strcmp(options[i].name, name) == 0) { + switch (options[i].type) { + case OPKG_OPT_TYPE_BOOL: + if (*(int *)options[i].value) { + opkg_msg(ERROR, "Duplicate boolean option %s, " + "leaving this option on.\n", name); + return 0; + } + *((int * const)options[i].value) = 1; + return 0; + case OPKG_OPT_TYPE_INT: + if (value) { + if (*(int *)options[i].value) { + opkg_msg(ERROR, "Duplicate option %s, " + "using first seen value \"%d\".\n", + name, *((int *)options[i].value)); + return 0; + } + *((int * const)options[i].value) = atoi(value); + return 0; + } else { + opkg_msg(ERROR, "Option %s needs an argument\n", + name); + return -1; + } + case OPKG_OPT_TYPE_STRING: + if (value) { + if (*(char **)options[i].value) { + opkg_msg(ERROR, "Duplicate option %s, " + "using first seen value \"%s\".\n", + name, *((char **)options[i].value)); + return 0; + } + *((char ** const)options[i].value) = xstrdup(value); + return 0; + } else { + opkg_msg(ERROR, "Option %s needs an argument\n", + name); + return -1; + } + } + } + i++; + } + + opkg_msg(ERROR, "Unrecognized option: %s=%s\n", name, value); + return -1; +} + +static int +opkg_conf_parse_file(const char *filename, pkg_src_list_t *pkg_src_list, nv_pair_list_t *tmp_dest_nv_pair_list) { int err; - opkg_option_t * options; FILE *file; regex_t valid_line_re, comment_re; #define regmatch_size 12 regmatch_t regmatch[regmatch_size]; - opkg_init_options_array(conf, &options); - file = fopen(filename, "r"); if (file == NULL) { - fprintf(stderr, "%s: failed to open %s: %s\n", - __FUNCTION__, filename, strerror(errno)); - free(options); + opkg_perror(ERROR, "Failed to open %s", filename); return -1; } - opkg_message(conf, OPKG_NOTICE, "loading conf file %s\n", filename); + + opkg_msg(INFO, "Loading conf file %s.\n", filename); err = xregcomp(&comment_re, "^[[:space:]]*(#.*|[[:space:]]*)$", REG_EXTENDED); if (err) { - free(options); return -1; } err = xregcomp(&valid_line_re, "^[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))[[:space:]]*(\"([^\"]*)\"|([^[:space:]]*))([[:space:]]+([^[:space:]]+))?[[:space:]]*$", REG_EXTENDED); if (err) { - free(options); return -1; } @@ -544,7 +266,7 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, } if (regexec(&valid_line_re, line, regmatch_size, regmatch, 0) == REG_NOMATCH) { - fprintf(stderr, "%s:%d: Ignoring invalid line: `%s'\n", + opkg_msg(ERROR, "%s:%d: Ignoring invalid line: `%s'\n", filename, line_num, line); goto NEXT_LINE; } @@ -584,36 +306,36 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, pkg_dest_list_init. (We do a similar thing with tmp_src_nv_pair_list for sake of symmetry.) */ if (strcmp(type, "option") == 0) { - opkg_conf_set_option(options, name, value); + opkg_conf_set_option(name, value); } else if (strcmp(type, "src") == 0) { if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) { pkg_src_list_append (pkg_src_list, name, value, extra, 0); } else { - opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n", - name, value); + opkg_msg(ERROR, "Duplicate src declaration (%s %s). " + "Skipping.\n", name, value); } } else if (strcmp(type, "src/gz") == 0) { if (!nv_pair_list_find((nv_pair_list_t*) pkg_src_list, name)) { pkg_src_list_append (pkg_src_list, name, value, extra, 1); } else { - opkg_message(conf, OPKG_ERROR, "ERROR: duplicate src declaration. Skipping:\n\t src %s %s\n", - name, value); + opkg_msg(ERROR, "Duplicate src declaration (%s %s). " + "Skipping.\n", name, value); } } else if (strcmp(type, "dest") == 0) { nv_pair_list_append(tmp_dest_nv_pair_list, name, value); } else if (strcmp(type, "lists_dir") == 0) { conf->lists_dir = xstrdup(value); } else if (strcmp(type, "arch") == 0) { - opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value); + opkg_msg(INFO, "Supported arch %s priority (%s)\n", name, value); if (!value) { - opkg_message(conf, OPKG_NOTICE, "defaulting architecture %s priority to 10\n", name); + opkg_msg(NOTICE, "No priority given for architecture %s," + "defaulting to 10\n", name); value = xstrdup("10"); } nv_pair_list_append(&conf->arch_list, name, value); } else { - fprintf(stderr, "WARNING: Ignoring unknown configuration " + opkg_msg(ERROR, "Ignoring unknown configuration " "parameter: %s %s %s\n", type, name, value); - free(options); return -1; } @@ -627,7 +349,6 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, free(line); } - free(options); regfree(&comment_re); regfree(&valid_line_re); fclose(file); @@ -635,45 +356,8 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, return 0; } -static int opkg_conf_set_option(const opkg_option_t *options, - const char *name, const char *value) -{ - int i = 0; - while (options[i].name) { - if (strcmp(options[i].name, name) == 0) { - switch (options[i].type) { - case OPKG_OPT_TYPE_BOOL: - *((int *)options[i].value) = 1; - return 0; - case OPKG_OPT_TYPE_INT: - if (value) { - *((int *)options[i].value) = atoi(value); - return 0; - } else { - printf("%s: Option %s need an argument\n", - __FUNCTION__, name); - return EINVAL; - } - case OPKG_OPT_TYPE_STRING: - if (value) { - *((char **)options[i].value) = xstrdup(value); - return 0; - } else { - printf("%s: Option %s need an argument\n", - __FUNCTION__, name); - return EINVAL; - } - } - } - i++; - } - - fprintf(stderr, "%s: Unrecognized option: %s=%s\n", - __FUNCTION__, name, value); - return EINVAL; -} - -int opkg_conf_write_status_files(opkg_conf_t *conf) +int +opkg_conf_write_status_files(void) { pkg_dest_list_elt_t *iter; pkg_dest_t *dest; @@ -689,14 +373,14 @@ int opkg_conf_write_status_files(opkg_conf_t *conf) dest->status_fp = fopen(dest->status_file_name, "w"); if (dest->status_fp == NULL) { - fprintf(stderr, "%s: Can't open status file: %s: %s\n", - __FUNCTION__, dest->status_file_name, strerror(errno)); + opkg_perror(ERROR, "Can't open status file %s", + dest->status_file_name); ret = -1; } } all = pkg_vec_alloc(); - pkg_hash_fetch_available(&conf->pkg_hash, all); + pkg_hash_fetch_available(all); for(i = 0; i < all->len; i++) { pkg = all->pkgs[i]; @@ -708,9 +392,8 @@ int opkg_conf_write_status_files(opkg_conf_t *conf) continue; } if (pkg->dest == NULL) { - fprintf(stderr, "%s: ERROR: Can't write status for " - "package %s since it has a NULL dest\n", - __FUNCTION__, pkg->name); + opkg_msg(ERROR, "Internal error: package %s has a NULL dest\n", + pkg->name); continue; } if (pkg->dest->status_fp) @@ -728,9 +411,210 @@ int opkg_conf_write_status_files(opkg_conf_t *conf) } -char *root_filename_alloc(opkg_conf_t *conf, char *filename) +char * +root_filename_alloc(char *filename) +{ + char *root_filename; + sprintf_alloc(&root_filename, "%s%s", + (conf->offline_root ? conf->offline_root : ""), filename); + return root_filename; +} + +int +opkg_conf_init(const args_t *args) { - char *root_filename; - sprintf_alloc(&root_filename, "%s%s", (conf->offline_root ? conf->offline_root : ""), filename); - return root_filename; + int err; + char *tmp_dir_base, *tmp2; + nv_pair_list_t tmp_dest_nv_pair_list; + char *lock_file = NULL; + glob_t globbuf; + char *etc_opkg_conf_pattern; + + conf->restrict_to_default_dest = 0; + conf->default_dest = NULL; +#if defined(HAVE_PATHFINDER) + conf->check_x509_path = 1; +#endif + + pkg_src_list_init(&conf->pkg_src_list); + + nv_pair_list_init(&tmp_dest_nv_pair_list); + pkg_dest_list_init(&conf->pkg_dest_list); + + nv_pair_list_init(&conf->arch_list); + + if (args->conf_file) { + struct stat stat_buf; + err = stat(args->conf_file, &stat_buf); + if (err == 0) + if (opkg_conf_parse_file(args->conf_file, + &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) { + /* Memory leakage from opkg_conf_parse-file */ + return -1; + } + } + + if (conf->offline_root) + sprintf_alloc(&etc_opkg_conf_pattern, "%s/etc/opkg/*.conf", conf->offline_root); + else { + const char *conf_file_dir = getenv("OPKG_CONF_DIR"); + if (conf_file_dir == NULL) + conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR; + sprintf_alloc(&etc_opkg_conf_pattern, "%s/*.conf", conf_file_dir); + } + memset(&globbuf, 0, sizeof(globbuf)); + err = glob(etc_opkg_conf_pattern, 0, NULL, &globbuf); + free (etc_opkg_conf_pattern); + if (!err) { + int i; + for (i = 0; i < globbuf.gl_pathc; i++) { + if (globbuf.gl_pathv[i]) + if (args->conf_file && + !strcmp(args->conf_file, globbuf.gl_pathv[i])) + continue; + if ( opkg_conf_parse_file(globbuf.gl_pathv[i], + &conf->pkg_src_list, &tmp_dest_nv_pair_list)<0) { + /* Memory leakage from opkg_conf_parse-file */ + return -1; + } + } + } + globfree(&globbuf); + + /* check for lock file */ + if (conf->offline_root) + sprintf_alloc (&lock_file, "%s/%s/lock", conf->offline_root, OPKG_STATE_DIR_PREFIX); + else + sprintf_alloc (&lock_file, "%s/lock", OPKG_STATE_DIR_PREFIX); + + if (creat(lock_file, S_IRUSR | S_IWUSR | S_IRGRP) == -1) { + opkg_perror(ERROR, "Could not create lock file %s", lock_file); + free(lock_file); + return -1; + } + + if (lockf(lock_fd, F_TLOCK, (off_t)0) == -1) { + opkg_perror(ERROR, "Could not lock %s", lock_file); + free(lock_file); + return -1; + } + + free(lock_file); + + if (conf->tmp_dir) + tmp_dir_base = conf->tmp_dir; + else + tmp_dir_base = getenv("TMPDIR"); + sprintf_alloc(&tmp2, "%s/%s", + tmp_dir_base ? tmp_dir_base : OPKG_CONF_DEFAULT_TMP_DIR_BASE, + OPKG_CONF_TMP_DIR_SUFFIX); + if (conf->tmp_dir) + free(conf->tmp_dir); + conf->tmp_dir = mkdtemp(tmp2); + if (conf->tmp_dir == NULL) { + opkg_perror(ERROR, "Creating temp dir %s failed", tmp2); + return -1; + } + + pkg_hash_init(); + hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN); + hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN/16); + + if (conf->lists_dir == NULL) + conf->lists_dir = xstrdup(OPKG_CONF_LISTS_DIR); + + if (conf->offline_root) { + char *tmp; + sprintf_alloc(&tmp, "%s/%s", conf->offline_root, conf->lists_dir); + free(conf->lists_dir); + conf->lists_dir = tmp; + } + + /* if no architectures were defined, then default all, noarch, and host architecture */ + if (nv_pair_list_empty(&conf->arch_list)) { + nv_pair_list_append(&conf->arch_list, "all", "1"); + nv_pair_list_append(&conf->arch_list, "noarch", "1"); + nv_pair_list_append(&conf->arch_list, HOST_CPU_STR, "10"); + } + + /* Even if there is no conf file, we'll need at least one dest. */ + if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) { + nv_pair_list_append(&tmp_dest_nv_pair_list, + OPKG_CONF_DEFAULT_DEST_NAME, + OPKG_CONF_DEFAULT_DEST_ROOT_DIR); + } + + if (!(args->nocheckfordirorfile)) { + + if (!(args->noreadfeedsfile)) { + if (set_and_load_pkg_src_list(&conf->pkg_src_list)) { + nv_pair_list_deinit(&tmp_dest_nv_pair_list); + return -1; + } + } + + /* Now that we have resolved conf->offline_root, we can commit to + the directory names for the dests and load in all the package + lists. */ + if (set_and_load_pkg_dest_list(&tmp_dest_nv_pair_list)) { + nv_pair_list_deinit(&tmp_dest_nv_pair_list); + return -1; + } + + if (args->dest) { + err = opkg_conf_set_default_dest(args->dest); + if (err) { + nv_pair_list_deinit(&tmp_dest_nv_pair_list); + return -1; + } + } + } + nv_pair_list_deinit(&tmp_dest_nv_pair_list); + + return 0; +} + +void +opkg_conf_deinit(void) +{ + int i; + char **tmp; + + rm_r(conf->tmp_dir); + + free(conf->lists_dir); + + pkg_src_list_deinit(&conf->pkg_src_list); + pkg_dest_list_deinit(&conf->pkg_dest_list); + nv_pair_list_deinit(&conf->arch_list); + + for (i=0; options[i].name; i++) { + if (options[i].type == OPKG_OPT_TYPE_STRING) { + tmp = (char **)options[i].value; + if (*tmp) { + free(*tmp); + *tmp = NULL; + } + } + } + + if (conf->verbosity >= DEBUG) { + hash_print_stats(&conf->pkg_hash); + hash_print_stats(&conf->file_hash); + hash_print_stats(&conf->obs_file_hash); + } + + if (&conf->pkg_hash) + pkg_hash_deinit(); + if (&conf->file_hash) + hash_table_deinit(&conf->file_hash); + if (&conf->obs_file_hash) + hash_table_deinit(&conf->obs_file_hash); + + /* lockf may be defined with warn_unused_result */ + if (lockf(lock_fd, F_ULOCK, (off_t)0) != 0) { + opkg_perror(ERROR, "unlock failed"); + } + + close(lock_fd); } diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h index fc14e09..a268bba 100644 --- a/libopkg/opkg_conf.h +++ b/libopkg/opkg_conf.h @@ -19,6 +19,7 @@ #define OPKG_CONF_H typedef struct opkg_conf opkg_conf_t; +extern opkg_conf_t *conf; #include "hash_table.h" #include "args.h" @@ -40,7 +41,6 @@ typedef struct opkg_conf opkg_conf_t; struct opkg_conf { - int lock_fd; /* file descriptor for the lock file */ pkg_src_list_t pkg_src_list; pkg_dest_list_t pkg_dest_list; nv_pair_list_t arch_list; @@ -51,6 +51,8 @@ struct opkg_conf char *tmp_dir; char *lists_dir; + uint pfm; /* package field mask */ + /* options */ int autoremove; int force_depends; @@ -65,9 +67,6 @@ struct opkg_conf int check_signature; int nodeps; /* do not follow dependences */ char *offline_root; - char *offline_root_path; - char *offline_root_pre_script_cmd; - char *offline_root_post_script_cmd; int query_all; int verbosity; int noaction; @@ -118,16 +117,13 @@ typedef struct opkg_option opkg_option_t; struct opkg_option { const char *name; const opkg_option_type_t type; - const void *value; + void * const value; }; -int opkg_conf_init(opkg_conf_t *conf, const args_t *args); -void opkg_conf_deinit(opkg_conf_t *conf); - -int opkg_conf_write_status_files(opkg_conf_t *conf); -char *root_filename_alloc(opkg_conf_t *conf, char *filename); - +int opkg_conf_init(const args_t *args); +void opkg_conf_deinit(void); -void opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options); +int opkg_conf_write_status_files(void); +char *root_filename_alloc(char *filename); #endif diff --git a/libopkg/opkg_configure.c b/libopkg/opkg_configure.c index 2c22bfc..154d3e6 100644 --- a/libopkg/opkg_configure.c +++ b/libopkg/opkg_configure.c @@ -21,7 +21,8 @@ #include "opkg_message.h" #include "opkg_cmd.h" -int opkg_configure(opkg_conf_t *conf, pkg_t *pkg) +int +opkg_configure(pkg_t *pkg) { int err; @@ -31,9 +32,9 @@ int opkg_configure(opkg_conf_t *conf, pkg_t *pkg) /* DPKG_INCOMPATIBILITY: dpkg actually includes a version number to this script call */ - err = pkg_run_script(conf, pkg, "postinst", "configure"); + err = pkg_run_script(pkg, "postinst", "configure"); if (err) { - opkg_message(conf, OPKG_ERROR, "ERROR: %s.postinst returned %d\n", pkg->name, err); + opkg_msg(ERROR, "%s.postinst returned %d.\n", pkg->name, err); return err; } diff --git a/libopkg/opkg_configure.h b/libopkg/opkg_configure.h index e3178b8..25236ae 100644 --- a/libopkg/opkg_configure.h +++ b/libopkg/opkg_configure.h @@ -20,6 +20,6 @@ #include "opkg_conf.h" -int opkg_configure(opkg_conf_t *opkg_conf, pkg_t *pkg); +int opkg_configure(pkg_t *pkg); #endif diff --git a/libopkg/opkg_download.c b/libopkg/opkg_download.c index c4b2f0c..7062766 100644 --- a/libopkg/opkg_download.c +++ b/libopkg/opkg_download.c @@ -58,7 +58,7 @@ static void openssl_init(void); #endif #ifdef HAVE_OPENSSL -static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath); +static X509_STORE *setup_verify(char *CAfile, char *CApath); #endif #ifdef HAVE_CURL @@ -67,7 +67,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath); * each time */ static CURL *curl = NULL; -static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data); +static CURL *opkg_curl_init(curl_progress_func cb, void *data); #endif static int @@ -76,8 +76,9 @@ str_starts_with(const char *str, const char *prefix) return (strncmp(str, prefix, strlen(prefix)) == 0); } -int opkg_download(opkg_conf_t *conf, const char *src, - const char *dest_file_name, curl_progress_func cb, void *data) +int +opkg_download(const char *src, const char *dest_file_name, + curl_progress_func cb, void *data) { int err = 0; @@ -85,37 +86,39 @@ int opkg_download(opkg_conf_t *conf, const char *src, char *src_base = basename(src_basec); char *tmp_file_location; - opkg_message(conf,OPKG_NOTICE,"Downloading %s\n", src); + free(src_basec); + + opkg_msg(NOTICE,"Downloading %s.\n", src); if (str_starts_with(src, "file:")) { const char *file_src = src + 5; - opkg_message(conf,OPKG_INFO,"Copying %s to %s...", file_src, dest_file_name); + opkg_msg(INFO, "Copying %s to %s...", file_src, dest_file_name); err = file_copy(file_src, dest_file_name); - opkg_message(conf,OPKG_INFO,"Done\n"); - free(src_basec); + opkg_msg(INFO, "Done.\n"); return err; } sprintf_alloc(&tmp_file_location, "%s/%s", conf->tmp_dir, src_base); err = unlink(tmp_file_location); if (err && errno != ENOENT) { - opkg_message(conf,OPKG_ERROR, "%s: ERROR: failed to unlink %s: %s\n", - __FUNCTION__, tmp_file_location, strerror(errno)); + opkg_perror(ERROR, "Failed to unlink %s\n", tmp_file_location); free(tmp_file_location); - free(src_basec); return -1; } if (conf->http_proxy) { - opkg_message(conf,OPKG_DEBUG,"Setting environment variable: http_proxy = %s\n", conf->http_proxy); + opkg_msg(DEBUG, "Setting environment variable: http_proxy = %s.\n", + conf->http_proxy); setenv("http_proxy", conf->http_proxy, 1); } if (conf->ftp_proxy) { - opkg_message(conf,OPKG_DEBUG,"Setting environment variable: ftp_proxy = %s\n", conf->ftp_proxy); + opkg_msg(DEBUG, "Setting environment variable: ftp_proxy = %s.\n", + conf->ftp_proxy); setenv("ftp_proxy", conf->ftp_proxy, 1); } if (conf->no_proxy) { - opkg_message(conf,OPKG_DEBUG,"Setting environment variable: no_proxy = %s\n", conf->no_proxy); + opkg_msg(DEBUG,"Setting environment variable: no_proxy = %s.\n", + conf->no_proxy); setenv("no_proxy", conf->no_proxy, 1); } @@ -123,7 +126,7 @@ int opkg_download(opkg_conf_t *conf, const char *src, CURLcode res; FILE * file = fopen (tmp_file_location, "w"); - curl = opkg_curl_init (conf, cb, data); + curl = opkg_curl_init (cb, data); if (curl) { curl_easy_setopt (curl, CURLOPT_URL, src); @@ -135,9 +138,9 @@ int opkg_download(opkg_conf_t *conf, const char *src, { long error_code; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &error_code); - opkg_message(conf, OPKG_ERROR, "Failed to download %s. \nerror detail: %s\n", src, curl_easy_strerror(res)); + opkg_msg(ERROR, "Failed to download %s: %s.\n", + src, curl_easy_strerror(res)); free(tmp_file_location); - free(src_basec); return res; } @@ -145,7 +148,6 @@ int opkg_download(opkg_conf_t *conf, const char *src, else { free(tmp_file_location); - free(src_basec); return -1; } #else @@ -167,9 +169,8 @@ int opkg_download(opkg_conf_t *conf, const char *src, res = xsystem(argv); if (res) { - opkg_message(conf, OPKG_ERROR, "Failed to download %s, error %d\n", src, res); + opkg_msg(ERROR, "Failed to download %s, wget returned %d.\n", src, res); free(tmp_file_location); - free(src_basec); return res; } } @@ -178,20 +179,20 @@ int opkg_download(opkg_conf_t *conf, const char *src, err = file_move(tmp_file_location, dest_file_name); free(tmp_file_location); - free(src_basec); return err; } -static int opkg_download_cache(opkg_conf_t *conf, const char *src, - const char *dest_file_name, curl_progress_func cb, void *data) +static int +opkg_download_cache(const char *src, const char *dest_file_name, + curl_progress_func cb, void *data) { char *cache_name = xstrdup(src); char *cache_location, *p; int err = 0; if (!conf->cache || str_starts_with(src, "file:")) { - err = opkg_download(conf, src, dest_file_name, cb, data); + err = opkg_download(src, dest_file_name, cb, data); goto out1; } @@ -201,9 +202,9 @@ static int opkg_download_cache(opkg_conf_t *conf, const char *src, sprintf_alloc(&cache_location, "%s/%s", conf->cache, cache_name); if (file_exists(cache_location)) - opkg_message(conf, OPKG_NOTICE, "Copying %s\n", cache_location); + opkg_msg(NOTICE, "Copying %s.\n", cache_location); else { - err = opkg_download(conf, src, cache_location, cb, data); + err = opkg_download(src, cache_location, cb, data); if (err) { (void) unlink(cache_location); goto out2; @@ -220,19 +221,21 @@ out1: return err; } -int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir) +int +opkg_download_pkg(pkg_t *pkg, const char *dir) { int err; char *url; char *stripped_filename; if (pkg->src == NULL) { - opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) is not available from any configured src.\n", - pkg->name, pkg->parent->name); + opkg_msg(ERROR, "Package %s is not available from any configured src.\n", + pkg->name); return -1; } if (pkg->filename == NULL) { - opkg_message(conf,OPKG_ERROR, "ERROR: Package %s (parent %s) does not have a valid filename field.\n",pkg->name, pkg->parent->name); + opkg_msg(ERROR, "Package %s does not have a valid filename field.\n", + pkg->name); return -1; } @@ -249,7 +252,7 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir) sprintf_alloc(&pkg->local_filename, "%s/%s", dir, stripped_filename); - err = opkg_download_cache(conf, url, pkg->local_filename, NULL, NULL); + err = opkg_download_cache(url, pkg->local_filename, NULL, NULL); free(url); return err; @@ -258,7 +261,8 @@ int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir) /* * Downloads file from url, installs in package database, return package name. */ -int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep) +int +opkg_prepare_url_for_install(const char *url, char **namep) { int err = 0; pkg_t *pkg; @@ -272,11 +276,11 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name char *file_base = basename(file_basec); sprintf_alloc(&tmp_file, "%s/%s", conf->tmp_dir, file_base); - err = opkg_download(conf, url, tmp_file, NULL, NULL); + err = opkg_download(url, tmp_file, NULL, NULL); if (err) return err; - err = pkg_init_from_file(conf, pkg, tmp_file); + err = pkg_init_from_file(pkg, tmp_file); if (err) return err; @@ -287,10 +291,11 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name || strcmp(&url[strlen(url) - 4], IPKG_PKG_EXTENSION) == 0 || strcmp(&url[strlen(url) - 4], DPKG_PKG_EXTENSION) == 0) { - err = pkg_init_from_file(conf, pkg, url); + err = pkg_init_from_file(pkg, url); if (err) return err; - opkg_message(conf, OPKG_DEBUG2, "Package %s provided by hand (%s).\n", pkg->name,pkg->local_filename); + opkg_msg(DEBUG2, "Package %s provided by hand (%s).\n", + pkg->name, pkg->local_filename); pkg->provided_by_hand = 1; } else { @@ -299,15 +304,10 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name return 0; } - if (!pkg->architecture) { - opkg_message(conf, OPKG_ERROR, "Package %s has no Architecture defined.\n", pkg->name); - return -1; - } - pkg->dest = conf->default_dest; pkg->state_want = SW_INSTALL; pkg->state_flag |= SF_PREFER; - pkg = hash_insert_pkg(&conf->pkg_hash, pkg, 1,conf); + hash_insert_pkg(pkg, 1); if (namep) { *namep = pkg->name; @@ -316,7 +316,7 @@ int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **name } int -opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file) +opkg_verify_file (char *text_file, char *sig_file) { #if defined HAVE_GPGME if (conf->check_signature == 0 ) @@ -324,7 +324,7 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file) int status = -1; gpgme_ctx_t ctx; gpgme_data_t sig, text, key; - gpgme_error_t err = -1; + gpgme_error_t err; gpgme_verify_result_t result; gpgme_signature_t s; char *trusted_path = NULL; @@ -397,31 +397,29 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file) openssl_init(); // Set-up the key store - if(!(store = setup_verify(conf, conf->signature_ca_file, conf->signature_ca_path))){ - opkg_message(conf, OPKG_ERROR, - "Can't open CA certificates\n"); + if(!(store = setup_verify(conf->signature_ca_file, conf->signature_ca_path))){ + opkg_msg(ERROR, "Can't open CA certificates.\n"); goto verify_file_end; } // Open a BIO to read the sig file if (!(in = BIO_new_file(sig_file, "rb"))){ - opkg_message(conf, OPKG_ERROR, - "Can't open signature file %s\n", sig_file); + opkg_msg(ERROR, "Can't open signature file %s.\n", sig_file); goto verify_file_end; } // Read the PKCS7 block contained in the sig file p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL); if(!p7){ - opkg_message(conf, OPKG_ERROR, - "Can't read signature file (Corrupted ?)\n"); + opkg_msg(ERROR, "Can't read signature file %s (Corrupted ?).\n", + sig_file); goto verify_file_end; } #if defined(HAVE_PATHFINDER) if(conf->check_x509_path){ if(!pkcs7_pathfinder_verify_signers(p7)){ - opkg_message(conf, OPKG_ERROR, "pkcs7_pathfinder_verify_signers: " - "Path verification failed\n"); + opkg_msg(ERROR, "pkcs7_pathfinder_verify_signers: " + "Path verification failed.\n"); goto verify_file_end; } } @@ -429,16 +427,14 @@ opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file) // Open the Package file to authenticate if (!(indata = BIO_new_file(text_file, "rb"))){ - opkg_message(conf, OPKG_ERROR, - "Can't open file %s\n", text_file); + opkg_msg(ERROR, "Can't open file %s.\n", text_file); goto verify_file_end; } // Let's verify the autenticity ! if (PKCS7_verify(p7, NULL, store, indata, NULL, PKCS7_BINARY) != 1){ // Get Off My Lawn! - opkg_message(conf, OPKG_ERROR, - "Verification failure\n"); + opkg_msg(ERROR, "Verification failure.\n"); }else{ // Victory ! status = 0; @@ -477,7 +473,9 @@ static void openssl_init(void){ #if defined HAVE_OPENSSL -static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){ +static X509_STORE * +setup_verify(char *CAfile, char *CApath) +{ X509_STORE *store = NULL; X509_LOOKUP *lookup = NULL; @@ -496,8 +494,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){ if (CAfile) { if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) { // Invalid CA => Bye bye - opkg_message(conf, OPKG_ERROR, - "Error loading file %s\n", CAfile); + opkg_msg(ERROR, "Error loading file %s.\n", CAfile); goto end; } } else { @@ -512,8 +509,7 @@ static X509_STORE *setup_verify(opkg_conf_t *conf, char *CAfile, char *CApath){ if (CApath) { if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) { - opkg_message(conf, OPKG_ERROR, - "Error loading directory %s\n", CApath); + opkg_msg(ERROR, "Error loading directory %s.\n", CApath); goto end; } } else { @@ -541,7 +537,9 @@ void opkg_curl_cleanup(void){ } } -static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data){ +static CURL * +opkg_curl_init(curl_progress_func cb, void *data) +{ if(curl == NULL){ curl = curl_easy_init(); @@ -553,7 +551,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data /* use crypto engine */ if (curl_easy_setopt(curl, CURLOPT_SSLENGINE, conf->ssl_engine) != CURLE_OK){ - opkg_message(conf, OPKG_ERROR, "can't set crypto engine: '%s'\n", + opkg_msg(ERROR, "Can't set crypto engine '%s'.\n", conf->ssl_engine); opkg_curl_cleanup(); @@ -561,7 +559,8 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data } /* set the crypto engine as default */ if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT, 1L) != CURLE_OK){ - opkg_message(conf, OPKG_ERROR, "can't set crypto engine as default\n"); + opkg_msg(ERROR, "Can't set crypto engine '%s' as default.\n", + conf->ssl_engine); opkg_curl_cleanup(); return NULL; @@ -572,7 +571,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data if(conf->ssl_key_passwd){ if (curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, conf->ssl_key_passwd) != CURLE_OK) { - opkg_message(conf, OPKG_DEBUG, "Failed to set key password\n"); + opkg_msg(DEBUG, "Failed to set key password.\n"); } } @@ -580,7 +579,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data if(conf->ssl_cert_type){ if (curl_easy_setopt(curl, CURLOPT_SSLCERTTYPE, conf->ssl_cert_type) != CURLE_OK) { - opkg_message(conf, OPKG_DEBUG, "Failed to set certificate format\n"); + opkg_msg(DEBUG, "Failed to set certificate format.\n"); } } /* SSL cert name isn't mandatory */ @@ -592,13 +591,13 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data if(conf->ssl_key_type){ if (curl_easy_setopt(curl, CURLOPT_SSLKEYTYPE, conf->ssl_key_type) != CURLE_OK) { - opkg_message(conf, OPKG_DEBUG, "Failed to set key format\n"); + opkg_msg(DEBUG, "Failed to set key format.\n"); } } if(conf->ssl_key){ if (curl_easy_setopt(curl, CURLOPT_SSLKEY, conf->ssl_key) != CURLE_OK) { - opkg_message(conf, OPKG_DEBUG, "Failed to set key\n"); + opkg_msg(DEBUG, "Failed to set key.\n"); } } @@ -612,7 +611,7 @@ static CURL *opkg_curl_init(opkg_conf_t *conf, curl_progress_func cb, void *data #ifdef HAVE_PATHFINDER if(conf->check_x509_path){ if (curl_easy_setopt(curl, CURLOPT_SSL_CTX_FUNCTION, curl_ssl_ctx_function) != CURLE_OK){ - opkg_message(conf, OPKG_DEBUG, "Failed to set ssl path verification callback\n"); + opkg_msg(DEBUG, "Failed to set ssl path verification callback.\n"); }else{ curl_easy_setopt(curl, CURLOPT_SSL_CTX_DATA, NULL); } diff --git a/libopkg/opkg_download.h b/libopkg/opkg_download.h index 10347ca..d98a311 100644 --- a/libopkg/opkg_download.h +++ b/libopkg/opkg_download.h @@ -24,14 +24,14 @@ typedef void (*opkg_download_progress_callback)(int percent, char *url); typedef int (*curl_progress_func)(void *data, double t, double d, double ultotal, double ulnow); -int opkg_download(opkg_conf_t *conf, const char *src, const char *dest_file_name, curl_progress_func cb, void *data); -int opkg_download_pkg(opkg_conf_t *conf, pkg_t *pkg, const char *dir); +int opkg_download(const char *src, const char *dest_file_name, curl_progress_func cb, void *data); +int opkg_download_pkg(pkg_t *pkg, const char *dir); /* * Downloads file from url, installs in package database, return package name. */ -int opkg_prepare_url_for_install(opkg_conf_t *conf, const char *url, char **namep); +int opkg_prepare_url_for_install(const char *url, char **namep); -int opkg_verify_file (opkg_conf_t *conf, char *text_file, char *sig_file); +int opkg_verify_file (char *text_file, char *sig_file); #ifdef HAVE_CURL void opkg_curl_cleanup(void); #endif diff --git a/libopkg/opkg_error.h b/libopkg/opkg_error.h deleted file mode 100644 index c40e635..0000000 --- a/libopkg/opkg_error.h +++ /dev/null @@ -1,24 +0,0 @@ -/* opkg_error.h - the opkg package management system - - Copyright (C) 2008 OpenMoko Inc - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. -*/ - -#ifndef OPKG_ERROR_H -#define OPKG_ERROR_H - -struct errlist { - char * errmsg; - struct errlist * next; -} ; - -#endif /* OPKG_ERROR_H */ diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c index a01a378..94d6188 100644 --- a/libopkg/opkg_install.c +++ b/libopkg/opkg_install.c @@ -39,11 +39,10 @@ #include "sprintf_alloc.h" #include "file_util.h" #include "xsystem.h" -#include "user.h" #include "libbb/libbb.h" static int -satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg) +satisfy_dependencies_for(pkg_t *pkg) { int i, err; pkg_vec_t *depends = pkg_vec_alloc(); @@ -51,24 +50,22 @@ satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg) char **tmp, **unresolved = NULL; int ndepends; - ndepends = pkg_hash_fetch_unsatisfied_dependencies(conf, - pkg, depends, + ndepends = pkg_hash_fetch_unsatisfied_dependencies(pkg, depends, &unresolved); if (unresolved) { - opkg_message(conf, OPKG_ERROR, - "%s: Cannot satisfy the following dependencies for %s:\n\t", - conf->force_depends ? "Warning" : "ERROR", pkg->name); + opkg_msg(ERROR, "Cannot satisfy the following dependencies for %s:\n", + pkg->name); tmp = unresolved; while (*unresolved) { - opkg_message(conf, OPKG_ERROR, " %s", *unresolved); + opkg_msg(ERROR, "\t%s", *unresolved); free(*unresolved); unresolved++; } free(tmp); - opkg_message(conf, OPKG_ERROR, "\n"); + opkg_msg(ERROR, "\n"); if (! conf->force_depends) { - opkg_message(conf, OPKG_INFO, + opkg_msg(INFO, "This could mean that your package list is out of date or that the packages\n" "mentioned above do not yet exist (try 'opkg update'). To proceed in spite\n" "of this problem try again with the '-force-depends' option.\n"); @@ -98,8 +95,8 @@ satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg) it in, so check first. */ if ((dep->state_status != SS_INSTALLED) && (dep->state_status != SS_UNPACKED)) { - opkg_message(conf, OPKG_DEBUG2,"Function: %s calling opkg_install_pkg \n",__FUNCTION__); - err = opkg_install_pkg(conf, dep,0); + opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n"); + err = opkg_install_pkg(dep, 0); /* mark this package as having been automatically installed to * satisfy a dependancy */ dep->auto_installed = 1; @@ -116,30 +113,28 @@ satisfy_dependencies_for(opkg_conf_t *conf, pkg_t *pkg) } static int -check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg) +check_conflicts_for(pkg_t *pkg) { int i; pkg_vec_t *conflicts = NULL; - int level; - const char *prefix; + message_level_t level; + if (conf->force_depends) { - level = OPKG_NOTICE; - prefix = "Warning"; + level = NOTICE; } else { - level = OPKG_ERROR; - prefix = "ERROR"; + level = ERROR; } if (!conf->force_depends) - conflicts = (pkg_vec_t *)pkg_hash_fetch_conflicts(&conf->pkg_hash, pkg); + conflicts = pkg_hash_fetch_conflicts(pkg); if (conflicts) { - opkg_message(conf, level, - "%s: The following packages conflict with %s:\n\t", prefix, pkg->name); + opkg_msg(level, "The following packages conflict with %s:\n", + pkg->name); i = 0; while (i < conflicts->len) - opkg_message(conf, level, " %s", conflicts->pkgs[i++]->name); - opkg_message(conf, level, "\n"); + opkg_msg(level, "\t%s", conflicts->pkgs[i++]->name); + opkg_msg(level, "\n"); pkg_vec_free(conflicts); return -1; } @@ -147,12 +142,12 @@ check_conflicts_for(opkg_conf_t *conf, pkg_t *pkg) } static int -update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg) +update_file_ownership(pkg_t *new_pkg, pkg_t *old_pkg) { str_list_t *new_list, *old_list; str_list_elt_t *iter, *niter; - new_list = pkg_get_installed_files(conf, new_pkg); + new_list = pkg_get_installed_files(new_pkg); if (new_list == NULL) return -1; @@ -160,15 +155,15 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg) iter; iter = niter, niter = str_list_next(new_list, niter)) { char *new_file = (char *)iter->data; - pkg_t *owner = file_hash_get_file_owner(conf, new_file); + pkg_t *owner = file_hash_get_file_owner(new_file); if (!new_file) - opkg_message(conf, OPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name); + opkg_msg(ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name); if (!owner || (owner == old_pkg)) - file_hash_set_file_owner(conf, new_file, new_pkg); + file_hash_set_file_owner(new_file, new_pkg); } if (old_pkg) { - old_list = pkg_get_installed_files(conf, old_pkg); + old_list = pkg_get_installed_files(old_pkg); if (old_list == NULL) { pkg_free_installed_files(new_pkg); return -1; @@ -178,7 +173,7 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg) iter; iter = niter, niter = str_list_next(old_list, niter)) { char *old_file = (char *)iter->data; - pkg_t *owner = file_hash_get_file_owner(conf, old_file); + pkg_t *owner = file_hash_get_file_owner(old_file); if (owner == old_pkg) { /* obsolete */ hash_table_insert(&conf->obs_file_hash, old_file, old_pkg); @@ -191,41 +186,32 @@ update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_pkg) } static int -verify_pkg_installable(opkg_conf_t *conf, pkg_t *pkg) +verify_pkg_installable(pkg_t *pkg) { - /* XXX: FEATURE: Anything else needed here? Maybe a check on free space? */ - - /* sma 6.20.02: yup; here's the first bit */ - /* - * XXX: BUG easy for cworth - * 1) please point the call below to the correct current root destination - * 2) we need to resolve how to check the required space for a pending pkg, - * my diddling with the .opk file size below isn't going to cut it. - * 3) return a proper error code instead of 1 - */ - int comp_size, blocks_available; - char *root_dir; - - if (!conf->force_space && pkg->installed_size != NULL) { - root_dir = pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir; - blocks_available = get_available_blocks(root_dir); - - comp_size = strtoul(pkg->installed_size, NULL, 0); - /* round up a blocks count without doing fancy-but-slow casting jazz */ - comp_size = (int)((comp_size + 1023) / 1024); - - if (comp_size >= blocks_available) { - opkg_message(conf, OPKG_ERROR, - "Only have %d available blocks on filesystem %s, pkg %s needs %d\n", - blocks_available, root_dir, pkg->name, comp_size); - return ENOSPC; - } - } + unsigned long kbs_available, pkg_size_kbs; + char *root_dir; + + if (conf->force_space || pkg->installed_size == 0) + return 0; + + root_dir = pkg->dest ? pkg->dest->root_dir : + conf->default_dest->root_dir; + kbs_available = get_available_kbytes(root_dir); + + pkg_size_kbs = (pkg->installed_size + 1023)/1024; + + if (pkg_size_kbs >= kbs_available) { + opkg_msg(ERROR, "Only have %dkb available on filesystem %s, " + "pkg %s needs %d\n", + kbs_available, root_dir, pkg->name, pkg_size_kbs); + return -1; + } + return 0; } static int -unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg) +unpack_pkg_control_files(pkg_t *pkg) { int err; char *conffiles_file_name; @@ -236,9 +222,8 @@ unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg) pkg->tmp_unpack_dir = mkdtemp(pkg->tmp_unpack_dir); if (pkg->tmp_unpack_dir == NULL) { - opkg_message(conf, OPKG_ERROR, - "%s: Failed to create temporary directory '%s': %s\n", - __FUNCTION__, pkg->tmp_unpack_dir, strerror(errno)); + opkg_perror(ERROR, "Failed to create temporary directory '%s'", + pkg->tmp_unpack_dir); return -1; } @@ -265,8 +250,7 @@ unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg) conffiles_file = fopen(conffiles_file_name, "r"); if (conffiles_file == NULL) { - fprintf(stderr, "%s: failed to open %s: %s\n", - __FUNCTION__, conffiles_file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open %s", conffiles_file_name); free(conffiles_file_name); return -1; } @@ -311,7 +295,7 @@ unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg) * which are no longer a dependency in the new (upgraded) pkg. */ static int -pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +pkg_remove_orphan_dependent(pkg_t *pkg, pkg_t *old_pkg) { int i, j, k, l, found; int n_deps; @@ -357,7 +341,7 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) /* * old_pkg has a dependency that pkg does not. */ - p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, + p = pkg_hash_fetch_installed_by_name( cd0->possibilities[j]->pkg->name); if (!p) @@ -366,13 +350,11 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) if (!p->auto_installed) continue; - n_deps = pkg_has_installed_dependents(conf, NULL, p, - &dependents); + n_deps = pkg_has_installed_dependents(p, &dependents); n_deps--; /* don't count old_pkg */ if (n_deps == 0) { - opkg_message (conf, OPKG_NOTICE, - "%s was autoinstalled and is " + opkg_msg(NOTICE, "%s was autoinstalled and is " "now orphaned, removing.\n", p->name); @@ -380,10 +362,9 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) * which we need to ignore during removal. */ p->state_flag |= SF_REPLACE; - opkg_remove_pkg(conf, p, 0); + opkg_remove_pkg(p, 0); } else - opkg_message(conf, OPKG_INFO, - "%s was autoinstalled and is " + opkg_msg(INFO, "%s was autoinstalled and is " "still required by %d " "installed packages.\n", p->name, n_deps); @@ -396,7 +377,7 @@ pkg_remove_orphan_dependent(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) /* returns number of installed replacees */ static int -pkg_get_installed_replacees(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_replacees) +pkg_get_installed_replacees(pkg_t *pkg, pkg_vec_t *installed_replacees) { abstract_pkg_t **replaces = pkg->replaces; int replaces_count = pkg->replaces_count; @@ -419,7 +400,7 @@ pkg_get_installed_replacees(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *installed_ } static int -pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees) +pkg_remove_installed_replacees(pkg_vec_t *replacees) { int i; int replaces_count = replacees->len; @@ -427,7 +408,7 @@ pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees) pkg_t *replacee = replacees->pkgs[i]; int err; replacee->state_flag |= SF_REPLACE; /* flag it so remove won't complain */ - err = opkg_remove_pkg(conf, replacee,0); + err = opkg_remove_pkg(replacee, 0); if (err) return err; } @@ -436,15 +417,15 @@ pkg_remove_installed_replacees(opkg_conf_t *conf, pkg_vec_t *replacees) /* to unwind the removal: make sure they are installed */ static int -pkg_remove_installed_replacees_unwind(opkg_conf_t *conf, pkg_vec_t *replacees) +pkg_remove_installed_replacees_unwind(pkg_vec_t *replacees) { int i, err; int replaces_count = replacees->len; for (i = 0; i < replaces_count; i++) { pkg_t *replacee = replacees->pkgs[i]; if (replacee->state_status != SS_INSTALLED) { - opkg_message(conf, OPKG_DEBUG2,"Function: %s calling opkg_install_pkg \n",__FUNCTION__); - err = opkg_install_pkg(conf, replacee,0); + opkg_msg(DEBUG2, "Calling opkg_install_pkg.\n"); + err = opkg_install_pkg(replacee, 0); if (err) return err; } @@ -454,7 +435,7 @@ pkg_remove_installed_replacees_unwind(opkg_conf_t *conf, pkg_vec_t *replacees) /* compares versions of pkg and old_pkg, returns 0 if OK to proceed with installation of pkg, 1 otherwise */ static int -opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int message) +opkg_install_check_downgrade(pkg_t *pkg, pkg_t *old_pkg, int message) { if (old_pkg) { char message_out[15]; @@ -472,26 +453,24 @@ opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int } if (cmp > 0) { - opkg_message(conf, OPKG_NOTICE, + opkg_msg(NOTICE, "Not downgrading package %s on %s from %s to %s.\n", old_pkg->name, old_pkg->dest->name, old_version, new_version); rc = 1; } else if (cmp < 0) { - opkg_message(conf, OPKG_NOTICE, - "%s%s on %s from %s to %s...\n", + opkg_msg(NOTICE, "%s%s on %s from %s to %s...\n", message_out, pkg->name, old_pkg->dest->name, old_version, new_version); pkg->dest = old_pkg->dest; rc = 0; } else /* cmp == 0 */ { if (conf->force_reinstall) { - opkg_message(conf, OPKG_NOTICE, - "Reinstalling %s (%s) on %s...\n", + opkg_msg(NOTICE, "Reinstalling %s (%s) on %s...\n", pkg->name, new_version, old_pkg->dest->name); pkg->dest = old_pkg->dest; rc = 0; } else { - opkg_message(conf, OPKG_NOTICE, - "Not installing %s (%s) on %s -- already installed.\n", + opkg_msg(NOTICE, "%s (%s) already install on %s." + " Not reinstalling.\n", pkg->name, new_version, old_pkg->dest->name); rc = 1; } @@ -508,8 +487,7 @@ opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int strncpy( message_out,"Installing ",strlen("Installing ") ); char *version = pkg_version_str_alloc(pkg); - opkg_message(conf, OPKG_NOTICE, - "%s%s (%s) to %s...\n", message_out, + opkg_msg(NOTICE, "%s%s (%s) to %s...\n", message_out, pkg->name, version, pkg->dest->name); free(version); return 0; @@ -518,7 +496,7 @@ opkg_install_check_downgrade(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg, int static int -prerm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +prerm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg) { /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't do yet. Do we care? @@ -534,7 +512,7 @@ prerm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -prerm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +prerm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg) { /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't do yet. Do we care? @@ -544,7 +522,7 @@ prerm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -prerm_deconfigure_conflictors(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors) +prerm_deconfigure_conflictors(pkg_t *pkg, pkg_vec_t *conflictors) { /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't do yet. Do we care? @@ -571,7 +549,7 @@ prerm_deconfigure_conflictors(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflict } static int -prerm_deconfigure_conflictors_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *conflictors) +prerm_deconfigure_conflictors_unwind(pkg_t *pkg, pkg_vec_t *conflictors) { /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't do yet. Do we care? (See prerm_deconfigure_conflictors for @@ -580,7 +558,7 @@ prerm_deconfigure_conflictors_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_vec_t *c } static int -preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +preinst_configure(pkg_t *pkg, pkg_t *old_pkg) { int err; char *preinst_args; @@ -597,11 +575,10 @@ preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) preinst_args = xstrdup("install"); } - err = pkg_run_script(conf, pkg, "preinst", preinst_args); + err = pkg_run_script(pkg, "preinst", preinst_args); if (err) { - opkg_message(conf, OPKG_ERROR, - "Aborting installation of %s\n", pkg->name); - return 1; + opkg_msg(ERROR, "Aborting installation of %s.\n", pkg->name); + return -1; } free(preinst_args); @@ -610,7 +587,7 @@ preinst_configure(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -preinst_configure_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +preinst_configure_unwind(pkg_t *pkg, pkg_t *old_pkg) { /* DPKG_INCOMPATIBILITY: dpkg does the following error unwind, should we? @@ -633,7 +610,7 @@ backup_filename_alloc(const char *file_name) static int -backup_make_backup(opkg_conf_t *conf, const char *file_name) +backup_make_backup(const char *file_name) { int err; char *backup; @@ -641,9 +618,8 @@ backup_make_backup(opkg_conf_t *conf, const char *file_name) backup = backup_filename_alloc(file_name); err = file_copy(file_name, backup); if (err) { - opkg_message(conf, OPKG_ERROR, - "%s: Failed to copy %s to %s\n", - __FUNCTION__, file_name, backup); + opkg_msg(ERROR, "Failed to copy %s to %s\n", + file_name, backup); } free(backup); @@ -679,7 +655,7 @@ backup_remove(const char *file_name) } static int -backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +backup_modified_conffiles(pkg_t *pkg, pkg_t *old_pkg) { int err; conffile_list_elt_t *iter; @@ -693,11 +669,11 @@ backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) char *cf_name; cf = iter->data; - cf_name = root_filename_alloc(conf, cf->name); + cf_name = root_filename_alloc(cf->name); /* Don't worry if the conffile is just plain gone */ - if (file_exists(cf_name) && conffile_has_been_modified(conf, cf)) { - err = backup_make_backup(conf, cf_name); + if (file_exists(cf_name) && conffile_has_been_modified(cf)) { + err = backup_make_backup(cf_name); if (err) { return err; } @@ -710,14 +686,14 @@ backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) { char *cf_name; cf = (conffile_t *)iter->data; - cf_name = root_filename_alloc(conf, cf->name); + cf_name = root_filename_alloc(cf->name); /* Ignore if this was a conffile in old_pkg as well */ if (pkg_get_conffile(old_pkg, cf->name)) { continue; } if (file_exists(cf_name) && (! backup_exists_for(cf_name))) { - err = backup_make_backup(conf, cf_name); + err = backup_make_backup(cf_name); if (err) { return err; } @@ -729,7 +705,7 @@ backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -backup_modified_conffiles_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +backup_modified_conffiles_unwind(pkg_t *pkg, pkg_t *old_pkg) { conffile_list_elt_t *iter; @@ -748,7 +724,7 @@ backup_modified_conffiles_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) static int -check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +check_data_file_clashes(pkg_t *pkg, pkg_t *old_pkg) { /* DPKG_INCOMPATIBILITY: opkg takes a slightly different approach than dpkg at this @@ -768,7 +744,7 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) int clashes = 0; - files_list = pkg_get_installed_files(conf, pkg); + files_list = pkg_get_installed_files(pkg); if (files_list == NULL) return -1; @@ -777,12 +753,11 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) iter = niter, niter = str_list_next(files_list, iter)) { char *root_filename; char *filename = (char *) iter->data; - root_filename = root_filename_alloc(conf, filename); + root_filename = root_filename_alloc(filename); if (file_exists(root_filename) && (! file_is_dir(root_filename))) { pkg_t *owner; pkg_t *obs; - /* Pre-existing conffiles are OK */ - /* @@@@ should have way to check that it is a conffile -Jamey */ + if (backup_exists_for(root_filename)) { continue; } @@ -790,11 +765,11 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) /* Pre-existing files are OK if force-overwrite was asserted. */ if (conf->force_overwrite) { /* but we need to change who owns this file */ - file_hash_set_file_owner(conf, filename, pkg); + file_hash_set_file_owner(filename, pkg); continue; } - owner = file_hash_get_file_owner(conf, filename); + owner = file_hash_get_file_owner(filename); /* Pre-existing files are OK if owned by the pkg being upgraded. */ if (owner && old_pkg) { @@ -805,14 +780,17 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) /* Pre-existing files are OK if owned by a package replaced by new pkg. */ if (owner) { - opkg_message(conf, OPKG_DEBUG2, "Checking for replaces for %s in package %s\n", filename, owner->name); + opkg_msg(DEBUG2, "Checking replaces for %s in package %s\n", + filename, owner->name); if (pkg_replaces(pkg, owner)) { continue; } /* If the file that would be installed is owned by the same package, ( as per a reinstall or similar ) then it's ok to overwrite. */ if (strcmp(owner->name,pkg->name)==0){ - opkg_message(conf, OPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name); + opkg_msg(INFO, "Replacing pre-existing file %s" + " owned by package %s\n", + filename, owner->name); continue; } } @@ -820,21 +798,21 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) /* Pre-existing files are OK if they are obsolete */ obs = hash_table_get(&conf->obs_file_hash, filename); if (obs) { - opkg_message(conf, OPKG_INFO, "Pre-exiting file %s is obsolete. obs_pkg=%s\n", filename, obs->name); + opkg_msg(INFO, "Pre-exiting file %s is obsolete." + " obs_pkg=%s\n", + filename, obs->name); continue; } /* We have found a clash. */ - opkg_message(conf, OPKG_ERROR, - "Package %s wants to install file %s\n" + opkg_msg(ERROR, "Package %s wants to install file %s\n" "\tBut that file is already provided by package ", pkg->name, filename); if (owner) { - opkg_message(conf, OPKG_ERROR, - "%s\n", owner->name); + opkg_msg(ERROR, "%s\n", owner->name); } else { - opkg_message(conf, OPKG_ERROR, - "\nPlease move this file out of the way and try again.\n"); + opkg_msg(ERROR, "\n" + "Please move this file out of the way and try again.\n"); } clashes++; } @@ -849,7 +827,7 @@ check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) * XXX: This function sucks, as does the below comment. */ static int -check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +check_data_file_clashes_change(pkg_t *pkg, pkg_t *old_pkg) { /* Basically that's the worst hack I could do to be able to change ownership of file list, but, being that we have no way to unwind the mods, due to structure @@ -864,7 +842,7 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) char *root_filename = NULL; - files_list = pkg_get_installed_files(conf, pkg); + files_list = pkg_get_installed_files(pkg); if (files_list == NULL) return -1; @@ -876,15 +854,15 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) free(root_filename); root_filename = NULL; } - root_filename = root_filename_alloc(conf, filename); + root_filename = root_filename_alloc(filename); if (file_exists(root_filename) && (! file_is_dir(root_filename))) { pkg_t *owner; - owner = file_hash_get_file_owner(conf, filename); + owner = file_hash_get_file_owner(filename); if (conf->force_overwrite) { /* but we need to change who owns this file */ - file_hash_set_file_owner(conf, filename, pkg); + file_hash_set_file_owner(filename, pkg); continue; } @@ -894,8 +872,10 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) if (pkg_replaces(pkg, owner)) { /* It's now time to change the owner of that file. It has been "replaced" from the new "Replaces", then I need to inform lists file about that. */ - opkg_message(conf, OPKG_INFO, "Replacing pre-existing file %s owned by package %s\n", filename, owner->name); - file_hash_set_file_owner(conf, filename, pkg); + opkg_msg(INFO, "Replacing pre-existing file %s " + "owned by package %s\n", + filename, owner->name); + file_hash_set_file_owner(filename, pkg); continue; } } @@ -912,14 +892,14 @@ check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -check_data_file_clashes_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +check_data_file_clashes_unwind(pkg_t *pkg, pkg_t *old_pkg) { /* Nothing to do since check_data_file_clashes doesn't change state */ return 0; } static int -postrm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +postrm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg) { /* DPKG_INCOMPATIBILITY: dpkg does the following here, should we? 1. If the package is being upgraded, call @@ -932,7 +912,7 @@ postrm_upgrade_old_pkg(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -postrm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +postrm_upgrade_old_pkg_unwind(pkg_t *pkg, pkg_t *old_pkg) { /* DPKG_INCOMPATIBILITY: dpkg does some things here that we don't do yet. Do we care? @@ -942,7 +922,7 @@ postrm_upgrade_old_pkg_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +remove_obsolesced_files(pkg_t *pkg, pkg_t *old_pkg) { int err; str_list_t *old_files; @@ -951,11 +931,11 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) str_list_elt_t *nf; hash_table_t new_files_table; - old_files = pkg_get_installed_files(conf, old_pkg); + old_files = pkg_get_installed_files(old_pkg); if (old_files == NULL) return -1; - new_files = pkg_get_installed_files(conf, pkg); + new_files = pkg_get_installed_files(pkg); if (new_files == NULL) { pkg_free_installed_files(old_pkg); return -1; @@ -979,20 +959,18 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) if (file_is_dir(old)) { continue; } - owner = file_hash_get_file_owner(conf, old); + owner = file_hash_get_file_owner(old); if (owner != old_pkg) { /* in case obsolete file no longer belongs to old_pkg */ continue; } /* old file is obsolete */ - opkg_message(conf, OPKG_INFO, - " removing obsolete file %s\n", old); + opkg_msg(INFO, "Removing obsolete file %s.\n", old); if (!conf->noaction) { err = unlink(old); if (err) { - opkg_message(conf, OPKG_ERROR, " Warning: remove %s failed: %s\n", old, - strerror(errno)); + opkg_perror(ERROR, "unlinking %s failed", old); } } } @@ -1005,7 +983,7 @@ remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -install_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) +install_maintainer_scripts(pkg_t *pkg, pkg_t *old_pkg) { int ret; char *prefix; @@ -1019,7 +997,7 @@ install_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg) } static int -remove_disappeared(opkg_conf_t *conf, pkg_t *pkg) +remove_disappeared(pkg_t *pkg) { /* DPKG_INCOMPATIBILITY: This is a fairly sophisticated dpkg operation. Shall we @@ -1040,7 +1018,7 @@ remove_disappeared(opkg_conf_t *conf, pkg_t *pkg) } static int -install_data_files(opkg_conf_t *conf, pkg_t *pkg) +install_data_files(pkg_t *pkg) { int err; @@ -1049,29 +1027,21 @@ install_data_files(opkg_conf_t *conf, pkg_t *pkg) actually do the data file installation now. See comments in check_data_file_clashes() for more details. */ - opkg_message(conf, OPKG_INFO, - " extracting data files to %s\n", pkg->dest->root_dir); + opkg_msg(INFO, "Extracting data files to %s.\n", pkg->dest->root_dir); err = pkg_extract_data_files_to_dir(pkg, pkg->dest->root_dir); if (err) { return err; } - /* XXX: BUG or FEATURE : We are actually loosing the Essential flag, - so we can't save ourself from removing important packages - At this point we (should) have extracted the .control file, so it - would be a good idea to reload the data in it, and set the Essential - state in *pkg. From now on the Essential is back in status file and - we can protect again. - We should operate this way: - fopen the file ( pkg->dest->root_dir/pkg->name.control ) - check for "Essential" in it - set the value in pkg->essential. - This new routine could be useful also for every other flag - Pigi: 16/03/2004 */ - set_flags_from_control(conf, pkg) ; + /* The "Essential" control field may only be present in the control + * file and not in the Packages list. Ensure we capture it regardless. + * + * XXX: This should be fixed outside of opkg, in the Package list. + */ + set_flags_from_control(pkg) ; - opkg_message(conf, OPKG_DEBUG, " Calling pkg_write_filelist from %s\n", __FUNCTION__); - err = pkg_write_filelist(conf, pkg); + opkg_msg(DEBUG, "Calling pkg_write_filelist.\n"); + err = pkg_write_filelist(pkg); if (err) return err; @@ -1090,55 +1060,7 @@ install_data_files(opkg_conf_t *conf, pkg_t *pkg) } static int -user_prefers_old_conffile(const char *file_name, const char *backup) -{ - char *response; - const char *short_file_name; - - short_file_name = strrchr(file_name, '/'); - if (short_file_name) { - short_file_name++; - } else { - short_file_name = file_name; - } - - while (1) { - response = get_user_response(" Configuration file '%s'\n" - " ==> File on system created by you or by a script.\n" - " ==> File also in package provided by package maintainer.\n" - " What would you like to do about it ? Your options are:\n" - " Y or I : install the package maintainer's version\n" - " N or O : keep your currently-installed version\n" - " D : show the differences between the versions (if diff is installed)\n" - " The default action is to keep your current version.\n" - " *** %s (Y/I/N/O/D) [default=N] ? ", file_name, short_file_name); - - if (response == NULL) - return 1; - - if (strcmp(response, "y") == 0 - || strcmp(response, "i") == 0 - || strcmp(response, "yes") == 0) { - free(response); - return 0; - } - - if (strcmp(response, "d") == 0) { - const char *argv[] = {"diff", "-u", backup, file_name, NULL}; - xsystem(argv); - printf(" [Press ENTER to continue]\n"); - response = file_read_line_alloc(stdin); - free(response); - continue; - } - - free(response); - return 1; - } -} - -static int -resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg) +resolve_conffiles(pkg_t *pkg) { conffile_list_elt_t *iter; conffile_t *cf; @@ -1150,7 +1072,7 @@ resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg) for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) { char *root_filename; cf = (conffile_t *)iter->data; - root_filename = root_filename_alloc(conf, cf->name); + root_filename = root_filename_alloc(cf->name); /* Might need to initialize the md5sum for each conffile */ if (cf->value == NULL) { @@ -1164,17 +1086,24 @@ resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg) cf_backup = backup_filename_alloc(root_filename); - if (file_exists(cf_backup)) { /* Let's compute md5 to test if files are changed */ md5sum = file_md5sum_alloc(cf_backup); if (md5sum && cf->value && strcmp(cf->value,md5sum) != 0 ) { if (conf->force_maintainer) { - opkg_message(conf, OPKG_NOTICE, "Conffile %s using maintainer's setting.\n", cf_backup); - } else if (conf->force_defaults - || user_prefers_old_conffile(root_filename, cf_backup) ) { + opkg_msg(NOTICE, "Conffile %s using maintainer's setting.\n", + cf_backup); + } else { + char *new_conffile; + sprintf_alloc(&new_conffile, "%s-opkg", root_filename); + opkg_msg(NOTICE, "Existing conffile %s " + "is different from the conffile in the new package." + " The new conffile will be placed at %s.\n", + root_filename, new_conffile); + rename(root_filename, new_conffile); rename(cf_backup, root_filename); - } + free(new_conffile); + } } unlink(cf_backup); if (md5sum) @@ -1190,24 +1119,25 @@ resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg) int -opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name) +opkg_install_by_name(const char *pkg_name) { int cmp; pkg_t *old, *new; char *old_version, *new_version; - old = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg_name); + old = pkg_hash_fetch_installed_by_name(pkg_name); if (old) - opkg_message(conf, OPKG_DEBUG2, "Old versions from pkg_hash_fetch %s \n", old->version); + opkg_msg(DEBUG2, "Old versions from pkg_hash_fetch %s.\n", + old->version); - new = pkg_hash_fetch_best_installation_candidate_by_name(conf, pkg_name); + new = pkg_hash_fetch_best_installation_candidate_by_name(pkg_name); if (new == NULL) return -1; - opkg_message(conf, OPKG_DEBUG2, "Versions from pkg_hash_fetch in %s ", __FUNCTION__); + opkg_msg(DEBUG2, "Versions from pkg_hash_fetch:"); if ( old ) - opkg_message(conf, OPKG_DEBUG2, " old %s ", old->version); - opkg_message(conf, OPKG_DEBUG2, " new %s\n", new->version); + opkg_msg(DEBUG2, " old %s ", old->version); + opkg_msg(DEBUG2, " new %s\n", new->version); new->state_flag |= SF_USER; if (old) { @@ -1216,26 +1146,25 @@ opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name) cmp = pkg_compare_versions(old, new); if ( (conf->force_downgrade==1) && (cmp > 0) ){ /* We've been asked to allow downgrade and version is precedent */ - opkg_message(conf, OPKG_DEBUG, " Forcing downgrade \n"); + opkg_msg(DEBUG, "Forcing downgrade\n"); cmp = -1 ; /* then we force opkg to downgrade */ /* We need to use a value < 0 because in the 0 case we are asking to */ /* reinstall, and some check could fail asking the "force-reinstall" option */ } - opkg_message(conf, OPKG_DEBUG, - "Comparing visible versions of pkg %s:" + opkg_msg(DEBUG, "Comparing visible versions of pkg %s:" "\n\t%s is installed " "\n\t%s is available " "\n\t%d was comparison result\n", pkg_name, old_version, new_version, cmp); if (cmp == 0 && !conf->force_reinstall) { - opkg_message(conf, OPKG_NOTICE, + opkg_msg(NOTICE, "Package %s (%s) installed in %s is up to date.\n", old->name, old_version, old->dest->name); free(old_version); free(new_version); return 0; } else if (cmp > 0) { - opkg_message(conf, OPKG_NOTICE, + opkg_msg(NOTICE, "Not downgrading package %s on %s from %s to %s.\n", old->name, old->dest->name, old_version, new_version); free(old_version); @@ -1249,15 +1178,15 @@ opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name) free(new_version); } - opkg_message(conf, OPKG_DEBUG2,"%s: calling opkg_install_pkg \n",__FUNCTION__); - return opkg_install_pkg(conf, new,0); + opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n"); + return opkg_install_pkg(new, 0); } /** * @brief Really install a pkg_t */ int -opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) +opkg_install_pkg(pkg_t *pkg, int from_upgrade) { int err = 0; int message = 0; @@ -1274,26 +1203,19 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) if ( from_upgrade ) message = 1; /* Coming from an upgrade, and should change the output message */ - if (!pkg) { - opkg_message(conf, OPKG_ERROR, - "INTERNAL ERROR: null pkg passed to opkg_install_pkg\n"); - return -1; - } - - opkg_message(conf, OPKG_DEBUG2, "Function: %s calling pkg_arch_supported %s \n", __FUNCTION__, __FUNCTION__); + opkg_msg(DEBUG2, "Calling pkg_arch_supported.\n"); - if (!pkg_arch_supported(conf, pkg)) { - opkg_message(conf, OPKG_ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n", + if (!pkg_arch_supported(pkg)) { + opkg_msg(ERROR, "INTERNAL ERROR: architecture %s for pkg %s is unsupported.\n", pkg->architecture, pkg->name); return -1; } if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0 && conf->nodeps == 0) { - err = satisfy_dependencies_for(conf, pkg); + err = satisfy_dependencies_for(pkg); if (err) return -1; - opkg_message(conf, OPKG_NOTICE, - "Package %s is already installed in %s.\n", + opkg_msg(NOTICE, "Package %s is already installed on %s.\n", pkg->name, pkg->dest->name); return 0; } @@ -1302,9 +1224,9 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) pkg->dest = conf->default_dest; } - old_pkg = pkg_hash_fetch_installed_by_name(&conf->pkg_hash, pkg->name); + old_pkg = pkg_hash_fetch_installed_by_name(pkg->name); - err = opkg_install_check_downgrade(conf, pkg, old_pkg, message); + err = opkg_install_check_downgrade(pkg, old_pkg, message); if (err) return -1; @@ -1313,7 +1235,7 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependences */ } - err = check_conflicts_for(conf, pkg); + err = check_conflicts_for(pkg); if (err) return -1; @@ -1324,15 +1246,15 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) if (pkg->state_status == SS_INSTALLED && conf->force_reinstall == 0) return 0; - err = verify_pkg_installable(conf, pkg); + err = verify_pkg_installable(pkg); if (err) return -1; if (pkg->local_filename == NULL) { - err = opkg_download_pkg(conf, pkg, conf->tmp_dir); + err = opkg_download_pkg(pkg, conf->tmp_dir); if (err) { - opkg_message(conf, OPKG_ERROR, - "Failed to download %s. Perhaps you need to run 'opkg update'?\n", + opkg_msg(ERROR, "Failed to download %s. " + "Perhaps you need to run 'opkg update'?\n", pkg->name); return -1; } @@ -1354,14 +1276,15 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) if (file_exists (sig_file_name)) { - if (opkg_verify_file (conf, list_file_name, sig_file_name)){ - opkg_message(conf, OPKG_ERROR, "Failed to verify the signature of: %s\n", + if (opkg_verify_file (list_file_name, sig_file_name)){ + opkg_msg(ERROR, "Failed to verify the signature of %s.\n", list_file_name); return -1; } }else{ - opkg_message(conf, OPKG_ERROR, "Signature file is missing. " - "Perhaps you need to run 'opkg update'?\n"); + opkg_msg(ERROR, "Signature file is missing for %s. " + "Perhaps you need to run 'opkg update'?\n", + pkg->name); return -1; } @@ -1377,9 +1300,10 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) file_md5 = file_md5sum_alloc(pkg->local_filename); if (file_md5 && strcmp(file_md5, pkg->md5sum)) { - opkg_message(conf, OPKG_ERROR, - "Package %s md5sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n", - pkg->name); + opkg_msg(ERROR, "Package %s md5sum mismatch. " + "Either the opkg or the package index are corrupt. " + "Try 'opkg update'.\n", + pkg->name); free(file_md5); return -1; } @@ -1394,9 +1318,10 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) file_sha256 = file_sha256sum_alloc(pkg->local_filename); if (file_sha256 && strcmp(file_sha256, pkg->sha256sum)) { - opkg_message(conf, OPKG_ERROR, - "Package %s sha256sum mismatch. Either the opkg or the package index are corrupt. Try 'opkg update'.\n", - pkg->name); + opkg_msg(ERROR, "Package %s sha256sum mismatch. " + "Either the opkg or the package index are corrupt. " + "Try 'opkg update'.\n", + pkg->name); free(file_sha256); return -1; } @@ -1406,22 +1331,19 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) #endif if (pkg->tmp_unpack_dir == NULL) { - if (unpack_pkg_control_files(conf, pkg) == -1) { - opkg_message(conf, OPKG_ERROR, "Failed to unpack control" - " files from %s.\n", pkg->local_filename); + if (unpack_pkg_control_files(pkg) == -1) { + opkg_msg(ERROR, "Failed to unpack control files from %s.\n", + pkg->local_filename); return -1; } } - /* We should update the filelist here, so that upgrades of packages that split will not fail. -Jamey 27-MAR-03 */ -/* Pigi: check if it will pass from here when replacing. It seems to fail */ -/* That's rather strange that files don't change owner. Investigate !!!!!!*/ - err = update_file_ownership(conf, pkg, old_pkg); + err = update_file_ownership(pkg, old_pkg); if (err) return -1; if (conf->nodeps == 0) { - err = satisfy_dependencies_for(conf, pkg); + err = satisfy_dependencies_for(pkg); if (err) return -1; if (pkg->state_status == SS_UNPACKED) @@ -1430,7 +1352,7 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) } replacees = pkg_vec_alloc(); - pkg_get_installed_replacees(conf, pkg, replacees); + pkg_get_installed_replacees(pkg, replacees); /* this next section we do with SIGINT blocked to prevent inconsistency between opkg database and filesystem */ @@ -1442,36 +1364,36 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) pkg->state_flag |= SF_FILELIST_CHANGED; if (old_pkg) - pkg_remove_orphan_dependent(conf, pkg, old_pkg); + pkg_remove_orphan_dependent(pkg, old_pkg); /* XXX: BUG: we really should treat replacement more like an upgrade * Instead, we're going to remove the replacees */ - err = pkg_remove_installed_replacees(conf, replacees); + err = pkg_remove_installed_replacees(replacees); if (err) goto UNWIND_REMOVE_INSTALLED_REPLACEES; - err = prerm_upgrade_old_pkg(conf, pkg, old_pkg); + err = prerm_upgrade_old_pkg(pkg, old_pkg); if (err) goto UNWIND_PRERM_UPGRADE_OLD_PKG; - err = prerm_deconfigure_conflictors(conf, pkg, replacees); + err = prerm_deconfigure_conflictors(pkg, replacees); if (err) goto UNWIND_PRERM_DECONFIGURE_CONFLICTORS; - err = preinst_configure(conf, pkg, old_pkg); + err = preinst_configure(pkg, old_pkg); if (err) goto UNWIND_PREINST_CONFIGURE; - err = backup_modified_conffiles(conf, pkg, old_pkg); + err = backup_modified_conffiles(pkg, old_pkg); if (err) goto UNWIND_BACKUP_MODIFIED_CONFFILES; - err = check_data_file_clashes(conf, pkg, old_pkg); + err = check_data_file_clashes(pkg, old_pkg); if (err) goto UNWIND_CHECK_DATA_FILE_CLASHES; - err = postrm_upgrade_old_pkg(conf, pkg, old_pkg); + err = postrm_upgrade_old_pkg(pkg, old_pkg); if (err) goto UNWIND_POSTRM_UPGRADE_OLD_PKG; @@ -1483,62 +1405,60 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) old_pkg->state_want = SW_DEINSTALL; if (old_pkg->state_flag & SF_NOPRUNE) { - opkg_message(conf, OPKG_INFO, - " not removing obsolesced files because package marked noprune\n"); + opkg_msg(INFO, "Not removing obsolesced files because " + "package %s marked noprune.\n", + old_pkg->name); } else { - opkg_message(conf, OPKG_INFO, - " removing obsolesced files\n"); - if (remove_obsolesced_files(conf, pkg, old_pkg)) { - opkg_message(conf, OPKG_ERROR, "Failed to determine " + opkg_msg(INFO, "Removing obsolesced files for %s\n", + old_pkg->name); + if (remove_obsolesced_files(pkg, old_pkg)) { + opkg_msg(ERROR, "Failed to determine " "obsolete files from previously " "installed %s\n", old_pkg->name); } } /* removing files from old package, to avoid ghost files */ - remove_data_files_and_list(conf, old_pkg); - remove_maintainer_scripts(conf, old_pkg); + remove_data_files_and_list(old_pkg); + remove_maintainer_scripts(old_pkg); } - opkg_message(conf, OPKG_INFO, - " installing maintainer scripts\n"); - if (install_maintainer_scripts(conf, pkg, old_pkg)) { - opkg_message(conf, OPKG_ERROR, "Failed to extract maintainer" - " scripts for %s. Package debris may remain!\n", + opkg_msg(INFO, "Installing maintainer scripts.\n"); + if (install_maintainer_scripts(pkg, old_pkg)) { + opkg_msg(ERROR, "Failed to extract maintainer scripts for %s." + " Package debris may remain!\n", pkg->name); goto pkg_is_hosed; } /* the following just returns 0 */ - remove_disappeared(conf, pkg); + remove_disappeared(pkg); - opkg_message(conf, OPKG_INFO, - " installing data files\n"); + opkg_msg(INFO, "Installing data files for %s.\n", pkg->name); - if (install_data_files(conf, pkg)) { - opkg_message(conf, OPKG_ERROR, "Failed to extract data files " - "for %s. Package debris may remain!\n", + if (install_data_files(pkg)) { + opkg_msg(ERROR, "Failed to extract data files for %s. " + "Package debris may remain!\n", pkg->name); goto pkg_is_hosed; } - err = check_data_file_clashes_change(conf, pkg, old_pkg); + err = check_data_file_clashes_change(pkg, old_pkg); if (err) { - opkg_message(conf, OPKG_ERROR, - "check_data_file_clashes_change() failed for " + opkg_msg(ERROR, "check_data_file_clashes_change() failed for " "for files belonging to %s.\n", pkg->name); } - opkg_message(conf, OPKG_INFO, - " resolving conf files\n"); - resolve_conffiles(conf, pkg); + opkg_msg(INFO, "Resolving conf files for %s\n", pkg->name); + resolve_conffiles(pkg); pkg->state_status = SS_UNPACKED; old_state_flag = pkg->state_flag; pkg->state_flag &= ~SF_PREFER; - opkg_message(conf, OPKG_DEBUG, " pkg=%s old_state_flag=%x state_flag=%x\n", pkg->name, old_state_flag, pkg->state_flag); + opkg_msg(DEBUG, "pkg=%s old_state_flag=%x state_flag=%x\n", + pkg->name, old_state_flag, pkg->state_flag); if (old_pkg && !conf->force_reinstall) { old_pkg->state_status = SS_NOT_INSTALLED; @@ -1550,32 +1470,27 @@ opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) if (ab_pkg) ab_pkg->state_status = pkg->state_status; - opkg_message(conf, OPKG_INFO, "Done.\n"); - sigprocmask(SIG_UNBLOCK, &newset, &oldset); pkg_vec_free (replacees); return 0; UNWIND_POSTRM_UPGRADE_OLD_PKG: - postrm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); + postrm_upgrade_old_pkg_unwind(pkg, old_pkg); UNWIND_CHECK_DATA_FILE_CLASHES: - check_data_file_clashes_unwind(conf, pkg, old_pkg); + check_data_file_clashes_unwind(pkg, old_pkg); UNWIND_BACKUP_MODIFIED_CONFFILES: - backup_modified_conffiles_unwind(conf, pkg, old_pkg); + backup_modified_conffiles_unwind(pkg, old_pkg); UNWIND_PREINST_CONFIGURE: - preinst_configure_unwind(conf, pkg, old_pkg); + preinst_configure_unwind(pkg, old_pkg); UNWIND_PRERM_DECONFIGURE_CONFLICTORS: - prerm_deconfigure_conflictors_unwind(conf, pkg, replacees); + prerm_deconfigure_conflictors_unwind(pkg, replacees); UNWIND_PRERM_UPGRADE_OLD_PKG: - prerm_upgrade_old_pkg_unwind(conf, pkg, old_pkg); + prerm_upgrade_old_pkg_unwind(pkg, old_pkg); UNWIND_REMOVE_INSTALLED_REPLACEES: - pkg_remove_installed_replacees_unwind(conf, replacees); + pkg_remove_installed_replacees_unwind(replacees); pkg_is_hosed: - opkg_message(conf, OPKG_INFO, - "Failed.\n"); - sigprocmask(SIG_UNBLOCK, &newset, &oldset); pkg_vec_free (replacees); diff --git a/libopkg/opkg_install.h b/libopkg/opkg_install.h index 13d43d0..eaffff8 100644 --- a/libopkg/opkg_install.h +++ b/libopkg/opkg_install.h @@ -20,9 +20,8 @@ #include "pkg.h" #include "opkg_conf.h" -#include "opkg_error.h" -int opkg_install_by_name(opkg_conf_t *conf, const char *pkg_name); -int opkg_install_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrading); +int opkg_install_by_name(const char *pkg_name); +int opkg_install_pkg(pkg_t *pkg, int from_upgrading); #endif diff --git a/libopkg/opkg_message.c b/libopkg/opkg_message.c index 33a9c90..a21a1a2 100644 --- a/libopkg/opkg_message.c +++ b/libopkg/opkg_message.c @@ -1,5 +1,6 @@ /* opkg_message.c - the opkg package management system + Copyright (C) 2009 Ubiq Technologies Copyright (C) 2003 Daniele Nicolodi This program is free software; you can redistribute it and/or @@ -17,11 +18,63 @@ #include "includes.h" #include "opkg_conf.h" #include "opkg_message.h" -#include "opkg_error.h" -#include "opkg_utils.h" +#include "libbb/libbb.h" + +struct errlist { + char *errmsg; + struct errlist *next; +}; + +static struct errlist *error_list_head, *error_list_tail; + +static void +push_error_list(char *msg) +{ + struct errlist *e; + + e = xcalloc(1, sizeof(struct errlist)); + e->errmsg = xstrdup(msg); + e->next = NULL; + + if (error_list_head) { + error_list_tail->next = e; + error_list_tail = e; + } else { + error_list_head = error_list_tail = e; + } +} + +void +free_error_list(void) +{ + struct errlist *err, *err_tmp; + + err = error_list_head; + while (err != NULL) { + free(err->errmsg); + err_tmp = err; + err = err->next; + free(err_tmp); + } +} + +void +print_error_list(void) +{ + struct errlist *err = error_list_head; + + if (err) { + printf("Collected errors:\n"); + /* Here we print the errors collected and free the list */ + while (err != NULL) { + printf(" * %s", err->errmsg); + err = err->next; + } + } +} void -opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...) +opkg_message (message_level_t level, const char *fmt, ...) { va_list ap; @@ -30,7 +83,7 @@ opkg_message (opkg_conf_t * conf, message_level_t level, char *fmt, ...) va_start (ap, fmt); - if (level == OPKG_ERROR) { + if (level == ERROR) { char msg[256]; vsnprintf(msg, 256, fmt, ap); push_error_list(msg); diff --git a/libopkg/opkg_message.h b/libopkg/opkg_message.h index 2ca58d8..62a6b83 100644 --- a/libopkg/opkg_message.h +++ b/libopkg/opkg_message.h @@ -1,5 +1,6 @@ /* opkg_message.h - the opkg package management system + Copyright (C) 2009 Ubiq Technologies Copyright (C) 2003 Daniele Nicolodi This program is free software; you can redistribute it and/or @@ -16,16 +17,30 @@ #ifndef _OPKG_MESSAGE_H_ #define _OPKG_MESSAGE_H_ -#include "opkg_conf.h" +#include +#include typedef enum { - OPKG_ERROR, /* error conditions */ - OPKG_NOTICE, /* normal but significant condition */ - OPKG_INFO, /* informational message */ - OPKG_DEBUG, /* debug level message */ - OPKG_DEBUG2, /* more debug level message */ + ERROR, /* error conditions */ + NOTICE, /* normal but significant condition */ + INFO, /* informational message */ + DEBUG, /* debug level message */ + DEBUG2, /* more debug level message */ } message_level_t; -extern void opkg_message(opkg_conf_t *conf, message_level_t level, char *fmt, ...); +void free_error_list(void); +void print_error_list(void); +void opkg_message(message_level_t level, const char *fmt, ...); + +#define opkg_msg(l, fmt, args...) \ + do { \ + if (l == NOTICE) \ + opkg_message(l, fmt, ##args); \ + else \ + opkg_message(l, "%s: "fmt, __FUNCTION__, ##args); \ + } while (0) + +#define opkg_perror(l, fmt, args...) \ + opkg_msg(l, fmt": %s.\n", ##args, strerror(errno)) #endif /* _OPKG_MESSAGE_H_ */ diff --git a/libopkg/opkg_pathfinder.c b/libopkg/opkg_pathfinder.c index a53dd8e..71c8c11 100644 --- a/libopkg/opkg_pathfinder.c +++ b/libopkg/opkg_pathfinder.c @@ -56,7 +56,7 @@ static int pathfinder_verify_callback(X509_STORE_CTX *ctx, void *arg) int validated = pathfinder_dbus_verify(certdata_str, policy, 0, 0, &errmsg); if (!validated) - fprintf(stderr, "curlcb_pathfinder: Path verification failed: %s\n", errmsg); + opkg_msg(ERROR, "Path verification failed: %s.\n", errmsg); free(certdata_str); free(errmsg); diff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c index a2ef09c..b5045ea 100644 --- a/libopkg/opkg_remove.c +++ b/libopkg/opkg_remove.c @@ -21,7 +21,6 @@ #include #include "opkg_remove.h" -#include "opkg_error.h" #include "opkg_cmd.h" #include "file_util.h" @@ -33,11 +32,11 @@ * Every package implicitly provides itself. */ int -pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents) +pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents) { int nprovides = pkg->provides_count; abstract_pkg_t **provides = pkg->provides; - int n_installed_dependents = 0; + unsigned int n_installed_dependents = 0; int i; for (i = 0; i < nprovides; i++) { abstract_pkg_t *providee = provides[i]; @@ -82,7 +81,7 @@ pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg } static int -opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **dependents) +opkg_remove_dependent_pkgs(pkg_t *pkg, abstract_pkg_t **dependents) { int i; int a; @@ -91,8 +90,8 @@ opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **depe abstract_pkg_t * ab_pkg; if((ab_pkg = pkg->parent) == NULL){ - fprintf(stderr, "%s: unable to get dependent pkgs. pkg %s isn't in hash table\n", - __FUNCTION__, pkg->name); + opkg_msg(ERROR, "Internal error: pkg %s isn't in hash table\n", + pkg->name); return 0; } @@ -138,7 +137,7 @@ opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **depe int err=0; for (i = 0; i < dependent_pkgs->len; i++) { - err = opkg_remove_pkg(conf, dependent_pkgs->pkgs[i],0); + err = opkg_remove_pkg(dependent_pkgs->pkgs[i],0); if (err) { pkg_vec_free(dependent_pkgs); break; @@ -149,19 +148,19 @@ opkg_remove_dependent_pkgs (opkg_conf_t *conf, pkg_t *pkg, abstract_pkg_t **depe } static void -print_dependents_warning(opkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, abstract_pkg_t **dependents) +print_dependents_warning(pkg_t *pkg, abstract_pkg_t **dependents) { abstract_pkg_t *dep_ab_pkg; - opkg_message(conf, OPKG_ERROR, "Package %s is depended upon by packages:\n", pkg->name); + opkg_msg(ERROR, "Package %s is depended upon by packages:\n", pkg->name); while ((dep_ab_pkg = *dependents++) != NULL) { if (dep_ab_pkg->state_status == SS_INSTALLED) - opkg_message(conf, OPKG_ERROR, "\t%s\n", dep_ab_pkg->name); + opkg_msg(ERROR, "\t%s\n", dep_ab_pkg->name); } - opkg_message(conf, OPKG_ERROR, "These might cease to work if package %s is removed.\n\n", pkg->name); - opkg_message(conf, OPKG_ERROR, ""); - opkg_message(conf, OPKG_ERROR, "You can force removal of this package with --force-depends.\n"); - opkg_message(conf, OPKG_ERROR, "You can force removal of this package and its dependents\n"); - opkg_message(conf, OPKG_ERROR, "with --force-removal-of-dependent-packages\n"); + opkg_msg(ERROR, "These might cease to work if package %s is removed.\n\n", + pkg->name); + opkg_msg(ERROR, "Force removal of this package with --force-depends.\n"); + opkg_msg(ERROR, "Force removal of this package and its dependents\n"); + opkg_msg(ERROR, "with --force-removal-of-dependent-packages.\n"); } /* @@ -169,7 +168,7 @@ print_dependents_warning(opkg_conf_t *conf, abstract_pkg_t *abpkg, pkg_t *pkg, a * by the removal of pkg. */ static int -remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg) +remove_autoinstalled(pkg_t *pkg) { int i, j; int n_deps; @@ -187,7 +186,7 @@ remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg) if (cdep->type != DEPEND) continue; for (j=0; jpossibility_count; j++) { - p = pkg_hash_fetch_installed_by_name (&conf->pkg_hash, + p = pkg_hash_fetch_installed_by_name( cdep->possibilities[j]->pkg->name); /* If the package is not installed, this could have @@ -200,17 +199,14 @@ remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg) if (!p->auto_installed) continue; - n_deps = pkg_has_installed_dependents(conf, NULL, p, - &dependents); + n_deps = pkg_has_installed_dependents(p, &dependents); if (n_deps == 0) { - opkg_message(conf, OPKG_NOTICE, - "%s was autoinstalled and is " - "now orphaned, removing\n", + opkg_msg(NOTICE, "%s was autoinstalled and is " + "now orphaned, removing.\n", p->name); - opkg_remove_pkg(conf, p, 0); + opkg_remove_pkg(p, 0); } else - opkg_message(conf, OPKG_INFO, - "%s was autoinstalled and is " + opkg_msg(INFO, "%s was autoinstalled and is " "still required by %d " "installed packages.\n", p->name, n_deps); @@ -224,7 +220,7 @@ remove_autoinstalled(opkg_conf_t *conf, pkg_t *pkg) } int -opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) +opkg_remove_pkg(pkg_t *pkg, int from_upgrade) { int err; abstract_pkg_t *parent_pkg = NULL; @@ -235,11 +231,12 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) */ if (pkg->essential && !from_upgrade) { if (conf->force_removal_of_essential_packages) { - fprintf(stderr, "WARNING: Removing essential package %s under your coercion.\n" + opkg_msg(NOTICE, + "Removing essential package %s under your coercion.\n" "\tIf your system breaks, you get to keep both pieces\n", pkg->name); } else { - fprintf(stderr, "ERROR: Refusing to remove essential package %s.\n" + opkg_msg(NOTICE, "Refusing to remove essential package %s.\n" "\tRemoving an essential package may lead to an unusable system, but if\n" "\tyou enjoy that kind of pain, you can force opkg to proceed against\n" "\tits will with the option: --force-removal-of-essential-packages\n", @@ -259,7 +256,7 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) && !(pkg->state_flag & SF_REPLACE)) { abstract_pkg_t **dependents; int has_installed_dependents = - pkg_has_installed_dependents(conf, parent_pkg, pkg, &dependents); + pkg_has_installed_dependents(pkg, &dependents); if (has_installed_dependents) { /* @@ -268,13 +265,13 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) */ if (!conf->force_removal_of_dependent_packages) { - print_dependents_warning(conf, parent_pkg, pkg, dependents); + print_dependents_warning(pkg, dependents); free(dependents); return -1; } /* remove packages depending on this package - Karthik */ - err = opkg_remove_dependent_pkgs (conf, pkg, dependents); + err = opkg_remove_dependent_pkgs(pkg, dependents); if (err) { free(dependents); return err; @@ -285,26 +282,26 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) } if (from_upgrade == 0) { - opkg_message (conf, OPKG_NOTICE, - "Removing package %s from %s...\n", pkg->name, pkg->dest->name); + opkg_msg(NOTICE, "Removing package %s from %s...\n", + pkg->name, pkg->dest->name); } pkg->state_flag |= SF_FILELIST_CHANGED; pkg->state_want = SW_DEINSTALL; opkg_state_changed++; - pkg_run_script(conf, pkg, "prerm", "remove"); + pkg_run_script(pkg, "prerm", "remove"); /* DPKG_INCOMPATIBILITY: dpkg is slightly different here. It maintains an empty filelist rather than deleting it. That seems like a big pain, and I don't see that that should make a big difference, but for anyone who wants tighter compatibility, feel free to fix this. */ - remove_data_files_and_list(conf, pkg); + remove_data_files_and_list(pkg); - pkg_run_script(conf, pkg, "postrm", "remove"); + pkg_run_script(pkg, "postrm", "remove"); - remove_maintainer_scripts(conf, pkg); + remove_maintainer_scripts(pkg); pkg->state_status = SS_NOT_INSTALLED; if (parent_pkg) @@ -312,13 +309,13 @@ opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg, int from_upgrade) /* remove autoinstalled packages that are orphaned by the removal of this one */ if (conf->autoremove) - remove_autoinstalled (conf, pkg); + remove_autoinstalled(pkg); return 0; } void -remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg) +remove_data_files_and_list(pkg_t *pkg) { str_list_t installed_dirs; str_list_t *installed_files; @@ -329,9 +326,9 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg) pkg_t *owner; int rootdirlen = 0; - installed_files = pkg_get_installed_files(conf, pkg); + installed_files = pkg_get_installed_files(pkg); if (installed_files == NULL) { - opkg_message(conf, OPKG_ERROR, "Failed to determine installed " + opkg_msg(ERROR, "Failed to determine installed " "files for %s. None removed.\n", pkg->name); return; } @@ -352,16 +349,20 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg) conffile = pkg_get_conffile(pkg, file_name+rootdirlen); if (conffile) { - if (conffile_has_been_modified(conf, conffile)) { - opkg_message (conf, OPKG_NOTICE, - " not deleting modified conffile %s\n", file_name); + if (conffile_has_been_modified(conffile)) { + opkg_msg(NOTICE, "Not deleting modified conffile %s.\n", + file_name); continue; } } - opkg_message(conf, OPKG_INFO, " deleting %s (noaction=%d)\n", file_name, conf->noaction); - if (!conf->noaction) + if (!conf->noaction) { + opkg_msg(INFO, "Deleting %s.\n", file_name, conf->noaction); unlink(file_name); + } else + opkg_msg(INFO, "Not deleting %s. (noaction)\n", + file_name); + } /* Remove empty directories */ @@ -372,7 +373,7 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg) file_name = (char *)iter->data; if (rmdir(file_name) == 0) { - opkg_message(conf, OPKG_INFO, " deleting %s\n", file_name); + opkg_msg(INFO, "Deleting %s.\n", file_name); removed_a_dir = 1; str_list_remove(&installed_dirs, &iter); } @@ -381,13 +382,13 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg) } pkg_free_installed_files(pkg); - pkg_remove_installed_files_list(conf, pkg); + pkg_remove_installed_files_list(pkg); /* Don't print warning for dirs that are provided by other packages */ for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) { file_name = (char *)iter->data; - owner = file_hash_get_file_owner(conf, file_name); + owner = file_hash_get_file_owner(file_name); if (owner) { free(iter->data); iter->data = NULL; @@ -405,7 +406,7 @@ remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg) } void -remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg) +remove_maintainer_scripts(pkg_t *pkg) { int i, err; char *globpattern; @@ -423,8 +424,7 @@ remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg) return; for (i = 0; i < globbuf.gl_pathc; i++) { - opkg_message(conf, OPKG_INFO, "deleting %s\n", - globbuf.gl_pathv[i]); + opkg_msg(INFO, "Deleting %s.\n", globbuf.gl_pathv[i]); unlink(globbuf.gl_pathv[i]); } globfree(&globbuf); diff --git a/libopkg/opkg_remove.h b/libopkg/opkg_remove.h index 650d8bf..f0c45d2 100644 --- a/libopkg/opkg_remove.h +++ b/libopkg/opkg_remove.h @@ -21,10 +21,10 @@ #include "pkg.h" #include "opkg_conf.h" -int opkg_remove_pkg(opkg_conf_t *conf, pkg_t *pkg,int message); -int pkg_has_installed_dependents(opkg_conf_t *conf, abstract_pkg_t *parent_apkg, pkg_t *pkg, abstract_pkg_t *** pdependents); -void remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg); -void remove_maintainer_scripts(opkg_conf_t *conf, pkg_t *pkg); +int opkg_remove_pkg(pkg_t *pkg,int message); +int pkg_has_installed_dependents(pkg_t *pkg, abstract_pkg_t *** pdependents); +void remove_data_files_and_list(pkg_t *pkg); +void remove_maintainer_scripts(pkg_t *pkg); #endif diff --git a/libopkg/opkg_upgrade.c b/libopkg/opkg_upgrade.c index f0ae875..0d4833a 100644 --- a/libopkg/opkg_upgrade.c +++ b/libopkg/opkg_upgrade.c @@ -18,27 +18,26 @@ #include "includes.h" #include "opkg_install.h" +#include "opkg_upgrade.h" #include "opkg_message.h" int -opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old) +opkg_upgrade_pkg(pkg_t *old) { pkg_t *new; int cmp; char *old_version, *new_version; if (old->state_flag & SF_HOLD) { - opkg_message(conf, OPKG_NOTICE, - "Not upgrading package %s which is marked " - "hold (flags=%#x)\n", old->name, old->state_flag); + opkg_msg(NOTICE, "Not upgrading package %s which is marked " + "hold (flags=%#x).\n", old->name, old->state_flag); return 0; } - new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name); + new = pkg_hash_fetch_best_installation_candidate_by_name(old->name); if (new == NULL) { old_version = pkg_version_str_alloc(old); - opkg_message(conf, OPKG_NOTICE, - "Assuming locally installed package %s (%s) " + opkg_msg(NOTICE, "Assuming locally installed package %s (%s) " "is up to date.\n", old->name, old_version); free(old_version); return 0; @@ -48,22 +47,19 @@ opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old) new_version = pkg_version_str_alloc(new); cmp = pkg_compare_versions(old, new); - opkg_message(conf, OPKG_DEBUG, - "comparing visible versions of pkg %s:" + opkg_msg(DEBUG, "Comparing visible versions of pkg %s:" "\n\t%s is installed " "\n\t%s is available " "\n\t%d was comparison result\n", old->name, old_version, new_version, cmp); if (cmp == 0) { - opkg_message(conf, OPKG_INFO, - "Package %s (%s) installed in %s is up to date.\n", + opkg_msg(INFO, "Package %s (%s) installed in %s is up to date.\n", old->name, old_version, old->dest->name); free(old_version); free(new_version); return 0; } else if (cmp > 0) { - opkg_message(conf, OPKG_NOTICE, - "Not downgrading package %s on %s from %s to %s.\n", + opkg_msg(NOTICE, "Not downgrading package %s on %s from %s to %s.\n", old->name, old->dest->name, old_version, new_version); free(old_version); free(new_version); @@ -76,7 +72,7 @@ opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old) free(old_version); free(new_version); new->state_flag |= SF_USER; - return opkg_install_pkg(conf, new,1); + return opkg_install_pkg(new,1); } @@ -101,14 +97,14 @@ pkg_hash_check_installed_pkg_helper(const char *pkg_name, void *entry, } struct active_list * -prepare_upgrade_list(opkg_conf_t *conf) +prepare_upgrade_list(void) { struct active_list *head = active_list_head_new(); struct active_list *all = active_list_head_new(); struct active_list *node=NULL; /* ensure all data is valid */ - pkg_info_preinstall_check (conf); + pkg_info_preinstall_check(); hash_table_foreach(&conf->pkg_hash, pkg_hash_check_installed_pkg_helper, all); for (node=active_list_next(all,all); node; node = active_list_next(all, node)) { @@ -116,7 +112,7 @@ prepare_upgrade_list(opkg_conf_t *conf) int cmp; old = list_entry(node, pkg_t, list); - new = pkg_hash_fetch_best_installation_candidate_by_name(conf, old->name); + new = pkg_hash_fetch_best_installation_candidate_by_name(old->name); if (new == NULL) continue; diff --git a/libopkg/opkg_upgrade.h b/libopkg/opkg_upgrade.h index ac4952d..6545fa8 100644 --- a/libopkg/opkg_upgrade.h +++ b/libopkg/opkg_upgrade.h @@ -16,7 +16,7 @@ #define OPKG_UPGRADE_H #include "active_list.h" -int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old); -struct active_list * prepare_upgrade_list (opkg_conf_t *conf); +int opkg_upgrade_pkg(pkg_t *old); +struct active_list * prepare_upgrade_list (void); #endif diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c index 2bb7c2e..d39690e 100644 --- a/libopkg/opkg_utils.c +++ b/libopkg/opkg_utils.c @@ -18,7 +18,7 @@ #include "includes.h" #include #include -#include +#include #include "opkg_utils.h" #include "pkg.h" @@ -27,23 +27,25 @@ void print_pkg_status(pkg_t * pkg, FILE * file); -long unsigned int get_available_blocks(char * filesystem) +unsigned long +get_available_kbytes(char * filesystem) { - struct statfs sfs; + struct statvfs f; - if(statfs(filesystem, &sfs)){ - fprintf(stderr, "bad statfs\n"); + if (statvfs(filesystem, &f) == -1) { + opkg_perror(ERROR, "Failed to statvfs for %s", filesystem); return 0; } - /* fprintf(stderr, "reported fs type %x\n", sfs.f_type); */ - // Actually ((sfs.f_bavail * sfs.f_bsize) / 1024) + // Actually ((sfs.f_bavail * sfs.f_frsize) / 1024) // and here we try to avoid overflow. - if (sfs.f_bsize >= 1024) - return (sfs.f_bavail * (sfs.f_bsize / 1024)); - else if (sfs.f_bsize > 0) - return sfs.f_bavail / (1024 / sfs.f_bsize); - fprintf(stderr, "bad statfs f_bsize == 0\n"); + if (f.f_frsize >= 1024) + return (f.f_bavail * (f.f_frsize / 1024)); + else if (f.f_frsize > 0) + return f.f_bavail / (1024 / f.f_frsize); + + opkg_msg(ERROR, "Unknown block size for target filesystem.\n"); + return 0; } @@ -81,52 +83,3 @@ int line_is_blank(const char *line) } return 1; } - -static struct errlist *error_list_head, *error_list_tail; - -/* - * XXX: this function should not allocate memory as it may be called to - * print an error because we are out of memory. - */ -void push_error_list(char * msg) -{ - struct errlist *e; - - e = xcalloc(1, sizeof(struct errlist)); - e->errmsg = xstrdup(msg); - e->next = NULL; - - if (error_list_head) { - error_list_tail->next = e; - error_list_tail = e; - } else { - error_list_head = error_list_tail = e; - } -} - -void free_error_list(void) -{ - struct errlist *err, *err_tmp; - - err = error_list_head; - while (err != NULL) { - free(err->errmsg); - err_tmp = err; - err = err->next; - free(err_tmp); - } -} - -void print_error_list (void) -{ - struct errlist *err = error_list_head; - - if (err) { - printf ("Collected errors:\n"); - /* Here we print the errors collected and free the list */ - while (err != NULL) { - printf (" * %s", err->errmsg); - err = err->next; - } - } -} diff --git a/libopkg/opkg_utils.h b/libopkg/opkg_utils.h index 7cb0693..ecdd3f5 100644 --- a/libopkg/opkg_utils.h +++ b/libopkg/opkg_utils.h @@ -18,14 +18,7 @@ #ifndef OPKG_UTILS_H #define OPKG_UTILS_H -#include "pkg.h" -#include "opkg_error.h" - -void push_error_list(char * msg); -void free_error_list(void); -void print_error_list(void); - -long unsigned int get_available_blocks(char * filesystem); +unsigned long get_available_kbytes(char * filesystem); char *trim_xstrdup(const char *line); int line_is_blank(const char *line); diff --git a/libopkg/pkg.c b/libopkg/pkg.c index 58c133d..411817b 100644 --- a/libopkg/pkg.c +++ b/libopkg/pkg.c @@ -38,8 +38,8 @@ typedef struct enum_map enum_map_t; struct enum_map { - int value; - char *str; + unsigned int value; + const char *str; }; static const enum_map_t pkg_state_want_map[] = { @@ -98,11 +98,9 @@ pkg_init(pkg_t *pkg) active_list_init(&pkg->list); - /* Abhaya: added init for conflicts fields */ pkg->conflicts = NULL; pkg->conflicts_count = 0; - /* added for replaces. Jamey 7/23/2002 */ pkg->replaces = NULL; pkg->replaces_count = 0; @@ -117,8 +115,8 @@ pkg_init(pkg_t *pkg) #if defined HAVE_SHA256 pkg->sha256sum = NULL; #endif - pkg->size = NULL; - pkg->installed_size = NULL; + pkg->size = 0; + pkg->installed_size = 0; pkg->priority = NULL; pkg->source = NULL; conffile_list_init(&pkg->conffiles); @@ -249,14 +247,6 @@ pkg_deinit(pkg_t *pkg) pkg->sha256sum = NULL; #endif - if (pkg->size) - free(pkg->size); - pkg->size = NULL; - - if (pkg->installed_size) - free(pkg->installed_size); - pkg->installed_size = NULL; - if (pkg->priority) free(pkg->priority); pkg->priority = NULL; @@ -280,7 +270,7 @@ pkg_deinit(pkg_t *pkg) } int -pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename) +pkg_init_from_file(pkg_t *pkg, const char *filename) { int fd, err = 0; FILE *control_file; @@ -295,14 +285,14 @@ pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename) basename(filename)); fd = mkstemp(control_path); if (fd == -1) { - perror_msg("%s: mkstemp(%s)", __FUNCTION__, control_path); + opkg_perror(ERROR, "Failed to make temp file %s", control_path); err = -1; goto err0; } control_file = fdopen(fd, "r+"); if (control_file == NULL) { - perror_msg("%s: fdopen", __FUNCTION__, control_path); + opkg_perror(ERROR, "Failed to fdopen %s", control_path); close(fd); err = -1; goto err1; @@ -310,14 +300,14 @@ pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename) err = pkg_extract_control_file_to_stream(pkg, control_file); if (err) { - opkg_message(conf, OPKG_ERROR, "Failed to extract control file" - " from %s\n", filename); + opkg_msg(ERROR, "Failed to extract control file from %s.\n", + filename); goto err2; } rewind(control_file); - if (pkg_parse_from_stream(pkg, control_file, PFM_ALL)) + if (pkg_parse_from_stream(pkg, control_file, 0)) err = -1; err2: @@ -331,15 +321,8 @@ err0: } /* Merge any new information in newpkg into oldpkg */ -/* XXX: CLEANUP: This function shouldn't actually modify anything in - newpkg, but should leave it usable. This rework is so that - pkg_hash_insert doesn't clobber the pkg that you pass into it. */ -/* - * uh, i thought that i had originally written this so that it took - * two pkgs and returned a new one? we can do that again... -sma - */ int -pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status) +pkg_merge(pkg_t *oldpkg, pkg_t *newpkg) { if (oldpkg == newpkg) { return 0; @@ -362,18 +345,6 @@ pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status) oldpkg->maintainer = xstrdup(newpkg->maintainer); if(!oldpkg->description) oldpkg->description = xstrdup(newpkg->description); - if (set_status) { - /* merge the state_flags from the new package */ - oldpkg->state_want = newpkg->state_want; - oldpkg->state_status = newpkg->state_status; - oldpkg->state_flag = newpkg->state_flag; - } else { - if (oldpkg->state_want == SW_UNKNOWN) - oldpkg->state_want = newpkg->state_want; - if (oldpkg->state_status == SS_NOT_INSTALLED) - oldpkg->state_status = newpkg->state_status; - oldpkg->state_flag |= newpkg->state_flag; - } if (!oldpkg->depends_count && !oldpkg->pre_depends_count && !oldpkg->recommends_count && !oldpkg->suggests_count) { oldpkg->depends_count = newpkg->depends_count; @@ -431,22 +402,24 @@ pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status) oldpkg->sha256sum = xstrdup(newpkg->sha256sum); #endif if (!oldpkg->size) - oldpkg->size = xstrdup(newpkg->size); + oldpkg->size = newpkg->size; if (!oldpkg->installed_size) - oldpkg->installed_size = xstrdup(newpkg->installed_size); + oldpkg->installed_size = newpkg->installed_size; if (!oldpkg->priority) oldpkg->priority = xstrdup(newpkg->priority); if (!oldpkg->source) oldpkg->source = xstrdup(newpkg->source); + if (nv_pair_list_empty(&oldpkg->conffiles)){ list_splice_init(&newpkg->conffiles.head, &oldpkg->conffiles.head); - conffile_list_init(&newpkg->conffiles); } + if (!oldpkg->installed_files){ oldpkg->installed_files = newpkg->installed_files; oldpkg->installed_files_ref_cnt = newpkg->installed_files_ref_cnt; newpkg->installed_files = NULL; } + if (!oldpkg->essential) oldpkg->essential = newpkg->essential; @@ -473,7 +446,7 @@ abstract_pkg_new(void) } void -set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){ +set_flags_from_control(pkg_t *pkg){ char *file_name; FILE *fp; @@ -481,16 +454,16 @@ set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){ fp = fopen(file_name, "r"); if (fp == NULL) { - opkg_message(conf, OPKG_ERROR, "%s: fopen(%s): %s\n", - __FUNCTION__, file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open %s"); free(file_name); return; } free(file_name); - if (pkg_parse_from_stream(pkg, fp, PFM_ESSENTIAL)) { - opkg_message(conf, OPKG_DEBUG, "unable to read control file for %s. May be empty\n", pkg->name); + if (pkg_parse_from_stream(pkg, fp, PFM_ALL ^ PFM_ESSENTIAL)) { + opkg_msg(DEBUG, "Unable to read control file for %s. May be empty.\n", + pkg->name); } fclose(fp); @@ -498,7 +471,7 @@ set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg){ return; } -static char * +static const char * pkg_state_want_to_str(pkg_state_want_t sw) { int i; @@ -509,8 +482,7 @@ pkg_state_want_to_str(pkg_state_want_t sw) } } - fprintf(stderr, "%s: ERROR: Illegal value for state_want: %d\n", - __FUNCTION__, sw); + opkg_msg(ERROR, "Internal error: state_want=%d\n", sw); return ""; } @@ -525,8 +497,7 @@ pkg_state_want_from_str(char *str) } } - fprintf(stderr, "%s: ERROR: Illegal value for state_want string: %s\n", - __FUNCTION__, str); + opkg_msg(ERROR, "Internal error: state_want=%s\n", str); return SW_UNKNOWN; } @@ -534,7 +505,7 @@ static char * pkg_state_flag_to_str(pkg_state_flag_t sf) { int i; - int len; + unsigned int len; char *str; /* clear the temporary flags before converting to string */ @@ -570,13 +541,15 @@ pkg_state_flag_from_str(const char *str) { int i; int sf = SF_OK; + const char *sfname; + unsigned int sfname_len; if (strcmp(str, "ok") == 0) { return SF_OK; } for (i=0; i < ARRAY_SIZE(pkg_state_flag_map); i++) { - const char *sfname = pkg_state_flag_map[i].str; - int sfname_len = strlen(sfname); + sfname = pkg_state_flag_map[i].str; + sfname_len = strlen(sfname); if (strncmp(str, sfname, sfname_len) == 0) { sf |= pkg_state_flag_map[i].value; str += sfname_len; @@ -591,7 +564,7 @@ pkg_state_flag_from_str(const char *str) return sf; } -static char * +static const char * pkg_state_status_to_str(pkg_state_status_t ss) { int i; @@ -602,8 +575,7 @@ pkg_state_status_to_str(pkg_state_status_t ss) } } - fprintf(stderr, "%s: ERROR: Illegal value for state_status: %d\n", - __FUNCTION__, ss); + opkg_msg(ERROR, "Internal error: state_status=%d\n", ss); return ""; } @@ -618,8 +590,7 @@ pkg_state_status_from_str(const char *str) } } - fprintf(stderr, "%s: ERROR: Illegal value for state_status string: %s\n", - __FUNCTION__, str); + opkg_msg(ERROR, "Internal error: state_status=%s\n", str); return SS_NOT_INSTALLED; } @@ -726,7 +697,7 @@ pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field) case 'i': case 'I': if (strcasecmp(field, "Installed-Size") == 0) { - fprintf(fp, "Installed-Size: %s\n", pkg->installed_size); + fprintf(fp, "Installed-Size: %ld\n", pkg->installed_size); } else if (strcasecmp(field, "Installed-Time") == 0 && pkg->installed_time) { fprintf(fp, "Installed-Time: %lu\n", pkg->installed_time); } @@ -806,7 +777,7 @@ pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field) #endif } else if (strcasecmp(field, "Size") == 0) { if (pkg->size) { - fprintf(fp, "Size: %s\n", pkg->size); + fprintf(fp, "Size: %ld\n", pkg->size); } } else if (strcasecmp(field, "Source") == 0) { if (pkg->source) { @@ -861,7 +832,7 @@ pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field) return; UNKNOWN_FMT_FIELD: - fprintf(stderr, "%s: ERROR: Unknown field name: %s\n", __FUNCTION__, field); + opkg_msg(ERROR, "Internal error: field=%s\n", field); } void @@ -898,26 +869,6 @@ pkg_print_status(pkg_t * pkg, FILE * file) return; } - /* XXX: QUESTION: Do we actually want more fields here? The - original idea was to save space by installing only what was - needed for actual computation, (package, version, status, - essential, conffiles). The assumption is that all other fields - can be found in th available file. - - But, someone proposed the idea to make it possible to - reconstruct a .opk from an installed package, (ie. for beaming - from one handheld to another). So, maybe we actually want a few - more fields here, (depends, suggests, etc.), so that that would - be guaranteed to work even in the absence of more information - from the available file. - - 28-MAR-03: kergoth and I discussed this yesterday. We think - the essential info needs to be here for all installed packages - because they may not appear in the Packages files on various - feeds. Furthermore, one should be able to install from URL or - local storage without requiring a Packages file from any feed. - -Jamey - */ pkg_formatted_field(file, pkg, "Package"); pkg_formatted_field(file, pkg, "Version"); pkg_formatted_field(file, pkg, "Depends"); @@ -1030,7 +981,7 @@ pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op) return r == 0; } - fprintf(stderr, "unknown operator: %s", op); + opkg_msg(ERROR, "Unknown operator: %s.\n", op); return 0; } @@ -1042,8 +993,8 @@ pkg_name_version_and_architecture_compare(const void *p1, const void *p2) int namecmp; int vercmp; if (!a->name || !b->name) { - fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->name=%p b=%p b->name=%p\n", - a, a->name, b, b->name); + opkg_msg(ERROR, "Internal error: a->name=%p, b->name=%p.\n", + a->name, b->name); return 0; } @@ -1054,8 +1005,8 @@ pkg_name_version_and_architecture_compare(const void *p1, const void *p2) if (vercmp) return vercmp; if (!a->arch_priority || !b->arch_priority) { - fprintf(stderr, "pkg_name_version_and_architecture_compare: a=%p a->arch_priority=%i b=%p b->arch_priority=%i\n", - a, a->arch_priority, b, b->arch_priority); + opkg_msg(ERROR, "Internal error: a->arch_priority=%i b->arch_priority=%i.\n", + a->arch_priority, b->arch_priority); return 0; } if (a->arch_priority > b->arch_priority) @@ -1071,8 +1022,8 @@ abstract_pkg_name_compare(const void *p1, const void *p2) const abstract_pkg_t *a = *(const abstract_pkg_t **)p1; const abstract_pkg_t *b = *(const abstract_pkg_t **)p2; if (!a->name || !b->name) { - fprintf(stderr, "abstract_pkg_name_compare: a=%p a->name=%p b=%p b->name=%p\n", - a, a->name, b, b->name); + opkg_msg(ERROR, "Internal error: a->name=%p b->name=%p.\n", + a->name, b->name); return 0; } return strcmp(a->name, b->name); @@ -1106,14 +1057,14 @@ pkg_version_str_alloc(pkg_t *pkg) * XXX: this should be broken into two functions */ str_list_t * -pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg) +pkg_get_installed_files(pkg_t *pkg) { int err, fd; char *list_file_name = NULL; FILE *list_file = NULL; char *line; char *installed_file_name; - int rootdirlen = 0; + unsigned int rootdirlen = 0; pkg->installed_files_ref_cnt++; @@ -1138,15 +1089,15 @@ pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg) conf->tmp_dir, pkg->name); fd = mkstemp(list_file_name); if (fd == -1) { - opkg_message(conf, OPKG_ERROR, "%s: mkstemp(%s): %s", - __FUNCTION__, list_file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to make temp file %s.", + list_file_name); free(list_file_name); return pkg->installed_files; } list_file = fdopen(fd, "r+"); if (list_file == NULL) { - opkg_message(conf, OPKG_ERROR, "%s: fdopen: %s", - __FUNCTION__, strerror(errno)); + opkg_perror(ERROR, "Failed to fdopen temp file %s.", + list_file_name); close(fd); unlink(list_file_name); free(list_file_name); @@ -1154,8 +1105,7 @@ pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg) } err = pkg_extract_data_file_names_to_stream(pkg, list_file); if (err) { - opkg_message(conf, OPKG_ERROR, "%s: Error extracting file list " - "from %s\n", __FUNCTION__, + opkg_msg(ERROR, "Error extracting file list from %s.\n", pkg->local_filename); fclose(list_file); unlink(list_file_name); @@ -1170,8 +1120,8 @@ pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg) pkg->dest->info_dir, pkg->name); list_file = fopen(list_file_name, "r"); if (list_file == NULL) { - opkg_message(conf, OPKG_ERROR, "%s: fopen(%s): %s\n", - __FUNCTION__, list_file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open %s.\n", + list_file_name); free(list_file_name); return pkg->installed_files; } @@ -1245,7 +1195,7 @@ pkg_free_installed_files(pkg_t *pkg) } void -pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg) +pkg_remove_installed_files_list(pkg_t *pkg) { char *list_file_name; @@ -1280,8 +1230,7 @@ pkg_get_conffile(pkg_t *pkg, const char *file_name) } int -pkg_run_script(opkg_conf_t *conf, pkg_t *pkg, - const char *script, const char *args) +pkg_run_script(pkg_t *pkg, const char *script, const char *args) { int err; char *path; @@ -1290,52 +1239,33 @@ pkg_run_script(opkg_conf_t *conf, pkg_t *pkg, if (conf->noaction) return 0; - /* XXX: CLEANUP: There must be a better way to handle maintainer - scripts when running with offline_root mode and/or a dest other - than '/'. I've been playing around with some clever chroot - tricks and I might come up with something workable. */ - /* - * Attempt to provide a restricted environment for offline operation - * Need the following set as a minimum: - * OPKG_OFFLINE_ROOT = absolute path to root dir - * D = absolute path to root dir (for OE generated postinst) - * PATH = something safe (a restricted set of utilities) - */ - - if (conf->offline_root) { - if (conf->offline_root_path) { - setenv("PATH", conf->offline_root_path, 1); - } else { - opkg_message(conf, OPKG_NOTICE, - "(offline root mode: not running %s.%s)\n", pkg->name, script); - return 0; - } - setenv("OPKG_OFFLINE_ROOT", conf->offline_root, 1); - setenv("D", conf->offline_root, 1); - } - /* XXX: FEATURE: When conf->offline_root is set, we should run the maintainer script within a chroot environment. */ + if (conf->offline_root) { + opkg_msg(INFO, "Offline root mode: not running %s.%s.\n", + pkg->name, script); + return 0; + } /* Installed packages have scripts in pkg->dest->info_dir, uninstalled packages have scripts in pkg->tmp_unpack_dir. */ if (pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) { if (pkg->dest == NULL) { - fprintf(stderr, "%s: ERROR: installed package %s has a NULL dest\n", - __FUNCTION__, pkg->name); - return EINVAL; + opkg_msg(ERROR, "Internal error: %s has a NULL dest.\n", + pkg->name); + return -1; } sprintf_alloc(&path, "%s/%s.%s", pkg->dest->info_dir, pkg->name, script); } else { if (pkg->tmp_unpack_dir == NULL) { - fprintf(stderr, "%s: ERROR: uninstalled package %s has a NULL tmp_unpack_dir\n", - __FUNCTION__, pkg->name); - return EINVAL; + opkg_msg(ERROR, "Internal error: %s has a NULL tmp_unpack_dir.\n", + pkg->name); + return -1; } sprintf_alloc(&path, "%s/%s", pkg->tmp_unpack_dir, script); } - opkg_message(conf, OPKG_INFO, "Running script %s\n", path); + opkg_msg(INFO, "Running script %s.\n", path); setenv("PKG_ROOT", pkg->dest ? pkg->dest->root_dir : conf->default_dest->root_dir, 1); @@ -1354,7 +1284,7 @@ pkg_run_script(opkg_conf_t *conf, pkg_t *pkg, free(cmd); if (err) { - fprintf(stderr, "%s script returned status %d\n", script, err); + opkg_msg(ERROR, "%s script returned status %d.\n", script, err); return err; } @@ -1362,7 +1292,7 @@ pkg_run_script(opkg_conf_t *conf, pkg_t *pkg, } int -pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg) +pkg_arch_supported(pkg_t *pkg) { nv_pair_list_elt_t *l; @@ -1372,17 +1302,19 @@ pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg) list_for_each_entry(l , &conf->arch_list.head, node) { nv_pair_t *nv = (nv_pair_t *)l->data; if (strcmp(nv->name, pkg->architecture) == 0) { - opkg_message(conf, OPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name); + opkg_msg(DEBUG, "Arch %s (priority %s) supported for pkg %s.\n", + nv->name, nv->value, pkg->name); return 1; } } - opkg_message(conf, OPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name); + opkg_msg(DEBUG, "Arch %s unsupported for pkg %s.\n", + pkg->architecture, pkg->name); return 0; } -int -pkg_get_arch_priority(opkg_conf_t *conf, const char *archname) +static int +pkg_get_arch_priority(const char *archname) { nv_pair_list_elt_t *l; @@ -1397,27 +1329,21 @@ pkg_get_arch_priority(opkg_conf_t *conf, const char *archname) } void -pkg_info_preinstall_check(opkg_conf_t *conf) +pkg_info_preinstall_check(void) { int i; - hash_table_t *pkg_hash = &conf->pkg_hash; pkg_vec_t *available_pkgs = pkg_vec_alloc(); pkg_vec_t *installed_pkgs = pkg_vec_alloc(); - opkg_message(conf, OPKG_INFO, "pkg_info_preinstall_check: updating arch priority for each package\n"); - pkg_hash_fetch_available(pkg_hash, available_pkgs); + opkg_msg(INFO, "Updating arch priority for each package.\n"); + pkg_hash_fetch_available(available_pkgs); /* update arch_priority for each package */ for (i = 0; i < available_pkgs->len; i++) { pkg_t *pkg = available_pkgs->pkgs[i]; int arch_priority = 1; if (!pkg) continue; - // opkg_message(conf, OPKG_DEBUG2, " package %s version=%s arch=%p:", pkg->name, pkg->version, pkg->architecture); - if (pkg->architecture) - arch_priority = pkg_get_arch_priority(conf, pkg->architecture); - else - opkg_message(conf, OPKG_ERROR, "pkg_info_preinstall_check: no architecture for package %s\n", pkg->name); - // opkg_message(conf, OPKG_DEBUG2, "%s arch_priority=%d\n", pkg->architecture, arch_priority); + arch_priority = pkg_get_arch_priority(pkg->architecture); pkg->arch_priority = arch_priority; } @@ -1425,8 +1351,10 @@ pkg_info_preinstall_check(opkg_conf_t *conf) pkg_t *pkg = available_pkgs->pkgs[i]; if (!pkg->arch_priority && (pkg->state_flag || (pkg->state_want != SW_UNKNOWN))) { /* clear flags and want for any uninstallable package */ - opkg_message(conf, OPKG_DEBUG, "Clearing state_want and state_flag for pkg=%s (arch_priority=%d flag=%d want=%d)\n", - pkg->name, pkg->arch_priority, pkg->state_flag, pkg->state_want); + opkg_msg(DEBUG, "Clearing state_want and state_flag for pkg=%s " + "(arch_priority=%d flag=%d want=%d)\n", + pkg->name, pkg->arch_priority, + pkg->state_flag, pkg->state_want); pkg->state_want = SW_UNKNOWN; pkg->state_flag = 0; } @@ -1434,14 +1362,14 @@ pkg_info_preinstall_check(opkg_conf_t *conf) pkg_vec_free(available_pkgs); /* update the file owner data structure */ - opkg_message(conf, OPKG_INFO, "pkg_info_preinstall_check: update file owner list\n"); - pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs); + opkg_msg(INFO, "Updating file owner list.\n"); + pkg_hash_fetch_all_installed(installed_pkgs); for (i = 0; i < installed_pkgs->len; i++) { pkg_t *pkg = installed_pkgs->pkgs[i]; - str_list_t *installed_files = pkg_get_installed_files(conf, pkg); /* this causes installed_files to be cached */ + str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */ str_list_elt_t *iter, *niter; if (installed_files == NULL) { - opkg_message(conf, OPKG_ERROR, "Failed to determine installed " + opkg_msg(ERROR, "Failed to determine installed " "files for pkg %s.\n", pkg->name); break; } @@ -1449,8 +1377,7 @@ pkg_info_preinstall_check(opkg_conf_t *conf) iter; iter = niter, niter = str_list_next(installed_files, iter)) { char *installed_file = (char *) iter->data; - // opkg_message(conf, OPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file); - file_hash_set_file_owner(conf, installed_file, pkg); + file_hash_set_file_owner(installed_file, pkg); } pkg_free_installed_files(pkg); } @@ -1458,12 +1385,11 @@ pkg_info_preinstall_check(opkg_conf_t *conf) } struct pkg_write_filelist_data { - opkg_conf_t *conf; pkg_t *pkg; FILE *stream; }; -void +static void pkg_write_filelist_helper(const char *key, void *entry_, void *data_) { struct pkg_write_filelist_data *data = data_; @@ -1474,7 +1400,7 @@ pkg_write_filelist_helper(const char *key, void *entry_, void *data_) } int -pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg) +pkg_write_filelist(pkg_t *pkg) { struct pkg_write_filelist_data data; char *list_file_name; @@ -1482,19 +1408,18 @@ pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg) sprintf_alloc(&list_file_name, "%s/%s.list", pkg->dest->info_dir, pkg->name); - opkg_message(conf, OPKG_INFO, "%s: creating %s file for pkg %s\n", - __FUNCTION__, list_file_name, pkg->name); + opkg_msg(INFO, "Creating %s file for pkg %s.\n", + list_file_name, pkg->name); data.stream = fopen(list_file_name, "w"); if (!data.stream) { - opkg_message(conf, OPKG_ERROR, "%s: fopen(%s, \"w\"): %s\n", - __FUNCTION__, list_file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open %s", + list_file_name); free(list_file_name); return -1; } data.pkg = pkg; - data.conf = conf; hash_table_foreach(&conf->file_hash, pkg_write_filelist_helper, &data); fclose(data.stream); free(list_file_name); @@ -1505,23 +1430,21 @@ pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg) } int -pkg_write_changed_filelists(opkg_conf_t *conf) +pkg_write_changed_filelists(void) { pkg_vec_t *installed_pkgs = pkg_vec_alloc(); - hash_table_t *pkg_hash = &conf->pkg_hash; int i, err, ret = 0; if (conf->noaction) return 0; - opkg_message(conf, OPKG_INFO, "%s: saving changed filelists\n", - __FUNCTION__); + opkg_msg(INFO, "Saving changed filelists.\n"); - pkg_hash_fetch_all_installed(pkg_hash, installed_pkgs); + pkg_hash_fetch_all_installed(installed_pkgs); for (i = 0; i < installed_pkgs->len; i++) { pkg_t *pkg = installed_pkgs->pkgs[i]; if (pkg->state_flag & SF_FILELIST_CHANGED) { - err = pkg_write_filelist(conf, pkg); + err = pkg_write_filelist(pkg); if (err) ret = -1; } diff --git a/libopkg/pkg.h b/libopkg/pkg.h index 229594d..81f2f67 100644 --- a/libopkg/pkg.h +++ b/libopkg/pkg.h @@ -85,7 +85,10 @@ struct abstract_pkg{ pkg_vec_t * pkgs; pkg_state_status_t state_status; pkg_state_flag_t state_flag; - struct abstract_pkg ** depended_upon_by; /* @@@@ this should be abstract_pkg_vec_t -Jamey */ + + /* XXX: This should be abstract_pkg_vec_t for consistency. */ + struct abstract_pkg ** depended_upon_by; + abstract_pkg_vec_t * provided_by; abstract_pkg_vec_t * replaced_by; }; @@ -129,43 +132,39 @@ struct pkg pkg_state_flag_t state_flag; pkg_state_status_t state_status; char **depends_str; - int depends_count; + unsigned int depends_count; char **pre_depends_str; - int pre_depends_count; + unsigned int pre_depends_count; char **recommends_str; - int recommends_count; + unsigned int recommends_count; char **suggests_str; - int suggests_count; + unsigned int suggests_count; struct active_list list; /* Used for installing|upgrading */ compound_depend_t * depends; - /* Abhaya: new conflicts */ char **conflicts_str; compound_depend_t * conflicts; - int conflicts_count; + unsigned int conflicts_count; char **replaces_str; - int replaces_count; + unsigned int replaces_count; abstract_pkg_t ** replaces; char **provides_str; - int provides_count; + unsigned int provides_count; abstract_pkg_t ** provides; abstract_pkg_t *parent; - pkg_t *old_pkg; /* during upgrade, points from installee to previously installed */ - char *filename; char *local_filename; - char *url; char *tmp_unpack_dir; char *md5sum; #if defined HAVE_SHA256 char *sha256sum; #endif - char *size; - char *installed_size; + unsigned long size; /* in bytes */ + unsigned long installed_size; /* in bytes */ char *priority; char *source; conffile_list_t conffiles; @@ -189,14 +188,14 @@ struct pkg pkg_t *pkg_new(void); void pkg_deinit(pkg_t *pkg); -int pkg_init_from_file(opkg_conf_t *conf, pkg_t *pkg, const char *filename); +int pkg_init_from_file(pkg_t *pkg, const char *filename); abstract_pkg_t *abstract_pkg_new(void); /* * merges fields from newpkg into oldpkg. - * Forcibly sets oldpkg state_status, state_want and state_flags if set_status is nonzero + * Forcibly sets oldpkg state_status, state_want and state_flags */ -int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status); +int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg); char *pkg_version_str_alloc(pkg_t *pkg); @@ -207,15 +206,14 @@ int abstract_pkg_name_compare(const void *a, const void *b); void pkg_formatted_info(FILE *fp, pkg_t *pkg); void pkg_formatted_field(FILE *fp, pkg_t *pkg, const char *field); -void set_flags_from_control(opkg_conf_t *conf, pkg_t *pkg); +void set_flags_from_control(pkg_t *pkg); void pkg_print_status(pkg_t * pkg, FILE * file); -str_list_t *pkg_get_installed_files(opkg_conf_t *conf, pkg_t *pkg); +str_list_t *pkg_get_installed_files(pkg_t *pkg); void pkg_free_installed_files(pkg_t *pkg); -void pkg_remove_installed_files_list(opkg_conf_t *conf, pkg_t *pkg); +void pkg_remove_installed_files_list(pkg_t *pkg); conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name); -int pkg_run_script(struct opkg_conf *conf, pkg_t *pkg, - const char *script, const char *args); +int pkg_run_script(pkg_t *pkg, const char *script, const char *args); /* enum mappings */ pkg_state_want_t pkg_state_want_from_str(char *str); @@ -224,10 +222,10 @@ pkg_state_status_t pkg_state_status_from_str(const char *str); int pkg_version_satisfied(pkg_t *it, pkg_t *ref, const char *op); -int pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg); -void pkg_info_preinstall_check(opkg_conf_t *conf); +int pkg_arch_supported(pkg_t *pkg); +void pkg_info_preinstall_check(void); -int pkg_write_filelist(opkg_conf_t *conf, pkg_t *pkg); -int pkg_write_changed_filelists(opkg_conf_t *conf); +int pkg_write_filelist(pkg_t *pkg); +int pkg_write_changed_filelists(void); #endif diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c index 9fe9a71..3a7c9ea 100644 --- a/libopkg/pkg_depends.c +++ b/libopkg/pkg_depends.c @@ -27,7 +27,7 @@ #include "hash_table.h" #include "libbb/libbb.h" -static int parseDepends(compound_depend_t *compound_depend, hash_table_t * hash, char * depend_str); +static int parseDepends(compound_depend_t *compound_depend, char * depend_str); static depend_t * depend_init(void); static char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx); static char ** merge_unresolved(char ** oldstuff, char ** newstuff); @@ -52,8 +52,9 @@ static int pkg_constraint_satisfied(pkg_t *pkg, void *cdata) } /* returns ndependences or negative error value */ -int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, - pkg_vec_t *unsatisfied, char *** unresolved) +int +pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t *unsatisfied, + char *** unresolved) { pkg_t * satisfier_entry_pkg; int i, j, k; @@ -66,7 +67,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, * which are marked at the abstract_pkg level */ if (!(ab_pkg = pkg->parent)) { - fprintf(stderr, "%s:%d: something terribly wrong with pkg %s\n", __FUNCTION__, __LINE__, pkg->name); + opkg_msg(ERROR, "Internal error, with pkg %s.\n", pkg->name); *unresolved = NULL; return 0; } @@ -120,8 +121,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, int rc; pkg_vec_t *tmp_vec = pkg_vec_alloc (); /* check for not-already-installed dependencies */ - rc = pkg_hash_fetch_unsatisfied_dependencies(conf, - pkg_scout, + rc = pkg_hash_fetch_unsatisfied_dependencies(pkg_scout, tmp_vec, &newstuff); if (newstuff == NULL) { @@ -131,18 +131,28 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, pkg_t *p = tmp_vec->pkgs[m]; if (p->state_want == SW_INSTALL) continue; - opkg_message(conf, OPKG_DEBUG, "not installing %s due to requirement for %s\n", pkg_scout->name, p->name); + opkg_msg(DEBUG, + "Not installing %s due" + " to requirement for %s.\n", + pkg_scout->name, + p->name); ok = 0; break; } pkg_vec_free (tmp_vec); if (ok) { /* mark this one for installation */ - opkg_message(conf, OPKG_NOTICE, "Adding satisfier for greedy dependence: %s\n", pkg_scout->name); + opkg_msg(NOTICE, + "Adding satisfier for greedy" + " dependence %s.\n", + pkg_scout->name); pkg_vec_insert(unsatisfied, pkg_scout); } } else { - opkg_message(conf, OPKG_DEBUG, "not installing %s due to broken depends \n", pkg_scout->name); + opkg_msg(DEBUG, + "Not installing %s due to " + "broken depends.\n", + pkg_scout->name); free (newstuff); } } @@ -159,7 +169,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, depend_t *dependence_to_satisfy = possible_satisfiers[j]; abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; pkg_t *satisfying_pkg = - pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, + pkg_hash_fetch_best_installation_candidate(satisfying_apkg, pkg_installed_and_constraint_satisfied, dependence_to_satisfy, 1); /* Being that I can't test constraing in pkg_hash, I will test it here */ @@ -168,7 +178,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, satisfying_pkg = NULL; } } - opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p \n", __FILE__, __LINE__, satisfying_pkg); + opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg); if (satisfying_pkg != NULL) { found = 1; break; @@ -183,7 +193,7 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, depend_t *dependence_to_satisfy = possible_satisfiers[j]; abstract_pkg_t *satisfying_apkg = possible_satisfiers[j]->pkg; pkg_t *satisfying_pkg = - pkg_hash_fetch_best_installation_candidate(conf, satisfying_apkg, + pkg_hash_fetch_best_installation_candidate(satisfying_apkg, pkg_constraint_satisfied, dependence_to_satisfy, 1); /* Being that I can't test constraing in pkg_hash, I will test it here too */ @@ -197,12 +207,13 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, if (satisfying_pkg != NULL && (compound_depend->type == RECOMMEND || compound_depend->type == SUGGEST) && (satisfying_pkg->state_want == SW_DEINSTALL || satisfying_pkg->state_want == SW_PURGE)) { - opkg_message (conf, OPKG_NOTICE, "%s: ignoring recommendation for %s at user request\n", - pkg->name, satisfying_pkg->name); + opkg_msg(NOTICE, "%s: ignoring recommendation for " + "%s at user request\n", + pkg->name, satisfying_pkg->name); continue; } - opkg_message(conf, OPKG_DEBUG, "%s:%d: satisfying_pkg=%p\n", __FILE__, __LINE__, satisfying_pkg); + opkg_msg(DEBUG, "satisfying_pkg=%p\n", satisfying_pkg); if (satisfying_pkg != NULL) { satisfier_entry_pkg = satisfying_pkg; break; @@ -217,22 +228,23 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, if (compound_depend->type != RECOMMEND && compound_depend->type != SUGGEST) the_lost = add_unresolved_dep(pkg, the_lost, i); else - opkg_message (conf, OPKG_NOTICE, "%s: unsatisfied recommendation for %s\n", - pkg->name, compound_depend->possibilities[0]->pkg->name); + opkg_msg(NOTICE, + "%s: unsatisfied recommendation for %s\n", + pkg->name, + compound_depend->possibilities[0]->pkg->name); } else { if (compound_depend->type == SUGGEST) { /* just mention it politely */ - opkg_message (conf, OPKG_NOTICE, "package %s suggests installing %s\n", - pkg->name, satisfier_entry_pkg->name); + opkg_msg(NOTICE, "package %s suggests installing %s\n", + pkg->name, satisfier_entry_pkg->name); } else { char ** newstuff = NULL; if (satisfier_entry_pkg != pkg && !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg)) { pkg_vec_insert(unsatisfied, satisfier_entry_pkg); - pkg_hash_fetch_unsatisfied_dependencies(conf, - satisfier_entry_pkg, + pkg_hash_fetch_unsatisfied_dependencies(satisfier_entry_pkg, unsatisfied, &newstuff); the_lost = merge_unresolved(the_lost, newstuff); @@ -253,7 +265,8 @@ int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, really conflicts returns 0 if conflicts <> replaces or 1 if conflicts == replaces */ -int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) +static int +is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) { int i ; int replaces_count = pkg->replaces_count; @@ -266,7 +279,8 @@ int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) for (i = 0; i < replaces_count; i++) { if (strcmp(pkg_scout->name,pkg->replaces[i]->name)==0) { // Found - opkg_message(NULL, OPKG_DEBUG2, "Seems I've found a replace %s %s \n",pkg_scout->name,pkg->replaces[i]->name); + opkg_msg(DEBUG2, "Seems I've found a replace %s %s\n", + pkg_scout->name, pkg->replaces[i]->name); return 1; } } @@ -275,8 +289,7 @@ int is_pkg_a_replaces(pkg_t *pkg_scout,pkg_t *pkg) } -/* Abhaya: added support for conflicts */ -pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg) { pkg_vec_t * installed_conflicts, * test_vec; compound_depend_t * conflicts; @@ -293,7 +306,7 @@ pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) * which are marked at the abstract_pkg level */ if(!(ab_pkg = pkg->parent)){ - fprintf(stderr, "dependency check error. pkg %s isn't in hash table\n", pkg->name); + opkg_msg(ERROR, "Internal error: %s not in hash table\n", pkg->name); return (pkg_vec_t *)NULL; } @@ -316,9 +329,9 @@ pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) for(j = 0; j < conflicts->possibility_count; j++){ possible_satisfier = possible_satisfiers[j]; if (!possible_satisfier) - fprintf(stderr, "%s:%d: possible_satisfier is null\n", __FUNCTION__, __LINE__); + opkg_msg(ERROR, "Internal error: possible_satisfier=NULL\n"); if (!possible_satisfier->pkg) - fprintf(stderr, "%s:%d: possible_satisfier->pkg is null\n", __FUNCTION__, __LINE__); + opkg_msg(ERROR, "Internal error: possible_satisfier->pkg=NULL\n"); test_vec = possible_satisfier->pkg->pkgs; if (test_vec) { /* pkg_vec found, it is an actual package conflict @@ -327,7 +340,7 @@ pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg) for(k = 0; k < test_vec->len; k++){ pkg_scout = pkg_scouts[k]; if (!pkg_scout) { - fprintf(stderr, "%s: null pkg scout\n", __FUNCTION__); + opkg_msg(ERROR, "Internal error: pkg_scout=NULL\n"); continue; } if ((pkg_scout->state_status == SS_INSTALLED || pkg_scout->state_want == SW_INSTALL) && @@ -383,7 +396,7 @@ int version_constraints_satisfied(depend_t * depends, pkg_t * pkg) return 0; } -int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend) +int pkg_dependence_satisfiable(depend_t *depend) { abstract_pkg_t *apkg = depend->pkg; abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; @@ -410,7 +423,7 @@ int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend) return 0; } -int pkg_dependence_satisfied(opkg_conf_t *conf, depend_t *depend) +int pkg_dependence_satisfied(depend_t *depend) { abstract_pkg_t *apkg = depend->pkg; abstract_pkg_vec_t *provider_apkgs = apkg->provided_by; @@ -564,7 +577,7 @@ char ** add_unresolved_dep(pkg_t * pkg, char ** the_lost, int ref_ndx) return resized; } -void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) +void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg) { int i; @@ -575,7 +588,7 @@ void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) pkg->provides[0] = ab_pkg; for (i=1; iprovides_count; i++) { - abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name(hash, + abstract_pkg_t *provided_abpkg = ensure_abstract_pkg_by_name( pkg->provides_str[i-1]); free(pkg->provides_str[i-1]); @@ -587,8 +600,7 @@ void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) free(pkg->provides_str); } -/* Abhaya: added conflicts support */ -void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) +void buildConflicts(pkg_t * pkg) { int i; compound_depend_t * conflicts; @@ -599,8 +611,7 @@ void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) conflicts = pkg->conflicts = xcalloc(pkg->conflicts_count, sizeof(compound_depend_t)); for (i = 0; i < pkg->conflicts_count; i++) { conflicts->type = CONFLICTS; - parseDepends(conflicts, hash, - pkg->conflicts_str[i]); + parseDepends(conflicts, pkg->conflicts_str[i]); free(pkg->conflicts_str[i]); conflicts++; } @@ -608,7 +619,7 @@ void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) free(pkg->conflicts_str); } -void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) +void buildReplaces(abstract_pkg_t * ab_pkg, pkg_t * pkg) { int i; @@ -618,7 +629,7 @@ void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) pkg->replaces = xcalloc(pkg->replaces_count, sizeof(abstract_pkg_t *)); for(i = 0; i < pkg->replaces_count; i++){ - abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(hash, pkg->replaces_str[i]); + abstract_pkg_t *old_abpkg = ensure_abstract_pkg_by_name(pkg->replaces_str[i]); pkg->replaces[i] = old_abpkg; free(pkg->replaces_str[i]); @@ -636,9 +647,9 @@ void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg) free(pkg->replaces_str); } -void buildDepends(hash_table_t * hash, pkg_t * pkg) +void buildDepends(pkg_t * pkg) { - int count; + unsigned int count; int i; compound_depend_t * depends; @@ -648,7 +659,7 @@ void buildDepends(hash_table_t * hash, pkg_t * pkg) depends = pkg->depends = xcalloc(count, sizeof(compound_depend_t)); for(i = 0; i < pkg->pre_depends_count; i++){ - parseDepends(depends, hash, pkg->pre_depends_str[i]); + parseDepends(depends, pkg->pre_depends_str[i]); free(pkg->pre_depends_str[i]); depends->type = PREDEPEND; depends++; @@ -657,7 +668,7 @@ void buildDepends(hash_table_t * hash, pkg_t * pkg) free(pkg->pre_depends_str); for(i = 0; i < pkg->depends_count; i++){ - parseDepends(depends, hash, pkg->depends_str[i]); + parseDepends(depends, pkg->depends_str[i]); free(pkg->depends_str[i]); depends++; } @@ -665,7 +676,7 @@ void buildDepends(hash_table_t * hash, pkg_t * pkg) free(pkg->depends_str); for(i = 0; i < pkg->recommends_count; i++){ - parseDepends(depends, hash, pkg->recommends_str[i]); + parseDepends(depends, pkg->recommends_str[i]); free(pkg->recommends_str[i]); depends->type = RECOMMEND; depends++; @@ -674,7 +685,7 @@ void buildDepends(hash_table_t * hash, pkg_t * pkg) free(pkg->recommends_str); for(i = 0; i < pkg->suggests_count; i++){ - parseDepends(depends, hash, pkg->suggests_str[i]); + parseDepends(depends, pkg->suggests_str[i]); free(pkg->suggests_str[i]); depends->type = SUGGEST; depends++; @@ -705,19 +716,20 @@ constraint_to_str(enum version_constraint c) } /* - * Returns a printable string for pkg's dependency at the specified index. The + * Returns a printable string for pkg's dependency at the specified idx. The * resultant string must be passed to free() by the caller. */ char * -pkg_depend_str(pkg_t *pkg, int index) +pkg_depend_str(pkg_t *pkg, int idx) { - int i, len; + int i; + unsigned int len; char *str; compound_depend_t *cdep; depend_t *dep; len = 0; - cdep = &pkg->depends[index]; + cdep = &pkg->depends[idx]; /* calculate string length */ for (i=0; ipossibility_count; i++) { @@ -808,10 +820,10 @@ static depend_t * depend_init(void) } static int parseDepends(compound_depend_t *compound_depend, - hash_table_t * hash, char * depend_str) + char * depend_str) { char * pkg_name, buffer[2048]; - int num_of_ors = 0; + unsigned int num_of_ors = 0; int i; char * src, * dest; depend_t ** possibilities; @@ -841,8 +853,6 @@ static int parseDepends(compound_depend_t *compound_depend, *dest++ = *src++; *dest = '\0'; pkg_name = trim_xstrdup(buffer); - if (pkg_name == NULL ) - return -ENOMEM; /* now look at possible version info */ @@ -891,17 +901,11 @@ static int parseDepends(compound_depend_t *compound_depend, while(*src && *src != ')') *dest++ = *src++; *dest = '\0'; - - possibilities[i]->version = trim_xstrdup(buffer); - /* fprintf(stderr, "let's print the depends version string:"); - fprintf(stderr, "version %s\n", possibilities[i]->version);*/ - if (possibilities[i]->version == NULL ) - return -ENOMEM; - + possibilities[i]->version = trim_xstrdup(buffer); } /* hook up the dependency to its abstract pkg */ - possibilities[i]->pkg = ensure_abstract_pkg_by_name(hash, pkg_name); + possibilities[i]->pkg = ensure_abstract_pkg_by_name(pkg_name); free(pkg_name); diff --git a/libopkg/pkg_depends.h b/libopkg/pkg_depends.h index 05ee1c4..402288c 100644 --- a/libopkg/pkg_depends.h +++ b/libopkg/pkg_depends.h @@ -56,12 +56,10 @@ struct compound_depend{ }; typedef struct compound_depend compound_depend_t; -#include "hash_table.h" - -void buildProvides(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); -void buildConflicts(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); -void buildReplaces(hash_table_t * hash, abstract_pkg_t * ab_pkg, pkg_t * pkg); -void buildDepends(hash_table_t * hash, pkg_t * pkg); +void buildProvides(abstract_pkg_t * ab_pkg, pkg_t * pkg); +void buildConflicts(pkg_t * pkg); +void buildReplaces(abstract_pkg_t * ab_pkg, pkg_t * pkg); +void buildDepends(pkg_t * pkg); /** * pkg_replaces returns 1 if pkg->replaces contains one of replacee's provides and 0 @@ -84,10 +82,10 @@ int pkg_conflicts(pkg_t *pkg, pkg_t *conflicts); char *pkg_depend_str(pkg_t *pkg, int index); void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg); int version_constraints_satisfied(depend_t * depends, pkg_t * pkg); -int pkg_hash_fetch_unsatisfied_dependencies(opkg_conf_t *conf, pkg_t * pkg, pkg_vec_t *depends, char *** unresolved); -pkg_vec_t * pkg_hash_fetch_conflicts(hash_table_t * hash, pkg_t * pkg); -int pkg_dependence_satisfiable(opkg_conf_t *conf, depend_t *depend); -int pkg_dependence_satisfied(opkg_conf_t *conf, depend_t *depend); +int pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t *depends, char *** unresolved); +pkg_vec_t * pkg_hash_fetch_conflicts(pkg_t * pkg); +int pkg_dependence_satisfiable(depend_t *depend); +int pkg_dependence_satisfied(depend_t *depend); const char* constraint_to_str(enum version_constraint c); #endif diff --git a/libopkg/pkg_extract.c b/libopkg/pkg_extract.c index c4d74a3..fffb993 100644 --- a/libopkg/pkg_extract.c +++ b/libopkg/pkg_extract.c @@ -24,9 +24,6 @@ #include "file_util.h" #include "sprintf_alloc.h" -/* assuage libb functions */ -const char *applet_name = "opkg"; - int pkg_extract_control_file_to_stream(pkg_t *pkg, FILE *stream) { diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c index 907ef0e..06a0ac5 100644 --- a/libopkg/pkg_hash.c +++ b/libopkg/pkg_hash.c @@ -31,9 +31,10 @@ #include "libbb/libbb.h" void -pkg_hash_init(const char *name, hash_table_t *hash, int len) +pkg_hash_init(void) { - hash_table_init(name, hash, len); + hash_table_init("pkg-hash", &conf->pkg_hash, + OPKG_CONF_DEFAULT_HASH_LEN); } static void @@ -64,42 +65,16 @@ free_pkgs(const char *key, void *entry, void *data) } void -pkg_hash_deinit(hash_table_t *hash) +pkg_hash_deinit(void) { - hash_table_foreach(hash, free_pkgs, NULL); - hash_table_deinit(hash); -} - - -/* Find the default arch for a given package status file if none is given. */ -static char * -pkg_get_default_arch(opkg_conf_t *conf) -{ - nv_pair_list_elt_t *l; - char *def_arch = HOST_CPU_STR; /* Default arch */ - int def_prio = 0; /* Other archs override this */ - - list_for_each_entry(l , &conf->arch_list.head, node) { - nv_pair_t *nv = (nv_pair_t *)l->data; - int priority = strtol(nv->value, NULL, 0); - - /* Check if this arch has higher priority, and is valid */ - if ((priority > def_prio) && - (strcmp(nv->name, "all")) && (strcmp(nv->name, "noarch"))) { - /* Our new default */ - def_prio = priority; - def_arch = nv->name; - } - } - - return xstrdup(def_arch); + hash_table_foreach(&conf->pkg_hash, free_pkgs, NULL); + hash_table_deinit(&conf->pkg_hash); } int -pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, +pkg_hash_add_from_file(const char *file_name, pkg_src_t *src, pkg_dest_t *dest, int is_status_file) { - hash_table_t *hash = &conf->pkg_hash; pkg_t *pkg; FILE *fp; char *buf; @@ -108,8 +83,7 @@ pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, fp = fopen(file_name, "r"); if (fp == NULL) { - fprintf(stderr, "%s: fopen(%s): %s\n", - __FUNCTION__, file_name, strerror(errno)); + opkg_perror(ERROR, "Failed to open %s", file_name); return -1; } @@ -120,14 +94,14 @@ pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, pkg->src = src; pkg->dest = dest; - ret = pkg_parse_from_stream_nomalloc(pkg, fp, PFM_ALL, + ret = pkg_parse_from_stream_nomalloc(pkg, fp, 0, &buf, len); if (ret) { pkg_deinit (pkg); free(pkg); if (ret == -1) break; - if (ret == EINVAL) + if (ret == 1) /* Probably a blank line, continue parsing. */ ret = 0; continue; @@ -135,13 +109,14 @@ pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, if (!pkg->architecture) { char *version_str = pkg_version_str_alloc(pkg); - pkg->architecture = pkg_get_default_arch(conf); - opkg_message(conf, OPKG_ERROR, "Package %s version %s has no architecture specified, defaulting to %s.\n", - pkg->name, version_str, pkg->architecture); + opkg_msg(ERROR, "Package %s version %s has no " + "architecture specified, ignoring.\n", + pkg->name, version_str); free(version_str); + continue; } - hash_insert_pkg(hash, pkg, is_status_file, conf); + hash_insert_pkg(pkg, is_status_file); } while (!feof(fp)); @@ -152,14 +127,13 @@ pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, } static abstract_pkg_t * -abstract_pkg_fetch_by_name(hash_table_t * hash, const char * pkg_name) +abstract_pkg_fetch_by_name(const char * pkg_name) { - return (abstract_pkg_t *)hash_table_get(hash, pkg_name); + return (abstract_pkg_t *)hash_table_get(&conf->pkg_hash, pkg_name); } pkg_t * -pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, - abstract_pkg_t *apkg, +pkg_hash_fetch_best_installation_candidate(abstract_pkg_t *apkg, int (*constraint_fcn)(pkg_t *pkg, void *cdata), void *cdata, int quiet) { @@ -185,18 +159,18 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, matching_apkgs = abstract_pkg_vec_alloc(); providers = abstract_pkg_vec_alloc(); - opkg_message(conf, OPKG_DEBUG, "best installation candidate for %s\n", apkg->name); + opkg_msg(DEBUG, "Best installation candidate for %s:\n", apkg->name); provided_apkg_vec = apkg->provided_by; nprovides = provided_apkg_vec->len; provided_apkgs = provided_apkg_vec->pkgs; if (nprovides > 1) - opkg_message(conf, OPKG_DEBUG, " apkg=%s nprovides=%d\n", apkg->name, nprovides); + opkg_msg(DEBUG, "apkg=%s nprovides=%d.\n", apkg->name, nprovides); /* accumulate all the providers */ for (i = 0; i < nprovides; i++) { abstract_pkg_t *provider_apkg = provided_apkgs[i]; - opkg_message(conf, OPKG_DEBUG, " adding %s to providers\n", provider_apkg->name); + opkg_msg(DEBUG, "Adding %s to providers.\n", provider_apkg->name); abstract_pkg_vec_insert(providers, provider_apkg); } nprovides = providers->len; @@ -209,13 +183,14 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, if (provider_apkg->replaced_by && provider_apkg->replaced_by->len) { replacement_apkg = provider_apkg->replaced_by->pkgs[0]; if (provider_apkg->replaced_by->len > 1) { - opkg_message(conf, OPKG_NOTICE, "Multiple replacers for %s, using first one (%s)\n", - provider_apkg->name, replacement_apkg->name); + opkg_msg(NOTICE, "Multiple replacers for %s, " + "using first one (%s).\n", + provider_apkg->name, replacement_apkg->name); } } if (replacement_apkg) - opkg_message(conf, OPKG_DEBUG, " replacement_apkg=%s for provider_apkg=%s\n", + opkg_msg(DEBUG, "replacement_apkg=%s for provider_apkg=%s.\n", replacement_apkg->name, provider_apkg->name); if (replacement_apkg && (replacement_apkg != provider_apkg)) { @@ -226,7 +201,8 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, } if (!(vec = provider_apkg->pkgs)) { - opkg_message(conf, OPKG_DEBUG, " no pkgs for provider_apkg %s\n", provider_apkg->name); + opkg_msg(DEBUG, "No pkgs for provider_apkg %s.\n", + provider_apkg->name); continue; } @@ -234,13 +210,13 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, /* now check for supported architecture */ { int max_count = 0; - int i; /* count packages matching max arch priority and keep track of last one */ for (i = 0; i < vec->len; i++) { pkg_t *maybe = vec->pkgs[i]; - opkg_message(conf, OPKG_DEBUG, " %s arch=%s arch_priority=%d version=%s \n", - maybe->name, maybe->architecture, maybe->arch_priority, maybe->version); + opkg_msg(DEBUG, "%s arch=%s arch_priority=%d version=%s.\n", + maybe->name, maybe->architecture, + maybe->arch_priority, maybe->version); /* We make sure not to add the same package twice. Need to search for the reason why they show up twice sometimes. */ if ((maybe->arch_priority > 0) && (! pkg_vec_contains(matching_pkgs, maybe))) { @@ -257,7 +233,7 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, if (matching_pkgs->len < 1) { if (wrong_arch_found) - opkg_message (conf, OPKG_ERROR, "Packages for %s found, but" + opkg_msg(ERROR, "Packages for %s found, but" " incompatible with the architectures configured\n", apkg->name); pkg_vec_free(matching_pkgs); @@ -272,22 +248,14 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, if (matching_apkgs->len > 1) abstract_pkg_vec_sort(matching_pkgs, abstract_pkg_name_compare); -/* Here it is usefull, if ( matching_apkgs->len > 1 ), to test if one of this matching packages has the same name of the - needed package. In this case, I would return it for install, otherwise I will continue with the procedure */ -/* The problem is what to do when there are more than a mathing package, with the same name and several version ? - Until now I always got the latest, but that breaks the downgrade option. - If I stop at the first one, I would probably miss the new ones - Maybe the way is to have some kind of flag somewhere, to see if the package been asked to install is from a file, - or from a Packages feed. - It it is from a file it always need to be checked whatever version I have in feeds or everywhere, according to force-down or whatever options*/ -/*Pigi*/ - for (i = 0; i < matching_pkgs->len; i++) { pkg_t *matching = matching_pkgs->pkgs[i]; - if (constraint_fcn(matching, cdata)) { /* We found it */ - opkg_message(conf, OPKG_DEBUG, " Found a valid candidate for the install: %s %s \n", matching->name, matching->version) ; + if (constraint_fcn(matching, cdata)) { + opkg_msg(DEBUG, "Candidate: %s %s.\n", + matching->name, matching->version) ; good_pkg_by_name = matching; - if ( matching->provided_by_hand == 1 ) /* It has been provided by hand, so it is what user want */ + /* It has been provided by hand, so it is what user want */ + if (matching->provided_by_hand == 1) break; } } @@ -300,8 +268,10 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, latest_installed_parent = matching; if (matching->state_flag & (SF_HOLD|SF_PREFER)) { if (held_pkg) - opkg_message(conf, OPKG_NOTICE, "Multiple packages (%s and %s) providing same name marked HOLD or PREFER. Using latest.\n", - held_pkg->name, matching->name); + opkg_msg(NOTICE, "Multiple packages (%s and %s) providing" + " same name marked HOLD or PREFER. " + "Using latest.\n", + held_pkg->name, matching->name); held_pkg = matching; } } @@ -313,19 +283,21 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, if (matching->arch_priority > prio) { priorized_matching = matching; prio = matching->arch_priority; - opkg_message(conf, OPKG_DEBUG, "Match with priority %i %s\n", prio, matching->name); + opkg_msg(DEBUG, "Match %s with priority %i.\n", + matching->name, prio); } } } - if (conf->verbosity >= OPKG_INFO && matching_apkgs->len > 1) { - opkg_message(conf, OPKG_INFO, "%s: for apkg=%s, %d matching pkgs\n", - __FUNCTION__, apkg->name, matching_pkgs->len); + if (conf->verbosity >= INFO && matching_apkgs->len > 1) { + opkg_msg(INFO, "%d matching pkgs for apkg=%s:\n", + matching_pkgs->len, apkg->name); for (i = 0; i < matching_pkgs->len; i++) { pkg_t *matching = matching_pkgs->pkgs[i]; - opkg_message(conf, OPKG_INFO, " %s %s %s\n", - matching->name, matching->version, matching->architecture); + opkg_msg(INFO, "%s %s %s\n", + matching->name, matching->version, + matching->architecture); } } @@ -339,25 +311,29 @@ pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, return good_pkg_by_name; } if (held_pkg) { - opkg_message(conf, OPKG_INFO, " using held package %s\n", held_pkg->name); + opkg_msg(INFO, "Using held package %s.\n", held_pkg->name); return held_pkg; } if (latest_installed_parent) { - opkg_message(conf, OPKG_INFO, " using latest version of installed package %s\n", latest_installed_parent->name); + opkg_msg(INFO, "Using latest version of installed package %s.\n", + latest_installed_parent->name); return latest_installed_parent; } if (priorized_matching) { - opkg_message(conf, OPKG_INFO, " using priorized matching %s %s %s\n", - priorized_matching->name, priorized_matching->version, priorized_matching->architecture); + opkg_msg(INFO, "Using priorized matching %s %s %s.\n", + priorized_matching->name, priorized_matching->version, + priorized_matching->architecture); return priorized_matching; } if (nmatching > 1) { - opkg_message(conf, OPKG_INFO, " no matching pkg out of matching_apkgs=%d\n", nmatching); + opkg_msg(INFO, "No matching pkg out of %d matching_apkgs.\n", + nmatching); return NULL; } if (latest_matching) { - opkg_message(conf, OPKG_INFO, " using latest matching %s %s %s\n", - latest_matching->name, latest_matching->version, latest_matching->architecture); + opkg_msg(INFO, "Using latest matching %s %s %s.\n", + latest_matching->name, latest_matching->version, + latest_matching->architecture); return latest_matching; } return NULL; @@ -375,11 +351,11 @@ pkg_name_constraint_fcn(pkg_t *pkg, void *cdata) } static pkg_vec_t * -pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name) +pkg_vec_fetch_by_name(const char *pkg_name) { abstract_pkg_t * ab_pkg; - if(!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))) + if(!(ab_pkg = abstract_pkg_fetch_by_name(pkg_name))) return NULL; if (ab_pkg->pkgs) @@ -398,29 +374,26 @@ pkg_vec_fetch_by_name(hash_table_t *hash, const char *pkg_name) pkg_t * -pkg_hash_fetch_best_installation_candidate_by_name(opkg_conf_t *conf, - const char *name) +pkg_hash_fetch_best_installation_candidate_by_name(const char *name) { - hash_table_t *hash = &conf->pkg_hash; abstract_pkg_t *apkg = NULL; - if (!(apkg = abstract_pkg_fetch_by_name(hash, name))) + if (!(apkg = abstract_pkg_fetch_by_name(name))) return NULL; - return pkg_hash_fetch_best_installation_candidate(conf, apkg, + return pkg_hash_fetch_best_installation_candidate(apkg, pkg_name_constraint_fcn, apkg->name, 0); } pkg_t * -pkg_hash_fetch_by_name_version(hash_table_t *hash, - const char *pkg_name, const char * version) +pkg_hash_fetch_by_name_version(const char *pkg_name, const char * version) { pkg_vec_t * vec; int i; char *version_str = NULL; - if(!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) + if(!(vec = pkg_vec_fetch_by_name(pkg_name))) return NULL; for(i = 0; i < vec->len; i++) { @@ -439,13 +412,12 @@ pkg_hash_fetch_by_name_version(hash_table_t *hash, } pkg_t * -pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, - const char *pkg_name, pkg_dest_t *dest) +pkg_hash_fetch_installed_by_name_dest(const char *pkg_name, pkg_dest_t *dest) { pkg_vec_t * vec; int i; - if (!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) { + if (!(vec = pkg_vec_fetch_by_name(pkg_name))) { return NULL; } @@ -460,13 +432,12 @@ pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, } pkg_t * -pkg_hash_fetch_installed_by_name(hash_table_t *hash, - const char *pkg_name) +pkg_hash_fetch_installed_by_name(const char *pkg_name) { pkg_vec_t * vec; int i; - if (!(vec = pkg_vec_fetch_by_name(hash, pkg_name))) { + if (!(vec = pkg_vec_fetch_by_name(pkg_name))) { return NULL; } @@ -499,9 +470,10 @@ pkg_hash_fetch_available_helper(const char *pkg_name, void *entry, void *data) } void -pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *all) +pkg_hash_fetch_available(pkg_vec_t *all) { - hash_table_foreach(hash, pkg_hash_fetch_available_helper, all); + hash_table_foreach(&conf->pkg_hash, pkg_hash_fetch_available_helper, + all); } static void @@ -524,93 +496,81 @@ pkg_hash_fetch_all_installed_helper(const char *pkg_name, void *entry, void *dat } void -pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *all) +pkg_hash_fetch_all_installed(pkg_vec_t *all) { - hash_table_foreach(hash, pkg_hash_fetch_all_installed_helper, all); + hash_table_foreach(&conf->pkg_hash, pkg_hash_fetch_all_installed_helper, + all); } /* * This assumes that the abstract pkg doesn't exist. */ static abstract_pkg_t * -add_new_abstract_pkg_by_name(hash_table_t *hash, const char *pkg_name) +add_new_abstract_pkg_by_name(const char *pkg_name) { abstract_pkg_t *ab_pkg; ab_pkg = abstract_pkg_new(); ab_pkg->name = xstrdup(pkg_name); - hash_table_insert(hash, pkg_name, ab_pkg); + hash_table_insert(&conf->pkg_hash, pkg_name, ab_pkg); return ab_pkg; } abstract_pkg_t * -ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name) +ensure_abstract_pkg_by_name(const char *pkg_name) { abstract_pkg_t * ab_pkg; - if (!(ab_pkg = abstract_pkg_fetch_by_name(hash, pkg_name))) - ab_pkg = add_new_abstract_pkg_by_name(hash, pkg_name); + if (!(ab_pkg = abstract_pkg_fetch_by_name(pkg_name))) + ab_pkg = add_new_abstract_pkg_by_name(pkg_name); return ab_pkg; } -pkg_t * -hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status, - opkg_conf_t *conf) +void +hash_insert_pkg(pkg_t *pkg, int set_status) { abstract_pkg_t * ab_pkg; - if(!pkg) - return pkg; - - buildDepends(hash, pkg); - - ab_pkg = ensure_abstract_pkg_by_name(hash, pkg->name); + ab_pkg = ensure_abstract_pkg_by_name(pkg->name); + if (!ab_pkg->pkgs) + ab_pkg->pkgs = pkg_vec_alloc(); - if (set_status) { - if (pkg->state_status == SS_INSTALLED) { - ab_pkg->state_status = SS_INSTALLED; - } else if (pkg->state_status == SS_UNPACKED) { - ab_pkg->state_status = SS_UNPACKED; - } + if (pkg->state_status == SS_INSTALLED) { + ab_pkg->state_status = SS_INSTALLED; + } else if (pkg->state_status == SS_UNPACKED) { + ab_pkg->state_status = SS_UNPACKED; } - if(!ab_pkg->pkgs) - ab_pkg->pkgs = pkg_vec_alloc(); + buildDepends(pkg); - buildProvides(hash, ab_pkg, pkg); + buildProvides(ab_pkg, pkg); /* Need to build the conflicts graph before replaces for correct * calculation of replaced_by relation. */ - buildConflicts(hash, ab_pkg, pkg); + buildConflicts(pkg); - buildReplaces(hash, ab_pkg, pkg); + buildReplaces(ab_pkg, pkg); buildDependedUponBy(pkg, ab_pkg); - /* pkg_vec_insert_merge might munge package, but it returns an - * unmunged pkg. - */ - pkg = pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status,conf ); + pkg_vec_insert_merge(ab_pkg->pkgs, pkg, set_status); pkg->parent = ab_pkg; - - return pkg; } pkg_t * -file_hash_get_file_owner(opkg_conf_t *conf, const char *file_name) +file_hash_get_file_owner(const char *file_name) { return hash_table_get(&conf->file_hash, file_name); } void -file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, - pkg_t *owning_pkg) +file_hash_set_file_owner(const char *file_name, pkg_t *owning_pkg) { pkg_t *old_owning_pkg = hash_table_get(&conf->file_hash, file_name); int file_name_len = strlen(file_name); @@ -619,7 +579,7 @@ file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, return; if (conf->offline_root) { - int len = strlen(conf->offline_root); + unsigned int len = strlen(conf->offline_root); if (strncmp(file_name, conf->offline_root, len) == 0) { file_name += len; } @@ -628,7 +588,7 @@ file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, hash_table_insert(&conf->file_hash, file_name, owning_pkg); if (old_owning_pkg) { - pkg_get_installed_files(conf, old_owning_pkg); + pkg_get_installed_files(old_owning_pkg); str_list_remove_elt(old_owning_pkg->installed_files, file_name); pkg_free_installed_files(old_owning_pkg); diff --git a/libopkg/pkg_hash.h b/libopkg/pkg_hash.h index 1c6db86..67134d2 100644 --- a/libopkg/pkg_hash.h +++ b/libopkg/pkg_hash.h @@ -25,32 +25,28 @@ #include "hash_table.h" -void pkg_hash_init(const char *name, hash_table_t *hash, int len); -void pkg_hash_deinit(hash_table_t *hash); -void pkg_hash_map(hash_table_t *hash, void (*f)(void *data, void *entry), void *data); +void pkg_hash_init(void); +void pkg_hash_deinit(void); -void pkg_hash_fetch_available(hash_table_t *hash, pkg_vec_t *available); +void pkg_hash_fetch_available(pkg_vec_t *available); -int pkg_hash_add_from_file(opkg_conf_t *conf, const char *file_name, - pkg_src_t *src, pkg_dest_t *dest, int is_status_file); -pkg_t *hash_insert_pkg(hash_table_t *hash, pkg_t *pkg, int set_status,opkg_conf_t *conf); +int pkg_hash_add_from_file(const char *file_name, pkg_src_t *src, + pkg_dest_t *dest, int is_status_file); +void hash_insert_pkg(pkg_t *pkg, int set_status); -abstract_pkg_t * ensure_abstract_pkg_by_name(hash_table_t * hash, const char * pkg_name); -void pkg_hash_fetch_all_installed(hash_table_t *hash, pkg_vec_t *installed); -pkg_t * pkg_hash_fetch_by_name_version(hash_table_t *hash, - const char *pkg_name, +abstract_pkg_t * ensure_abstract_pkg_by_name(const char * pkg_name); +void pkg_hash_fetch_all_installed(pkg_vec_t *installed); +pkg_t * pkg_hash_fetch_by_name_version(const char *pkg_name, const char * version); -pkg_t *pkg_hash_fetch_best_installation_candidate(opkg_conf_t *conf, abstract_pkg_t *apkg, +pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t *apkg, int (*constraint_fcn)(pkg_t *pkg, void *data), void *cdata, int quiet); -pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(opkg_conf_t *conf, const char *name); -pkg_t *pkg_hash_fetch_installed_by_name(hash_table_t *hash, - const char *pkg_name); -pkg_t *pkg_hash_fetch_installed_by_name_dest(hash_table_t *hash, - const char *pkg_name, +pkg_t *pkg_hash_fetch_best_installation_candidate_by_name(const char *name); +pkg_t *pkg_hash_fetch_installed_by_name(const char *pkg_name); +pkg_t *pkg_hash_fetch_installed_by_name_dest(const char *pkg_name, pkg_dest_t *dest); -pkg_t *file_hash_get_file_owner(opkg_conf_t *conf, const char *file_name); -void file_hash_set_file_owner(opkg_conf_t *conf, const char *file_name, pkg_t *pkg); +pkg_t *file_hash_get_file_owner(const char *file_name); +void file_hash_set_file_owner(const char *file_name, pkg_t *pkg); #endif diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c index e0de41f..0c884fa 100644 --- a/libopkg/pkg_parse.c +++ b/libopkg/pkg_parse.c @@ -25,7 +25,7 @@ #include "libbb/libbb.h" static int -is_field(char *type, const char *line) +is_field(const char *type, const char *line) { if (!strncmp(line, type, strlen(type))) return 1; @@ -33,7 +33,7 @@ is_field(char *type, const char *line) } static char * -parse_simple(char *type, const char *line) +parse_simple(const char *type, const char *line) { return trim_xstrdup(line + strlen(type) + 1); } @@ -42,7 +42,7 @@ parse_simple(char *type, const char *line) * Parse a comma separated string into an array. */ static char ** -parse_comma_separated(const char *raw, int *count) +parse_comma_separated(const char *raw, unsigned int *count) { char **depends = NULL; const char *start, *end; @@ -90,8 +90,8 @@ parse_status(pkg_t *pkg, const char *sstr) if (sscanf(sstr, "Status: %63s %63s %63s", sw_str, sf_str, ss_str) != 3) { - fprintf(stderr, "%s: failed to parse Status line for %s\n", - __FUNCTION__, pkg->name); + opkg_msg(ERROR, "Failed to parse Status line for %s\n", + pkg->name); return; } @@ -106,8 +106,8 @@ parse_conffiles(pkg_t *pkg, const char *cstr) char file_name[1024], md5sum[35]; if (sscanf(cstr, "%1023s %34s", file_name, md5sum) != 2) { - fprintf(stderr, "%s: failed to parse Conffiles line for %s\n", - __FUNCTION__, pkg->name); + opkg_msg(ERROR, "Failed to parse Conffiles line for %s\n", + pkg->name); return; } @@ -130,8 +130,7 @@ parse_version(pkg_t *pkg, const char *vstr) errno = 0; pkg->epoch = strtoul(vstr, NULL, 10); if (errno) { - fprintf(stderr, "%s: %s: invalid epoch: %s\n", - __FUNCTION__, pkg->name, strerror(errno)); + opkg_perror(ERROR, "%s: invalid epoch", pkg->name); } vstr = ++colon; } else { @@ -154,6 +153,12 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask) static int reading_conffiles = 0, reading_description = 0; int ret = 0; + /* Exclude globally masked fields. */ + mask |= conf->pfm; + + /* Flip the semantics of the mask. */ + mask ^= PFM_ALL; + switch (*line) { case 'A': if ((mask & PFM_ARCHITECTURE ) && is_field("Architecture", line)) @@ -201,9 +206,11 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask) break; case 'I': - if ((mask && PFM_INSTALLED_SIZE) && is_field("Installed-Size", line)) - pkg->installed_size = parse_simple("Installed-Size", line); - else if ((mask && PFM_INSTALLED_TIME) && is_field("Installed-Time", line)) { + if ((mask && PFM_INSTALLED_SIZE) && is_field("Installed-Size", line)) { + char *tmp = parse_simple("Installed-Size", line); + pkg->installed_size = strtoul(tmp, NULL, 0); + free (tmp); + } else if ((mask && PFM_INSTALLED_TIME) && is_field("Installed-Time", line)) { char *tmp = parse_simple("Installed-Time", line); pkg->installed_time = strtoul(tmp, NULL, 0); free (tmp); @@ -248,9 +255,11 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask) else if ((mask & PFM_SHA256SUM) && is_field("SHA256sum", line)) pkg->sha256sum = parse_simple("SHA256sum", line); #endif - else if ((mask & PFM_SIZE) && is_field("Size", line)) - pkg->size = parse_simple("Size", line); - else if ((mask & PFM_SOURCE) && is_field("Source", line)) + else if ((mask & PFM_SIZE) && is_field("Size", line)) { + char *tmp = parse_simple("Size", line); + pkg->size = strtoul(tmp, NULL, 0); + free (tmp); + } else if ((mask & PFM_SOURCE) && is_field("Source", line)) pkg->source = parse_simple("Source", line); else if ((mask & PFM_STATUS) && is_field("Status", line)) parse_status(pkg, line); @@ -314,15 +323,13 @@ pkg_parse_from_stream_nomalloc(pkg_t *pkg, FILE *fp, uint mask, buf[0] = '\0'; while (1) { - if (fgets(buf, buflen, fp) == NULL) { + if (fgets(buf, (int)buflen, fp) == NULL) { if (ferror(fp)) { - fprintf(stderr, "%s: fgets: %s\n", - __FUNCTION__, strerror(errno)); + opkg_perror(ERROR, "fgets"); ret = -1; } else if (strlen(*buf0) == buf0len-1) { - fprintf(stderr, "%s: missing new line character" - " at end of file!\n", - __FUNCTION__); + opkg_msg(ERROR, "Missing new line character" + " at end of file!\n"); pkg_parse_line(pkg, *buf0, mask); } break; @@ -336,16 +343,15 @@ pkg_parse_from_stream_nomalloc(pkg_t *pkg, FILE *fp, uint mask, * missing a newline, but we won't know until * fgets fails to read more data. */ - fprintf(stderr, "%s: missing new line character" - " at end of file!\n", - __FUNCTION__); + opkg_msg(ERROR, "Missing new line character" + " at end of file!\n"); pkg_parse_line(pkg, *buf0, mask); break; } if (buf0len >= EXCESSIVE_LINE_LEN) { - fprintf(stderr, "%s: excessively long line at " + opkg_msg(ERROR, "Excessively long line at " "%d. Corrupt file?\n", - __FUNCTION__, lineno); + lineno); ret = -1; break; } @@ -380,7 +386,7 @@ pkg_parse_from_stream_nomalloc(pkg_t *pkg, FILE *fp, uint mask, if (pkg->name == NULL) { /* probably just a blank line */ - ret = EINVAL; + ret = 1; } return ret; diff --git a/libopkg/pkg_vec.c b/libopkg/pkg_vec.c index 9e4f26b..51b9bda 100644 --- a/libopkg/pkg_vec.c +++ b/libopkg/pkg_vec.c @@ -48,54 +48,48 @@ void pkg_vec_free(pkg_vec_t *vec) * so identical versions have identical version strings, * implying identical packages; let's marry these */ -pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,opkg_conf_t *conf) +void pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status) { int i; int found = 0; /* look for a duplicate pkg by name, version, and architecture */ for (i = 0; i < vec->len; i++){ - opkg_message(conf, OPKG_DEBUG2, "Function: %s. Found pkg=%s version=%s arch=%s cmp=%s version=%s arch=%s \n", - __FUNCTION__, pkg->name, pkg->version, pkg->architecture, - vec->pkgs[i]->name, vec->pkgs[i]->version,vec->pkgs[i]->architecture ); + opkg_msg(DEBUG2, "%s %s arch=%s vs. %s %s arch=%s.\n", + pkg->name, pkg->version, pkg->architecture, + vec->pkgs[i]->name, vec->pkgs[i]->version, + vec->pkgs[i]->architecture); if ((strcmp(pkg->name, vec->pkgs[i]->name) == 0) && (pkg_compare_versions(pkg, vec->pkgs[i]) == 0) && (strcmp(pkg->architecture, vec->pkgs[i]->architecture) == 0)) { found = 1; - opkg_message(conf, OPKG_DEBUG2, "Function: %s. Found duplicate for pkg=%s version=%s arch=%s\n", - __FUNCTION__, pkg->name, pkg->version, pkg->architecture); + opkg_msg(DEBUG2, "Duplicate for pkg=%s version=%s arch=%s.\n", + pkg->name, pkg->version, pkg->architecture); break; } } /* we didn't find one, add it */ if (!found){ - opkg_message(conf, OPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n", - __FUNCTION__, pkg->name, pkg->version, pkg->architecture); + opkg_msg(DEBUG2, "Adding new pkg=%s version=%s arch=%s.\n", + pkg->name, pkg->version, pkg->architecture); pkg_vec_insert(vec, pkg); - return pkg; + return; } + /* update the one that we have */ - else { - opkg_message(conf, OPKG_DEBUG2, "Function: %s. calling pkg_merge for pkg=%s version=%s arch=%s", - __FUNCTION__, pkg->name, pkg->version, pkg->architecture); - if (set_status) { - /* this is from the status file, so need to merge with existing database */ - opkg_message(conf, OPKG_DEBUG2, " with set_status\n"); - pkg_merge(vec->pkgs[i], pkg, set_status); - /* XXX: CLEANUP: It's not so polite to free something here - that was passed in from above. */ - pkg_deinit(pkg); - free(pkg); - } else { - opkg_message(conf, OPKG_DEBUG2, " WITHOUT set_status\n"); - /* just overwrite the old one */ - pkg_deinit(vec->pkgs[i]); - free(vec->pkgs[i]); - vec->pkgs[i] = pkg; - } - return vec->pkgs[i]; + opkg_msg(DEBUG2, "Merging %s %s arch=%s, set_status=%d.\n", + pkg->name, pkg->version, pkg->architecture, set_status); + if (set_status) { + /* This is from the status file, + * so need to merge with existing database */ + pkg_merge(pkg, vec->pkgs[i]); } + + /* overwrite the old one */ + pkg_deinit(vec->pkgs[i]); + free(vec->pkgs[i]); + vec->pkgs[i] = pkg; } void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg) diff --git a/libopkg/pkg_vec.h b/libopkg/pkg_vec.h index 0f9aac6..0b5d82b 100644 --- a/libopkg/pkg_vec.h +++ b/libopkg/pkg_vec.h @@ -28,24 +28,20 @@ typedef struct abstract_pkg_vec abstract_pkg_vec_t; struct pkg_vec { pkg_t **pkgs; - int len; + unsigned int len; }; struct abstract_pkg_vec { abstract_pkg_t **pkgs; - int len; + unsigned int len; }; pkg_vec_t * pkg_vec_alloc(void); void pkg_vec_free(pkg_vec_t *vec); -void marry_two_packages(pkg_t * newpkg, pkg_t * oldpkg); -/* pkg_vec_insert_merge: might munge pkg. -* returns the pkg that is in the pkg graph */ -pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status, opkg_conf_t *conf); -/* this one never munges pkg */ +void pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status); void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg); int pkg_vec_contains(pkg_vec_t *vec, pkg_t *apkg); diff --git a/libopkg/sprintf_alloc.c b/libopkg/sprintf_alloc.c index 7989493..2e3200b 100644 --- a/libopkg/sprintf_alloc.c +++ b/libopkg/sprintf_alloc.c @@ -24,14 +24,15 @@ int sprintf_alloc(char **str, const char *fmt, ...) { va_list ap; - int n, size = 100; + int n; + unsigned size = 100; if (!str) { - fprintf(stderr, "Null string pointer passed to sprintf_alloc\n"); + opkg_msg(ERROR, "Internal error: str=NULL.\n"); return -1; } if (!fmt) { - fprintf(stderr, "Null fmt string passed to sprintf_alloc\n"); + opkg_msg(ERROR, "Internal error: fmt=NULL.\n"); return -1; } diff --git a/libopkg/user.c b/libopkg/user.c deleted file mode 100644 index ee54eb6..0000000 --- a/libopkg/user.c +++ /dev/null @@ -1,46 +0,0 @@ -/* user.c - the opkg package management system - - Jamey Hicks - - Copyright (C) 2002 Hewlett Packard Company - Copyright (C) 2001 University of Southern California - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. -*/ -#include -#include -#include -#include - -#include "file_util.h" - -char *get_user_response(const char *format, ...) -{ - int i; - va_list ap; - char *response; - - va_start(ap, format); - vprintf(format, ap); - va_end(ap); - - if (!isatty(fileno(stdin))) - return NULL; - - response = (char *)file_read_line_alloc(stdin); - if (response == NULL) - return NULL; - - for (i=0; response[i]; i++) - response[i] = tolower(response[i]); - - return response; -} diff --git a/libopkg/user.h b/libopkg/user.h deleted file mode 100644 index 81d7262..0000000 --- a/libopkg/user.h +++ /dev/null @@ -1,23 +0,0 @@ -/* user.c - the opkg package management system - - Jamey Hicks - - Copyright (C) 2002 Hewlett Packard Company - Copyright (C) 2001 University of Southern California - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License as - published by the Free Software Foundation; either version 2, or (at - your option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. -*/ - -#include -#include - -char *get_user_response(const char *format, ...); - diff --git a/libopkg/void_list.c b/libopkg/void_list.c index f2b5890..04066bf 100644 --- a/libopkg/void_list.c +++ b/libopkg/void_list.c @@ -26,7 +26,7 @@ void void_list_elt_init(void_list_elt_t *elt, void *data) elt->data = data; } -void_list_elt_t * void_list_elt_new (void *data) { +static void_list_elt_t * void_list_elt_new (void *data) { void_list_elt_t *elt; /* freed in void_list_elt_deinit */ elt = xcalloc(1, sizeof(void_list_elt_t)); @@ -96,7 +96,7 @@ void *void_list_remove(void_list_t *list, void_list_elt_t **iter) break; } if ( pos != old_elt) { - fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__); + opkg_msg(ERROR, "Internal error: element not found in list.\n"); return NULL; } diff --git a/libopkg/xregex.c b/libopkg/xregex.c index ba22b7d..639e3ef 100644 --- a/libopkg/xregex.c +++ b/libopkg/xregex.c @@ -35,13 +35,14 @@ int xregcomp(regex_t *preg, const char *regex, int cflags) static void print_regcomp_err(const regex_t *preg, int err) { - int size; + unsigned int size; char *error; - fprintf(stderr, "%s: Error compiling regex:", __FUNCTION__); size = regerror(err, preg, 0, 0); error = xcalloc(1, size); regerror(err, preg, error, size); - fprintf(stderr, "%s\n", error); + + opkg_msg(ERROR, "Internal error compiling regex: %s.", error); + free(error); } diff --git a/libopkg/xsystem.c b/libopkg/xsystem.c index 123510f..fc7db69 100644 --- a/libopkg/xsystem.c +++ b/libopkg/xsystem.c @@ -39,7 +39,7 @@ xsystem(const char *argv[]) switch (pid) { case -1: - perror_msg("%s: %s: vfork", __FUNCTION__, argv[0]); + opkg_perror(ERROR, "%s: vfork", argv[0]); return -1; case 0: /* child */ @@ -51,20 +51,20 @@ xsystem(const char *argv[]) } if (waitpid(pid, &status, 0) == -1) { - perror_msg("%s: %s: waitpid", __FUNCTION__, argv[0]); + opkg_perror(ERROR, "%s: waitpid", argv[0]); return -1; } if (WIFSIGNALED(status)) { - error_msg("%s: %s: Child killed by signal %d\n", - __FUNCTION__, argv[0], WTERMSIG(status)); + opkg_msg(ERROR, "%s: Child killed by signal %d.\n", + argv[0], WTERMSIG(status)); return -1; } if (!WIFEXITED(status)) { /* shouldn't happen */ - error_msg("%s: %s: Your system is broken: got status %d " - "from waitpid\n", __FUNCTION__, argv[0], status); + opkg_msg(ERROR, "%s: Your system is broken: got status %d " + "from waitpid.\n", argv[0], status); return -1; } diff --git a/tests/libopkg_test.c b/tests/libopkg_test.c index bee3968..42ef900 100644 --- a/tests/libopkg_test.c +++ b/tests/libopkg_test.c @@ -22,14 +22,14 @@ char *errors[10] = { #define TEST_PACKAGE "aspell" void -progress_callback (opkg_t *opkg, const opkg_progress_data_t *progress, void *data) +progress_callback (const opkg_progress_data_t *progress, void *data) { printf ("\r%s %3d%%", (char*) data, progress->percentage); fflush (stdout); } void -package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data) +package_list_callback (opkg_package_t *pkg, void *data) { static install_count = 0; static total_count = 0; @@ -52,7 +52,7 @@ package_list_callback (opkg_t *opkg, opkg_package_t *pkg, void *data) } void -package_list_upgradable_callback (opkg_t *opkg, opkg_package_t *pkg, void *data) +package_list_upgradable_callback (opkg_package_t *pkg, void *data) { printf ("%s - %s\n", pkg->name, pkg->version); opkg_package_free (pkg); @@ -68,7 +68,6 @@ print_package (opkg_package_t *pkg) "Architecture: %s\n" "Description: %s\n" "Tags: %s\n" - "URL: %s\n" "Size: %d\n" "Installed: %s\n", pkg->name, @@ -77,7 +76,6 @@ print_package (opkg_package_t *pkg) pkg->architecture, pkg->description, pkg->tags, - pkg->url, pkg->size, (pkg->installed ? "True" : "False") ); @@ -85,21 +83,21 @@ print_package (opkg_package_t *pkg) void -opkg_test (opkg_t *opkg) +opkg_test (void) { int err; opkg_package_t *pkg; - err = opkg_update_package_lists (opkg, progress_callback, "Updating..."); + err = opkg_update_package_lists (progress_callback, "Updating..."); printf ("\nopkg_update_package_lists returned %d (%s)\n", err, errors[err]); - opkg_list_packages (opkg, package_list_callback, NULL); + opkg_list_packages (package_list_callback, NULL); printf ("\n"); if (find_pkg) { printf ("Finding package \"%s\"\n", find_pkg->name); - pkg = opkg_find_package (opkg, find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository); + pkg = opkg_find_package (find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository); if (pkg) { print_package (pkg); @@ -112,19 +110,19 @@ opkg_test (opkg_t *opkg) else printf ("No package available to test find_package.\n"); - err = opkg_install_package (opkg, TEST_PACKAGE, progress_callback, "Installing..."); + err = opkg_install_package (TEST_PACKAGE, progress_callback, "Installing..."); printf ("\nopkg_install_package returned %d (%s)\n", err, errors[err]); - err = opkg_upgrade_package (opkg, TEST_PACKAGE, progress_callback, "Upgrading..."); + err = opkg_upgrade_package (TEST_PACKAGE, progress_callback, "Upgrading..."); printf ("\nopkg_upgrade_package returned %d (%s)\n", err, errors[err]); - err = opkg_remove_package (opkg, TEST_PACKAGE, progress_callback, "Removing..."); + err = opkg_remove_package (TEST_PACKAGE, progress_callback, "Removing..."); printf ("\nopkg_remove_package returned %d (%s)\n", err, errors[err]); printf ("Listing upgradable packages...\n"); - opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL); + opkg_list_upgradable_packages (package_list_upgradable_callback, NULL); - err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all..."); + err = opkg_upgrade_all (progress_callback, "Upgrading all..."); printf ("\nopkg_upgrade_all returned %d (%s)\n", err, errors[err]); } @@ -132,7 +130,6 @@ opkg_test (opkg_t *opkg) int main (int argc, char **argv) { - opkg_t *opkg; opkg_package_t *pkg; int err; @@ -154,16 +151,16 @@ main (int argc, char **argv) exit (0); } - opkg = opkg_new (); + opkg_new (); - opkg_set_option (opkg, "offline_root", "/tmp/"); + opkg_set_option ("offline_root", "/tmp/"); - opkg_re_read_config_files (opkg); + opkg_re_read_config_files (); switch (argv[1][0]) { case 'f': - pkg = opkg_find_package (opkg, argv[2], NULL, NULL, NULL); + pkg = opkg_find_package (argv[2], NULL, NULL, NULL); if (pkg) { print_package (pkg); @@ -174,7 +171,7 @@ main (int argc, char **argv) opkg_package_free (pkg); break; case 'i': - err = opkg_install_package (opkg, argv[1], progress_callback, "Installing..."); + err = opkg_install_package (argv[1], progress_callback, "Installing..."); printf ("\nopkg_install_package returned %d (%s)\n", err, errors[err]); break; @@ -183,7 +180,7 @@ main (int argc, char **argv) printf (""); if (argv[1][3] == 'd') { - err = opkg_update_package_lists (opkg, progress_callback, "Updating..."); + err = opkg_update_package_lists (progress_callback, "Updating..."); printf ("\nopkg_update_package_lists returned %d (%s)\n", err, errors[err]); break; } @@ -191,12 +188,12 @@ main (int argc, char **argv) { if (argc < 3) { - err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all..."); + err = opkg_upgrade_all (progress_callback, "Upgrading all..."); printf ("\nopkg_upgrade_all returned %d (%s)\n", err, errors[err]); } else { - err = opkg_upgrade_package (opkg, argv[2], progress_callback, "Upgrading..."); + err = opkg_upgrade_package (argv[2], progress_callback, "Upgrading..."); printf ("\nopkg_upgrade_package returned %d (%s)\n", err, errors[err]); } } @@ -213,11 +210,11 @@ main (int argc, char **argv) { case 'u': printf ("Listing upgradable packages...\n"); - opkg_list_upgradable_packages (opkg, package_list_upgradable_callback, NULL); + opkg_list_upgradable_packages (package_list_upgradable_callback, NULL); break; case 'a': printf ("Listing all packages...\n"); - opkg_list_packages (opkg, package_list_callback, NULL); + opkg_list_packages (package_list_callback, NULL); printf ("\n"); break; case 'i': @@ -232,12 +229,12 @@ main (int argc, char **argv) case 'r': if (argv[1][1] == 'e') { - err = opkg_remove_package (opkg, argv[2], progress_callback, "Removing..."); + err = opkg_remove_package (argv[2], progress_callback, "Removing..."); printf ("\nopkg_remove_package returned %d (%s)\n", err, errors[err]); break; }else if (argv[1][1] == 'p') { - err = opkg_repository_accessibility_check(opkg); + err = opkg_repository_accessibility_check(); printf("\nopkg_repository_accessibility_check returned (%d)\n", err); break; } @@ -247,7 +244,7 @@ main (int argc, char **argv) } - opkg_free (opkg); + opkg_free (); return 0; }