1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

Make all error messages use pm_fprintf

Tested using many easily generated error conditions.  Also added "malloc
failure" (conf.c) and "segmentation fault" (pacman.c) error messages for
translation.

Signed-off-by: Allan McRae <mcrae_allan@hotmail.com>
[Dan: fix trailing whitespace errors, other compilation issues]
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Allan McRae 2008-05-11 13:30:27 +10:00 committed by Dan McGee
parent 3175faace4
commit 3c3cb001a4
8 changed files with 54 additions and 42 deletions

View File

@ -25,6 +25,7 @@
/* pacman */ /* pacman */
#include "conf.h" #include "conf.h"
#include "util.h"
/* global config variable */ /* global config variable */
config_t *config = NULL; config_t *config = NULL;
@ -33,8 +34,9 @@ config_t *config_new(void)
{ {
config_t *newconfig = calloc(1, sizeof(config_t)); config_t *newconfig = calloc(1, sizeof(config_t));
if(!newconfig) { if(!newconfig) {
fprintf(stderr, "malloc failure: could not allocate %zd bytes\n", pm_fprintf(stderr, PM_LOG_ERROR,
sizeof(config_t)); _("malloc failure: could not allocate %zd bytes\n"),
sizeof(config_t));
return(NULL); return(NULL);
} }
/* defaults which may get overridden later */ /* defaults which may get overridden later */

View File

@ -195,8 +195,8 @@ void dump_pkg_backups(pmpkg_t *pkg)
char *md5sum = alpm_get_md5sum(path); char *md5sum = alpm_get_md5sum(path);
if(md5sum == NULL) { if(md5sum == NULL) {
fprintf(stderr, _("error: could not calculate checksums for %s\n"), pm_fprintf(stderr, PM_LOG_ERROR,
path); _("could not calculate checksums for %s\n"), path);
free(str); free(str);
continue; continue;
} }
@ -245,8 +245,7 @@ void dump_pkg_changelog(pmpkg_t *pkg)
void *fp = NULL; void *fp = NULL;
if((fp = alpm_pkg_changelog_open(pkg)) == NULL) { if((fp = alpm_pkg_changelog_open(pkg)) == NULL) {
/* TODO after string freeze use pm_fprintf */ pm_fprintf(stderr, PM_LOG_ERROR, _("no changelog available for '%s'.\n"),
fprintf(stderr, _("error: no changelog available for '%s'.\n"),
alpm_pkg_get_name(pkg)); alpm_pkg_get_name(pkg));
return; return;
} else { } else {

View File

@ -213,9 +213,10 @@ static RETSIGTYPE handler(int signum)
if(signum==SIGSEGV) if(signum==SIGSEGV)
{ {
/* write a log message and write to stderr */ /* write a log message and write to stderr */
pm_printf(PM_LOG_ERROR, "segmentation fault\n"); pm_printf(PM_LOG_ERROR, _("segmentation fault\n"));
pm_fprintf(stderr, PM_LOG_ERROR, "Internal pacman error: Segmentation fault.\n" pm_fprintf(stderr, PM_LOG_ERROR,
"Please submit a full bug report with --debug if appropriate.\n"); _("Internal pacman error: Segmentation fault.\n"
"Please submit a full bug report with --debug if appropriate.\n"));
exit(signum); exit(signum);
} else if((signum == SIGINT)) { } else if((signum == SIGINT)) {
if(alpm_trans_interrupt() == 0) { if(alpm_trans_interrupt() == 0) {

View File

@ -62,7 +62,7 @@ static int query_fileowner(alpm_list_t *targets)
/* This code is here for safety only */ /* This code is here for safety only */
if(targets == NULL) { if(targets == NULL) {
fprintf(stderr, _("error: no file was specified for --owns\n")); pm_fprintf(stderr, PM_LOG_ERROR, _("no file was specified for --owns\n"));
return(1); return(1);
} }
@ -75,14 +75,15 @@ static int query_fileowner(alpm_list_t *targets)
alpm_list_t *i, *j; alpm_list_t *i, *j;
if(stat(filename, &buf) == -1) { if(stat(filename, &buf) == -1) {
fprintf(stderr, _("error: failed to read file '%s': %s\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to read file '%s': %s\n"),
filename, strerror(errno)); filename, strerror(errno));
ret++; ret++;
continue; continue;
} }
if(S_ISDIR(buf.st_mode)) { if(S_ISDIR(buf.st_mode)) {
fprintf(stderr, _("error: cannot determine ownership of a directory\n")); pm_fprintf(stderr, PM_LOG_ERROR,
_("cannot determine ownership of a directory\n"));
ret++; ret++;
continue; continue;
} }
@ -93,7 +94,7 @@ static int query_fileowner(alpm_list_t *targets)
free(dname); free(dname);
if(!rpath) { if(!rpath) {
fprintf(stderr, _("error: cannot determine real path for '%s': %s\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
filename, strerror(errno)); filename, strerror(errno));
free(rpath); free(rpath);
ret++; ret++;
@ -133,7 +134,7 @@ static int query_fileowner(alpm_list_t *targets)
} }
} }
if(!found) { if(!found) {
fprintf(stderr, _("error: No package owns %s\n"), filename); pm_fprintf(stderr, PM_LOG_ERROR, _("No package owns %s\n"), filename);
ret++; ret++;
} }
free(rpath); free(rpath);
@ -237,7 +238,7 @@ static int query_group(alpm_list_t *targets)
printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p))); printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p)));
} }
} else { } else {
fprintf(stderr, _("error: group \"%s\" was not found\n"), grpname); pm_fprintf(stderr, PM_LOG_ERROR, _("group \"%s\" was not found\n"), grpname);
ret++; ret++;
} }
} }
@ -415,7 +416,7 @@ int pacman_query(alpm_list_t *targets)
} }
if(pkg == NULL) { if(pkg == NULL) {
fprintf(stderr, _("error: package \"%s\" not found\n"), strname); pm_fprintf(stderr, PM_LOG_ERROR, _("package \"%s\" not found\n"), strname);
ret++; ret++;
continue; continue;
} }

