Add 'kernel_read' wrapper for kernels < v4.14
[lttng-modules.git] / wrapper / random.c
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
886d51a3 3 * wrapper/random.c
a82c63f1
MD
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 *
886d51a3 9 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
a82c63f1
MD
10 */
11
2fa61a31
MD
12#include <linux/errno.h>
13
a82c63f1
MD
14/* boot_id depends on sysctl */
15#if defined(CONFIG_SYSCTL)
16
bce099b2 17#include <wrapper/fs.h>
a82c63f1
MD
18#include <linux/file.h>
19#include <linux/sched.h>
20#include <linux/uaccess.h>
5a2f5e92 21#include <wrapper/random.h>
a82c63f1
MD
22
23/*
24 * Returns string boot id.
25 */
26int wrapper_get_bootid(char *bootid)
27{
28 struct file *file;
29 int ret;
30 ssize_t len;
a82c63f1
MD
31
32 file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0);
33 if (IS_ERR(file))
34 return PTR_ERR(file);
35
bce099b2 36 len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos);
a82c63f1
MD
37 if (len != BOOT_ID_LEN - 1) {
38 ret = -EINVAL;
39 goto end;
40 }
41
42 bootid[BOOT_ID_LEN - 1] = '\0';
43 ret = 0;
44end:
a82c63f1
MD
45 filp_close(file, current->files);
46 return ret;
47}
d4d4da49 48EXPORT_SYMBOL_GPL(wrapper_get_bootid);
a82c63f1
MD
49
50#else
51
52int wrapper_get_bootid(char *bootid)
53{
54 return -ENOSYS;
55}
d4d4da49 56EXPORT_SYMBOL_GPL(wrapper_get_bootid);
a82c63f1
MD
57
58#endif
This page took 0.055245 seconds and 4 git commands to generate.