[Reproducible-commits] [dpkg] 18/105: dpkg: Factor find_command() out from checkpath()
Niko Tyni
ntyni at moszumanska.debian.org
Mon May 2 13:49:47 UTC 2016
This is an automated email from the git hooks/post-receive script.
ntyni pushed a commit to branch ntyni/reproducible_builds
in repository dpkg.
commit ccc09502395899eef8def40f4ef9b28cec74899e
Author: Guillem Jover <guillem at debian.org>
Date: Sun Mar 15 00:26:47 2015 +0100
dpkg: Factor find_command() out from checkpath()
---
src/help.c | 62 +++++++++++++++++++++++++++++++++++---------------------------
src/main.h | 1 +
2 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/src/help.c b/src/help.c
index a03c257..aa9b11c 100644
--- a/src/help.c
+++ b/src/help.c
@@ -77,6 +77,40 @@ namenodetouse(struct filenamenode *namenode, struct pkginfo *pkg,
return r;
}
+bool
+find_command(const char *prog)
+{
+ struct varbuf filename = VARBUF_INIT;
+ struct stat stab;
+ const char *path_list;
+ const char *path, *path_end;
+ size_t path_len;
+
+ path_list = getenv("PATH");
+ if (!path_list)
+ ohshit(_("PATH is not set"));
+
+ for (path = path_list; path; path = path_end ? path_end + 1 : NULL) {
+ path_end = strchr(path, ':');
+ path_len = path_end ? (size_t)(path_end - path) : strlen(path);
+
+ varbuf_reset(&filename);
+ varbuf_add_buf(&filename, path, path_len);
+ if (path_len)
+ varbuf_add_char(&filename, '/');
+ varbuf_add_str(&filename, prog);
+ varbuf_end_str(&filename);
+
+ if (stat(filename.buf, &stab) == 0 && (stab.st_mode & 0111)) {
+ varbuf_destroy(&filename);
+ return true;
+ }
+ }
+
+ varbuf_destroy(&filename);
+ return false;
+}
+
/**
* Verify that some programs can be found in the PATH.
*/
@@ -101,41 +135,15 @@ void checkpath(void) {
};
const char *const *prog;
- const char *path_list;
- struct varbuf filename = VARBUF_INIT;
int warned= 0;
- path_list = getenv("PATH");
- if (!path_list)
- ohshit(_("PATH is not set"));
-
for (prog = prog_list; *prog; prog++) {
- struct stat stab;
- const char *path, *path_end;
- size_t path_len;
-
- for (path = path_list; path; path = path_end ? path_end + 1 : NULL) {
- path_end = strchr(path, ':');
- path_len = path_end ? (size_t)(path_end - path) : strlen(path);
-
- varbuf_reset(&filename);
- varbuf_add_buf(&filename, path, path_len);
- if (path_len)
- varbuf_add_char(&filename, '/');
- varbuf_add_str(&filename, *prog);
- varbuf_end_str(&filename);
-
- if (stat(filename.buf, &stab) == 0 && (stab.st_mode & 0111))
- break;
- }
- if (!path) {
+ if (!find_command(*prog)) {
warning(_("'%s' not found in PATH or not executable"), *prog);
warned++;
}
}
- varbuf_destroy(&filename);
-
if (warned)
forcibleerr(fc_badpath,
P_("%d expected program not found in PATH or not executable\n%s",
diff --git a/src/main.h b/src/main.h
index b7c1db7..ed86e4e 100644
--- a/src/main.h
+++ b/src/main.h
@@ -241,6 +241,7 @@ bool force_depends(struct deppossi *possi);
bool force_conflicts(struct deppossi *possi);
void conffile_mark_obsolete(struct pkginfo *pkg, struct filenamenode *namenode);
void pkg_conffiles_mark_old(struct pkginfo *pkg);
+bool find_command(const char *prog);
void checkpath(void);
struct filenamenode *namenodetouse(struct filenamenode *namenode,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git
More information about the Reproducible-commits
mailing list