From owner-svn-src-head@freebsd.org Sun Jul 12 20:59:53 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AE81636E2F6; Sun, 12 Jul 2020 20:59:53 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4B4fL14B92z42rj; Sun, 12 Jul 2020 20:59:53 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 72F1BA5A5; Sun, 12 Jul 2020 20:59:53 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 06CKxrcC035280; Sun, 12 Jul 2020 20:59:53 GMT (envelope-from eugen@FreeBSD.org) Received: (from eugen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 06CKxrIx035279; Sun, 12 Jul 2020 20:59:53 GMT (envelope-from eugen@FreeBSD.org) Message-Id: <202007122059.06CKxrIx035279@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eugen set sender to eugen@FreeBSD.org using -f From: Eugene Grosbein Date: Sun, 12 Jul 2020 20:59:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r363136 - head/usr.bin/xinstall X-SVN-Group: head X-SVN-Commit-Author: eugen X-SVN-Commit-Paths: head/usr.bin/xinstall X-SVN-Commit-Revision: 363136 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Jul 2020 20:59:53 -0000 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);