LCOV - code coverage report
Current view: top level - arch/um/kernel - exitcode.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 18 16.7 %
Date: 2023-03-27 20:00:47 Functions: 1 4 25.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
       4             :  */
       5             : 
       6             : #include <linux/ctype.h>
       7             : #include <linux/init.h>
       8             : #include <linux/kernel.h>
       9             : #include <linux/module.h>
      10             : #include <linux/proc_fs.h>
      11             : #include <linux/seq_file.h>
      12             : #include <linux/types.h>
      13             : #include <linux/uaccess.h>
      14             : 
      15             : /*
      16             :  * If read and write race, the read will still atomically read a valid
      17             :  * value.
      18             :  */
      19             : int uml_exitcode = 0;
      20             : 
      21           0 : static int exitcode_proc_show(struct seq_file *m, void *v)
      22             : {
      23             :         int val;
      24             : 
      25             :         /*
      26             :          * Save uml_exitcode in a local so that we don't need to guarantee
      27             :          * that sprintf accesses it atomically.
      28             :          */
      29           0 :         val = uml_exitcode;
      30           0 :         seq_printf(m, "%d\n", val);
      31           0 :         return 0;
      32             : }
      33             : 
      34           0 : static int exitcode_proc_open(struct inode *inode, struct file *file)
      35             : {
      36           0 :         return single_open(file, exitcode_proc_show, NULL);
      37             : }
      38             : 
      39           0 : static ssize_t exitcode_proc_write(struct file *file,
      40             :                 const char __user *buffer, size_t count, loff_t *pos)
      41             : {
      42             :         char *end, buf[sizeof("nnnnn\0")];
      43             :         size_t size;
      44             :         int tmp;
      45             : 
      46           0 :         size = min(count, sizeof(buf));
      47           0 :         if (copy_from_user(buf, buffer, size))
      48             :                 return -EFAULT;
      49             : 
      50           0 :         tmp = simple_strtol(buf, &end, 0);
      51           0 :         if ((*end != '\0') && !isspace(*end))
      52             :                 return -EINVAL;
      53             : 
      54           0 :         uml_exitcode = tmp;
      55           0 :         return count;
      56             : }
      57             : 
      58             : static const struct proc_ops exitcode_proc_ops = {
      59             :         .proc_open      = exitcode_proc_open,
      60             :         .proc_read      = seq_read,
      61             :         .proc_lseek     = seq_lseek,
      62             :         .proc_release   = single_release,
      63             :         .proc_write     = exitcode_proc_write,
      64             : };
      65             : 
      66           1 : static int make_proc_exitcode(void)
      67             : {
      68             :         struct proc_dir_entry *ent;
      69             : 
      70           1 :         ent = proc_create("exitcode", 0600, NULL, &exitcode_proc_ops);
      71           1 :         if (ent == NULL) {
      72           0 :                 printk(KERN_WARNING "make_proc_exitcode : Failed to register "
      73             :                        "/proc/exitcode\n");
      74           0 :                 return 0;
      75             :         }
      76             :         return 0;
      77             : }
      78             : 
      79             : __initcall(make_proc_exitcode);

Generated by: LCOV version 1.14