mailing list of musl libc
 help / color / mirror / code / Atom feed
* Namespace issues, missing functions, _BSD_SOURCE for unistd.h
@ 2012-04-05 22:55 Isaac Dunham
  2012-04-06  0:10 ` Rich Felker
  0 siblings, 1 reply; 12+ messages in thread
From: Isaac Dunham @ 2012-04-05 22:55 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1035 bytes --]

Attached is a patch that should add proper BSD_SOURCE support for
<unistd.h>. I'm not sure that the formatting/style is proper, and the
exact arrangement is rather arbitrary.  But I've moved a lot of things
that were wrongly grouped in either ANSI namespace or GNU-only
namespace.

BSD || XOPEN means the macro test should be
#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
I see glibc turns on both of these with _GNU_SOURCE.

Misplaced (should be BSD || XOPEN):
(Properly, these require XOPEN >= 500)
usleep, ualarm, fchown, fchdir, lchown,vhangup,
apparently fsync?

Missing (BSD || XOPEN):
getwd,ttyslot,sethostid,get/setdomainname,revoke,profil,acct,get/end/setusershell

BSD||GNU:
setlogin, getpass

These and chroot also should be available with lower values of
_XOPEN_SOURCE

Incompatible:
BSD uses setpgrp the same way everyone else uses setpgid--a
substitution macro will do the job. That's what glibc does and what I
did.

And there may be one or two more that I didn't mention in here because
I lost track.

Isaac Dunham

[-- Attachment #2: unistd.diff --]
[-- Type: text/x-patch, Size: 3488 bytes --]

diff --git a/include/unistd.h b/include/unistd.h
index 7662e51..de173dc 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -16,6 +16,12 @@ extern "C" {
 #define SEEK_CUR 1
 #define SEEK_END 2
 
+#if defined(_BSD_SOURCE) && !defined(L_SET)
+#define L_SET
+#define L_INCR
+#define L_XTND
+#endif
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -47,13 +53,10 @@ ssize_t pread(int, void *, size_t, off_t);
 ssize_t pwrite(int, const void *, size_t, off_t);
 
 int chown(const char *, uid_t, gid_t);
-int fchown(int, uid_t, gid_t);
-int lchown(const char *, uid_t, gid_t);
 int fchownat(int, const char *, uid_t, gid_t, int);
 
 int link(const char *, const char *);
 int linkat(int, const char *, int, const char *, int);
-int symlink(const char *, const char *);
 int symlinkat(const char *, int, const char *);
 ssize_t readlink(const char *, char *, size_t);
 ssize_t readlinkat(int, const char *, char *, size_t);
@@ -61,7 +64,6 @@ int unlink(const char *);
 int unlinkat(int, const char *, int);
 int rmdir(const char *);
 int truncate(const char *, off_t);
-int ftruncate(int, off_t);
 
 #define F_OK 0
 #define R_OK 4
@@ -71,7 +73,6 @@ int access(const char *, int);
 int faccessat(int, const char *, int, int);
 
 int chdir(const char *);
-int fchdir(int);
 char *getcwd(char *, size_t);
 
 unsigned alarm(unsigned);
@@ -101,21 +102,23 @@ int isatty(int);
 pid_t tcgetpgrp(int);
 int tcsetpgrp(int, pid_t);
 
+#if defined(_BSD_SOURCE) && !defined(_POSIX_C_SOURCE) \
+ && !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE) \
+ && !defined(_GNU_SOURCE)
+#define setpgrp setpgid
+int symlink(const char *, const char *);
+#endif
+
 uid_t getuid(void);
 uid_t geteuid(void);
 gid_t getgid(void);
 gid_t getegid(void);
 int getgroups(int, gid_t []);
 int setuid(uid_t);
-int setreuid(uid_t, uid_t);
-int seteuid(uid_t);
 int setgid(gid_t);
-int setregid(gid_t, gid_t);
-int setegid(gid_t);
 
 char *getlogin(void);
 int getlogin_r(char *, size_t);
-int gethostname(char *, size_t);
 char *ctermid(char *);
 
 int getopt(int, char * const [], const char *);
@@ -138,23 +141,52 @@ pid_t setpgrp(void);
 char *crypt(const char *, const char *);
 void encrypt(char *, int);
 void swab(const void *, void *, ssize_t);
-long gethostid(void);
 int nice(int);
 void sync(void);
 int getdtablesize(void);
 #endif
 
+#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) \
+ || defined(_POSIX_SOURCE) || defined(_GNU_SOURCE)
+
+#if !( (_POSIX_SOURCE - 0) < 200112L )
+int seteuid(uid_t);
+int setegid(gid_t);
+#endif
+
+int ftruncate(int, off_t);
+int sethostname(const char *, size_t);
+#endif
+
+#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
+int setreuid(uid_t, uid_t);
+int setregid(gid_t, gid_t);
+
+int fchown(int, uid_t, gid_t);
+int lchown(const char *, uid_t, gid_t);
+
+int fchdir(int);
+
+pid_t vfork(void);
+int vhangup(void);
+int usleep(unsigned);
+unsigned ualarm(unsigned, unsigned);
+
+long gethostid(void);
+#endif
+
+#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
+int gethostname(char *, size_t);
+int chroot(const char *); /* Also old 
+#endif
+
+
 #ifdef _GNU_SOURCE
 int brk(void *);
 void *sbrk(intptr_t);
 pid_t forkall(void);
-pid_t vfork(void);
-int vhangup(void);
-int chroot(const char *);
 int getpagesize(void);
-int sethostname(const char *, size_t);
-int usleep(unsigned);
-unsigned ualarm(unsigned, unsigned);
+
 int setgroups(size_t, const gid_t []);
 int setresuid(uid_t, uid_t, uid_t);
 int setresgid(gid_t, gid_t, gid_t);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Namespace issues, missing functions, _BSD_SOURCE for unistd.h
  2012-04-05 22:55 Namespace issues, missing functions, _BSD_SOURCE for unistd.h Isaac Dunham
@ 2012-04-06  0:10 ` Rich Felker
  2012-04-06  1:03   ` Isaac Dunham
  2012-04-06  1:45   ` [PATCH] _BSD_SOURCE for unistd.h, take 2 Isaac Dunham
  0 siblings, 2 replies; 12+ messages in thread
