Remove global handle from util.c

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-03 12:33:18 -05:00
parent de36c5fac4
commit 7fc635fee0
6 changed files with 36 additions and 38 deletions

View file

@ -501,8 +501,8 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* pre_upgrade scriptlet */ /* pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
_alpm_runscriptlet(handle->root, newpkg->origin_data.file, _alpm_runscriptlet(handle, newpkg->origin_data.file,
"pre_upgrade", newpkg->version, oldpkg->version, trans); "pre_upgrade", newpkg->version, oldpkg->version);
} }
} else { } else {
is_upgrade = 0; is_upgrade = 0;
@ -513,8 +513,8 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
/* pre_install scriptlet */ /* pre_install scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
_alpm_runscriptlet(handle->root, newpkg->origin_data.file, _alpm_runscriptlet(handle, newpkg->origin_data.file,
"pre_install", newpkg->version, NULL, trans); "pre_install", newpkg->version, NULL);
} }
} }
@ -681,12 +681,12 @@ static int commit_single_pkg(pmpkg_t *newpkg, size_t pkg_current,
if(alpm_pkg_has_scriptlet(newpkg) if(alpm_pkg_has_scriptlet(newpkg)
&& !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
if(is_upgrade) { if(is_upgrade) {
_alpm_runscriptlet(handle->root, scriptlet, "post_upgrade", _alpm_runscriptlet(handle, scriptlet, "post_upgrade",
alpm_pkg_get_version(newpkg), alpm_pkg_get_version(newpkg),
oldpkg ? alpm_pkg_get_version(oldpkg) : NULL, trans); oldpkg ? alpm_pkg_get_version(oldpkg) : NULL);
} else { } else {
_alpm_runscriptlet(handle->root, scriptlet, "post_install", _alpm_runscriptlet(handle, scriptlet, "post_install",
alpm_pkg_get_version(newpkg), NULL, trans); alpm_pkg_get_version(newpkg), NULL);
} }
} }
@ -738,7 +738,7 @@ int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
if(!skip_ldconfig) { if(!skip_ldconfig) {
/* run ldconfig if it exists */ /* run ldconfig if it exists */
_alpm_ldconfig(handle->root); _alpm_ldconfig(handle);
} }
return ret; return ret;

View file

@ -385,8 +385,8 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* run the pre-remove scriptlet if it exists */ /* run the pre-remove scriptlet if it exists */
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
_alpm_runscriptlet(handle->root, scriptlet, "pre_remove", _alpm_runscriptlet(handle, scriptlet, "pre_remove",
alpm_pkg_get_version(info), NULL, trans); alpm_pkg_get_version(info), NULL);
} }
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) { if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
@ -430,8 +430,8 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
/* run the post-remove script if it exists */ /* run the post-remove script if it exists */
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) { if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
_alpm_runscriptlet(handle->root, scriptlet, "post_remove", _alpm_runscriptlet(handle, scriptlet, "post_remove",
alpm_pkg_get_version(info), NULL, trans); alpm_pkg_get_version(info), NULL);
} }
/* remove the package from the database */ /* remove the package from the database */
@ -451,7 +451,7 @@ int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
} }
/* run ldconfig if it exists */ /* run ldconfig if it exists */
_alpm_ldconfig(handle->root); _alpm_ldconfig(handle);
return 0; return 0;
} }

View file

