diff options
author | Aaron Griffin <aaron@archlinux.org> | 2007-01-31 06:10:21 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2007-01-31 06:10:21 +0000 |
commit | 670319c2fb41f5ce5b446ad52bf2d8ddcf8c1548 (patch) | |
tree | 61fd4b3e50f695aa6887b39958f902dcf2708037 /src | |
parent | f4340129d59377b32a7be64e09f71cb8faa3ac07 (diff) | |
download | pacman-670319c2fb41f5ce5b446ad52bf2d8ddcf8c1548.tar.xz |
Debug logging changes:
* The --debug params were goofy. New setup allows --debug without params,
--debug=<level> where level 1=debug output, 2=debug and download output,
3=debug, download, and function tracing output. This seems more sane to me.
* Removed PM_LOG_FLOW1 and PM_LOG_FLOW2. They were just confusing. When adding
new functions, it is near impossible to determin if your output should be
"flow1" or "flow2" without tracking all the way up the call chain. Rarely
would one ever say "ok, lets just show "flow2" output. These have both been
replaced with PM_LOG_DEBUG
* Removed the need for the root parameter on alpm_initialize. it is now
defaulted to PM_ROOT just like dbpath and cachedir. This allows alpm to be
initialized BEFORE option parsing in the front end, saving us some duplicate
variables in the frontend.
* Cleaned up front end variables due to early alpm_initialize call.
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/add.c | 6 | ||||
-rw-r--r-- | src/pacman/conf.c | 3 | ||||
-rw-r--r-- | src/pacman/conf.h | 5 | ||||
-rw-r--r-- | src/pacman/deptest.c | 2 | ||||
-rw-r--r-- | src/pacman/log.c | 11 | ||||
-rw-r--r-- | src/pacman/pacman.c | 72 | ||||
-rw-r--r-- | src/pacman/query.c | 2 | ||||
-rw-r--r-- | src/pacman/remove.c | 2 | ||||
-rw-r--r-- | src/pacman/sync.c | 4 |
9 files changed, 52 insertions, 55 deletions
diff --git a/src/pacman/add.c b/src/pacman/add.c index 111ea9de..6572b8fc 100644 --- a/src/pacman/add.c +++ b/src/pacman/add.c @@ -67,7 +67,7 @@ int pacman_add(alpm_list_t *targets) ERR(NL, "%s\n", alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } @@ -124,7 +124,7 @@ int pacman_add(alpm_list_t *targets) switch(alpm_conflict_get_type(conflict)) { case PM_CONFLICT_TYPE_TARGET: MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), - config->root, + alpm_option_get_root(), alpm_conflict_get_file(conflict), alpm_conflict_get_target(conflict), alpm_conflict_get_ctarget(conflict)); @@ -132,7 +132,7 @@ int pacman_add(alpm_list_t *targets) case PM_CONFLICT_TYPE_FILE: MSG(NL, _("%s: %s%s exists in filesystem"), alpm_conflict_get_target(conflict), - config->root, + alpm_option_get_root(), alpm_conflict_get_file(conflict)); break; } diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 185372e0..4c0381cf 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -26,7 +26,6 @@ #include <libintl.h> #include <alpm.h> -#include <alpm_list.h> /* pacman */ #include "util.h" #include "log.h" @@ -51,9 +50,7 @@ int config_free(config_t *config) return(-1); } - FREE(config->root); FREE(config->configfile); - FREELIST(config->op_s_ignore); free(config); return(0); diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 65e0f23e..ddd20ffc 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -25,9 +25,6 @@ typedef struct __config_t { /* command line options */ - char *root; - const char *dbpath; - const char *cachedir; char *configfile; unsigned short op; unsigned short verbose; @@ -49,14 +46,12 @@ typedef struct __config_t { unsigned short op_s_clean; unsigned short op_s_dependsonly; unsigned short op_s_downloadonly; - alpm_list_t *op_s_ignore; unsigned short op_s_info; unsigned short op_s_sync; unsigned short op_s_search; unsigned short op_s_upgrade; unsigned short group; unsigned int flags; - unsigned short debug; unsigned short noask; unsigned int ask; } config_t; diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index e37f4791..c04ecb0c 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -67,7 +67,7 @@ int pacman_deptest(alpm_list_t *targets) ERR(NL, "%s", alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } diff --git a/src/pacman/log.c b/src/pacman/log.c index d4db9848..ccdd9a66 100644 --- a/src/pacman/log.c +++ b/src/pacman/log.c @@ -66,13 +66,10 @@ void cb_log(unsigned short level, char *msg) case PM_LOG_WARNING: sprintf(str, _("warning")); break; - case PM_LOG_FLOW1: - sprintf(str, _("flow1")); - break; - case PM_LOG_FLOW2: - sprintf(str, _("flow2")); - break; case PM_LOG_FUNCTION: + /* TODO we should increase the indent level when this occurs so we can see + * program flow easier. It'll be fun + */ sprintf(str, _("function")); break; default: @@ -82,7 +79,7 @@ void cb_log(unsigned short level, char *msg) #ifdef PACMAN_DEBUG /* If debug is on, we'll timestamp the output */ - if(config->debug&PM_LOG_DEBUG) { + if(alpm_option_get_logmask() & PM_LOG_DEBUG) { time_t t; struct tm *tmp; char timestr[10] = {0}; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 808d8ad1..7f6f4192 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -251,7 +251,7 @@ static int parseargs(int argc, char *argv[]) {"noconfirm", no_argument, 0, 1000}, {"config", required_argument, 0, 1001}, {"ignore", required_argument, 0, 1002}, - {"debug", required_argument, 0, 1003}, + {"debug", optional_argument, 0, 1003}, {"noprogressbar", no_argument, 0, 1004}, {"noscriptlet", no_argument, 0, 1005}, {"ask", required_argument, 0, 1006}, @@ -259,6 +259,7 @@ static int parseargs(int argc, char *argv[]) }; char root[PATH_MAX]; struct stat st; + unsigned short logmask; while((opt = getopt_long(argc, argv, "ARUFQSTDYr:b:vkhscVfmnoldepiuwyg", opts, &option_index))) { if(opt < 0) { @@ -277,8 +278,32 @@ static int parseargs(int argc, char *argv[]) config->configfile = strndup(optarg, PATH_MAX); #endif break; - case 1002: config->op_s_ignore = alpm_list_add(config->op_s_ignore, strdup(optarg)); break; - case 1003: config->debug = atoi(optarg); break; + case 1002: alpm_option_add_ignorepkg(strdup(optarg)); break; + case 1003: + /* debug levels are made more 'human readable' than using a raw logmask + * here, we will ALWAYS set error and warning for now, though perhaps a + * --quiet option will remove these later */ + logmask = PM_LOG_ERROR | PM_LOG_WARNING; + + if(optarg) { + unsigned short debug = atoi(optarg); + printf("setting logmask to %s\n", optarg); + switch(debug) { + case 3: logmask |= PM_LOG_FUNCTION; /* fall through */ + case 2: logmask |= PM_LOG_DOWNLOAD; /*fall through */ + case 1: logmask |= PM_LOG_DEBUG; break; + default: + pm_fprintf(stderr, NL, _("error: '%s' is not a valid debug level"), optarg); + return(1); + } + printf("logmask = %d\n", logmask); + } else { + logmask |= PM_LOG_DEBUG; + } + /* progress bars get wonky with debug on, shut them off */ + config->noprogressbar = 1; + alpm_option_set_logmask(logmask); + break; case 1004: config->noprogressbar = 1; break; case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break; case 1006: config->noask = 1; config->ask = atoi(optarg); break; @@ -305,10 +330,9 @@ static int parseargs(int argc, char *argv[]) case 'b': if(stat(optarg, &st) == -1 || !S_ISDIR(st.st_mode)) { pm_fprintf(stderr, NL, _("error: '%s' is not a valid db path\n"), optarg); - exit(EXIT_FAILURE); + return(1); } alpm_option_set_dbpath(optarg); - config->dbpath = alpm_option_get_dbpath(optarg); break; case 'c': (config->op_s_clean)++; @@ -334,12 +358,11 @@ static int parseargs(int argc, char *argv[]) config->flags |= PM_TRANS_FLAG_PRINTURIS; break; case 'r': - printf("setting root path=%s\n", optarg); if(realpath(optarg, root) == NULL) { - perror(_("bad root path")); + pm_fprintf(stderr, NL, _("error: '%s' is not a valid root path\n"), optarg); return(1); } - config->root = strdup(root); + alpm_option_set_root(strdup(root)); break; case 's': config->op_s_search = 1; @@ -416,13 +439,17 @@ int main(int argc, char *argv[]) /* init config data */ config = config_new(); config->op = PM_OP_MAIN; - config->debug |= PM_LOG_ERROR; - config->debug |= PM_LOG_WARNING; /* disable progressbar if the output is redirected */ if(!isatty(1)) { config->noprogressbar = 1; } + /* initialize pm library */ + if(alpm_initialize() == -1) { + ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno)); + cleanup(1); + } + /* parse the command line */ ret = parseargs(argc, argv); if(ret != 0) { @@ -447,7 +474,7 @@ int main(int argc, char *argv[]) (config->op_s_search || config->group || config->op_q_list || config->op_q_info || config->flags & PM_TRANS_FLAG_PRINTURIS)) || (config->op == PM_OP_DEPTEST && !config->op_d_resolve) - || (config->root != NULL)) { + || (strcmp(alpm_option_get_root(), PM_ROOT) != 0)) { /* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */ /* special case: ignore root user check if -r is specified, fall back on * normal FS checking */ @@ -460,18 +487,7 @@ int main(int argc, char *argv[]) } #endif - if(config->root == NULL) { - config->root = strdup(PM_ROOT); - } - - /* initialize pm library */ - if(alpm_initialize(config->root) == -1) { - ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno)); - cleanup(1); - } - /* Setup logging as soon as possible, to print out maximum debugging info */ - alpm_option_set_logmask(config->debug); alpm_option_set_logcb(cb_log); if(config->configfile == NULL) { @@ -486,17 +502,9 @@ int main(int argc, char *argv[]) /* set library parameters */ alpm_option_set_dlcb(log_progress); - config->dbpath = alpm_option_get_dbpath(); - config->cachedir = alpm_option_get_cachedir(); - - alpm_list_t *i; - for(i = config->op_s_ignore; i; i = alpm_list_next(i)) { - alpm_option_add_ignorepkg(alpm_list_getdata(i)); - } - if(config->verbose > 0) { - printf("Root : %s\n", config->root); - printf("DBPath: %s\n", config->dbpath); + printf("Root : %s\n", alpm_option_get_root()); + printf("DBPath: %s\n", alpm_option_get_dbpath()); list_display(_("Targets:"), pm_targets); } diff --git a/src/pacman/query.c b/src/pacman/query.c index 62e7ef10..1b47a9b0 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -260,7 +260,7 @@ int pacman_query(alpm_list_t *targets) if(config->op_q_changelog) { char changelog[PATH_MAX]; snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog", - config->root, alpm_option_get_dbpath(), + alpm_option_get_root(), alpm_option_get_dbpath(), alpm_db_get_name(db_local), alpm_pkg_get_name(info), alpm_pkg_get_version(info)); diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 77e29d68..28f7411d 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -77,7 +77,7 @@ int pacman_remove(alpm_list_t *targets) ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } FREELIST(finaltargs); return(1); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index bbedb9ac..9d62da22 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -439,7 +439,7 @@ int pacman_sync(alpm_list_t *targets) ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } @@ -488,7 +488,7 @@ int pacman_sync(alpm_list_t *targets) ERR(NL, _("failed to init transaction (%s)\n"), alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { MSG(NL, _(" if you're sure a package manager is not already running,\n" - " you can remove %s%s\n"), config->root, PM_LOCK); + " you can remove %s%s\n"), alpm_option_get_root(), PM_LOCK); } return(1); } |