From: Rich Felker @ 2012-04-06  0:10 UTC (permalink / raw)
  To: musl

On Thu, Apr 05, 2012 at 03:55:08PM -0700, Isaac Dunham wrote:
> Attached is a patch that should add proper BSD_SOURCE support for
> <unistd.h>. I'm not sure that the formatting/style is proper, and the
> exact arrangement is rather arbitrary.  But I've moved a lot of things
> that were wrongly grouped in either ANSI namespace or GNU-only
> namespace.

There is no "ANSI" namespace in unistd.h because it's not a standard C
header but a POSIX header. It's definitely correct for POSIX 2008 base
as-is without any patching.

> BSD || XOPEN means the macro test should be
> #if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
> I see glibc turns on both of these with _GNU_SOURCE.

Yes, I think you overlooked some of the logic of how glibc's
features.h works...

> Misplaced (should be BSD || XOPEN):
> (Properly, these require XOPEN >= 500)
> usleep, ualarm, fchown, fchdir, lchown,vhangup,
> apparently fsync?

All incorrect.

usleep and ualarm were removed by SUSv4/POSIX 2008 and thus do not
belong in any profile except ones with nonstandard extensions.

fchown, fchdir, and lchown are all POSIX 2008 base.

vhangup was perhaps standard at one time but removed; it's only in the
nonstandard profiles now.

> Missing (BSD || XOPEN):
> getwd,ttyslot,sethostid,get/setdomainname,revoke,profil,acct,get/end/setusershell

AFAIK most of these do not exist in musl at the moment.

> BSD||GNU:
> setlogin, getpass
> 
> These and chroot also should be available with lower values of
> _XOPEN_SOURCE
> 
> Incompatible:
> BSD uses setpgrp the same way everyone else uses setpgid--a
> substitution macro will do the job. That's what glibc does and what I
> did.

So far musl's policy with GNU brokenness has been not to duplicate any
brokenness that conflicts with the standard behavior of standard
functions and makes them nonconformant. I intend to take the same
approach with BSD. _BSD_SOURCE should simply mean "make BSD extensions
available", not "break standard functions to duplicate broken legacy
BSD behavior".

