fix: jbd2 upper bound for v5.10.163
[lttng-modules.git] / wrapper / random.c
... / ...
CommitLineData
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
3 * wrapper/random.c
4 *
5 * wrapper around bootid read. Using KALLSYMS to get its address when
6 * available, else we need to have a kernel that exports this function to GPL
7 * modules.
8 *
9 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 */
11
12#include <linux/errno.h>
13#include <linux/module.h>
14
15/* boot_id depends on sysctl */
16#if defined(CONFIG_SYSCTL)
17
18#include <wrapper/fs.h>
19#include <linux/file.h>
20#include <linux/sched.h>
21#include <linux/uaccess.h>
22#include <wrapper/random.h>
23
24/*
25 * Returns string boot id.
26 */
27int wrapper_get_bootid(char *bootid)
28{
29 struct file *file;
30 int ret;
31 ssize_t len;
32
33 file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0);
34 if (IS_ERR(file))
35 return PTR_ERR(file);
36
37 len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos);
38 if (len != BOOT_ID_LEN - 1) {
39 ret = -EINVAL;
40 goto end;
41 }
42
43 bootid[BOOT_ID_LEN - 1] = '\0';
44 ret = 0;
45end:
46 filp_close(file, current->files);
47 return ret;
48}
49EXPORT_SYMBOL_GPL(wrapper_get_bootid);
50
51#else
52
53int wrapper_get_bootid(char *bootid)
54{
55 return -ENOSYS;
56}
57EXPORT_SYMBOL_GPL(wrapper_get_bootid);
58
59#endif
This page took 0.025974 seconds and 4 git commands to generate.