Commit graph

47 commits

Author SHA1 Message Date
Yu Watanabe 4c70109600 tree-wide: use IN_SET macro (#6977) 2017-10-04 16:01:32 +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
Lennart Poettering 4b61c87511 tree-wide: fput[cs]() → fput[cs]_unlocked() wherever that makes sense (#6396)
As a follow-up for db3f45e2d2 let's do the
same for all other cases where we create a FILE* with local scope and
know that no other threads hence can have access to it.

For most cases this shouldn't change much really, but this should speed
dbus introspection and calender time formatting up a bit.
2017-07-21 10:35:45 +02:00
Zbigniew Jędrzejewski-Szmek d80e5b74e8 calendarspec: parse unix timestamps (@...) (#5947)
Fixes #5810.
2017-05-17 11:40:49 +02:00
Doug Christman 963e3d8373 calendarspec: fix duplicate detection (#5310)
a2eb5ea79c added a new field to `CalendarComponent`; update
`normalize_chain` to compare all fields when dropping duplicates
2017-02-12 00:39:17 -05:00
Lennart Poettering 1bb4b028a3 time-util: refuse formatting/parsing times that we can't store
usec_t is always 64bit, which means it can cover quite a number of
years. However, 4 digit year display and glibc limitations around time_t
limit what we can actually parse and format. Let's make this explicit,
so that we never end up formatting dates we can#t parse and vice versa.

Note that this is really just about formatting/parsing. Internal
calculations with times outside of the formattable range are not
affected.
2017-02-02 20:12:31 +01:00
Lennart Poettering c477ff141b time: time_t is signed, and mktime() is happy to return negative time
Passing a year such as 1960 to mktime() will result in a negative return
value. This is quite confusing, as the man page claims that on failure
the call will return -1...

Given that our own usec_t type is unsigned, and we can't express times
before 1970 hence, let's consider all negative times returned by
mktime() as invalid, regardless if just -1, or anything else negative.
2017-02-02 20:12:31 +01:00
Douglas Christman 60bf5836a0 calendarspec: minor refactoring and style fix 2016-12-20 17:52:55 -05:00
Douglas Christman c0aebb4b3b calendarspec: improve overflow handling
Check if the parsed seconds value fits in an integer *after*
multiplying by USEC_PER_SEC, otherwise a large value can trigger
modulo by zero during normalization.
2016-12-20 17:52:55 -05:00
Douglas Christman 482f3b5441 calendarspec: remove superfluous variables 2016-12-16 19:47:04 -05:00
Douglas Christman e78fce48c4 calendarspec: rename fields of CalendarComponent
value/range_end -> start/stop
2016-12-16 19:45:06 -05:00
Douglas Christman a2eb5ea79c calendarspec: allow repetition values with ranges
"Every other hour from 9 until 5" can be written as
`9..17/2:00` instead of `9,11,13,15,17:00`
2016-12-16 19:27:33 -05:00
Doug Christman fc2371c7b1 calendarspec: free memory when parsing fails (#4890)
This prevents memory leaks on strings like `*~*-*`.

Fixes #4887
2016-12-14 19:21:27 +01:00
Doug Christman c0df71fa36 calendarspec: always interpret missing seconds as :00 (#4813)
"*:*" should be equivalent to "*-*-* *:*:00" (minutely)
rather than running every microsecond.

Fixes #4804
2016-12-06 20:41:15 +01:00
Douglas Christman 7c2503218e calendarspec: refactor format_chain()
Factor out repeated references to usec and remove nested ifs.
2016-11-25 11:21:21 -05:00
Douglas Christman c58b1b3abf calendarspec: rename "eom" to "end_of_month" 2016-11-24 18:40:14 -05:00
Douglas Christman 9904dc00e7 calendarspec: make specifications with ranges reversible
"*-*-01..03" is now formatted as "*-*-01..03" instead of "*-*-01,02,03"
2016-11-24 18:40:14 -05:00
Douglas Christman 36ff0c9792 calendarspec: allow whole second ranges
Previously a string like "00:00:01..03" would fail to parse due to the
ambiguity between a decimal point and the start of a range.
2016-11-24 18:22:08 -05:00
Douglas Christman 3215e35c40 calendarspec: make specifications with seconds wildcard reversible
"*:*:*" is now formatted as "*:*:*" instead of "*:*:00/1"
2016-11-24 18:22:08 -05:00
Douglas Christman 9dfa81a00a calendarspec: reject strings with spurious spaces and signs
strtoul() parses leading whitespace and an optional sign;
check that the first character is a digit to prevent odd
specifications like "00:  00:  00" and "-00:+00/-1".
2016-11-24 18:22:08 -05:00
Douglas Christman 6bae2fd4cd calendarspec: reject open weekday ranges
Forbid open ranges like "Tue.."; trailing commas are still OK.
2016-11-24 18:22:08 -05:00
Douglas Christman 04773cb50a calendarspec: reject strings that only contain a timezone
This makes " UTC" an illegal date specification.
2016-11-24 18:22:08 -05:00
Douglas Christman 408a51e156 calendarspec: always interpret a missing time as 00:00:00
"*-*-*" is now equivalent to "*-*-* 00:00:00" (daily)
rather than "*-*-* *:*:*" (every second).
2016-11-24 18:22:08 -05:00
Douglas Christman 8ea803516e calendarspec: add support for scheduling timers at the end of the month
"*-*~1"       => The last day of every month
"*-02~3..5"   => The third, fourth, and fifth last days in February
"Mon 05~07/1" => The last Monday in May

Resolves #3861
2016-11-23 12:37:43 -05:00
Douglas Christman f6e7d66b9f calendarspec: add upper bound on year
Stop looking for matches after MAX_YEAR so impossible dates like
"*-02-30" and "*-04-31" don't cause an infinite loop.
2016-11-23 12:28:00 -05:00
Lennart Poettering 21b3a0fcd1 util-lib: make timestamp generation and parsing reversible (#3869)
This patch improves parsing and generation of timestamps and calendar
specifications in two ways:

- The week day is now always printed in the abbreviated English form, instead
  of the locale's setting. This makes sure we can always parse the week day
  again, even if the locale is changed. Given that we don't follow locale
  settings for printing timestamps in any other way either (for example, we
  always use 24h syntax in order to make uniform parsing possible), it only
  makes sense to also stick to a generic, non-localized form for the timestamp,
  too.

- When parsing a timestamp, the local timezone (in its DST or non-DST name)
  may be specified, in addition to "UTC". Other timezones are still not
  supported however (not because we wouldn't want to, but mostly because libc
  offers no nice API for that). In itself this brings no new features, however
  it ensures that any locally formatted timestamp's timezone is also parsable
  again.

These two changes ensure that the output of format_timestamp() may always be
passed to parse_timestamp() and results in the original input. The related
flavours for usec/UTC also work accordingly. Calendar specifications are
extended in a similar way.

The man page is updated accordingly, in particular this removes the claim that
timestamps systemd prints wouldn't be parsable by systemd. They are now.

The man page previously showed invalid timestamps as examples. This has been
removed, as the man page shouldn't be a unit test, where such negative examples
would be useful. The man page also no longer mentions the names of internal
functions, such as format_timestamp_us() or UNIX error codes such as EINVAL.
2016-08-03 19:04:53 -04:00
Douglas Christman e638d0504f calendarspec: use ".." notation for ranges of weekdays
For backwards compatibility, both the new format (Mon..Wed) and
the old format (Mon-Wed) are supported.
2016-07-01 23:13:58 -04:00
Douglas Christman 32b5236916 calendarspec: allow ranges in date and time specifications
Resolves #3042
2016-07-01 23:13:58 -04:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Hristo Venev a022d76e6a calendarspec: fix find_next skipping times
reset usec when bumping hours/minutes
2016-02-22 08:02:48 -05:00
Lennart Poettering e308ddcae2 util-lib: fix returned error code
Make sure we propagate errors properly.
2016-02-21 23:27:20 +01:00
Lennart Poettering ea3894c1ba util-lib: add (void) cast to indicate that we don't care about the normalization success
After all, we verify that every calendar part is not out of bounds later on,
and it's fully OK if the normalization has no effect.
2016-02-21 23:25:38 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Thomas Hindoe Paaboel Andersen 93cc7779e0 basic: re-sort includes
My previous patch to only include what we use accidentially placed
the added inlcudes in non-sorted order.
2015-12-01 23:40:17 +01:00
Thomas Hindoe Paaboel Andersen 11c3a36649 basic: include only what we use
This is a cleaned up result of running iwyu but without forward
declarations on src/basic.
2015-11-30 21:51:03 +01:00
Hristo Venev 436dd70f53 calendarspec: sub-second support, v3 2015-11-17 23:52:09 +02:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Lennart Poettering 519cffec89 time-util: add parse_time(), which is like parse_sec() but allows specification of default time unit if none is specified
This is useful if we want to parse RLIMIT_RTTIME values where the common
UNIX syntax is without any units but refers to a non-second unit (µs in
this case), but where we want to allow specification of units.
2015-11-10 17:31:31 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Hristo Venev 078efddd37 basic: use the return value of endswith
It returns the position where the suffix begins, which can be used for
strndup to extract the prefix without calling strlen.
2015-10-25 18:46:20 +02:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Hristo Venev 51ffa239e8 basic: calendarspec UTC support
Just add " UTC" to the end of the event expression. Works for the
special expressions.
2015-10-15 02:57:59 +03:00
Lennart Poettering dacd6cee76 tree-wide: port everything over to fflush_and_check()
Some places invoked fflush() directly with their own manual error
checking, let's unify all that by using fflush_and_check().

This also unifies the general error paths of fflush()+rename() file
writers.
2015-07-29 20:31:07 +02:00
Kay Sievers a095315b3c build-sys: split internal basic/ library from shared/
basic/      can be used by everything
            cannot use anything outside of basic/

libsystemd/ can use basic/
            cannot use shared/

shared/     can use libsystemd/
2015-06-11 10:52:46 +02:00
Renamed from src/shared/calendarspec.c (Browse further)