4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * (C) Copyright (c) 2015, Cray Inc, all rights reserved.
8 * All rights reserved. This program and the accompanying materials
9 * are made available under the terms of the GNU Lesser General Public License
10 * LGPL version 2.1 or (at your discretion) any later version.
11 * LGPL version 2.1 accompanies this distribution, and is available at
12 * http://www.gnu.org/licenses/lgpl-2.1.html
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
22 * lustre/utils/liblustreapi_util.c
24 * Misc LGPL-licenced utility functions for liblustreapi.
26 * Author: Frank Zago <fzago@cray.com>
33 #include <sys/types.h>
36 #include <sys/syscall.h>
39 * Indicate whether the liblustreapi_init() constructor below has run or not.
41 * This can be used by external programs to ensure if the initialization
42 * mechanism has actually worked.
44 bool liblustreapi_initialized;
48 * Initializes the library
50 static __attribute__ ((constructor)) void liblustreapi_init(void)
56 /* Initializes the random number generator (random()). Get
57 * data from different places in case one of them fails. This
58 * is enough to get reasonably random numbers, but is not
59 * strong enough to be used for cryptography. */
60 seed = syscall(SYS_gettid);
62 if (gettimeofday(&tv, NULL) == 0) {
67 fd = open("/dev/urandom", O_RDONLY | O_NOFOLLOW);
71 (void)read(fd, &rnumber, sizeof(rnumber));
77 liblustreapi_initialized = true;