Commit Graph

99 Commits

Author SHA1 Message Date
Christopher Wong ba32084f08 Use new time zone list
When systemd retrieve the time zone it read what is in the file
/usr/share/zoneinfo/zone.tab provided by the Time Zone Database.
According to the comments in zone.tab its content is for backward-
compatibility aid for older programs. New programs should use
zone1970.tab. This patch replaces zone.tab with zone1970.tab.
2019-02-28 14:58:43 +01:00
Filipe Brandenburger 7b61ce3c44 time-util: Introduce parse_sec_def_infinity
This works like parse_sec() but defaults to USEC_INFINITY when passed an
empty string or only whitespace.

Also introduce config_parse_sec_def_infinity, which can be used to parse
config options using this function.

This is useful for time options that use "infinity" for default and that
can be reset by unsetting them.

Introduce a test case to ensure it works as expected.
2019-02-14 11:04:42 -08:00
Thomas Haller 911649fdd4 build: don't include shared's "serialize.h" in basic's "time-util.c"
"src/basic/time-util.c" is part of src/basic and should not include
"src/shared/serialize.h". It is one of the few cases where this
is done. Also, it's not even required.
2018-12-29 19:27:23 +09:00
Yu Watanabe 3c94e50486 util: drop missing.h from time-util.c 2018-12-06 13:31:16 +01:00
Yu Watanabe 36dd5ffd5d util: drop missing.h from util.h 2018-12-04 10:00:34 +01:00
Lennart Poettering da9fc98ded tree-wide: port more code over to PATH_STARTSWITH_SET() 2018-11-26 14:08:46 +01:00
Zbigniew Jędrzejewski-Szmek fde32028a4 Move LONG_LINE_MAX definition to fileio.h
All users of the macro (except for one, in serialize.c), use the macro in
connection with read_line(), so they must include fileio.h.  Let's not play
libc games and require multiple header file to be included for the most common
use of a function.

The removal of def.h includes is not exact. I mostly went over the commits that
switch over to use read_line() and add def.h at the same time and reverted the
addition of def.h in those files.
2018-11-14 16:25:32 +01:00
Zbigniew Jędrzejewski-Szmek e44c5a3ba6
Merge pull request #10594 from poettering/env-reload-fix
change handling of environment block of PID1's manager object
2018-11-07 12:49:13 +01:00
Yu Watanabe ed2e7967be time-util: make parse_sec() not accept "12.34.56"
This also changes the rational number treatment.
So, the limitations introduced by 8079c90333
and f6a178e91d are relaxed.

Fixes #10619.
2018-11-06 19:24:47 +03:00
Lennart Poettering bea1a01310 strv: wrap strv_new() in a macro so that NULL sentinel is implicit 2018-10-31 18:00:52 +01:00
Lennart Poettering d68c645bd3 core: rework serialization
Let's be more careful with what we serialize: let's ensure we never
serialize strings that are longer than LONG_LINE_MAX, so that we know we
can read them back with read_line(…, LONG_LINE_MAX, …) safely.

In order to implement this all serialization functions are move to
serialize.[ch], and internally will do line size checks. We'd rather
skip a serialization line (with a loud warning) than write an overly
long line out. Of course, this is just a second level protection, after
all the data we serialize shouldn't be this long in the first place.

