Bail early if we don't have a valid lockfile path

This addresses FS#24292. If one does the bad thing of not checking
pm_errno after calling set_dbpath(), you may not realize the
initialization process went wrong and calling trans_init() resulted in a
segfault. If we don't have a lockfile path, bail out and have
trans_init() fail.

Also remove a ALPM_LOG_FUNC call that was causing pm_errno to return "no
handle"; this was due to a log call in the handle setup (whereby the log
attempts to use a callback attached to the handle).

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-05-19 17:42:22 -05:00
parent f2c4e7e552
commit 65c1880735
2 changed files with 2 additions and 3 deletions

View File

@ -46,8 +46,6 @@ pmhandle_t *_alpm_handle_new()
{
pmhandle_t *handle;
ALPM_LOG_FUNC;
CALLOC(handle, 1, sizeof(pmhandle_t), RET_ERR(PM_ERR_MEMORY, NULL));
return(handle);

View File

@ -58,6 +58,8 @@ static int make_lock(pmhandle_t *handle)
int fd;
char *dir, *ptr;
ASSERT(handle->lockfile != NULL, return -1);
/* create the dir of the lockfile first */
dir = strdup(handle->lockfile);
ptr = strrchr(dir, '/');
@ -110,7 +112,6 @@ int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
/* lock db */