> +#if defined(_BSD_SOURCE) && !defined(L_SET)
> +#define L_SET
> +#define L_INCR
> +#define L_XTND
> +#endif

I don't see how blank definitions can be useful for these...

> +#if defined(_BSD_SOURCE) && !defined(_POSIX_C_SOURCE) \
> + && !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE) \
> + && !defined(_GNU_SOURCE)
> +#define setpgrp setpgid
> +int symlink(const char *, const char *);
> +#endif

Moving symlink here is definitely wrong. And see above about setpgrp.

> +#if !( (_POSIX_SOURCE - 0) < 200112L )
> +int seteuid(uid_t);
> +int setegid(gid_t);
> +#endif

I have no intention of trying to make a profile that conforms to the
1990 version of POSIX.

> +#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)
> +int setreuid(uid_t, uid_t);
> +int setregid(gid_t, gid_t);

Definitely wrong. These are POSIX base.

> +int fchown(int, uid_t, gid_t);
> +int lchown(const char *, uid_t, gid_t);
> +
> +int fchdir(int);

And so are these.

> +pid_t vfork(void);
> +int vhangup(void);
> +int usleep(unsigned);
> +unsigned ualarm(unsigned, unsigned);

And these do not exist in SUSv4. (The first two are not in SUSv3 either.)

Rich


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Namespace issues, missing functions, _BSD_SOURCE for unistd.h
  2012-04-06  0:10 ` Rich Felker
@ 2012-04-06  1:03   ` Isaac Dunham
  2012-04-06  1:52     ` Rich Felker
  2012-04-06  1:45   ` [PATCH] _BSD_SOURCE for unistd.h, take 2 Isaac Dunham
  1 sibling, 1 reply; 12+ messages in thread
From: Isaac Dunham @ 2012-04-06  1:03 UTC (permalink / raw)
  To: musl

> There is no "ANSI" namespace in unistd.h because it's not a standard C
> header but a POSIX header. It's definitely correct for POSIX 2008 base
> as-is without any patching.
Should have checked that. 
I guess it will be a rewrite then.

Which profiles are you aiming to support? Latest versions only for
POSIX, ISO, and X/Open? Or only versions in the past decade?
I don't see any signs of  version checks, so I assume you want POSIX2008
and XOPEN2008 (_XOPEN_SOURCE >= 700) only, and no support for SUSv3.
This will make the patch a lot smaller and cleaner.

> > BSD || XOPEN means the macro test should be
> > #if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE)
> > I see glibc turns on both of these with _GNU_SOURCE.
> Yes, I think you overlooked some of the logic of how glibc's
> features.h works...
Tried to decode it, but it's pretty easy to lose track (especially in
the ifdef nest that handles XOPEN_SOURCE).

> > Misplaced (should be BSD || XOPEN):
> > (Properly, these require XOPEN >= 500)
> > usleep, ualarm, fchown, fchdir, lchown,vhangup,
> > apparently fsync? 
> All incorrect.
> usleep and ualarm were removed by SUSv4/POSIX 2008 and thus do not
> belong in any profile except ones with nonstandard extensions.
> fchown, fchdir, and lchown are all POSIX 2008 base.
> vhangup was perhaps standard at one time but removed
OK. _GNU_SOURCE || _BSD_SOURCE
It's _XOPEN_SOURCE == 500 || 600, which I take it will not be supported.

<snip>
> AFAIK most of these do not exist in musl at the moment.
Guessed that.  It was meant as a comment on the status.

> > BSD||GNU:
..
 
> > +#if defined(_BSD_SOURCE) && !defined(L_SET)
> > +#define L_SET
> > +#define L_INCR
> > +#define L_XTND
> > +#endif
Forgot to add the SEEK_SET, etc. here.
Should be 
#define L_SET SEEK_SET
..
hence the placement.
 
> > +#if !( (_POSIX_SOURCE - 0) < 200112L )
> > +int seteuid(uid_t);
> > +int setegid(gid_t);
> > +#endif
> 
> I have no intention of trying to make a profile that conforms to the
> 1990 version of POSIX.
Forgot they went from straight from 1993 to 2001; I'll take that test
out. 

