Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 2 | * |
886d51a3 | 3 | * wrapper/random.c |
a82c63f1 | 4 | * |
5b4ea313 | 5 | * wrapper around bootid read. Read the boot id through the /proc filesystem. |
a82c63f1 | 6 | * |
886d51a3 | 7 | * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
a82c63f1 MD |
8 | */ |
9 | ||
2fa61a31 MD |
10 | #include <linux/errno.h> |
11 | ||
a82c63f1 MD |
12 | /* boot_id depends on sysctl */ |
13 | #if defined(CONFIG_SYSCTL) | |
14 | ||
62d0a59c | 15 | #include <wrapper/fs.h> |
a82c63f1 MD |
16 | #include <linux/file.h> |
17 | #include <linux/sched.h> | |
18 | #include <linux/uaccess.h> | |
5a2f5e92 | 19 | #include <wrapper/random.h> |
a82c63f1 MD |
20 | |
21 | /* | |
22 | * Returns string boot id. | |
23 | */ | |
24 | int wrapper_get_bootid(char *bootid) | |
25 | { | |
26 | struct file *file; | |
27 | int ret; | |
28 | ssize_t len; | |
a82c63f1 MD |
29 | |
30 | file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0); | |
31 | if (IS_ERR(file)) | |
32 | return PTR_ERR(file); | |
33 | ||
62d0a59c | 34 | len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos); |
a82c63f1 MD |
35 | if (len != BOOT_ID_LEN - 1) { |
36 | ret = -EINVAL; | |
37 | goto end; | |
38 | } | |
1e543e7c | 39 | |
a82c63f1 MD |
40 | bootid[BOOT_ID_LEN - 1] = '\0'; |
41 | ret = 0; | |
42 | end: | |
a82c63f1 MD |
43 | filp_close(file, current->files); |
44 | return ret; | |
45 | } | |
1c999280 | 46 | EXPORT_SYMBOL_GPL(wrapper_get_bootid); |
a82c63f1 MD |
47 | |
48 | #else | |
49 | ||
50 | int wrapper_get_bootid(char *bootid) | |
51 | { | |
52 | return -ENOSYS; | |
53 | } | |
1c999280 | 54 | EXPORT_SYMBOL_GPL(wrapper_get_bootid); |
a82c63f1 MD |
55 | |
56 | #endif |