c938ae35a4ac2a96a2a2deee26cb645a33792af2
[lttng-modules.git] / wrapper / random.c
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
14 /* boot_id depends on sysctl */
15 #if defined(CONFIG_SYSCTL)
16
17 #include <linux/fs.h>
18 #include <linux/file.h>
19 #include <linux/sched.h>
20 #include <linux/uaccess.h>
21 #include <wrapper/random.h>
22
23 /*
24 * Returns string boot id.
25 */
26 int wrapper_get_bootid(char *bootid)
27 {
28 struct file *file;
29 int ret;
30 ssize_t len;
31 mm_segment_t old_fs;
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 old_fs = get_fs();
38 set_fs(KERNEL_DS);
39
40 if (!file->f_op || !file->f_op->read) {
41 ret = -EINVAL;
42 goto end;
43 }
44
45 len = file->f_op->read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos);
46 if (len != BOOT_ID_LEN - 1) {
47 ret = -EINVAL;
48 goto end;
49 }
50
51 bootid[BOOT_ID_LEN - 1] = '\0';
52 ret = 0;
53 end:
54 set_fs(old_fs);
55 filp_close(file, current->files);
56 return ret;
57 }
58
59 #else
60
61 int wrapper_get_bootid(char *bootid)
62 {
63 return -ENOSYS;
64 }
65
66 #endif
This page took 0.029876 seconds and 3 git commands to generate.