> 
> > +#if defined(_BSD_SOURCE) || ...
 
> > +pid_t vfork(void);
> > +int vhangup(void);
> > +int usleep(unsigned);
> > +unsigned ualarm(unsigned, unsigned);
> 
> And these do not exist in SUSv4. (The first two are not in SUSv3
> either.)
Will fix.

Thanks for the comments.
Isaac Dunham



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06  0:10 ` Rich Felker
  2012-04-06  1:03   ` Isaac Dunham
@ 2012-04-06  1:45   ` Isaac Dunham
  2012-04-06  2:04     ` Rich Felker
  2012-04-06 14:48     ` Rich Felker
  1 sibling, 2 replies; 12+ messages in thread
From: Isaac Dunham @ 2012-04-06  1:45 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 357 bytes --]

This is what was left from the comments.

This adds L_SET & co., and defines 5 functions that had been under
_GNU_SOURCE only, when _BSD_SOURCE is defined.
If I wanted to make things a little easier on those porting, I might
add something like this when _BSD_SOURCE is defined:
#warn "BSD setpgrp should be changed to setpgid"
That's not essential, though.

[-- Attachment #2: unistd.diff --]
[-- Type: text/x-patch, Size: 1029 bytes --]

diff --git a/include/unistd.h b/include/unistd.h
index 7662e51..d924886 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -16,6 +16,12 @@ extern "C" {
 #define SEEK_CUR 1
 #define SEEK_END 2
 
+#if defined(_BSD_SOURCE) && !defined(L_SET)
+#define L_SET	SEEK_SET
+#define L_INCR	SEEK_CUR
+#define L_XTND	SEEK_END
+#endif
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -144,17 +150,20 @@ void sync(void);
 int getdtablesize(void);
 #endif
 
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+pid_t vfork(void);
+int vhangup(void);
+int chroot(const char *);
+int usleep(unsigned);
+unsigned ualarm(unsigned, unsigned);
+#endif
+
 #ifdef _GNU_SOURCE
 int brk(void *);
 void *sbrk(intptr_t);
 pid_t forkall(void);
-pid_t vfork(void);
-int vhangup(void);
-int chroot(const char *);
 int getpagesize(void);
 int sethostname(const char *, size_t);
-int usleep(unsigned);
-unsigned ualarm(unsigned, unsigned);
 int setgroups(size_t, const gid_t []);
 int setresuid(uid_t, uid_t, uid_t);
 int setresgid(gid_t, gid_t, gid_t);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Namespace issues, missing functions, _BSD_SOURCE for unistd.h
  2012-04-06  1:03   ` Isaac Dunham
@ 2012-04-06  1:52     ` Rich Felker
  0 siblings, 0 replies; 12+ messages in thread
From: Rich Felker @ 2012-04-06  1:52 UTC (permalink / raw)
  To: musl

On Thu, Apr 05, 2012 at 06:03:07PM -0700, Isaac Dunham wrote:
> > There is no "ANSI" namespace in unistd.h because it's not a standard C
> > header but a POSIX header. It's definitely correct for POSIX 2008 base
> > as-is without any patching.
> Should have checked that. 
> I guess it will be a rewrite then.
> 
> Which profiles are you aiming to support? Latest versions only for
> POSIX, ISO, and X/Open? Or only versions in the past decade?
> I don't see any signs of  version checks, so I assume you want POSIX2008
> and XOPEN2008 (_XOPEN_SOURCE >= 700) only, and no support for SUSv3.
> This will make the patch a lot smaller and cleaner.

My aim has always been the minimum set of profiles that will meet
real-world needs. Latest-version seems to be fine for that. The only
possible issue is interfaces that have been removed, but code that's
old enough to still be using interfaces that were marked obsolescent
11 years ago and removed 4 years ago probably needs _GNU_SOURCE or
similar anyway..

> <snip>
> > AFAIK most of these do not exist in musl at the moment.
> Guessed that.  It was meant as a comment on the status.

OK.

> > > +#if defined(_BSD_SOURCE) && !defined(L_SET)
> > > +#define L_SET
> > > +#define L_INCR
> > > +#define L_XTND
> > > +#endif
> Forgot to add the SEEK_SET, etc. here.
> Should be 
> #define L_SET SEEK_SET
> ...
> hence the placement.

OK.

Rich


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06  1:45   ` [PATCH] _BSD_SOURCE for unistd.h, take 2 Isaac Dunham
@ 2012-04-06  2:04     ` Rich Felker
  2012-04-06  2:40       ` Isaac Dunham
  2012-04-06 14:48     ` Rich Felker
  1 sibling, 1 reply; 12+ messages in thread
From: Rich Felker @ 2012-04-06  2:04 UTC (permalink / raw)
  To: musl

On Thu, Apr 05, 2012 at 06:45:34PM -0700, Isaac Dunham wrote:
> This is what was left from the comments.
> 
> This adds L_SET & co., and defines 5 functions that had been under
> _GNU_SOURCE only, when _BSD_SOURCE is defined.
> If I wanted to make things a little easier on those porting, I might
> add something like this when _BSD_SOURCE is defined:
> #warn "BSD setpgrp should be changed to setpgid"
> That's not essential, though.

The mismatching prototype should be enough to get a nice error. :)

Anyway, patch looks good now. Should I start committing or do you want
to prepare a unified patch for all the headers?

Rich


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06  2:04     ` Rich Felker
@ 2012-04-06  2:40       ` Isaac Dunham
  2012-04-06  2:51         ` Rich Felker
  0 siblings, 1 reply; 12+ messages in thread
