src/pacman/pacman.c : split cleanup function.
This function was used in two different ways : - as a signal handler : the argument was the signal number - called manually for freeing the resources : the argument was the return value So the first part is now handler(int), and the second cleanup(int). Ref: http://www.archlinux.org/pipermail/pacman-dev/2008-March/011388.html Remaining problems : - the return values are messy. for example, 2 can mean both that it was interrupted (SIGINT == 2), or that --help or -V was used (returned by parseargs). - apparently signal is not portable and sigaction should be used instead Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
This commit is contained in:
parent
1dfcf1495b
commit
2f9f48eddd
1 changed files with 25 additions and 18 deletions
|
@ -188,11 +188,31 @@ static void setuseragent(void)
|
||||||
setenv("HTTP_USER_AGENT", agent, 0);
|
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
|
/** Catches thrown signals. Performs necessary cleanup to ensure database is
|
||||||
* in a consistant state.
|
* in a consistant state.
|
||||||
* @param signum the thrown signal
|
* @param signum the thrown signal
|
||||||
*/
|
*/
|
||||||
static void cleanup(int signum)
|
static void handler(int signum)
|
||||||
{
|
{
|
||||||
if(signum==SIGSEGV)
|
if(signum==SIGSEGV)
|
||||||
{
|
{
|
||||||
|
@ -211,20 +231,7 @@ static void cleanup(int signum)
|
||||||
/* output a newline to be sure we clear any line we may be on */
|
/* output a newline to be sure we clear any line we may be on */
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
cleanup(signum);
|
||||||
/* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets all libalpm required paths in one go. Called after the command line
|
/** Sets all libalpm required paths in one go. Called after the command line
|
||||||
|
@ -756,9 +763,9 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* set signal handlers */
|
/* set signal handlers */
|
||||||
signal(SIGINT, cleanup);
|
signal(SIGINT, handler);
|
||||||
signal(SIGTERM, cleanup);
|
signal(SIGTERM, handler);
|
||||||
signal(SIGSEGV, cleanup);
|
signal(SIGSEGV, handler);
|
||||||
|
|
||||||
/* i18n init */
|
/* i18n init */
|
||||||
#if defined(ENABLE_NLS)
|
#if defined(ENABLE_NLS)
|
||||||
|
|
Loading…
Add table
Reference in a new issue