From owner-freebsd-questions Tue Aug 28 0:48:37 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mail.XtremeDev.com (xtremedev.com [216.241.38.65]) by hub.freebsd.org (Postfix) with ESMTP id DA22937B405 for ; Tue, 28 Aug 2001 00:48:32 -0700 (PDT) (envelope-from freebsd@XtremeDev.com) Received: from xtremedev.com (xtremedev.com [216.241.38.65]) by mail.XtremeDev.com (Postfix) with ESMTP id B697613640; Tue, 28 Aug 2001 01:48:31 -0600 (MDT) Date: Tue, 28 Aug 2001 01:48:31 -0600 (MDT) From: FreeBSD To: Dan Nelson Cc: Subject: Re: open() in FreeBSD? In-Reply-To: <20010827222534.B17383@dan.emsphone.com> Message-ID: <20010828014650.T44951-100000@Amber.XtremeDev.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Ahh, thanks all! Out of curiosity however, wouldn't it be a good thing to have it default to umask if no arguments were passed rather than making it a required arg, and just using random data if none was passed? Seems awfully iffy doing that.. O'well. Just a thought. Thanks for the rapid replies all! On Mon, 27 Aug 2001, Dan Nelson wrote: > In the last episode (Aug 27), FreeBSD said: > > Hello, I have the following test program: > > > > #include > > #include > > #include > > > > int main() > > { > > int fd = open("blah", O_WRONLY|O_CREAT); > > close(fd); > > return EXIT_SUCCESS; > > } > > > > When I compiled this and run it, ls -l blah gives me: > > > > ---------x 1 freebsd freebsd - 0 Aug 27 20:46 blah* > > > > Looking through man 2 umask, the default umask is 022. Yet the file > > created by open() gives me a mask of 001? In the shell I checked the > > umask, and it indeed is at 022. If the default umask is 022, why does > > leaving out the third argument to open() not follow chmod/umask as > > implied by the man 2 open? > > > > "open requires a third argument mode_t mode, and the file is created > > with mode mode as described in chmod(2) and modified by the process' > > umask value (see umask(2))." - man 2 open > > > > In this case it wasn't modified by the process' umask value (as it is > > set to 022 and verified). fopen() works fine. Can anyone shed some > > light on this subject? I'm sure I'm missing something simple. Or > > atleast clear up the man page on what's default and what's not. > > You're missing the word "requires" in that manpage you quoted :) If > you create a file with open() you *must* pass a mode, which is masked > by the current umask setting. You didn't, so the system pulled a > random value off the stack, which when masked with your umask, happened > to come out 001. Since the default umask is 022 (filter group and > other write access), if the value on the stack happened to be 023, the > resulting mode would be 001. (all values in octal because we're > dealing with modes) > > -- > Dan Nelson > dnelson@emsphone.com > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message