ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/gvpe.C
(Generate patch)

Comparing gvpe/src/gvpe.C (file contents):
Revision 1.23 by root, Fri Jul 5 10:04:22 2013 UTC vs.
Revision 1.24 by root, Sat Jul 13 04:10:29 2013 UTC

1/* 1/*
2 gvpe.C -- the main file for gvpe 2 gvpe.C -- the main file for gvpe
3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl> 3 Copyright (C) 1998-2002 Ivo Timmermans <ivo@o2w.nl>
4 2000-2002 Guus Sliepen <guus@sliepen.eu.org> 4 2000-2002 Guus Sliepen <guus@sliepen.eu.org>
5 2003-2011 Marc Lehmann <gvpe@schmorp.de> 5 2003-2013 Marc Lehmann <gvpe@schmorp.de>
6 6
7 This file is part of GVPE. 7 This file is part of GVPE.
8 8
9 GVPE is free software; you can redistribute it and/or modify it 9 GVPE is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License as published by the 10 under the terms of the GNU General Public License as published by the
40#include <errno.h> 40#include <errno.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <getopt.h> 42#include <getopt.h>
43#include <signal.h> 43#include <signal.h>
44#include <sys/types.h> 44#include <sys/types.h>
45#include <sys/stat.h>
45#include <unistd.h> 46#include <unistd.h>
46#include <signal.h> 47#include <signal.h>
47#include <termios.h> 48#include <termios.h>
48 49
49#if HAVE_SYS_MMAN_H 50#if HAVE_SYS_MMAN_H
206 act.sa_flags = SA_RESETHAND; 207 act.sa_flags = SA_RESETHAND;
207 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL); 208 act.sa_handler = sigterm_handler; sigaction (SIGINT , &act, NULL);
208 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL); 209 act.sa_handler = sigterm_handler; sigaction (SIGTERM, &act, NULL);
209} 210}
210 211
212static int rand_fd;
213
214// antique C++ requires external linkage :/
215void
216reseed_rng (ev::timer &w, int revents)
217{
218 char buf [SEED_SIZE];
219 int n = read (rand_fd, buf, sizeof (buf));
220
221 if (n > 0)
222 RAND_seed (buf, n);
223}
224
225static void
226setup_rng (void)
227{
228 if (!*conf.seed_dev)
229 return;
230
231#ifndef O_BINARY
232# define O_BINARY 0
233#endif
234#ifndef O_NONBLOCK
235# define O_NONBLOCK 0
236#endif
237
238 rand_fd = open (conf.seed_dev, O_RDONLY | O_NONBLOCK | O_BINARY);
239
240 if (rand_fd < 0)
241 {
242 slog (L_ERR, _("unable to open seed device '%s': %s, exiting."), conf.seed_dev, strerror (errno));
243 exit (EXIT_FAILURE);
244 }
245
246 static ev::timer reseed_timer;
247
248 if (conf.reseed)
249 {
250 reseed_timer.set<reseed_rng> ();
251 reseed_timer.set (conf.reseed, conf.reseed);
252 reseed_timer.start (EV_DEFAULT);
253 }
254
255 reseed_rng (reseed_timer, 0);
256}
257
211int 258int
212main (int argc, char **argv, char **envp) 259main (int argc, char **argv, char **envp)
213{ 260{
214 ERR_load_crypto_strings (); // we have the RAM 261 ERR_load_crypto_strings (); // we have the RAM
215 262
270 configuration_parser (conf, true, argc, argv); 317 configuration_parser (conf, true, argc, argv);
271 } 318 }
272 319
273 set_loglevel (llevel != L_NONE ? llevel : conf.llevel); 320 set_loglevel (llevel != L_NONE ? llevel : conf.llevel);
274 321
275 RAND_load_file ("/dev/urandom", 1024); 322 setup_rng ();
276 323
277 if (!THISNODE) 324 if (!THISNODE)
278 { 325 {
279 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, specify the nodename when starting gvpe."), 326 slog (L_ERR, _("current node not set, or node '%s' not found in configfile, specify the nodename when starting gvpe."),
280 thisnode ? thisnode : "<unset>"); 327 thisnode ? thisnode : "<unset>");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines