From: ebiederm@xmission.com (Eric W. Biederman)
To: Jamie Lokier <lk@tantalophile.demon.co.uk>
Cc: "Albert D. Cahalan" <acahalan@cs.uml.edu>,
Thunder from the hill <thunder@ngforever.de>,
Dave Jones <davej@suse.de>,
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
linux-kernel@vger.kernel.org, chaffee@cs.berkeley.edu
Subject: Re: [patch] fat/msdos/vfat crud removal
Date: 12 Jun 2002 00:50:45 -0600 [thread overview]
Message-ID: <m1n0u1uh16.fsf@frodo.biederman.org> (raw)
In-Reply-To: <200206092104.g59L4JD448386@saturn.cs.uml.edu> <m1vg8rutjm.fsf@frodo.biederman.org> <20020611174951.A24310@kushida.apsleyroad.org>
Jamie Lokier <lk@tantalophile.demon.co.uk> writes:
> Eric W. Biederman wrote:
> > Actually by now most applications have been fixed and do not use
> > them. The policy has been in place for several years now.
>
> I like this policy and understand how to use it, except...
First early adopters of any feature have a challenge.
> Once upon a time I wrote a program which used O_NOFOLLOW, before Glibc
> had support for that flag.
>
> It had to read the kernel headers, as this macro is an
> architecture-dependent flag, and I did not want to write a program that
> was so non-portable it would only compile on some architectures.
>
> Even if I'd copied all the definitions for all architectures out of the
> kernel, that wouldn't do: the program wouldn't compile on architectures
> added later, or ones that aren't part of the standard distribution.
>
> So to keep the program relatively portable, it searched for definitions
> of O_NOFOLLOW in the kernel headers. (It was a Glibc/kernel conflict
> nightmare).
>
> Please can you suggest how I should write this sort of code, the next
> time it occurs?
Hmm. I think I would do:
/* use the standard open includes */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef O_NOFOLLOW
#ifdef __i386__
#define O_NOFOLLOW 0400000
#else
#error I must have O_NOFOLLOW fix glibc
#endif
#endif
Or if it really didn't matter much:
#ifndef O_NOFOLLOW
#define O_NOFOLLOW 0
#endif
But even beyond that it makes a lot of sense to have autoconf add
a test for O_NOFOLLOW, and do something appropriate if it isn't
defined, or supported. Otherwise your code gets brittle anyway.
Where generic API extensions end up in the future is pretty well
defined, so you don't have to guess where libc will put them.
In most cases the kernel header rule only applies to pure linux
specific interfaces where the numbers don't change between
architectures, and to interfaces that are specific to a small subset
of programs, (device specific code like hdparm).
But even using kernel headers doesn't help on current systems,
as you should have headers that correspond to the version of the
kernel your libc was compiled against. So if libc didn't support
O_NOFOLLOW it is quite unlikely that user space would in any form.
Eric
next prev parent reply other threads:[~2002-06-12 7:00 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-09 2:47 [patch] fat/msdos/vfat crud removal Albert D. Cahalan
2002-06-09 4:24 ` OGAWA Hirofumi
2002-06-09 4:32 ` OGAWA Hirofumi
2002-06-09 4:46 ` Albert D. Cahalan
2002-06-09 5:07 ` OGAWA Hirofumi
2002-06-09 6:03 ` Albert D. Cahalan
2002-06-09 6:32 ` OGAWA Hirofumi
2002-06-09 7:09 ` Albert D. Cahalan
2002-06-09 7:49 ` OGAWA Hirofumi
2002-06-09 9:46 ` Dave Jones
2002-06-09 17:52 ` Eric W. Biederman
2002-06-09 18:49 ` H. Peter Anvin
2002-06-09 19:00 ` Thunder from the hill
2002-06-09 19:29 ` David Woodhouse
2002-06-09 20:19 ` Thunder from the hill
2002-06-10 13:51 ` Eric W. Biederman
2002-06-09 21:04 ` Albert D. Cahalan
2002-06-10 13:55 ` Eric W. Biederman
2002-06-11 16:49 ` Jamie Lokier
2002-06-12 6:50 ` Eric W. Biederman [this message]
2002-06-12 11:47 ` Thunder from the hill
2002-06-09 9:00 ` OGAWA Hirofumi
2002-06-09 13:51 ` Martin Dalecki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m1n0u1uh16.fsf@frodo.biederman.org \
--to=ebiederm@xmission.com \
--cc=acahalan@cs.uml.edu \
--cc=chaffee@cs.berkeley.edu \
--cc=davej@suse.de \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=lk@tantalophile.demon.co.uk \
--cc=thunder@ngforever.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox