From owner-freebsd-hackers Wed Jan 16 2:48:54 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from gw.gbch.net (gw.gbch.net [203.143.238.93]) by hub.freebsd.org (Postfix) with SMTP id 4A53437B41A for ; Wed, 16 Jan 2002 02:48:48 -0800 (PST) Received: (qmail 76661 invoked by uid 1001); 16 Jan 2002 20:48:46 +1000 X-Posted-By: GJB-Post 2.23 27-Nov-2001 X-Operating-System: FreeBSD 4.2-RELEASE i386 X-Uptime: 7 days, 3:15 X-Location: Brisbane, Australia; 27.49841S 152.98439E X-URL: http://www.gbch.net/gjb.html X-Image-URL: http://www.gbch.net/gjb/gjb-auug048.gif X-GPG-Fingerprint: EBB2 2A92 A79D 1533 AC00 3C46 5D83 B6FB 4B04 B7D6 X-PGP-Public-Keys: http://www.gbch.net/keys.html Message-Id: Date: Wed, 16 Jan 2002 20:48:46 +1000 From: Greg Black Mail-Followup-To: Foldi Tamas To: Foldi Tamas Cc: freebsd-hackers@freebsd.org Subject: Re: interesting open() issue References: <20020116105923.A29210@hax0r.hu> In-reply-to: <20020116105923.A29210@hax0r.hu> of Wed, 16 Jan 2002 10:59:23 +0100 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Foldi Tamas wrote: | Hello hackers, Don't send this sort of newbie programmer question to the hackers list (or to any of the FreeBSD lists). | I tried the following program on Tru64, FreeBSD and linux: | | #include | #include | #include | #include | main() { | int fd; | fd = open ( "/tmp/foobar", (O_RDWR | O_CREAT), 0020); | perror("open"); | close(fd); | } | | The program ran successfully, but the created file was different. | On Linux: | -----w---- 1 crow crow 0 Jan 16 10:32 /tmp/foobar | | On Tru64/FreeBSD: | ---------- 1 crow users 0 Jan 16 10:30 /tmp/foobar | | I'm not sure what the result supposed to be. Any ideas ? If you want the exact same results on each system and if you want the file to have the mode you set, you need to put two additional system calls *before* the open(2) call: unlink("/tmp/foobar"); umask(0); If the file exists, the mode in the open() won't affect it and it will retain whatever it already had, so you need to ensure that it's not there first. If your umask setting masks the group write bit, it won't be set unless you first clear the umask setting. Now go and read about Unix programming. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message