@ -354,9 +354,8 @@ static int grep(const char *fn, const char *needle)
return 0; return 0;
} }
int _alpm_runscriptlet(const char *root, const char *installfn, int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn,
const char *script, const char *ver, const char *script, const char *ver, const char *oldver)
const char *oldver, pmtrans_t UNUSED *trans)
{ {
char scriptfn[PATH_MAX]; char scriptfn[PATH_MAX];
char cmdline[PATH_MAX]; char cmdline[PATH_MAX];
@ -373,11 +372,11 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
} }
/* creates a directory in $root/tmp/ for copying/extracting the scriptlet */ /* creates a directory in $root/tmp/ for copying/extracting the scriptlet */
snprintf(tmpdir, PATH_MAX, "%stmp/", root); snprintf(tmpdir, PATH_MAX, "%stmp/", handle->root);
if(access(tmpdir, F_OK) != 0) { if(access(tmpdir, F_OK) != 0) {
_alpm_makepath_mode(tmpdir, 01777); _alpm_makepath_mode(tmpdir, 01777);
} }
snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", root); snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", handle->root);
if(mkdtemp(tmpdir) == NULL) { if(mkdtemp(tmpdir) == NULL) {
_alpm_log(PM_LOG_ERROR, _("could not create temp directory\n")); _alpm_log(PM_LOG_ERROR, _("could not create temp directory\n"));
return 1; return 1;
@ -402,7 +401,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
} }
/* chop off the root so we can find the tmpdir in the chroot */ /* chop off the root so we can find the tmpdir in the chroot */
scriptpath = scriptfn + strlen(root) - 1; scriptpath = scriptfn + strlen(handle->root) - 1;
if(!grep(scriptfn, script)) { if(!grep(scriptfn, script)) {
/* script not found in scriptlet file */ /* script not found in scriptlet file */
@ -419,7 +418,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
_alpm_log(PM_LOG_DEBUG, "executing \"%s\"\n", cmdline); _alpm_log(PM_LOG_DEBUG, "executing \"%s\"\n", cmdline);
retval = _alpm_run_chroot(root, "/bin/sh", argv); retval = _alpm_run_chroot(handle, "/bin/sh", argv);
cleanup: cleanup:
if(clean_tmpdir && _alpm_rmrf(tmpdir)) { if(clean_tmpdir && _alpm_rmrf(tmpdir)) {

View file

@ -71,9 +71,8 @@ void _alpm_trans_free(pmtrans_t *trans);
int _alpm_trans_init(pmtrans_t *trans, pmtransflag_t flags, int _alpm_trans_init(pmtrans_t *trans, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv, alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress); alpm_trans_cb_progress progress);
int _alpm_runscriptlet(const char *root, const char *installfn, int _alpm_runscriptlet(pmhandle_t *handle, const char *installfn,
const char *script, const char *ver, const char *script, const char *ver, const char *oldver);
const char *oldver, pmtrans_t *trans);
#endif /* _ALPM_TRANS_H */ #endif /* _ALPM_TRANS_H */

View file

@ -57,9 +57,6 @@
#include "alpm_list.h" #include "alpm_list.h"
#include "handle.h" #include "handle.h"
/* global handle variable */
extern pmhandle_t *handle;
#ifndef HAVE_STRSEP #ifndef HAVE_STRSEP
/* This is a replacement for strsep which is not portable (missing on Solaris). /* This is a replacement for strsep which is not portable (missing on Solaris).
* Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> */ * Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> */
@ -418,7 +415,7 @@ int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args)
return ret; return ret;
} }
int _alpm_run_chroot(const char *root, const char *path, char *const argv[]) int _alpm_run_chroot(pmhandle_t *handle, const char *path, char *const argv[])
{ {
char cwd[PATH_MAX]; char cwd[PATH_MAX];
pid_t pid; pid_t pid;
@ -434,12 +431,14 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
} }
/* just in case our cwd was removed in the upgrade operation */ /* just in case our cwd was removed in the upgrade operation */
if(chdir(root) != 0) { if(chdir(handle->root) != 0) {
_alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), root, strerror(errno)); _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
handle->root, strerror(errno));
goto cleanup; goto cleanup;
} }
_alpm_log(PM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n", path, root); _alpm_log(PM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n",
path, handle->root);
/* Flush open fds before fork() to avoid cloning buffers */ /* Flush open fds before fork() to avoid cloning buffers */
fflush(NULL); fflush(NULL);
@ -468,7 +467,7 @@ int _alpm_run_chroot(const char *root, const char *path, char *const argv[])
close(pipefd[1]); close(pipefd[1]);
/* use fprintf instead of _alpm_log to send output through the parent */ /* use fprintf instead of _alpm_log to send output through the parent */
if(chroot(root) != 0) { if(chroot(handle->root) != 0) {
fprintf(stderr, _("could not change the root directory (%s)\n"), strerror(errno)); fprintf(stderr, _("could not change the root directory (%s)\n"), strerror(errno));
exit(1); exit(1);
} }
@ -533,18 +532,18 @@ cleanup:
return retval; return retval;
} }
int _alpm_ldconfig(const char *root) int _alpm_ldconfig(pmhandle_t *handle)
{ {
char line[PATH_MAX]; char line[PATH_MAX];
_alpm_log(PM_LOG_DEBUG, "running ldconfig\n"); _alpm_log(PM_LOG_DEBUG, "running ldconfig\n");
snprintf(line, PATH_MAX, "%setc/ld.so.conf", root); snprintf(line, PATH_MAX, "%setc/ld.so.conf", handle->root);
if(access(line, F_OK) == 0) { if(access(line, F_OK) == 0) {
snprintf(line, PATH_MAX, "%ssbin/ldconfig", root); snprintf(line, PATH_MAX, "%ssbin/ldconfig", handle->root);
if(access(line, X_OK) == 0) { if(access(line, X_OK) == 0) {
char *argv[] = { "ldconfig", NULL }; char *argv[] = { "ldconfig", NULL };
_alpm_run_chroot(root, "/sbin/ldconfig", argv); _alpm_run_chroot(handle, "/sbin/ldconfig", argv);
} }
} }

View file

@ -27,6 +27,7 @@
#include "config.h" #include "config.h"
#include "alpm_list.h" #include "alpm_list.h"
#include "alpm.h"
#include "package.h" /* pmpkg_t */ #include "package.h" /* pmpkg_t */
#include <stdio.h> #include <stdio.h>
@ -93,8 +94,8 @@ int _alpm_unpack_single(const char *archive, const char *prefix, const char *fn)
int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst); int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int breakfirst);
int _alpm_rmrf(const char *path); int _alpm_rmrf(const char *path);
int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args); int _alpm_logaction(int usesyslog, FILE *f, const char *fmt, va_list args);
int _alpm_run_chroot(const char *root, const char *path, char *const argv[]); int _alpm_run_chroot(pmhandle_t *handle, const char *path, char *const argv[]);
int _alpm_ldconfig(const char *root); int _alpm_ldconfig(pmhandle_t *handle);
int _alpm_str_cmp(const void *s1, const void *s2); int _alpm_str_cmp(const void *s1, const void *s2);
char *_alpm_filecache_find(const char *filename); char *_alpm_filecache_find(const char *filename);
const char *_alpm_filecache_setup(void); const char *_alpm_filecache_setup(void);