From: Isaac Dunham @ 2012-04-06  2:40 UTC (permalink / raw)
  To: musl

On Thu, 5 Apr 2012 22:04:35 -0400
Rich Felker <dalias@aerifal.cx> wrote:

> > If I wanted to make things a little easier on those porting, I might
> > add something like this when _BSD_SOURCE is defined:
> > #warn "BSD setpgrp should be changed to setpgid"
> > That's not essential, though.
> The mismatching prototype should be enough to get a nice error. :)

Sometimes I enjoy having a hint about how to change it, rather than
needing to read the glibc headers...
I put #warn instead of #error because they could well be using only the
other _BSD_SOURCE functions.

> Anyway, patch looks good now. Should I start committing or do you want
> to prepare a unified patch for all the headers?

Feel free to start committing.
I may not be able to get all of the headers very soon, with my classes.
But this patch alone should solve at least one of Rob Landley's issues
with toybox (namely, chroot()).

Isaac Dunham



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06  2:40       ` Isaac Dunham
@ 2012-04-06  2:51         ` Rich Felker
  0 siblings, 0 replies; 12+ messages in thread
From: Rich Felker @ 2012-04-06  2:51 UTC (permalink / raw)
  To: musl

On Thu, Apr 05, 2012 at 07:40:45PM -0700, Isaac Dunham wrote:
> On Thu, 5 Apr 2012 22:04:35 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> 
> > > If I wanted to make things a little easier on those porting, I might
> > > add something like this when _BSD_SOURCE is defined:
> > > #warn "BSD setpgrp should be changed to setpgid"
> > > That's not essential, though.
> > The mismatching prototype should be enough to get a nice error. :)
> 
> Sometimes I enjoy having a hint about how to change it, rather than
> needing to read the glibc headers...
> I put #warn instead of #error because they could well be using only the
> other _BSD_SOURCE functions.

I just mean the fact that the legacy BSD function's signature does not
match the POSIX prototype will cause an error if the code is assuming
the BSD version and trying to call it with the wrong number of
arguments.

> > Anyway, patch looks good now. Should I start committing or do you want
> > to prepare a unified patch for all the headers?
> 
> Feel free to start committing.
> I may not be able to get all of the headers very soon, with my classes.
> But this patch alone should solve at least one of Rob Landley's issues
> with toybox (namely, chroot()).

OK.

Rich


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06  1:45   ` [PATCH] _BSD_SOURCE for unistd.h, take 2 Isaac Dunham
  2012-04-06  2:04     ` Rich Felker
@ 2012-04-06 14:48     ` Rich Felker
  2012-04-06 15:48       ` Isaac Dunham
  1 sibling, 1 reply; 12+ messages in thread
