]> git.ipfire.org Git - thirdparty/rng-tools.git/blob - rngd.h
Create PID file at startup, in daemon mode
[thirdparty/rng-tools.git] / rngd.h
1 /*
2 * rngd.h -- rngd globals
3 *
4 * Copyright (C) 2001 Philipp Rumpf
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #ifndef RNGD__H
22 #define RNGD__H
23
24 #define _GNU_SOURCE
25
26 #include "rng-tools-config.h"
27
28 #include <unistd.h>
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include <stdio.h>
32 #include <syslog.h>
33
34 #include "fips.h"
35
36 enum {
37 MAX_RNG_FAILURES = 25,
38 };
39
40 /* Command line arguments and processing */
41 struct arguments {
42 char *random_name;
43 char *pid_file;
44
45 int random_step;
46 int fill_watermark;
47 double poll_timeout;
48
49 int quiet;
50 int verbose;
51 int daemon;
52 int enable_tpm;
53 };
54 extern struct arguments *arguments;
55
56 /* structures to store rng information */
57 struct rng {
58 char *rng_name;
59 int rng_fd;
60 bool disabled;
61 int failures;
62
63 int (*xread) (void *buf, size_t size, struct rng *ent_src);
64 fips_ctx_t *fipsctx;
65
66 struct rng *next;
67 };
68
69 /* Background/daemon mode */
70 extern int am_daemon; /* Nonzero if we went daemon */
71
72
73 /*
74 * Routines and macros
75 */
76 #define message(priority,fmt,args...) do { \
77 if (am_daemon) { \
78 syslog((priority), fmt, ##args); \
79 } else { \
80 fprintf(stderr, fmt, ##args); \
81 fprintf(stderr, "\n"); \
82 } \
83 } while (0)
84
85 extern void src_list_add(struct rng *ent_src);
86 extern int write_pid_file(const char *pid_fn);
87 #endif /* RNGD__H */
88