Rename "tsc" to "timestamp"
[lttng-modules.git] / src / wrapper / random.c
CommitLineData
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 10#include <linux/errno.h>
477c93ad 11#include <linux/module.h>
2fa61a31 12
a82c63f1
MD
13/* boot_id depends on sysctl */
14#if defined(CONFIG_SYSCTL)
15
62d0a59c 16#include <wrapper/fs.h>
a82c63f1
MD
17#include <linux/file.h>
18#include <linux/sched.h>
19#include <linux/uaccess.h>
5a2f5e92 20#include <wrapper/random.h>
a82c63f1
MD
21
22/*
23 * Returns string boot id.
24 */
25int wrapper_get_bootid(char *bootid)
26{
27 struct file *file;
28 int ret;
29 ssize_t len;
a82c63f1
MD
30
31 file = filp_open("/proc/sys/kernel/random/boot_id", O_RDONLY, 0);
32 if (IS_ERR(file))
33 return PTR_ERR(file);
34
62d0a59c 35 len = lttng_kernel_read(file, bootid, BOOT_ID_LEN - 1, &file->f_pos);
a82c63f1
MD
36 if (len != BOOT_ID_LEN - 1) {
37 ret = -EINVAL;
38 goto end;
39 }
1e543e7c 40
a82c63f1
MD
41 bootid[BOOT_ID_LEN - 1] = '\0';
42 ret = 0;
43end:
a82c63f1
MD
44 filp_close(file, current->files);
45 return ret;
46}
1c999280 47EXPORT_SYMBOL_GPL(wrapper_get_bootid);
a82c63f1
MD
48
49#else
50
51int wrapper_get_bootid(char *bootid)
52{
53 return -ENOSYS;
54}
1c999280 55EXPORT_SYMBOL_GPL(wrapper_get_bootid);
a82c63f1
MD
56
57#endif
This page took 0.060409 seconds and 4 git commands to generate.