From: Rich Felker @ 2012-04-06 14:48 UTC (permalink / raw)
  To: musl

On Thu, Apr 05, 2012 at 06:45:34PM -0700, Isaac Dunham wrote:
> +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> +pid_t vfork(void);
> +int vhangup(void);
> +int chroot(const char *);
> +int usleep(unsigned);
> +unsigned ualarm(unsigned, unsigned);
> +#endif
> +
>  #ifdef _GNU_SOURCE
>  int brk(void *);
>  void *sbrk(intptr_t);
>  pid_t forkall(void);
> -pid_t vfork(void);
> -int vhangup(void);
> -int chroot(const char *);
>  int getpagesize(void);
>  int sethostname(const char *, size_t);
> -int usleep(unsigned);
> -unsigned ualarm(unsigned, unsigned);
>  int setgroups(size_t, const gid_t []);
>  int setresuid(uid_t, uid_t, uid_t);
>  int setresgid(gid_t, gid_t, gid_t);

Looking at this again, it looks to me like almost all of the functions
under _GNU_SOURCE are also present on BSD. That is to say, just
replacing #ifdef _GNU_SOURCE with

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)

would give a closer approximation to what _BSD_SOURCE is supposed to
do. I'm not saying this is the best solution, but before I go
committing patches to support _BSD_SOURCE, I'd at least like it to be
reasonably complete and not just a few functions to make Toybox
happy...

Rich


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06 14:48     ` Rich Felker
@ 2012-04-06 15:48       ` Isaac Dunham
  2012-04-06 23:32         ` Rich Felker
  0 siblings, 1 reply; 12+ messages in thread
From: Isaac Dunham @ 2012-04-06 15:48 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

On Fri, 6 Apr 2012 10:48:29 -0400
Rich Felker <dalias@aerifal.cx> wrote:
> Looking at this again, it looks to me like almost all of the functions
> under _GNU_SOURCE are also present on BSD. That is to say, just
> replacing #ifdef _GNU_SOURCE with
> 
> #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> 
> would give a closer approximation to what _BSD_SOURCE is supposed to
> do. I'm not saying this is the best solution, but before I go
> committing patches to support _BSD_SOURCE, 
Yep, looks like I missed some.
get_current_dir_name, setresuid and setresgid (as well as forkall...)
are the only ones that aren't defined with _BSD_SOURCE.

Still, I tend to prefer having some respect for even unofficial
namespaces.

Attached is a patch (3rd revision) that has all the _BSD_SOURCE
functions properly classified.

Isaac Dunham

[-- Attachment #2: unistd.diff --]
[-- Type: text/x-patch, Size: 973 bytes --]

diff --git a/include/unistd.h b/include/unistd.h
index 7662e51..5381eea 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -16,6 +16,12 @@ extern "C" {
 #define SEEK_CUR 1
 #define SEEK_END 2
 
+#if defined(_BSD_SOURCE) && !defined(L_SET)
+#define L_SET	SEEK_SET
+#define L_INCR	SEEK_CUR
+#define L_XTND	SEEK_END
+#endif
+
 #undef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -144,10 +150,9 @@ void sync(void);
 int getdtablesize(void);
 #endif
 
-#ifdef _GNU_SOURCE
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int brk(void *);
 void *sbrk(intptr_t);
-pid_t forkall(void);
 pid_t vfork(void);
 int vhangup(void);
 int chroot(const char *);
@@ -156,6 +161,10 @@ int sethostname(const char *, size_t);
 int usleep(unsigned);
 unsigned ualarm(unsigned, unsigned);
 int setgroups(size_t, const gid_t []);
+#endif
+
+#ifdef _GNU_SOURCE
+pid_t forkall(void);
 int setresuid(uid_t, uid_t, uid_t);
 int setresgid(gid_t, gid_t, gid_t);
 char *get_current_dir_name(void);

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06 15:48       ` Isaac Dunham
@ 2012-04-06 23:32         ` Rich Felker
  2012-04-07  5:47           ` Isaac Dunham
  0 siblings, 1 reply; 12+ messages in thread
From: Rich Felker @ 2012-04-06 23:32 UTC (permalink / raw)
  To: musl

