From owner-svn-src-head@FreeBSD.ORG Tue Nov 20 13:38:41 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C2353250; Tue, 20 Nov 2012 13:38:41 +0000 (UTC) (envelope-from baptiste.daroussin@gmail.com) Received: from mail-we0-f182.google.com (mail-we0-f182.google.com [74.125.82.182]) by mx1.freebsd.org (Postfix) with ESMTP id 5E0D28FC12; Tue, 20 Nov 2012 13:38:40 +0000 (UTC) Received: by mail-we0-f182.google.com with SMTP id u54so1556475wey.13 for ; Tue, 20 Nov 2012 05:38:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=b9b/Ucbj0s0UhbaL4nTbHb9u79XSKDR7INdsPq9nDsE=; b=OxRMs8zwd7Xz2llhBW5D9FNtmq4gVmaCJI4QqX3boK4+F4Ne32qtGeIUvyh1gSLlBp TAFaB6jmOKbJLdNBip8H6/W8xDHrKVCuBzkNjmQqNyIyP1PcV8s6grV/AN1Bol7+GHZW 675xKJgkthdSwbmO+z/KUEWToTOhU0uGjT3MdfQuO0P0DoXBGtAIqSbzdxkwktjsbvpU JCX/YnPvgx/KOJ7HnYVchTzrsEAnCpldW+QJFVzQJDBKDyWgf772Qr1m5bASqdQxc0cK HLV5XOKFnC3jm02Vd15et+gtBXSMFEHNCK3NzIK0zMDwuZwl55oD7Tuo2KN34PndTQiS co7Q== Received: by 10.216.226.213 with SMTP id b63mr3501989weq.183.1353418719307; Tue, 20 Nov 2012 05:38:39 -0800 (PST) Received: from ithaqua.etoilebsd.net (ithaqua.etoilebsd.net. [37.59.37.188]) by mx.google.com with ESMTPS id en20sm20052691wid.4.2012.11.20.05.38.38 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Nov 2012 05:38:38 -0800 (PST) Sender: Baptiste Daroussin Date: Tue, 20 Nov 2012 14:38:37 +0100 From: Baptiste Daroussin To: Jaakko Heinonen Subject: Re: svn commit: r243328 - head/lib/libutil Message-ID: <20121120133837.GK71195@ithaqua.etoilebsd.net> References: <201211200722.qAK7M7Im057617@svn.freebsd.org> <20121120122226.GA1828@a91-153-116-96.elisa-laajakaista.fi> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="/ZYM6PqDyfNytx60" Content-Disposition: inline In-Reply-To: <20121120122226.GA1828@a91-153-116-96.elisa-laajakaista.fi> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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: Tue, 20 Nov 2012 13:38:42 -0000 --/ZYM6PqDyfNytx60 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Nov 20, 2012 at 02:22:26PM +0200, Jaakko Heinonen wrote: >=20 > Hi! >=20 > On 2012-11-20, Baptiste Daroussin wrote: > > change mode the group file to 0644 after a successfull rename(2) > >=20 > > int > > gr_mkdb(void) > > { > > - return (rename(tempname, group_file)); > > + int ret; > > + > > + ret =3D rename(tempname, group_file); > > + > > + if (ret =3D=3D 0) > > + chmod(group_file, 0644); > > + > > + return (ret); > > } >=20 > Rename+chmod is not an atomic operation. There is a window when the file > has wrong permissions. Also, you don't check the return value of > chmod(). Maybe chmod first and then rename? >=20 > --=20 > Jaakko Does this looks better to you? http://people.freebsd.org/~bapt/gr_util.diff regards, Bapt --/ZYM6PqDyfNytx60 Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlCrh90ACgkQ8kTtMUmk6EzfsQCfVkPtjjtCQ+dtDWdHuiLSUv1I PrEAn1RGIPNR7vctapc25JWf3daeIChw =sc/T -----END PGP SIGNATURE----- --/ZYM6PqDyfNytx60--