summaryrefslogtreecommitdiff
path: root/lib/libalpm/trans.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-06-15 19:15:36 -0500
committerDan McGee <dan@archlinux.org>2008-06-15 22:52:27 -0500
commit29bf6814f74096e5d8ea22058e638eb362717b8a (patch)
tree1b608ba8071c1c7e52808a4b178ba8225ef6d2b1 /lib/libalpm/trans.c
parent7ff5a917fd0a91cd03ba61419a57053e4ae17e92 (diff)
downloadpacman-29bf6814f74096e5d8ea22058e638eb362717b8a.tar.xz
Use access() instead of stat() when possible
We were using the stat() system call in quite a few places when we didn't actually need anything the stat struct returned- we were simply checking for file existence. access() will be more efficient in those cases. Before (strace pacman -Ss pacman): % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 33.16 0.005987 0 19016 stat64 After: % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 34.85 0.003863 0 12633 1 access 7.95 0.000881 0 6391 7 stat64 Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/trans.c')
-rw-r--r--lib/libalpm/trans.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index eb53e952..06084ae9 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -451,7 +452,6 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
char tmpdir[PATH_MAX];
char cwd[PATH_MAX];
char *scriptpath;
- struct stat buf;
pid_t pid;
int clean_tmpdir = 0;
int restore_cwd = 0;
@@ -459,14 +459,14 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
ALPM_LOG_FUNC;
- if(stat(installfn, &buf)) {
+ if(access(installfn, R_OK)) {
/* not found */
_alpm_log(PM_LOG_DEBUG, "scriptlet '%s' not found\n", installfn);
return(0);
}
/* NOTE: popen will use the PARENT's /bin/sh, not the chroot's */
- if(stat("/bin/sh", &buf)) {
+ if(access("/bin/sh", X_OK)) {
/* not found */
_alpm_log(PM_LOG_ERROR, _("No /bin/sh in parent environment, aborting scriptlet\n"));
return(0);
@@ -474,7 +474,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
/* creates a directory in $root/tmp/ for copying/extracting the scriptlet */
snprintf(tmpdir, PATH_MAX, "%stmp/", root);
- if(stat(tmpdir, &buf)) {
+ if(access(tmpdir, F_OK) != 0) {
_alpm_makepath_mode(tmpdir, 01777);
}
snprintf(tmpdir, PATH_MAX, "%stmp/alpm_XXXXXX", root);