mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "A. Wilcox" <awilfox@adelielinux.org>
To: musl@lists.openwall.com
Subject: The Great Big POSIX Conformance Thread [phase 1]
Date: Sun, 5 Feb 2017 17:04:43 -0600	[thread overview]
Message-ID: <5897AF8B.9020208@adelielinux.org> (raw)

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

Hello fellow muslers,

I have been reading through the source tree of musl for two reasons.
One is to familiarise myself with the codebase more so that I can be
of better use if/when patches need to be written.  The other is doing
a cursory audit of POSIX conformance per XSH 2008 (2016 ed.); we at
Adélie are in the beginning stages of acquiring a license to the
VSX-PCTS2016 test suite (which would be phase 2) and I thought it'd be
prudent to find any obvious errors before obtaining it.

I have found some non-conformant functions through my audit.  Four are
(hopefully) easy to fix; two require more thought; and one will likely
need to be discussed.



Easy fixes
==========

catopen
-------

This function is not implemented, and always fails.  This is [barely]
legal in POSIX, but the failure must set errno.  None of the errors
are very appropriate (unfortunately ENOSYS is invalid); maybe ENOMEM
will work.


getservbyport
-------------

Non-conformance of this function was discussed on IRC.  Rich Felker
had said he would apply the patch I wrote[1], but it has not been
applied yet.  If there is an issue with said patch, please let me know
so that I may fix it.


[1]:
https://code.foxkit.us/adelie/patches/raw/master/sys-libs/musl/musl-1.1.15-posix-getservbyport.patch


if_nameindex
------------

This function always sets errno to ENOBUFS, even when the function
completes succesfully.  A full test case is available[2], and a
suggested patch is also available[3].


[2]: https://code.foxkit.us/adelie/musl-posix/tree/master/if_nameindex
[3]:
https://code.foxkit.us/adelie/patches/raw/master/sys-libs/musl/musl-1.1.15-if_nameindex-errno.patch


pathconf
--------

This function does not provide a reference for timestamp resolution.
See the POSIX reference[4] for more information.  This should be easy
to fix.


[4]:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html#tag_13_77_03_03



Further thought required
========================

confstr
-------

musl returns the empty string ("") for options where it does not have
any values.  The POSIX standard states[5] that if an option is
recognised but does not have a value, errno should not be set and NULL
should be returned.


[5]:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html


getlogin
--------

musl simply returns getenv("LOGNAME").  getlogin(3) is used to
determine the login name of the controlling terminal for the process.
 In addition to getenv("LOGNAME") being improper behaviour (since
getlogin(3) could be used within a su or sudo-run shell), it also
causes both coreutils and busybox logname(1) to break conformance:

```
awilcox on ciall ~ $ su
Password:
ciall ~ # LOGNAME=helloworld logname
helloworld
```

The correct behaviour is shown here on glibc:

```
awilcox on ciall [pts/16 Sun 5 16:51] ~: su
Password:
ciall awilcox # LOGNAME=helloworld logname
awilcox
```

The POSIX standard states that implementations generally check the
terminal of fds 0/1/2, then fall back to /dev/tty.[6]


[6]:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html



Discussion required
===================

getdate
-------

The musl implementation of getdate(3)[7] sets getdate_err to 7 for any
of the reasons that it should set to 5 (I/O error while reading
template file - i.e., fgets fails), 7 (there is no line in the
template that matches the input), or 8 (invalid input specification)[8].

While I realise musl will probably never implement all conditions that
could provide error condition 8, I feel that error condition 5 should
at least be implemented.  Something as simple as if (ferror(f))
getdate_err = 5;  else getdate_err = 7;  could suffice, IMO.  However,
it would be nice to see better, more robust error handling for
condition 8 as well.


[7]: http://git.musl-libc.org/cgit/musl/tree/src/time/getdate.c#n32
[8]:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/getdate.html



Best regards,
--arw

-- 
A. Wilcox (awilfox)
Project Lead, Adélie Linux
http://adelielinux.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

             reply	other threads:[~2017-02-05 23:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-05 23:04 A. Wilcox [this message]
2017-02-06  0:01 ` Rich Felker
2017-02-06  0:26   ` A. Wilcox
2017-02-06 22:25   ` A. Wilcox
2017-06-09  5:26     ` POSIX conformance patches (phase 1) A. Wilcox
2017-06-09  5:26       ` [PATCH 1/3] catopen: set errno to EOPNOTSUPP A. Wilcox
2017-06-09  5:26       ` [PATCH 2/3] confstr: don't give empty strings for unset values A. Wilcox
2017-06-15  0:00         ` Rich Felker
2017-06-09  5:26       ` [PATCH 3/3] getdate: correctly specify error number A. Wilcox

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=5897AF8B.9020208@adelielinux.org \
    --to=awilfox@adelielinux.org \
    --cc=musl@lists.openwall.com \
    /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.
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).