]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/CalendarEvent.pm
fix #1819: fork_worker: ensure sync'ed workers control terminal
[pve-common.git] / src / PVE / CalendarEvent.pm
index 2714841c1aab6039c4f6337e348d61d68231734d..3c08eb06899d2f2134eee74f84a6239df802353c 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use Data::Dumper;
 use Time::Local;
 use PVE::JSONSchema;
 use Data::Dumper;
 use Time::Local;
 use PVE::JSONSchema;
+use PVE::Tools qw(trim);
 
 # Note: This class implements a parser/utils for systemd like calender exents
 # Date specification is currently not implemented
 
 # Note: This class implements a parser/utils for systemd like calender exents
 # Date specification is currently not implemented
@@ -26,7 +27,7 @@ sub pve_verify_calendar_event {
     eval { parse_calendar_event($text); };
     if (my $err = $@) {
        return undef if $noerr;
     eval { parse_calendar_event($text); };
     if (my $err = $@) {
        return undef if $noerr;
-       die "invalid calendar event '$text'\n";
+       die "invalid calendar event '$text' - $err\n";
     }
     return $text;
 }
     }
     return $text;
 }
@@ -36,6 +37,12 @@ sub pve_verify_calendar_event {
 sub parse_calendar_event {
     my ($event) = @_;
 
 sub parse_calendar_event {
     my ($event) = @_;
 
+    $event = trim($event);
+
+    if ($event eq '') {
+       die "unable to parse calendar event - event is empty\n";
+    }
+
     my $parse_single_timespec = sub {
        my ($p, $max, $matchall_ref, $res_hash) = @_;
 
     my $parse_single_timespec = sub {
        my ($p, $max, $matchall_ref, $res_hash) = @_;
 
@@ -55,6 +62,7 @@ sub parse_calendar_event {
                    $$matchall_ref = 1;
                } else {
                    $start = int($start);
                    $$matchall_ref = 1;
                } else {
                    $start = int($start);
+                   die "value '$start' out of range\n" if $start >= $max;
                    $res_hash->{$start} = 1;
                }
            }
                    $res_hash->{$start} = 1;
                }
            }
@@ -120,8 +128,12 @@ sub parse_calendar_event {
 
     if ($time_spec =~ m/^($chars+):($chars+)$/) {
        my ($p1, $p2) = ($1, $2);
 
     if ($time_spec =~ m/^($chars+):($chars+)$/) {
        my ($p1, $p2) = ($1, $2);
-       $parse_single_timespec->($p1, 24, \$matchall_hours, $hours_hash);
-       $parse_single_timespec->($p2, 60, \$matchall_minutes, $minutes_hash);
+       foreach my $p (split(',', $p1)) {
+           $parse_single_timespec->($p, 24, \$matchall_hours, $hours_hash);
+       }
+       foreach my $p (split(',', $p2)) {
+           $parse_single_timespec->($p, 60, \$matchall_minutes, $minutes_hash);
+       }
     } elsif ($time_spec =~ m/^($chars)+$/) { # minutes only
        $matchall_hours = 1;
        foreach my $p (split(',', $time_spec)) {
     } elsif ($time_spec =~ m/^($chars)+$/) { # minutes only
        $matchall_hours = 1;
        foreach my $p (split(',', $time_spec)) {
@@ -165,9 +177,13 @@ sub compute_next_event {
 
        if ($utc) {
            (undef, $min, $hour, $mday, $mon, $year, $wday) = gmtime($last);
 
        if ($utc) {
            (undef, $min, $hour, $mday, $mon, $year, $wday) = gmtime($last);
+           # gmtime and timegm interpret two-digit years differently
+           $year += 1900;
            $startofday = timegm(0, 0, 0, $mday, $mon, $year);
        } else {
            (undef, $min, $hour, $mday, $mon, $year, $wday) = localtime($last);
            $startofday = timegm(0, 0, 0, $mday, $mon, $year);
        } else {
            (undef, $min, $hour, $mday, $mon, $year, $wday) = localtime($last);
+           # localtime and timelocal interpret two-digit years differently
+           $year += 1900;
            $startofday = timelocal(0, 0, 0, $mday, $mon, $year);
        }
 
            $startofday = timelocal(0, 0, 0, $mday, $mon, $year);
        }