LCOV - code coverage report
Current view: top level - hibernate-resume - hibernate-resume.c (source / functions) Hit Total Coverage
Test: systemd_full.info Lines: 0 25 0.0 %
Date: 2019-08-23 13:36:53 Functions: 0 1 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 22 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: LGPL-2.1+ */
       2                 :            : 
       3                 :            : #include <errno.h>
       4                 :            : #include <stdio.h>
       5                 :            : #include <sys/stat.h>
       6                 :            : 
       7                 :            : #include "alloc-util.h"
       8                 :            : #include "fileio.h"
       9                 :            : #include "log.h"
      10                 :            : #include "util.h"
      11                 :            : 
      12                 :          0 : int main(int argc, char *argv[]) {
      13                 :            :         struct stat st;
      14                 :            :         const char *device;
      15                 :          0 :         _cleanup_free_ char *major_minor = NULL;
      16                 :            :         int r;
      17                 :            : 
      18         [ #  # ]:          0 :         if (argc != 2) {
      19         [ #  # ]:          0 :                 log_error("This program expects one argument.");
      20                 :          0 :                 return EXIT_FAILURE;
      21                 :            :         }
      22                 :            : 
      23                 :          0 :         log_setup_service();
      24                 :            : 
      25                 :          0 :         umask(0022);
      26                 :            : 
      27                 :            :         /* Refuse to run unless we are in an initrd() */
      28         [ #  # ]:          0 :         if (!in_initrd())
      29                 :          0 :                 return EXIT_SUCCESS;
      30                 :            : 
      31                 :          0 :         device = argv[1];
      32                 :            : 
      33         [ #  # ]:          0 :         if (stat(device, &st) < 0) {
      34         [ #  # ]:          0 :                 log_error_errno(errno, "Failed to stat '%s': %m", device);
      35                 :          0 :                 return EXIT_FAILURE;
      36                 :            :         }
      37                 :            : 
      38         [ #  # ]:          0 :         if (!S_ISBLK(st.st_mode)) {
      39         [ #  # ]:          0 :                 log_error("Resume device '%s' is not a block device.", device);
      40                 :          0 :                 return EXIT_FAILURE;
      41                 :            :         }
      42                 :            : 
      43         [ #  # ]:          0 :         if (asprintf(&major_minor, "%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) {
      44                 :          0 :                 log_oom();
      45                 :          0 :                 return EXIT_FAILURE;
      46                 :            :         }
      47                 :            : 
      48                 :          0 :         r = write_string_file("/sys/power/resume", major_minor, WRITE_STRING_FILE_DISABLE_BUFFER);
      49         [ #  # ]:          0 :         if (r < 0) {
      50         [ #  # ]:          0 :                 log_error_errno(r, "Failed to write '%s' to /sys/power/resume: %m", major_minor);
      51                 :          0 :                 return EXIT_FAILURE;
      52                 :            :         }
      53                 :            : 
      54                 :            :         /*
      55                 :            :          * The write above shall not return.
      56                 :            :          *
      57                 :            :          * However, failed resume is a normal condition (may mean that there is
      58                 :            :          * no hibernation image).
      59                 :            :          */
      60                 :            : 
      61         [ #  # ]:          0 :         log_info("Could not resume from '%s' (%s).", device, major_minor);
      62                 :          0 :         return EXIT_SUCCESS;
      63                 :            : }

Generated by: LCOV version 1.14