LCOV - code coverage report
Current view: top level - libsystemd/sd-event - event-util.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 29 46 63.0 %
Date: 2019-08-23 13:36:53 Functions: 2 3 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 16 66 24.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <errno.h>
       4                 :            : 
       5                 :            : #include "event-source.h"
       6                 :            : #include "event-util.h"
       7                 :            : #include "log.h"
       8                 :            : #include "string-util.h"
       9                 :            : 
      10                 :        228 : int event_reset_time(
      11                 :            :                 sd_event *e,
      12                 :            :                 sd_event_source **s,
      13                 :            :                 clockid_t clock,
      14                 :            :                 uint64_t usec,
      15                 :            :                 uint64_t accuracy,
      16                 :            :                 sd_event_time_handler_t callback,
      17                 :            :                 void *userdata,
      18                 :            :                 int64_t priority,
      19                 :            :                 const char *description,
      20                 :            :                 bool force_reset) {
      21                 :            : 
      22                 :        228 :         bool created = false;
      23                 :            :         int enabled, r;
      24                 :            :         clockid_t c;
      25                 :            : 
      26         [ -  + ]:        228 :         assert(e);
      27         [ -  + ]:        228 :         assert(s);
      28                 :            : 
      29         [ +  + ]:        228 :         if (*s) {
      30         [ -  + ]:        172 :                 if (!force_reset) {
      31                 :          0 :                         r = sd_event_source_get_enabled(*s, &enabled);
      32         [ #  # ]:          0 :                         if (r < 0)
      33   [ #  #  #  # ]:          0 :                                 return log_debug_errno(r, "sd-event: Failed to query whether event source \"%s\" is enabled or not: %m",
      34                 :            :                                                        strna((*s)->description ?: description));
      35                 :            : 
      36         [ #  # ]:          0 :                         if (enabled != SD_EVENT_OFF)
      37                 :          0 :                                 return 0;
      38                 :            :                 }
      39                 :            : 
      40                 :        172 :                 r = sd_event_source_get_time_clock(*s, &c);
      41         [ -  + ]:        172 :                 if (r < 0)
      42   [ #  #  #  # ]:          0 :                         return log_debug_errno(r, "sd-event: Failed to get clock id of event source \"%s\": %m", strna((*s)->description ?: description));
      43                 :            : 
      44         [ -  + ]:        172 :                 if (c != clock)
      45   [ #  #  #  # ]:          0 :                         return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
      46                 :            :                                                "sd-event: Current clock id %i of event source \"%s\" is different from specified one %i.",
      47                 :            :                                                (int)c,
      48                 :            :                                                strna((*s)->description ? : description),
      49                 :            :                                                (int)clock);
      50                 :            : 
      51                 :        172 :                 r = sd_event_source_set_time(*s, usec);
      52         [ -  + ]:        172 :                 if (r < 0)
      53   [ #  #  #  # ]:          0 :                         return log_debug_errno(r, "sd-event: Failed to set time for event source \"%s\": %m", strna((*s)->description ?: description));
      54                 :            : 
      55                 :        172 :                 r = sd_event_source_set_time_accuracy(*s, accuracy);
      56         [ -  + ]:        172 :                 if (r < 0)
      57   [ #  #  #  # ]:          0 :                         return log_debug_errno(r, "sd-event: Failed to set accuracy for event source \"%s\": %m", strna((*s)->description ?: description));
      58                 :            : 
      59                 :            :                 /* callback function is not updated, as we do not have sd_event_source_set_time_callback(). */
      60                 :            : 
      61                 :        172 :                 (void) sd_event_source_set_userdata(*s, userdata);
      62                 :            : 
      63                 :        172 :                 r = sd_event_source_set_enabled(*s, SD_EVENT_ONESHOT);
      64         [ -  + ]:        172 :                 if (r < 0)
      65   [ #  #  #  # ]:          0 :                         return log_debug_errno(r, "sd-event: Failed to enable event source \"%s\": %m", strna((*s)->description ?: description));
      66                 :            :         } else {
      67                 :         56 :                 r = sd_event_add_time(e, s, clock, usec, accuracy, callback, userdata);
      68         [ -  + ]:         56 :                 if (r < 0)
      69         [ #  # ]:          0 :                         return log_debug_errno(r, "sd-event: Failed to create timer event \"%s\": %m", strna(description));
      70                 :            : 
      71                 :         56 :                 created = true;
      72                 :            :         }
      73                 :            : 
      74                 :        228 :         r = sd_event_source_set_priority(*s, priority);
      75         [ -  + ]:        228 :         if (r < 0)
      76   [ #  #  #  # ]:          0 :                 return log_debug_errno(r, "sd-event: Failed to set priority for event source \"%s\": %m", strna((*s)->description ?: description));
      77                 :            : 
      78         [ +  - ]:        228 :         if (description) {
      79                 :        228 :                 r = sd_event_source_set_description(*s, description);
      80         [ -  + ]:        228 :                 if (r < 0)
      81         [ #  # ]:          0 :                         return log_debug_errno(r, "sd-event: Failed to set description for event source \"%s\": %m", description);
      82                 :            :         }
      83                 :            : 
      84                 :        228 :         return created;
      85                 :            : }
      86                 :            : 
      87                 :        364 : int event_source_disable(sd_event_source *s) {
      88         [ +  + ]:        364 :         if (!s)
      89                 :        268 :                 return 0;
      90                 :            : 
      91                 :         96 :         return sd_event_source_set_enabled(s, SD_EVENT_OFF);
      92                 :            : }
      93                 :            : 
      94                 :          0 : int event_source_is_enabled(sd_event_source *s) {
      95         [ #  # ]:          0 :         if (!s)
      96                 :          0 :                 return false;
      97                 :            : 
      98                 :          0 :         return sd_event_source_get_enabled(s, NULL);
      99                 :            : }

Generated by: LCOV version 1.14