On Fri, Apr 06, 2012 at 08:48:08AM -0700, Isaac Dunham wrote:
> On Fri, 6 Apr 2012 10:48:29 -0400
> Rich Felker <dalias@aerifal.cx> wrote:
> > Looking at this again, it looks to me like almost all of the functions
> > under _GNU_SOURCE are also present on BSD. That is to say, just
> > replacing #ifdef _GNU_SOURCE with
> > 
> > #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
> > 
> > would give a closer approximation to what _BSD_SOURCE is supposed to
> > do. I'm not saying this is the best solution, but before I go
> > committing patches to support _BSD_SOURCE, 
> Yep, looks like I missed some.
> get_current_dir_name, setresuid and setresgid (as well as forkall...)
> are the only ones that aren't defined with _BSD_SOURCE.
> 
> Still, I tend to prefer having some respect for even unofficial
> namespaces.
> 
> Attached is a patch (3rd revision) that has all the _BSD_SOURCE
> functions properly classified.

Looks good. One change I will probably make when committing is to just
remove forkall; it does not work and in fact this function is
fundamentally impossible to have working correctly on any OS due to
contradictory requirements for mutex behavior.

A more general issue: this patch addresses _BSD_SOURCE enabling the
nonstandard functions, but what should the behavior of _BSD_SOURCE be
with regards to functions that are in XSI but not POSIX base? My
inclination is to make it so _BSD_SOURCE implies _XOPEN_SOURCE and
_POSIX_C_SOURCE everywhere (i.e. add it to all the big || lists in all
the headers) unless there's a strong argument against doing this. As
it stands, defining just _BSD_SOURCE but not _POSIX_C_SOURCE or
_XOPEN_SOURCE would leave you with a fairly broken set of headers, I
think..

Rich


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] _BSD_SOURCE for unistd.h, take 2
  2012-04-06 23:32         ` Rich Felker
@ 2012-04-07  5:47           ` Isaac Dunham
  0 siblings, 0 replies; 12+ messages in thread
From: Isaac Dunham @ 2012-04-07  5:47 UTC (permalink / raw)
  To: musl

> > Still, I tend to prefer having some respect for even unofficial
> > namespaces.
..
> A more general issue: this patch addresses _BSD_SOURCE enabling the
> nonstandard functions, but what should the behavior of _BSD_SOURCE be
> with regards to functions that are in XSI but not POSIX base? My
> inclination is to make it so _BSD_SOURCE implies _XOPEN_SOURCE and
> _POSIX_C_SOURCE everywhere (i.e. add it to all the big || lists in all
> the headers) unless there's a strong argument against doing this. As
> it stands, defining just _BSD_SOURCE but not _POSIX_C_SOURCE or
> _XOPEN_SOURCE would leave you with a fairly broken set of headers, I
> think..

There seemed to be large numbers of functions that were _XOPEN_SOURCE
but not _BSD_SOURCE, if I'm remembering right.  It seemed to mostly
fall somewhere between *old* X/Open and POSIX, with some extensions;
it definitely should imply POSIX, but I'd avoid *automatically* adding
X/Open (see previous comment about respecting nonstandard namespaces).
It would be annoying to write a program, use -D_BSD_SOURCE, have it
work, move to another libc, and have to change CFLAGS--especially if
that's because of disregard for the namespace. 

In some places assuming _XOPEN_SOURCE would be appropriate; we should
look at each case. 

Isaac Dunham



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-04-07  5:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-05 22:55 Namespace issues, missing functions, _BSD_SOURCE for unistd.h Isaac Dunham
2012-04-06  0:10 ` Rich Felker
2012-04-06  1:03   ` Isaac Dunham
2012-04-06  1:52     ` Rich Felker
2012-04-06  1:45   ` [PATCH] _BSD_SOURCE for unistd.h, take 2 Isaac Dunham
2012-04-06  2:04     ` Rich Felker
2012-04-06  2:40       ` Isaac Dunham
2012-04-06  2:51         ` Rich Felker
2012-04-06 14:48     ` Rich Felker
2012-04-06 15:48       ` Isaac Dunham
2012-04-06 23:32         ` Rich Felker
2012-04-07  5:47           ` Isaac Dunham

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).