Revision 1108,
1.2 KB
checked in by daisuke, 14 years ago
(diff) |
import initscripts-8.90.6 from internal cvs repository
|
Rev | Line | |
---|
[1108] | 1 | /* Copyright (C) 2003 Red Hat, Inc. |
---|
| 2 | * |
---|
| 3 | * This program is free software; you can redistribute it and/or modify |
---|
| 4 | * it under the terms of the GNU General Public License, version 2, |
---|
| 5 | * as published by the Free Software Foundation. |
---|
| 6 | * |
---|
| 7 | * This program is distributed in the hope that it will be useful, |
---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 10 | * GNU General Public License for more details. |
---|
| 11 | * |
---|
| 12 | * You should have received a copy of the GNU General Public License |
---|
| 13 | * along with this program; if not, write to the Free Software |
---|
| 14 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
---|
| 15 | * |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | #include <fcntl.h> |
---|
| 19 | #include <stdlib.h> |
---|
| 20 | #include <time.h> |
---|
| 21 | #include <unistd.h> |
---|
| 22 | #include <sys/stat.h> |
---|
| 23 | int |
---|
| 24 | main (void) |
---|
| 25 | { |
---|
| 26 | struct stat st; |
---|
| 27 | long int n; |
---|
| 28 | if (stat ("/etc/hostid", &st) == 0 && S_ISREG (st.st_mode) |
---|
| 29 | && st.st_size >= sizeof (n)) |
---|
| 30 | return 0; |
---|
| 31 | int fd = open ("/dev/random", O_RDONLY); |
---|
| 32 | if (fd == -1 || read (fd, &n, sizeof (n)) != sizeof (n)) |
---|
| 33 | { |
---|
| 34 | srand48 ((long int) time (NULL) ^ (long int) getpid ()); |
---|
| 35 | n = lrand48 (); |
---|
| 36 | } |
---|
| 37 | return sethostid ((int32_t)n); |
---|
| 38 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.