From 0f56b68eac220d77293d39dda644f2d7177b5368 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Tue, 26 Jan 2016 14:11:10 +0100 Subject: [PATCH 1/5] add HAVE_STRNSTR --- configure | 21 +++++++++++++++++++++ lib/fetch/common.c | 3 +++ 2 files changed, 24 insertions(+) diff --git a/configure b/configure index 4cf4b6c0..1006d4d5 100755 --- a/configure +++ b/configure @@ -474,6 +474,27 @@ else fi rm -f _$func.c _$func +# +# Check for strnstr(). +func=strnstr +printf "Checking for $func() ... " +cat < _$func.c +#include +int main(void) { + const char big[] = "foo"; + const char little[] = "f"; + strnstr(big, little, 3); + return 0; +} +EOF +if $XCC _$func.c -o _$func 2>/dev/null; then + echo yes. + echo "CPPFLAGS += -DHAVE_STRNSTR" >>$CONFIG_MK +else + echo no. +fi +rm -f _$func.c _$func + # # Check for humanize_number(). func=humanize_number diff --git a/lib/fetch/common.c b/lib/fetch/common.c index d035ae62..49874d2e 100644 --- a/lib/fetch/common.c +++ b/lib/fetch/common.c @@ -444,6 +444,8 @@ fetch_cache_put(conn_t *conn, int (*closecb)(conn_t *)) #ifdef WITH_SSL + +#ifndef HAVE_STRNSTR /* * Find the first occurrence of find in s, where the search is limited to the * first slen characters of s. @@ -468,6 +470,7 @@ strnstr(const char *s, const char *find, size_t slen) } return ((char *)__UNCONST(s)); } +#endif /* * Convert characters A-Z to lowercase (intentionally avoid any locale From 618e504d30d493992f84a570218ee33774a58066 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Tue, 26 Jan 2016 14:21:40 +0100 Subject: [PATCH 2/5] actually use HAVE_FDATASYNC --- bin/xbps-create/main.c | 4 ++++ bin/xbps-rindex/repoflush.c | 4 ++++ lib/package_script.c | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/bin/xbps-create/main.c b/bin/xbps-create/main.c index 6c60d2e9..c5ca2acd 100644 --- a/bin/xbps-create/main.c +++ b/bin/xbps-create/main.c @@ -954,7 +954,11 @@ main(int argc, char **argv) */ binpkg = xbps_xasprintf("%s.%s.xbps", pkgver, arch); +#ifdef HAVE_FDATASYNC (void)fdatasync(pkg_fd); +#else + (void)fsync(pkg_fd); +#endif myumask = umask(0); (void)umask(myumask); diff --git a/bin/xbps-rindex/repoflush.c b/bin/xbps-rindex/repoflush.c index 0b56a95e..650e15fe 100644 --- a/bin/xbps-rindex/repoflush.c +++ b/bin/xbps-rindex/repoflush.c @@ -86,7 +86,11 @@ repodata_flush(struct xbps_handle *xhp, const char *repodir, /* Write data to tempfile and rename */ archive_write_finish(ar); +#ifdef HAVE_FDATASYNC fdatasync(repofd); +#else + fsync(repofd); +#endif assert(fchmod(repofd, 0664) != -1); close(repofd); rename(tname, repofile); diff --git a/lib/package_script.c b/lib/package_script.c index d44a7cd2..9280601d 100644 --- a/lib/package_script.c +++ b/lib/package_script.c @@ -87,7 +87,11 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp, goto out; } fchmod(fd, 0750); +#ifdef HAVE_FDATASYNC fdatasync(fd); +#else + fsync(fd); +#endif close(fd); /* exec script */ From ab0d5c847ded11d9871005381f1dfb0c4ef3ed20 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Tue, 26 Jan 2016 14:22:23 +0100 Subject: [PATCH 3/5] libxbps: define _WITH_GETLINE for FreeBSD --- lib/initend.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/initend.c b/lib/initend.c index 1c00b274..a925f98d 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -26,6 +26,9 @@ #include #include +#ifdef __FreeBSD__ +#define _WITH_GETLINE /* getline() */ +#endif #include #include #define _BSD_SOURCE /* required by strlcpy with musl */ From 3bfc7b5e6d4cf796690ab589b90cbaba6e94ce54 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Mon, 8 Feb 2016 14:26:03 +0100 Subject: [PATCH 4/5] alternatives: fix dirname() buffer reuse --- lib/package_alternatives.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/package_alternatives.c b/lib/package_alternatives.c index 467b6a1b..3c66f57b 100644 --- a/lib/package_alternatives.c +++ b/lib/package_alternatives.c @@ -150,7 +150,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) cnt = xbps_array_count(a); for (i = 0; i < cnt; i++) { xbps_string_t str; - char *tgt_dup, *tgt_dir, *lnk_dup, *lnk_dir; + char *tgt_dup, *tgt_dir, *tgt_dir_dup, *lnk_dup, *lnk_dir; char *l, *lnk, *tgt = NULL; const char *tgt0; int rv; @@ -164,6 +164,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) tgt_dup = strdup(tgt0); assert(tgt_dup); tgt_dir = dirname(tgt_dup); + tgt_dir_dup = strdup(tgt_dir); if (strcmp(tgt_dir, ".")) { tgt = xbps_xasprintf("%s%s", xhp->rootdir, tgt_dir); if (xbps_mkpath(tgt, 0755) != 0) { @@ -172,6 +173,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) xbps_dbg_printf(xhp, "failed to create " "target dir '%s' for group '%s': %s\n", tgt, grname, strerror(errno)); + free(tgt_dir_dup); free(tgt_dup); free(tgt); free(l); @@ -192,6 +194,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) xbps_dbg_printf(xhp, "failed to create symlink" "dir '%s' for group '%s': %s\n", lnk, grname, strerror(errno)); + free(tgt_dir_dup); free(tgt_dup); free(lnk_dup); free(lnk); @@ -204,7 +207,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) free(lnk_dup); if (l[0] != '/') { - lnk = xbps_xasprintf("%s%s/%s", xhp->rootdir, tgt_dir, l); + lnk = xbps_xasprintf("%s%s/%s", xhp->rootdir, tgt_dir_dup, l); free(tgt_dup); tgt_dup = strdup(tgt0); assert(tgt_dup); @@ -215,6 +218,7 @@ create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) tgt = strdup(tgt0); lnk = xbps_xasprintf("%s%s", xhp->rootdir, l); } + free(tgt_dir_dup); xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_LINK_ADDED, 0, NULL, "Creating '%s' alternatives group symlink: %s -> %s", grname, l, tgt); unlink(lnk); From 604499d6f28a96197dc14f8ec21e7f56dfef29f4 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Mon, 8 Feb 2016 15:03:14 +0100 Subject: [PATCH 5/5] contributors: fix typo --- CONTRIBUTORS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index ffa0db3a..ee72ca70 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -9,4 +9,4 @@ Steve Prybylski Wolfgang Draxinger Bheesham Persaud Joey Gouly -Michael Ghering +Michael Gehring