View File

@ -86,7 +86,7 @@ int pacman_remove(alpm_list_t *targets)
for(i = finaltargs; i; i = alpm_list_next(i)) { for(i = finaltargs; i; i = alpm_list_next(i)) {
char *targ = alpm_list_getdata(i); char *targ = alpm_list_getdata(i);
if(alpm_trans_addtarget(targ) == -1) { if(alpm_trans_addtarget(targ) == -1) {
fprintf(stderr, _("error: '%s': %s\n"), pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast()); targ, alpm_strerrorlast());
trans_release(); trans_release();
FREELIST(finaltargs); FREELIST(finaltargs);
@ -96,7 +96,7 @@ int pacman_remove(alpm_list_t *targets)
/* Step 2: prepare the transaction based on its type, targets and flags */ /* Step 2: prepare the transaction based on its type, targets and flags */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS: case PM_ERR_UNSATISFIED_DEPS:
@ -142,7 +142,7 @@ int pacman_remove(alpm_list_t *targets)
/* Step 3: actually perform the removal */ /* Step 3: actually perform the removal */
if(alpm_trans_commit(NULL) == -1) { if(alpm_trans_commit(NULL) == -1) {
fprintf(stderr, _("error: failed to commit transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
trans_release(); trans_release();
FREELIST(finaltargs); FREELIST(finaltargs);

View File

@ -46,7 +46,7 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
dir = opendir(dbpath); dir = opendir(dbpath);
if(dir == NULL) { if(dir == NULL) {
fprintf(stderr, _("error: could not access database directory\n")); pm_fprintf(stderr, PM_LOG_ERROR, _("could not access database directory\n"));
return(1); return(1);
} }
@ -90,7 +90,8 @@ static int sync_cleandb(const char *dbpath, int keep_used) {
} }
if(rmrf(path)) { if(rmrf(path)) {
fprintf(stderr, _("error: could not remove repository directory\n")); pm_fprintf(stderr, PM_LOG_ERROR,
_("could not remove repository directory\n"));
return(1); return(1);
} }
} }
@ -151,7 +152,7 @@ static int sync_cleancache(int level)
dir = opendir(cachedir); dir = opendir(cachedir);
if(dir == NULL) { if(dir == NULL) {
fprintf(stderr, _("error: could not access cache directory\n")); pm_fprintf(stderr, PM_LOG_ERROR, _("could not access cache directory\n"));
return(1); return(1);
} }
@ -220,12 +221,12 @@ static int sync_cleancache(int level)
printf(_("removing all packages from cache... ")); printf(_("removing all packages from cache... "));
if(rmrf(cachedir)) { if(rmrf(cachedir)) {
fprintf(stderr, _("error: could not remove cache directory\n")); pm_fprintf(stderr, PM_LOG_ERROR, _("could not remove cache directory\n"));
return(1); return(1);
} }
if(makepath(cachedir)) { if(makepath(cachedir)) {
fprintf(stderr, _("error: could not create new cache directory\n")); pm_fprintf(stderr, PM_LOG_ERROR, _("could not create new cache directory\n"));
return(1); return(1);
} }
printf(_("done.\n")); printf(_("done.\n"));
@ -248,7 +249,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
ret = alpm_db_update((level < 2 ? 0 : 1), db); ret = alpm_db_update((level < 2 ? 0 : 1), db);
if(ret < 0) { if(ret < 0) {
fprintf(stderr, _("error: failed to update %s (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to update %s (%s)\n"),
alpm_db_get_name(db), alpm_strerrorlast()); alpm_db_get_name(db), alpm_strerrorlast());
} else if(ret == 1) { } else if(ret == 1) {
printf(_(" %s is up to date\n"), alpm_db_get_name(db)); printf(_(" %s is up to date\n"), alpm_db_get_name(db));
@ -266,7 +267,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
* expected * expected
*/ */
if(!success) { if(!success) {
fprintf(stderr, _("error: failed to synchronize any databases\n")); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to synchronize any databases\n"));
} }
return(success > 0); return(success > 0);
} }
@ -418,7 +419,8 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
} }
if(!db) { if(!db) {
fprintf(stderr, _("error: repository '%s' does not exist\n"), repo); pm_fprintf(stderr, PM_LOG_ERROR,
_("repository '%s' does not exist\n"), repo);
return(1); return(1);
} }
@ -433,7 +435,8 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
} }
if(!foundpkg) { if(!foundpkg) {
fprintf(stderr, _("error: package '%s' was not found in repository '%s'\n"), pkgstr, repo); pm_fprintf(stderr, PM_LOG_ERROR,
_("package '%s' was not found in repository '%s'\n"), pkgstr, repo);
ret++; ret++;
} }
} else { } else {
@ -453,7 +456,8 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
} }
} }
if(!foundpkg) { if(!foundpkg) {
fprintf(stderr, _("error: package '%s' was not found\n"), pkgstr); pm_fprintf(stderr, PM_LOG_ERROR,
_("package '%s' was not found\n"), pkgstr);
ret++; ret++;
} }
} }
@ -490,7 +494,8 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
} }
if(db == NULL) { if(db == NULL) {
fprintf(stderr, _("error: repository \"%s\" was not found.\n"),repo); pm_fprintf(stderr, PM_LOG_ERROR,
_("repository \"%s\" was not found.\n"),repo);
alpm_list_free(ls); alpm_list_free(ls);
return(1); return(1);
} }
@ -538,7 +543,7 @@ static int sync_trans(alpm_list_t *targets)
printf(_(":: Starting full system upgrade...\n")); printf(_(":: Starting full system upgrade...\n"));
alpm_logaction("starting full system upgrade\n"); alpm_logaction("starting full system upgrade\n");
if(alpm_trans_sysupgrade() == -1) { if(alpm_trans_sysupgrade() == -1) {
fprintf(stderr, _("error: %s\n"), alpm_strerrorlast()); pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
retval = 1; retval = 1;
goto cleanup; goto cleanup;
} }
@ -567,7 +572,8 @@ static int sync_trans(alpm_list_t *targets)
return(1); return(1);
} }
if(alpm_trans_addtarget("pacman") == -1) { if(alpm_trans_addtarget("pacman") == -1) {
fprintf(stderr, _("error: pacman: %s\n"), alpm_strerrorlast()); pm_fprintf(stderr, PM_LOG_ERROR, _("pacman: %s\n"),
alpm_strerrorlast());
return(1); return(1);
} }
break; break;
@ -591,7 +597,7 @@ static int sync_trans(alpm_list_t *targets)
continue; continue;
} }
if(pm_errno != PM_ERR_PKG_NOT_FOUND) { if(pm_errno != PM_ERR_PKG_NOT_FOUND) {
fprintf(stderr, _("error: '%s': %s\n"), pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast()); targ, alpm_strerrorlast());
retval = 1; retval = 1;
goto cleanup; goto cleanup;
@ -647,7 +653,8 @@ static int sync_trans(alpm_list_t *targets)
targets = alpm_list_add(targets, strdup(pname)); targets = alpm_list_add(targets, strdup(pname));
} else { } else {
alpm_list_t *k; alpm_list_t *k;
fprintf(stderr, _("error: several packages provide %s, please specify one :\n"), targ); pm_fprintf(stderr, PM_LOG_ERROR,
_("several packages provide %s, please specify one :\n"), targ);
for(k = prov; k; k = alpm_list_next(k)) { for(k = prov; k; k = alpm_list_next(k)) {
pmpkg_t *pkg = alpm_list_getdata(k); pmpkg_t *pkg = alpm_list_getdata(k);
printf("%s ", alpm_pkg_get_name(pkg)); printf("%s ", alpm_pkg_get_name(pkg));
@ -658,7 +665,8 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup; goto cleanup;
} }
} else { } else {
fprintf(stderr, _("error: '%s': not found in sync db\n"), targ); pm_fprintf(stderr, PM_LOG_ERROR,
_("'%s': not found in sync db\n"), targ);
retval = 1; retval = 1;
goto cleanup; goto cleanup;
} }
@ -669,7 +677,7 @@ static int sync_trans(alpm_list_t *targets)
/* Step 2: "compute" the transaction based on targets and flags */ /* Step 2: "compute" the transaction based on targets and flags */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
alpm_list_t *i; alpm_list_t *i;
@ -722,7 +730,7 @@ static int sync_trans(alpm_list_t *targets)
/* Step 3: actually perform the installation */ /* Step 3: actually perform the installation */
if(alpm_trans_commit(&data) == -1) { if(alpm_trans_commit(&data) == -1) {
fprintf(stderr, _("error: failed to commit transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
alpm_list_t *i; alpm_list_t *i;

View File

@ -73,7 +73,7 @@ int pacman_upgrade(alpm_list_t *targets)
for(i = targets; i; i = alpm_list_next(i)) { for(i = targets; i; i = alpm_list_next(i)) {
char *targ = alpm_list_getdata(i); char *targ = alpm_list_getdata(i);
if(alpm_trans_addtarget(targ) == -1) { if(alpm_trans_addtarget(targ) == -1) {
fprintf(stderr, _("error: '%s': %s\n"), pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast()); targ, alpm_strerrorlast());
trans_release(); trans_release();
return(1); return(1);
@ -83,7 +83,7 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 2: "compute" the transaction based on targets and flags */ /* Step 2: "compute" the transaction based on targets and flags */
/* TODO: No, compute nothing. This is stupid. */ /* TODO: No, compute nothing. This is stupid. */
if(alpm_trans_prepare(&data) == -1) { if(alpm_trans_prepare(&data) == -1) {
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
switch(pm_errno) { switch(pm_errno) {
case PM_ERR_UNSATISFIED_DEPS: case PM_ERR_UNSATISFIED_DEPS:
@ -137,7 +137,8 @@ int pacman_upgrade(alpm_list_t *targets)
/* Step 3: perform the installation */ /* Step 3: perform the installation */
if(alpm_trans_commit(NULL) == -1) { if(alpm_trans_commit(NULL) == -1) {
fprintf(stderr, _("error: failed to commit transaction (%s)\n"), alpm_strerrorlast()); pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerrorlast());
trans_release(); trans_release();
return(1); return(1);
} }

View File

@ -49,7 +49,7 @@ int trans_init(pmtranstype_t type, pmtransflag_t flags)
{ {
if(alpm_trans_init(type, flags, cb_trans_evt, if(alpm_trans_init(type, flags, cb_trans_evt,
cb_trans_conv, cb_trans_progress) == -1) { cb_trans_conv, cb_trans_progress) == -1) {
fprintf(stderr, _("error: failed to init transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to init transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
if(pm_errno == PM_ERR_HANDLE_LOCK) { if(pm_errno == PM_ERR_HANDLE_LOCK) {
fprintf(stderr, _(" if you're sure a package manager is not already\n" fprintf(stderr, _(" if you're sure a package manager is not already\n"
@ -63,7 +63,7 @@ int trans_init(pmtranstype_t type, pmtransflag_t flags)
int trans_release() int trans_release()
{ {
if(alpm_trans_release() == -1) { if(alpm_trans_release() == -1) {
fprintf(stderr, _("error: failed to release transaction (%s)\n"), pm_fprintf(stderr, PM_LOG_ERROR, _("failed to release transaction (%s)\n"),
alpm_strerrorlast()); alpm_strerrorlast());
return(-1); return(-1);
} }