While we are at it also clean up logging: while serializing make sure to
always log about errors immediately. Also, (void)ify all calls we don't
expect errors in (or catch errors as part of the general
fflush_and_check() at the end.
2018-10-26 10:52:41 +02:00
Lennart Poettering def34f63fe time-util: change parse_sec_fix_0() to accept "0s" for infinity too (#10501)
This function is about compatibility, nothing else, hence we should make
it properly compatible.

Fixes: #9556
2018-10-25 05:21:28 +09:00
Yu Watanabe f6a178e91d util: check overflow in parse_nsec() 2018-10-23 22:24:16 +09:00
Yu Watanabe 8079c90333 util: check overflow in parse_time() 2018-10-23 22:23:34 +09:00
Lennart Poettering 490c5a37cb tree-wide: some automatic coccinelle fixes (#10463)
Nothing fancy, just coccinelle doing its work.
2018-10-20 00:07:46 +09:00
Lennart Poettering 8d2b9d14c4 time-util: FOREACH_LINE excorcism 2018-10-18 16:23:45 +02:00
Thomas Haller f21f31b24b trivial: fix spelling in code comments
Based-on-patch-by: Rafael Fontenelle <rafaelff@gnome.org>
2018-09-30 21:32:33 +02:00
Filipe Brandenburger 279f52a1d3 parse-util: make sure "3.+1s" or "3. 1s" are not considered valid time specification
Indeed, strtoll() is super-hard to use properly! :-(

Also added more tests for those cases and copied the tests to parse_nsec as well.
2018-07-19 22:09:54 -07:00
Lennart Poettering 5a9fb35843 parse-util: make sure "-0.-0s" is not considered a valid time specification
Did I mention that strtoll() is super-hard to use properly?
2018-07-17 13:01:46 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Yu Watanabe 1c73b60b4d util-lib: reject too long path for timedate_is_valid()
This should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8827.
2018-06-11 12:38:34 +09:00
Lennart Poettering 4f811d27d6 time-util: introduce common implementation of TFD_TIMER_CANCEL_ON_SET client code
We now use pretty much the same code at three places, let's unify that.
2018-06-06 10:55:45 +02:00
Martin Jansa 5fd8d5be11 time-util: fix build with gcc8 -Werror=format-truncation=
* it fails with gcc8 when -O1 or -Os is used (and -ftree-vrp which is added by -O2 and higher isn't used)

../git/src/basic/time-util.c: In function 'format_timespan':
../git/src/basic/time-util.c:508:46: error: '%0*llu' directive output between 1 and 2147483647 bytes may cause result to exceed 'INT_MAX' [-Werror=format-truncation=]
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ^~~~
../git/src/basic/time-util.c:508:60: note: format string is defined here
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
../git/src/basic/time-util.c:508:46: note: directive argument in the range [0, 18446744073709551614]
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ^~~~
../git/src/basic/time-util.c:507:37: note: 'snprintf' output 4 or more bytes (assuming 2147483651) into a destination of size 4294967295
                                 k = snprintf(p, l,
                                     ^~~~~~~~~~~~~~
                                              "%s"USEC_FMT".%0*"PRI_USEC"%s",
                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                              p > buf ? " " : "",
                                              ~~~~~~~~~~~~~~~~~~~
                                              a,
                                              ~~
                                              j,
                                              ~~
                                              b,
                                              ~~
                                              table[i].suffix);
                                              ~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

[zj: change 'char' to 'signed char']
2018-06-02 10:41:03 +02:00
Zbigniew Jędrzejewski-Szmek d3d280242c Always allow timestamps to be printed
If the timestamp is above 9999-12-30, (or 2038-something-something on 32 bit),
use XXXX-XX-XX XX:XX:XX as the replacement.

The problem with refusing to print timestamps is that our code accepts such
timestamps, so we can't really just refuse to process them afterwards. Also, it
makes journal files non-portable, because suddently we might completely refuse
to print entries which are totally OK on a different machine.
2018-05-31 14:30:23 +02:00
Mike Gilbert 089fb8653f basic: add log_level argument to timezone_is_valid 2018-05-12 15:20:13 -04:00
Mike Gilbert a2932d5116 basic: timezone_is_valid: check for magic bytes "TZif"
Fixes: https://github.com/systemd/systemd/issues/8905
2018-05-11 14:11:30 -04:00
Yu Watanabe 947f9f01a1 time-util: fix indentation for comments 2018-05-09 22:50:07 +09:00
Lennart Poettering da6053d0a7 tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.

Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.

So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.

This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:

1. strv_length()' return type becomes size_t

2. the unit file changes array size becomes size_t

3. DNS answer and query array sizes become size_t

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:29:06 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Yu Watanabe 1cc6c93a95 tree-wide: use TAKE_PTR() and TAKE_FD() macros 2018-04-05 14:26:26 +09:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
Lennart Poettering 1f5d1e0247 process-spec: add another flag FORK_WAIT to safe_fork()
This new flag will cause safe_fork() to wait for the forked off child
before returning. This allows us to unify a number of cases where we
immediately wait on the forked off child, witout running any code in the
parent after the fork, and without direct interest in the precise exit
status of the process, except recgonizing EXIT_SUCCESS vs everything
else.
2018-01-04 13:27:27 +01:00
Lennart Poettering 4c253ed1ca tree-wide: introduce new safe_fork() helper and port everything over
This adds a new safe_fork() wrapper around fork() and makes use of it
everywhere. The new wrapper does a couple of things we previously did
manually and separately in a safer, more correct and automatic way:

1. Optionally resets signal handlers/mask in the child

2. Sets a name on all processes we fork off right after forking off (and
   the patch assigns useful names for all processes we fork off now,
   following a systematic naming scheme: always enclosed in () – in order
   to indicate that these are not proper, exec()ed processes, but only
   forked off children, and if the process is long-running with only our
   own code, without execve()'ing something else, it gets am "sd-" prefix.)

3. Optionally closes all file descriptors in the child

4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe
   way so that the parent dying before this happens being handled
   safely.

5. Optionally reopens the logs

6. Optionally connects stdin/stdout/stderr to /dev/null

7. Debug logs about the forked off processes.
2017-12-25 11:48:21 +01:00
Lennart Poettering 234519ae6d tree-wide: drop a few == NULL and != NULL comparison
Our CODING_STYLE suggests not comparing with NULL, but relying on C's
downgrade-to-bool feature for that. Fix up some code to match these
guidelines. (This is not comprehensive, the coccinelle output for this
is unfortunately kinda borked)
2017-12-11 16:05:40 +01:00
Shawn Landden 4831981d89 tree-wide: adjust fall through comments so that gcc is happy
Distcc removes comments, making the comment silencing
not work.

I know there was a decision against a macro in commit
ec251fe7d5
2017-11-20 13:06:25 -08:00
Lennart Poettering 9a9a4f10e9 util: add new helper in_utc_timezone()
As the name suggests it checks whether we are running in an UTC
timezone.
2017-11-20 10:53:26 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering eae51da36e unit: when JobTimeoutSec= is turned off, implicitly turn off JobRunningTimeoutSec= too
We added JobRunningTimeoutSec= late, and Dracut configured only
JobTimeoutSec= to turn of root device timeouts before. With this change
we'll propagate a reset of JobTimeoutSec= into JobRunningTimeoutSec=,
but only if the latter wasn't set explicitly.

This should restore compatibility with older systemd versions.

Fixes: #6402
2017-10-05 13:06:44 +02:00
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +02:00
Marcel Hollerbach 214cc95d7b time-util: mktime_or_timegm are changing the struct tm
after that wm_day etc. seems to be changed. Moving the check infront of
the mktime_or_timegm fixes that.
2017-09-22 14:01:33 +02:00
Marcel Hollerbach 3fd4929b96 time-util: correctly handle the timezone when parsing
The timezone was cut off the string once the timezone was not UTC.
If it is not UTC but a other timezone that matches tzname[0] or
tzname[1], then we can leave it to the impl function to parse that
correctly. If not we can just fallback to whatever is the current
timezone is in the given t_timezone.

This should fix the testuite and tests.
2017-09-22 14:01:33 +02:00
Marcel Hollerbach ff69484a1f time-util: fix shadowing of timezone
timezone was shadowing timezone from time.h which leads to a buildbreak
since systemd is built with -Werror
2017-09-21 14:39:08 +02:00
Ivan Kurnosov 2e72b79459 Fix for dst/non-dst timezones
The problem was with the tm.tm_isdst that is set to the current environment
value: either DST or not. While the current state is not relevant to the state
in the desired date.

Hence — it should be reset so that the mktime_or_timegm could normalise it
later.
2017-09-17 13:49:14 +02:00
Zbigniew Jędrzejewski-Szmek a2932a0d1a Simplify the if cases for timezone checking
Just to reduce the indentation a bit.
2017-09-17 09:42:20 +02:00
Ivan Kurnosov 48d26c0164 Added timezone to the CalendarSpec, parser/formatter and the timedatectl 2017-09-17 09:42:20 +02:00
Yu Watanabe 68bdd2d2d3 time-util: make parse_timestamp() return -EINVAL if the input is very old date (#6327)
This reverts 7635ab8e74 and makes parse_timestamp()
return -EINVAL if the input is older than 1970-01-01.

Fixes #6290.
2017-07-11 19:12:48 +02:00
Yu Watanabe 7635ab8e74 time-util: make parse_timestamp() set 0 if the input is very old date (#6297)
If the input is older than "1970-01-01 UTC", then `parse_timestamp()`
fails and returns -EINVAL. However, if the input is e.g. `-100years`,
then the function succeeds and sets `usec = 0`.
This commit makes the function also succeed for old dates and set
`usec = 0`.

Fixes #6290.
2017-07-08 15:59:07 -04:00
Zbigniew Jędrzejewski-Szmek 0004f698df Parse "timeout=0" as infinity in various generators (#6264)
This extends 2d79a0bbb9 to the kernel
command line parsing.

The parsing is changed a bit to only understand "0" as infinity. If units are
specified, parse normally, e.g. "0s" is just 0. This makes it possible to
provide a zero timeout if necessary.

Simple test is added.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1462378.
2017-07-03 14:29:32 +02:00
Lennart Poettering 1007ec60e6 time-util: add new call usec_shift_clock() for converting times between clocks
We use that quite often, let's implement one clean version of it.
2017-06-22 20:52:23 +02:00