summaryrefslogtreecommitdiff
path: root/lib/libalpm/trans.c
diff options
context:
space:
mode:
authorChantry Xavier <shiningxc@gmail.com>2007-09-08 00:36:38 +0200
committerDan McGee <dan@archlinux.org>2007-09-16 20:17:44 -0500
commitb0aa51059233849b0a7ef8d6a851750776ce6645 (patch)
tree29341593cb82011f65e901aa63bc76f7449d85a2 /lib/libalpm/trans.c
parent046c8a6819a0533fb10434f30100f80bb960fe46 (diff)
downloadpacman-b0aa51059233849b0a7ef8d6a851750776ce6645.tar.xz
trans.c : reworking of transaction interruptions
My two previous hacks related to this part (8038190c7c4786e1c49494eea1b40cdddcbd5136 and b15a5194d1a8485a2769560e49e6ff03e1862533) were caused by the lack of understanding of a feature introduced a while ago: Better control over CTRL-C interruptions -- do not leave the DB in an inconsistent state (54008798efcc9646f622f6b052ecd83281d57cda). Now I have been looking at this commit, and the added feature is indeed interesting. The main problem I had with it is that it does a rather unusual use of alpm_trans_release, which caused a few problems that I tried to fix in a weird way. I think these problems were caused by the fact that there weren't any difference between "interrupt transaction" and "release a transaction which failed" actions from the alpm_trans_release POV. So I decided to add a new function instead, alpm_trans_interrupt, which is called on Ctrl+C, and which only sets trans->state to STATE_INTERRUPTED so that remove_commit and add_commit can exit cleanly at a safe moment. This allowed me to revert my two previous hacks as well. Also ensure we handle SIGINT correctly in all cases- if a transaction is not ongoing, then we can free the transaction and exit quickly. Signed-off-by: Chantry Xavier <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/trans.c')
-rw-r--r--lib/libalpm/trans.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index fe37a1f9..9eb27c30 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -165,13 +165,34 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
return(_alpm_trans_commit(handle->trans, data));
}
+/** Interrupt a transaction.
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_trans_interrupt()
+{
+ pmtrans_t *trans;
+
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+
+ trans = handle->trans;
+ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_COMMITING || trans->state == STATE_INTERRUPTED,
+ RET_ERR(PM_ERR_TRANS_TYPE, -1));
+
+ trans->state = STATE_INTERRUPTED;
+
+ return(0);
+}
+
/** Release a transaction.
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
int SYMEXPORT alpm_trans_release()
{
pmtrans_t *trans;
- int ret = 0;
ALPM_LOG_FUNC;
@@ -182,15 +203,6 @@ int SYMEXPORT alpm_trans_release()
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(trans->state != STATE_IDLE, RET_ERR(PM_ERR_TRANS_NULL, -1));
- /* during a commit do not interrupt immediately, just after a target */
- if(trans->state == STATE_COMMITING || trans->state == STATE_INTERRUPTED) {
- if(trans->state == STATE_COMMITING) {
- trans->state = STATE_INTERRUPTED;
- }
- pm_errno = PM_ERR_TRANS_COMMITING;
- ret = -1;
- }
-
_alpm_trans_free(trans);
handle->trans = NULL;
@@ -206,7 +218,7 @@ int SYMEXPORT alpm_trans_release()
alpm_option_get_lockfile());
}
- return(ret);
+ return(0);
}
/** @} */