Date: Sun, 12 Jul 2020 20:59:53 +0000 (UTC) From: Eugene Grosbein <eugen@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363136 - head/usr.bin/xinstall Message-ID: <202007122059.06CKxrIx035279@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eugen Date: Sun Jul 12 20:59:52 2020 New Revision: 363136 URL: https://svnweb.freebsd.org/changeset/base/363136 Log: install(1): another correction after r363064 Make sure we call fsync(2) on strip result in case of "safecopy" and "strip -o tempcopy -- src" before renaming tempcopy to destination. MFC after: 3 weeks X-MFC-With: r363064 Modified: head/usr.bin/xinstall/xinstall.c Modified: head/usr.bin/xinstall/xinstall.c ============================================================================== --- head/usr.bin/xinstall/xinstall.c Sun Jul 12 19:39:56 2020 (r363135) +++ head/usr.bin/xinstall/xinstall.c Sun Jul 12 20:59:52 2020 (r363136) @@ -147,7 +147,7 @@ static void install_dir(char *); static void metadata_log(const char *, const char *, struct timespec *, const char *, const char *, off_t); static int parseid(const char *, id_t *); -static int strip(const char *, const char *, char **); +static int strip(const char *, int, const char *, char **); static int trymmap(int); static void usage(void); @@ -862,7 +862,7 @@ install(const char *from_name, const char *to_name, u_ if (!devnull) { if (dostrip) stripped = strip(tempcopy ? tempfile : to_name, - from_name, &digestresult); + to_fd, from_name, &digestresult); if (!stripped) digestresult = copy(from_fd, from_name, to_fd, tempcopy ? tempfile : to_name, from_sb.st_size); @@ -871,8 +871,8 @@ install(const char *from_name, const char *to_name, u_ if (dostrip) { if (!stripped) - (void)strip(tempcopy ? tempfile : to_name, NULL, - &digestresult); + (void)strip(tempcopy ? tempfile : to_name, to_fd, + NULL, &digestresult); /* * Re-open our fd on the target, in case @@ -1310,17 +1310,18 @@ copy(int from_fd, const char *from_name, int to_fd, co /* * strip -- * Use strip(1) to strip the target file. - * Just invoke strip(1) on to_name if from_name is NULL, - * else try to run "strip -o to_name -- from_name" and return 0 on failure. - * Return 1 on success and assign result of digest_file(to_name) to *dresp. + * Just invoke strip(1) on to_name if from_name is NULL, else try + * to run "strip -o to_name -- from_name" and return 0 on failure. + * Return 1 on success and assign result of digest_file(to_name) + * to *dresp. */ static int -strip(const char *to_name, const char *from_name, char **dresp) +strip(const char *to_name, int to_fd, const char *from_name, char **dresp) { const char *stripbin; const char *args[6]; pid_t pid; - int error, status; + int error, serrno, status; stripbin = getenv("STRIPBIN"); if (stripbin == NULL) @@ -1355,6 +1356,12 @@ strip(const char *to_name, const char *from_name, char (void)unlink(to_name); errx(EX_SOFTWARE, "strip command %s failed on %s", stripbin, to_name); + } + if (from_name != NULL && safecopy && fsync(to_fd) == -1) { + serrno = errno; + (void)unlink(to_name); + errno = serrno; + err(EX_OSERR, "fsync failed for %s", to_name); } if (dresp != NULL) *dresp = digest_file(to_name);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007122059.06CKxrIx035279>