From owner-svn-src-all@FreeBSD.ORG Tue Sep 23 11:41:10 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 4CED3ECB; Tue, 23 Sep 2014 11:41:10 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id F2FD3D0C; Tue, 23 Sep 2014 11:41:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8NBf9x5033177; Tue, 23 Sep 2014 11:41:09 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8NBf9WD033171; Tue, 23 Sep 2014 11:41:09 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201409231141.s8NBf9WD033171@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Tue, 23 Sep 2014 11:41:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r272026 - head/usr.bin/xinstall X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Sep 2014 11:41:10 -0000 Author: mjg Date: Tue Sep 23 11:41:09 2014 New Revision: 272026 URL: http://svnweb.freebsd.org/changeset/base/272026 Log: install: re-check failed mkdir for EEXIST Since the code stats and mkdirs in 2 separate steps, it is possible that the directory will be created in the meantime by something else (e.g. concurrent install).[1] While here alter the code to properly report stat failure, previously it would always claim it was mkdir which failed. Noted by: royger [1] MFC after: 1 week Modified: head/usr.bin/xinstall/xinstall.c Modified: head/usr.bin/xinstall/xinstall.c ============================================================================== --- head/usr.bin/xinstall/xinstall.c Tue Sep 23 11:27:43 2014 (r272025) +++ head/usr.bin/xinstall/xinstall.c Tue Sep 23 11:41:09 2014 (r272026) @@ -1263,13 +1263,18 @@ install_dir(char *path) if (!*p || (p != path && *p == '/')) { ch = *p; *p = '\0'; - if (stat(path, &sb)) { - if (errno != ENOENT || mkdir(path, 0755) < 0) { +again: + if (stat(path, &sb) < 0) { + if (errno != ENOENT) + err(EX_OSERR, "stat %s", path); + if (mkdir(path, 0755) < 0) { + if (errno == EEXIST) + goto again; err(EX_OSERR, "mkdir %s", path); - /* NOTREACHED */ - } else if (verbose) + } + if (verbose) (void)printf("install: mkdir %s\n", - path); + path); } else if (!S_ISDIR(sb.st_mode)) errx(EX_OSERR, "%s exists but is not a directory", path); if (!(*p = ch))