Implement recvmmsg also as socketcall
[glibc.git] / nscd / nscd.h
blob3279b8543266307e7f1f4c5dbf50a0d0dee2b767
1 /* Copyright (c) 1998-2001, 2003-2008, 2009 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _NSCD_H
21 #define _NSCD_H 1
23 #include <pthread.h>
24 #include <stdbool.h>
25 #include <time.h>
26 #include <sys/uio.h>
28 /* The declarations for the request and response types are in the file
29 "nscd-client.h", which should contain everything needed by client
30 functions. */
31 #include "nscd-client.h"
34 /* Handle databases. */
35 typedef enum
37 pwddb,
38 grpdb,
39 hstdb,
40 servdb,
41 lastdb
42 } dbtype;
45 /* Default limit on the number of times a value gets reloaded without
46 being used in the meantime. NSCD does not throw a value out as
47 soon as it times out. It tries to reload the value from the
48 server. Only if the value has not been used for so many rounds it
49 is removed. */
50 #define DEFAULT_RELOAD_LIMIT 5
53 /* Time before restarting the process in paranoia mode. */
54 #define RESTART_INTERVAL (60 * 60)
57 /* Stack size for worker threads. */
58 #define NSCD_THREAD_STACKSIZE 1024 * 1024 * (sizeof (void *) / 4)
60 /* Maximum size of stack frames we allow the thread to use. We use
61 80% of the thread stack size. */
62 #define MAX_STACK_USE ((8 * NSCD_THREAD_STACKSIZE) / 10)
65 /* Structure describing dynamic part of one database. */
66 struct database_dyn
68 pthread_rwlock_t lock;
69 pthread_cond_t prune_cond;
70 pthread_mutex_t prune_lock;
71 pthread_mutex_t prune_run_lock;
72 time_t wakeup_time;
74 int enabled;
75 int check_file;
76 int inotify_descr;
77 int clear_cache;
78 int persistent;
79 int shared;
80 int propagate;
81 int reset_res;
82 const char filename[16];
83 const char *db_filename;
84 time_t file_mtime;
85 size_t suggested_module;
86 size_t max_db_size;
88 unsigned long int postimeout; /* In seconds. */
89 unsigned long int negtimeout; /* In seconds. */
91 int wr_fd; /* Writable file descriptor. */
92 int ro_fd; /* Unwritable file descriptor. */
94 const struct iovec *disabled_iov;
96 struct database_pers_head *head;
97 char *data;
98 size_t memsize;
99 pthread_mutex_t memlock;
100 bool mmap_used;
101 bool last_alloc_failed;
105 /* Paths of the file for the persistent storage. */
106 #define _PATH_NSCD_PASSWD_DB "/var/db/nscd/passwd"
107 #define _PATH_NSCD_GROUP_DB "/var/db/nscd/group"
108 #define _PATH_NSCD_HOSTS_DB "/var/db/nscd/hosts"
109 #define _PATH_NSCD_SERVICES_DB "/var/db/nscd/services"
111 /* Path used when not using persistent storage. */
112 #define _PATH_NSCD_XYZ_DB_TMP "/var/run/nscd/dbXXXXXX"
114 /* Maximum alignment requirement we will encounter. */
115 #define BLOCK_ALIGN_LOG 3
116 #define BLOCK_ALIGN (1 << BLOCK_ALIGN_LOG)
117 #define BLOCK_ALIGN_M1 (BLOCK_ALIGN - 1)
119 /* Default value for the maximum size of the database files. */
120 #define DEFAULT_MAX_DB_SIZE (32 * 1024 * 1024)
122 /* Number of bytes of data we initially reserve for each hash table bucket. */
123 #define DEFAULT_DATASIZE_PER_BUCKET 1024
125 /* Default module of hash table. */
126 #define DEFAULT_SUGGESTED_MODULE 211
129 /* Number of seconds between two cache pruning runs if we do not have
130 better information when it is really needed. */
131 #define CACHE_PRUNE_INTERVAL 15
134 /* Global variables. */
135 extern struct database_dyn dbs[lastdb] attribute_hidden;
136 extern const char *const dbnames[lastdb];
137 extern const char *const serv2str[LASTREQ];
139 extern const struct iovec pwd_iov_disabled;
140 extern const struct iovec grp_iov_disabled;
141 extern const struct iovec hst_iov_disabled;
142 extern const struct iovec serv_iov_disabled;
145 /* Initial number of threads to run. */
146 extern int nthreads;
147 /* Maximum number of threads to use. */
148 extern int max_nthreads;
150 /* User name to run server processes as. */
151 extern const char *server_user;
153 /* Name and UID of user who is allowed to request statistics. */
154 extern const char *stat_user;
155 extern uid_t stat_uid;
157 /* Time the server was started. */
158 extern time_t start_time;
160 /* Number of times clients had to wait. */
161 extern unsigned long int client_queued;
163 /* Maximum needed alignment. */
164 extern const size_t block_align;
166 /* Number of times a value is reloaded without being used. UINT_MAX
167 means unlimited. */
168 extern unsigned int reload_count;
170 /* Pagesize minus one. */
171 extern uintptr_t pagesize_m1;
173 /* Nonzero if paranoia mode is enabled. */
174 extern int paranoia;
175 /* Time after which the process restarts. */
176 extern time_t restart_time;
177 /* How much time between restarts. */
178 extern time_t restart_interval;
179 /* Old current working directory. */
180 extern const char *oldcwd;
181 /* Old user and group ID. */
182 extern uid_t old_uid;
183 extern gid_t old_gid;
186 /* Prototypes for global functions. */
188 /* nscd.c */
189 extern void termination_handler (int signum) __attribute__ ((__noreturn__));
190 extern int nscd_open_socket (void);
192 /* connections.c */
193 extern void nscd_init (void);
194 extern void close_sockets (void);
195 extern void start_threads (void) __attribute__ ((__noreturn__));
197 /* nscd_conf.c */
198 extern int nscd_parse_file (const char *fname,
199 struct database_dyn dbs[lastdb]);
201 /* nscd_stat.c */
202 extern void send_stats (int fd, struct database_dyn dbs[lastdb]);
203 extern int receive_print_stats (void) __attribute__ ((__noreturn__));
205 /* cache.c */
206 extern struct datahead *cache_search (request_type, void *key, size_t len,
207 struct database_dyn *table,
208 uid_t owner);
209 extern int cache_add (int type, const void *key, size_t len,
210 struct datahead *packet, bool first,
211 struct database_dyn *table, uid_t owner,
212 bool prune_wakeup);
213 extern time_t prune_cache (struct database_dyn *table, time_t now, int fd);
215 /* pwdcache.c */
216 extern void addpwbyname (struct database_dyn *db, int fd, request_header *req,
217 void *key, uid_t uid);
218 extern void addpwbyuid (struct database_dyn *db, int fd, request_header *req,
219 void *key, uid_t uid);
220 extern void readdpwbyname (struct database_dyn *db, struct hashentry *he,
221 struct datahead *dh);
222 extern void readdpwbyuid (struct database_dyn *db, struct hashentry *he,
223 struct datahead *dh);
225 /* grpcache.c */
226 extern void addgrbyname (struct database_dyn *db, int fd, request_header *req,
227 void *key, uid_t uid);
228 extern void addgrbygid (struct database_dyn *db, int fd, request_header *req,
229 void *key, uid_t uid);
230 extern void readdgrbyname (struct database_dyn *db, struct hashentry *he,
231 struct datahead *dh);
232 extern void readdgrbygid (struct database_dyn *db, struct hashentry *he,
233 struct datahead *dh);
235 /* hstcache.c */
236 extern void addhstbyname (struct database_dyn *db, int fd, request_header *req,
237 void *key, uid_t uid);
238 extern void addhstbyaddr (struct database_dyn *db, int fd, request_header *req,
239 void *key, uid_t uid);
240 extern void addhstbynamev6 (struct database_dyn *db, int fd,
241 request_header *req, void *key, uid_t uid);
242 extern void addhstbyaddrv6 (struct database_dyn *db, int fd,
243 request_header *req, void *key, uid_t uid);
244 extern void readdhstbyname (struct database_dyn *db, struct hashentry *he,
245 struct datahead *dh);
246 extern void readdhstbyaddr (struct database_dyn *db, struct hashentry *he,
247 struct datahead *dh);
248 extern void readdhstbynamev6 (struct database_dyn *db, struct hashentry *he,
249 struct datahead *dh);
250 extern void readdhstbyaddrv6 (struct database_dyn *db, struct hashentry *he,
251 struct datahead *dh);
253 /* aicache.c */
254 extern void addhstai (struct database_dyn *db, int fd, request_header *req,
255 void *key, uid_t uid);
256 extern void readdhstai (struct database_dyn *db, struct hashentry *he,
257 struct datahead *dh);
260 /* initgrcache.c */
261 extern void addinitgroups (struct database_dyn *db, int fd,
262 request_header *req, void *key, uid_t uid);
263 extern void readdinitgroups (struct database_dyn *db, struct hashentry *he,
264 struct datahead *dh);
266 /* servicecache.c */
267 extern void addservbyname (struct database_dyn *db, int fd,
268 request_header *req, void *key, uid_t uid);
269 extern void readdservbyname (struct database_dyn *db, struct hashentry *he,
270 struct datahead *dh);
271 extern void addservbyport (struct database_dyn *db, int fd,
272 request_header *req, void *key, uid_t uid);
273 extern void readdservbyport (struct database_dyn *db, struct hashentry *he,
274 struct datahead *dh);
276 /* mem.c */
277 extern void *mempool_alloc (struct database_dyn *db, size_t len,
278 int data_alloc);
279 extern void gc (struct database_dyn *db);
282 /* nscd_setup_thread.c */
283 extern int setup_thread (struct database_dyn *db);
286 /* Special version of TEMP_FAILURE_RETRY for functions returning error
287 values. */
288 #define TEMP_FAILURE_RETRY_VAL(expression) \
289 (__extension__ \
290 ({ long int __result; \
291 do __result = (long int) (expression); \
292 while (__result == EINTR); \
293 __result; }))
295 #endif /* nscd.h */