casaroli opened a new pull request, #21733:
URL: https://github.com/apache/nuttx/pull/21733
depends-on: apache/nuttx/pull/21729
## Summary
Programs from other systems use four names that NuttX does not have, so
these programs do not compile.
- `libs/libc/time`: XSI `<time.h>` has two variables next to `tzname`:
`timezone`, the seconds west of UTC of the local standard time, and `daylight`,
nonzero if the time zone has daylight saving time. `tzset()` sets them.
`<time.h>` said "not supported". With `CONFIG_LIBC_LOCALTIME`, `settzname()`
now sets them from the same zone types that give `tzname`, in a new helper
`update_tzname()` that `localtime()` also uses. Without
`CONFIG_LIBC_LOCALTIME`, local time is UTC and both variables are 0.
- `libs/libc/unistd`: `getdomainname()` and `setdomainname()` read and set
the NIS domain name (for example, the `hostname` program uses them). The name
is kept as the host name is kept: in libc in the FLAT build, and in the kernel
in the PROTECTED and KERNEL builds, where user space calls the functions
through two new system calls. The name is empty at boot and has at most
`HOST_NAME_MAX` bytes (the `CONFIG_HOST_NAME_MAX` help now says so). As on
Linux, `setdomainname()` fails with `EINVAL` if the name is longer, and
`getdomainname()` fails with `EINVAL` if the name and its terminating null byte
do not fit in the buffer.
- `Documentation`: `timezone` and `daylight` are supported in the POSIX
table; the two functions are in the `unistd.h` list.
## Impact
New interfaces only; no new Kconfig option. In the FLAT build the two
functions are linked only when a program calls them.
The two new system calls are at the end of `include/sys/syscall_lookup.h`,
so no existing system call number changes in any configuration. They get the
next two numbers after the last system call of the configuration.
`<time.h>` now declares `timezone` and `daylight` in all configurations, as
glibc and other C libraries do. In nuttx and nuttx-apps the only other use of
these names is the struct member `timezone` in
`drivers/modem/alt1250/altcom_cmd.h`, which does not clash. Out-of-tree code
that defines its own global variable `timezone` or `daylight` gets a conflict
with the libc definition (the same as with glibc). `struct timezone` of
`<sys/time.h>` is a different name space and does not change.
## Testing
Two test programs, run on `qemu-armv8a:nsh` (FLAT, built in as applications)
and `qemu-armv8a:knsh` (KERNEL, built against the export), QEMU with HVF,
`CONFIG_LIBC_LOCALTIME=y`, `CONFIG_LIBC_TZ_MAX_TIMES=1000`, master 52e6c0abcab:
- `domainname`: the name is empty at boot; set and get round trip;
`getdomainname()` with room for the name and its null byte, without room for
the null byte (`EINVAL`) and with size 0 (`EINVAL`); `setdomainname("abcdef",
3)` gives `"abc"`; `HOST_NAME_MAX` bytes are allowed and `HOST_NAME_MAX + 1`
gives `EINVAL` and keeps the old name; the empty name. A second process then
reads the name that the first process set.
- `tzvars`: `tzset()` with `TZ` set to `UTC0`, `JST-9`,
`EST5EDT,M3.2.0,M11.1.0`, `CET-1CEST,M3.5.0,M10.5.0/3` and `IST-5:30` gives
`timezone` 0, -32400, 18000, -3600, -19800 and `daylight` 0, 0, 1, 1, 0 (the
same values as on a host libc); `localtime()` of a summer and a winter date
keeps `timezone` at the standard offset.
| | master | this PR |
|---|---|---|
| `domainname` | does not compile (`getdomainname`, `setdomainname` not
declared) | knsh and nsh: 11/11 PASS |
| `tzvars` | does not compile (`timezone`, `daylight` undeclared) | knsh and
nsh: 7/7 PASS |
| `localtime()` with a POSIX `TZ` rule, summer and winter | knsh and nsh:
PASS | knsh and nsh: PASS |
| ostest | knsh 0, nsh 0 | knsh 0, nsh 0 |
| system call numbers (`qemu-armv8a:knsh`, `qemu-armv8a:nsh`,
`mps2-an500:knsh`, `rv-virt:knsh64`) | 147, 149, 144, 145 calls | the same
numbers, and `getdomainname`, `setdomainname` added as the last two |
The system call numbers come from the preprocessed
`include/sys/syscall_lookup.h` of each configuration (the order that gives the
`SYS_` enum in `include/sys/syscall.h`), master against this PR.
The `localtime()` summer check needs `CONFIG_LIBC_TZ_MAX_TIMES=1000`. With
the default 370, `localtime()` gives standard time for a summer date in 2026
with a POSIX `TZ` rule, on master and with this PR: `tzparse()` starts the
transitions 200 years before 1970 for the 64-bit `time_t`, and 370 transitions
end near 1954. This PR does not change it.
`-Werror` builds: `qemu-armv8a:nsh` (FLAT), `qemu-armv8a:knsh` (KERNEL),
`rv-virt:knsh64` (KERNEL), `mps2-an500:knsh` (PROTECTED, with and without
`CONFIG_LIBC_LOCALTIME`).
`tools/checkpatch.sh -c -u -m -g` passes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]