summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-03-09 12:03:54 -0500
committerDan McGee <dan@archlinux.org>2008-03-09 12:03:54 -0500
commit91b7f288fe65b96d4af64f6308b0e33b14ad85e0 (patch)
treec60650d6bcd9677c53e757a8e98c645dfab8377a /src
parentfc48dc3118318d4b26b63a9453cd23cf2158cba3 (diff)
parent51e0303e840c94e5943f30e311d053058f657327 (diff)
downloadpacman-91b7f288fe65b96d4af64f6308b0e33b14ad85e0.tar.xz
Merge branch 'maint'
Conflicts: configure.ac
Diffstat (limited to 'src')
-rw-r--r--src/pacman/pacman.c60
-rw-r--r--src/util/testpkg.c48
2 files changed, 72 insertions, 36 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 32fbaced..f87db275 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -184,11 +184,31 @@ static void setuseragent(void)
setenv("HTTP_USER_AGENT", agent, 0);
}
+/** Free the resources.
+ *
+ * @param ret the return value
+ */
+static void cleanup(int ret) {
+ /* free alpm library resources */
+ if(alpm_release() == -1) {
+ pm_printf(PM_LOG_ERROR, alpm_strerrorlast());
+ }
+
+ /* free memory */
+ FREELIST(pm_targets);
+ if(config) {
+ config_free(config);
+ config = NULL;
+ }
+
+ exit(ret);
+}
+
/** Catches thrown signals. Performs necessary cleanup to ensure database is
* in a consistant state.
* @param signum the thrown signal
*/
-static void cleanup(int signum)
+static void handler(int signum)
{
if(signum==SIGSEGV)
{
@@ -207,20 +227,7 @@ static void cleanup(int signum)
/* output a newline to be sure we clear any line we may be on */
printf("\n");
}
-
- /* free alpm library resources */
- if(alpm_release() == -1) {
- pm_printf(PM_LOG_ERROR, alpm_strerrorlast());
- }
-
- /* free memory */
- FREELIST(pm_targets);
- if(config) {
- config_free(config);
- config = NULL;
- }
-
- exit(signum);
+ cleanup(signum);
}
/** Sets all libalpm required paths in one go. Called after the command line
@@ -745,6 +752,7 @@ static int parseconfig(const char *file)
int main(int argc, char *argv[])
{
int ret = 0;
+ struct sigaction new_action, old_action;
#if defined(HAVE_GETEUID)
/* geteuid undefined in CYGWIN */
uid_t myuid = geteuid();
@@ -755,10 +763,24 @@ int main(int argc, char *argv[])
mtrace();
#endif
- /* set signal handlers */
- signal(SIGINT, cleanup);
- signal(SIGTERM, cleanup);
- signal(SIGSEGV, cleanup);
+ /* Set signal handlers */
+ /* Set up the structure to specify the new action. */
+ new_action.sa_handler = handler;
+ sigemptyset(&new_action.sa_mask);
+ new_action.sa_flags = 0;
+
+ sigaction(SIGINT, NULL, &old_action);
+ if(old_action.sa_handler != SIG_IGN) {
+ sigaction(SIGINT, &new_action, NULL);
+ }
+ sigaction(SIGTERM, NULL, &old_action);
+ if(old_action.sa_handler != SIG_IGN) {
+ sigaction(SIGTERM, &new_action, NULL);
+ }
+ sigaction(SIGSEGV, NULL, &old_action);
+ if(old_action.sa_handler != SIG_IGN) {
+ sigaction(SIGSEGV, &new_action, NULL);
+ }
/* i18n init */
#if defined(ENABLE_NLS)
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index e32b013d..64056ce4 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -29,44 +29,58 @@
static void output_cb(pmloglevel_t level, char *fmt, va_list args)
{
- if(strlen(fmt)) {
- switch(level) {
- case PM_LOG_ERROR: printf("error: "); break;
- case PM_LOG_WARNING: printf("warning: "); break;
- default: break;
- }
- vprintf(fmt, args);
- }
+ if(fmt[0] == '\0') {
+ return;
+ }
+ switch(level) {
+ case PM_LOG_ERROR: printf("error: "); break;
+ case PM_LOG_WARNING: printf("warning: "); break;
+ default: return; /* skip other messages */
+ }
+ vprintf(fmt, args);
}
int main(int argc, char **argv)
{
- int retval = 1; /* default = false */
- pmpkg_t *pkg = NULL;
+ int retval = 1; /* default = false */
+ pmpkg_t *pkg = NULL;
- if(argc != 2) {
+ if(argc != 2) {
fprintf(stderr, "usage: %s <package file>\n", BASENAME);
return(1);
}
if(alpm_initialize() == -1) {
- fprintf(stderr, "cannot initilize alpm: %s\n", alpm_strerrorlast());
- return(1);
+ fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerrorlast());
+ return(1);
}
- /* let us get log messages from libalpm */
+ /* let us get log messages from libalpm */
alpm_option_set_logcb(output_cb);
if(alpm_pkg_load(argv[1], 1, &pkg) == -1 || pkg == NULL) {
- retval = 1;
+ switch(pm_errno) {
+ case PM_ERR_PKG_OPEN:
+ printf("Cannot open the given file.\n");
+ break;
+ case PM_ERR_LIBARCHIVE_ERROR:
+ case PM_ERR_PKG_INVALID:
+ printf("Package is invalid.\n");
+ break;
+ default:
+ printf("libalpm error: %s\n", alpm_strerrorlast());
+ break;
+ }
+ retval = 1;
} else {
alpm_pkg_free(pkg);
- retval = 0;
+ printf("Package is valid.\n");
+ retval = 0;
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerrorlast());
}
- return(retval);
+ return(retval);
}