xbps-bin: use a signal handler for SIGINT, SIGTERM and SIGQUIT to
free resources used by libxbps. --HG-- extra : convert_revision : xtraeme%40gmail.com-20091023092025-gav4w23f1oc7mgjy
This commit is contained in:
parent
236b86ae50
commit
ca39d1667e
@ -28,11 +28,13 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
#include <xbps_api.h>
|
#include <xbps_api.h>
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "../xbps-repo/util.h"
|
#include "../xbps-repo/util.h"
|
||||||
|
|
||||||
|
static void cleanup(int);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
static int list_pkgs_in_dict(prop_object_t, void *, bool *);
|
static int list_pkgs_in_dict(prop_object_t, void *, bool *);
|
||||||
|
|
||||||
@ -91,6 +93,7 @@ int
|
|||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
|
struct sigaction sa;
|
||||||
int c, flags = 0, rv = 0;
|
int c, flags = 0, rv = 0;
|
||||||
bool force = false, verbose = false;
|
bool force = false, verbose = false;
|
||||||
|
|
||||||
@ -126,6 +129,15 @@ main(int argc, char **argv)
|
|||||||
if (flags != 0)
|
if (flags != 0)
|
||||||
xbps_set_flags(flags);
|
xbps_set_flags(flags);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register a signal handler to clean up resources used by libxbps.
|
||||||
|
*/
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
sa.sa_handler = cleanup;
|
||||||
|
sigaction(SIGINT, &sa, NULL);
|
||||||
|
sigaction(SIGTERM, &sa, NULL);
|
||||||
|
sigaction(SIGQUIT, &sa, NULL);
|
||||||
|
|
||||||
if ((dict = xbps_prepare_regpkgdb_dict()) == NULL) {
|
if ((dict = xbps_prepare_regpkgdb_dict()) == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
@ -271,10 +283,21 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
cleanup(rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cleanup(int signum)
|
||||||
|
{
|
||||||
|
switch (signum) {
|
||||||
|
case SIGINT:
|
||||||
|
case SIGTERM:
|
||||||
|
case SIGQUIT:
|
||||||
|
printf("\nSignal caught, cleaning up...\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
xbps_release_repolist_data();
|
xbps_release_repolist_data();
|
||||||
xbps_release_regpkgdb_dict();
|
xbps_release_regpkgdb_dict();
|
||||||
if (rv != 0)
|
|
||||||
exit(EXIT_FAILURE);
|
_exit(signum);
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user