LCOV - code coverage report
Current view: top level - lib/log - log_linux.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 14 14 100.0 %
Date: 2024-01-22 16:26:08 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2010-2014 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <stdio.h>
       6                 :            : #include <sys/types.h>
       7                 :            : #include <syslog.h>
       8                 :            : 
       9                 :            : #include <rte_log.h>
      10                 :            : 
      11                 :            : #include "log_internal.h"
      12                 :            : 
      13                 :            : /*
      14                 :            :  * default log function
      15                 :            :  */
      16                 :            : static ssize_t
      17                 :       1919 : console_log_write(__rte_unused void *c, const char *buf, size_t size)
      18                 :            : {
      19                 :            :         ssize_t ret;
      20                 :            : 
      21                 :            :         /* write on stderr */
      22                 :       1919 :         ret = fwrite(buf, 1, size, stderr);
      23                 :       1919 :         fflush(stderr);
      24                 :            : 
      25                 :            :         /* Syslog error levels are from 0 to 7, so subtract 1 to convert */
      26                 :       1919 :         syslog(rte_log_cur_msg_loglevel() - 1, "%.*s", (int)size, buf);
      27                 :            : 
      28                 :       1919 :         return ret;
      29                 :            : }
      30                 :            : 
      31                 :            : static int
      32                 :        167 : console_log_close(__rte_unused void *c)
      33                 :            : {
      34                 :        167 :         closelog();
      35                 :        167 :         return 0;
      36                 :            : }
      37                 :            : 
      38                 :            : static cookie_io_functions_t console_log_func = {
      39                 :            :         .write = console_log_write,
      40                 :            :         .close = console_log_close,
      41                 :            : };
      42                 :            : 
      43                 :            : /*
      44                 :            :  * set the log to default function, called during eal init process,
      45                 :            :  * once memzones are available.
      46                 :            :  */
      47                 :            : int
      48                 :        167 : eal_log_init(const char *id, int facility)
      49                 :            : {
      50                 :            :         FILE *log_stream;
      51                 :            : 
      52                 :        167 :         log_stream = fopencookie(NULL, "w+", console_log_func);
      53         [ +  - ]:        167 :         if (log_stream == NULL)
      54                 :            :                 return -1;
      55                 :            : 
      56                 :        167 :         openlog(id, LOG_NDELAY | LOG_PID, facility);
      57                 :            : 
      58                 :        167 :         eal_log_set_default(log_stream);
      59                 :            : 
      60                 :        167 :         return 0;
      61                 :            : }

Generated by: LCOV version 1.14