Cleanup: remove trailing white spaces across project
[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
17#include <linux/fs.h>
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;
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 }
1e543e7c 50
a82c63f1
MD
51 bootid[BOOT_ID_LEN - 1] = '\0';
52 ret = 0;
53end:
54 set_fs(old_fs);
55 filp_close(file, current->files);
56 return ret;
57}
58
59#else
60
61int wrapper_get_bootid(char *bootid)
62{
63 return -ENOSYS;
64}
65
66#endif
This page took 0.035193 seconds and 4 git commands to generate.