Commit | Line | Data |
---|---|---|
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 | 12 | #include <linux/errno.h> |
4a1a9a9a | 13 | #include <linux/module.h> |
2fa61a31 | 14 | |
a82c63f1 MD |
15 | /* boot_id depends on sysctl */ |
16 | #if defined(CONFIG_SYSCTL) | |
17 | ||
bce099b2 | 18 | #include <wrapper/fs.h> |
a82c63f1 MD |
19 | #include <linux/file.h> |
20 | #include <linux/sched.h> | |
21 | #include <linux/uaccess.h> | |
5a2f5e92 | 22 | #include <wrapper/random.h> |
a82c63f1 MD |
23 | |
24 | /* | |
25 | * Returns string boot id. | |
26 | */ | |
27 | int wrapper_get_bootid(char *bootid) | |
28 | { | |
29 | struct file *file; | |
30 | int ret; | |
31 | ssize_t len; | |
a82c63f1 MD |
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 | ||
bce099b2 | 37 | len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); |
a82c63f1 MD |
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; | |
45 | end: | |
a82c63f1 MD |
46 | filp_close(file, current->files); |
47 | return ret; | |
48 | } | |
d4d4da49 | 49 | EXPORT_SYMBOL_GPL(wrapper_get_bootid); |
a82c63f1 MD |
50 | |
51 | #else | |
52 | ||
53 | int wrapper_get_bootid(char *bootid) | |
54 | { | |
55 | return -ENOSYS; | |
56 | } | |
d4d4da49 | 57 | EXPORT_SYMBOL_GPL(wrapper_get_bootid); |
a82c63f1 MD |
58 | |
59 | #endif |