Codebase list nfdump / upstream/1.5.7 bookkeeper.c
upstream/1.5.7

Tree @upstream/1.5.7 (Download .tar.gz)

bookkeeper.c @upstream/1.5.7raw · history · blame

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/*
 *  Copyright (c) 2004, SWITCH - Teleinformatikdienste fuer Lehre und Forschung
 *  All rights reserved.
 *  
 *  Redistribution and use in source and binary forms, with or without 
 *  modification, are permitted provided that the following conditions are met:
 *  
 *   * Redistributions of source code must retain the above copyright notice, 
 *     this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above copyright notice, 
 *     this list of conditions and the following disclaimer in the documentation 
 *     and/or other materials provided with the distribution.
 *   * Neither the name of SWITCH nor the names of its contributors may be 
 *     used to endorse or promote products derived from this software without 
 *     specific prior written permission.
 *  
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 *  POSSIBILITY OF SUCH DAMAGE.
 *  
 *  $Author: peter $
 *
 *  $Id: bookkeeper.c 97 2008-02-21 09:50:02Z peter $
 *
 *  $LastChangedRevision: 97 $
 *	
 *
 */

#include "config.h"

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>

#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif

#ifndef HAVE_SEMUN
union semun {
	int		val;			// value for SETVAL
	struct	semid_ds *buf;	// buffer for IPC_STAT & IPC_SET
	u_short	*array;			// array for GETALL & SETALL
};
#endif

#include "config.h"

#include "bookkeeper.h"

static bookkeeper_list_t *bookkeeper_list = NULL;

/* function prototypes */

/* 
 * bookkeeper.c is needed for daemon code as well as normal stdio code 
 * therefore a generic LogError is defined, which maps to the 
 * approriate logging channel - either stderr or syslog
 */
void LogError(char *format, ...);

static key_t _ftok(const char *path, int id);

static void sem_lock(int sem_set_id);

static void sem_unlock(int sem_set_id);

static inline bookkeeper_list_t *Get_bookkeeper_list_entry(bookkeeper_t *bookkeeper);

/* Create shared memory object and set its size */

/* our own ftok implementation - the standard C library ftok is not reliable enough */
static key_t _ftok(const char *path, int id) {
struct stat st;

    if (stat(path, &st) < 0)
        return (key_t)-1;

    return (key_t) ( ((st.st_dev & 0xffff) << 16) ^ st.st_ino ) + id;
}


// locks the semaphore, for exclusive access to the bookkeeping record
static void sem_lock(int sem_set_id) {
struct sembuf sem_op;

	/* wait on the semaphore, unless it's value is non-negative. */
	sem_op.sem_num =  0;
	sem_op.sem_op  = -1;
	sem_op.sem_flg =  0;
	if ( semop(sem_set_id, &sem_op, 1) == 0 )
		return;

	LogError("semop() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );

} // End of sem_lock

// sem_unlock. un-locks the semaphore.
static void sem_unlock(int sem_set_id) {
struct sembuf sem_op;

	/* signal the semaphore - increase its value by one. */
	sem_op.sem_num = 0;
	sem_op.sem_op  = 1;
	sem_op.sem_flg = 0;
	if ( semop(sem_set_id, &sem_op, 1) == 0 )
		return;

	LogError("semop() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );

} // End of sem_unlock

static inline bookkeeper_list_t *Get_bookkeeper_list_entry(bookkeeper_t *bookkeeper) {
bookkeeper_list_t	*bookkeeper_list_entry;

	if ( bookkeeper == NULL ) 
		return NULL;

	bookkeeper_list_entry = bookkeeper_list;
	while ( bookkeeper_list_entry != NULL && bookkeeper_list_entry->bookkeeper != bookkeeper ) 
		bookkeeper_list_entry = bookkeeper_list_entry->next;

	return bookkeeper_list_entry;

} // End of Get_bookkeeper_list_entry

int InitBookkeeper(bookkeeper_t **bookkeeper, char *path, pid_t nfcapd_pid, pid_t launcher_pid) {
int sem_key, shm_key, shm_id, sem_id;
union semun sem_val;
bookkeeper_list_t	**bookkeeper_list_entry;

	*bookkeeper = NULL;

	shm_key = _ftok(path, 1); 
	if ( shm_key == - 1 ) 
		return ERR_PATHACCESS;

	// check if the shared memory is already allocated
	shm_id = shmget(shm_key, sizeof(bookkeeper_t), 0600);

	if ( shm_id > 0 ) {
		// the segment already exists. Either a running process is active
		// or an unclean shutdown happened
		
		// map the segement and check the record
		*bookkeeper = (bookkeeper_t *)shmat(shm_id, NULL, 0);
		if ( *bookkeeper == (bookkeeper_t *)-1 ) {
			LogError("shmat() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
			return ERR_FAILED;
		}
		if ( (*bookkeeper)->nfcapd_pid <= 0 ) {
			// rubbish or invalid pid of nfcapd process.
			// Assume unclean shutdown or something else. We clean up and take this record.
			memset((void *)(*bookkeeper), 0, sizeof(bookkeeper_t));
		} else {
			// check if the process created this record is still alive
			int ret = kill((*bookkeeper)->nfcapd_pid, 0);
			if ( ret == - 1 ) {
				switch (errno) {
					case ESRCH:
						// process does not exist, we can clean up this record and use it
						memset((void *)(*bookkeeper), 0, sizeof(bookkeeper_t));
						break;
					case EPERM:
						// A process exists, but we are not allowed to signal this process
						LogError("Another collector with pid %i but different user ID is already running, and configured for '%s'",
							(*bookkeeper)->nfcapd_pid, path);
						return ERR_EXISTS;
						break;
					default:
						// This should never happen, but catch it anyway
						LogError("semop() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
						return ERR_FAILED;
				}
			} else {
				// process exists;
				LogError("Another collector with pid %i is already running, and configured for '%s'",
					(*bookkeeper)->nfcapd_pid, path);
				return ERR_EXISTS;
			}
			// if we pass this point, we have recycled an existing record

		}
	} else {
		// no valid shared segment was found
		switch (errno) {
			case ENOENT:
				// this is ok - no shared segemtn exists, we can create a new one below
				break;
			case EACCES:
				// there is such a segment, but we are not allowed to get it
				// Assume it's another nfcapd
				LogError("Another collector with different user ID is already running, and configured for '%s'",
						path);
				return ERR_EXISTS;
				break;
			default:
				// This should never happen, but catch it anyway
				LogError("semop() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
				return ERR_FAILED;
		}
		// we now create a new segement, this hould not fail now
		shm_id = shmget(shm_key, sizeof(bookkeeper_t), IPC_CREAT | 0600);
		if ( shm_id == - 1 ) {
			// but did anyway - give up
			LogError("shmget() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
			return ERR_FAILED;
		}
		*bookkeeper = (bookkeeper_t *)shmat(shm_id, NULL, 0);
		if ( (*bookkeeper) == (bookkeeper_t *)-1 ) {
			LogError("shmget() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
			return ERR_FAILED;
		}
		memset((void *)(*bookkeeper), 0, sizeof(bookkeeper_t));
	}
	// at this point we now have a valid record and can proceed
	(*bookkeeper)->nfcapd_pid   = nfcapd_pid;
	(*bookkeeper)->launcher_pid = launcher_pid;
	(*bookkeeper)->sequence++;

	// create semaphore

	sem_key = _ftok(path, 2); 
	// this should never fail, as we aleady got a key for the shared memory
	if ( sem_key == - 1 ) {
		// .. but catch it anyway .. and release shared memory. something is fishy
		struct shmid_ds buf;
		shmdt((void *)(*bookkeeper));
		shmctl(shm_id, IPC_RMID, &buf);
		return ERR_FAILED;
	}
	
	// get the semaphore
	sem_id = semget(sem_key, 1, IPC_CREAT | 0600);
	if ( sem_id == - 1 ) {
		struct shmid_ds buf;

		// this should not have failed
		LogError("semget() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );

		// release shared memory 
		shmdt((void *)(*bookkeeper));
		shmctl(shm_id, IPC_RMID, &buf);
		return ERR_FAILED;
	}

	// initialize the semaphore
	sem_val.val = 1;
	if ( semctl(sem_id, 0, SETVAL, sem_val) == -1) {
		struct shmid_ds buf;

		// this should not have failed
		LogError("semctl() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );

		// release shared memory 
		shmdt((void *)(*bookkeeper));
		shmctl(shm_id, IPC_RMID, &buf);
		return ERR_FAILED;
	}

	bookkeeper_list_entry = &bookkeeper_list;
	while ( *bookkeeper_list_entry != NULL )
		bookkeeper_list_entry = &((*bookkeeper_list_entry)->next);

	(*bookkeeper_list_entry) = (bookkeeper_list_t *)malloc(sizeof(bookkeeper_list_t));
	if ( !*bookkeeper_list_entry ) {
		struct shmid_ds buf;

		LogError("malloc() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
		shmdt((void *)(*bookkeeper));
		shmctl(shm_id, IPC_RMID, &buf);
		semctl( sem_id, 0, IPC_RMID );
		return ERR_FAILED;
	}
	memset((void *)*bookkeeper_list_entry, 0, sizeof(bookkeeper_list_t));

	(*bookkeeper_list_entry)->shm_id = shm_id;
	(*bookkeeper_list_entry)->sem_id = sem_id;
	(*bookkeeper_list_entry)->bookkeeper = *bookkeeper;
	(*bookkeeper_list_entry)->next = NULL;
	
	// we are done
	return BOOKKEEPER_OK;

} // End of InitBookkeeper

int AccessBookkeeper(bookkeeper_t **bookkeeper, char *path) {
bookkeeper_list_t	**bookkeeper_list_entry;
int sem_key, shm_key, shm_id, sem_id;

	*bookkeeper = NULL;

	shm_key = _ftok(path, 1); 
	if ( shm_key == - 1 ) 
		return ERR_PATHACCESS;

	// check if the shared memory is already allocated
	shm_id = shmget(shm_key, sizeof(bookkeeper_t), 0600);

	if ( shm_id < 0 ) {
		// the segment does not exists. Check why
		
		switch (errno) {
			case ENOENT:
				// no shared segemtn exists.
				return ERR_NOTEXISTS;
				break;
			case EACCES:
				// there is such a segment, but we are not allowed to get it
				// Assume it's another nfcapd
				LogError("A collector with different user ID is running, and configured for '%s'",
						path);
				return ERR_FAILED;
				break;
			default:
				// This should never happen, but catch it anyway
				LogError("semop() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
				return ERR_FAILED;
		}
		// not reached
	}
	// at this point we now have a valid record and can proceed

	// create semaphore
	sem_key = _ftok(path, 2); 
	// this should never fail, as we aleady got a key for the shared memory
	if ( sem_key == - 1 ) {
		// .. but catch it anyway .. and release shared memory. something is fishy
		return ERR_FAILED;
	}
	
	// get the semaphore
	sem_id = semget(sem_key, 1, 0600);
	if ( sem_id == - 1 ) {
		// this should not have failed
		LogError("semget() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );

		return ERR_FAILED;
	}

	// map the shared segment
	*bookkeeper = (bookkeeper_t *)shmat(shm_id, NULL, 0);
	if ( *bookkeeper == (bookkeeper_t *)-1 ) {
		LogError("shmat() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
		return ERR_FAILED;
	}

	bookkeeper_list_entry = &bookkeeper_list;
	while ( *bookkeeper_list_entry != NULL && (*bookkeeper_list_entry)->bookkeeper != NULL )
		bookkeeper_list_entry = &((*bookkeeper_list_entry)->next);

	// allocate new slot, else use unused slot
	if ( *bookkeeper_list_entry == NULL ) {
		(*bookkeeper_list_entry) = (bookkeeper_list_t *)malloc(sizeof(bookkeeper_list_t));
		if ( !*bookkeeper_list_entry ) {
			LogError("malloc() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
			return ERR_FAILED;
		}
		memset((void *)*bookkeeper_list_entry, 0, sizeof(bookkeeper_list_t));
	}

	(*bookkeeper_list_entry)->shm_id = shm_id;
	(*bookkeeper_list_entry)->sem_id = sem_id;
	(*bookkeeper_list_entry)->bookkeeper = *bookkeeper;
	(*bookkeeper_list_entry)->next = NULL;
	
	return BOOKKEEPER_OK;


} // End of AccessBookkeeper

void ReleaseBookkeeper(bookkeeper_t *bookkeeper, int destroy) {
bookkeeper_list_t	*bookkeeper_list_entry;
struct shmid_ds buf;

	if ( !bookkeeper )
		return;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return;
	}

	// detach from my process addr space memory
	if ( shmdt((void *)bookkeeper) == -1 ) {
		// ups .. 
		LogError("shmdt() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
	}
	bookkeeper = NULL;

	if ( destroy == 0 ) {
		// Entry no longer valid
		bookkeeper_list_entry->bookkeeper = NULL;
		bookkeeper_list_entry->shm_id = 0;
		bookkeeper_list_entry->sem_id = 0;
		return;
	}

	// prevent other proceeses to access the share memory, while we are removing it
	// try to clean up.
	sem_lock(bookkeeper_list_entry->sem_id);
	if ( shmctl(bookkeeper_list_entry->shm_id, IPC_RMID, &buf) ) {
		// ups .. 
		LogError("shmctl() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
	}
	sem_unlock(bookkeeper_list_entry->sem_id);

	if ( semctl( bookkeeper_list_entry->sem_id, 0, IPC_RMID ) == -1 ) {
		// ups .. 
		LogError("semctl() error in %s line %d: %s", __FILE__, __LINE__, strerror(errno) );
	}

	// Entry no longer valid
	bookkeeper_list_entry->bookkeeper = NULL;
	bookkeeper_list_entry->shm_id = 0;
	bookkeeper_list_entry->sem_id = 0;


} // End of ReleaseBookkeeper

int  LookBooks(bookkeeper_t *bookkeeper) {
bookkeeper_list_t	*bookkeeper_list_entry;

	if ( !bookkeeper )
		return 0;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return 1;
	}

	sem_lock(bookkeeper_list_entry->sem_id);

	return 0;

} // End of LookBooks

int  UnlookBooks(bookkeeper_t *bookkeeper) {
bookkeeper_list_t	*bookkeeper_list_entry;

	if ( !bookkeeper )
		return 0;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return 1;
	}

	sem_unlock(bookkeeper_list_entry->sem_id);

	return 0;

} // End of UnlookBooks

void ClearBooks(bookkeeper_t *bookkeeper, bookkeeper_t *tmp_books) {
bookkeeper_list_t	*bookkeeper_list_entry;

	if ( !bookkeeper )
		return;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return;
	}

	sem_lock(bookkeeper_list_entry->sem_id);
	// backup copy
	if ( tmp_books != NULL ) {
		memcpy((void *)tmp_books, (void *)bookkeeper, sizeof(bookkeeper_t));
	}
	bookkeeper->first 	  = 0;
	bookkeeper->last  	  = 0;
	bookkeeper->numfiles  = 0;
	bookkeeper->filesize  = 0;
	bookkeeper->sequence++;
	sem_unlock(bookkeeper_list_entry->sem_id);

} // End of ClearBooks

uint64_t BookSequence(bookkeeper_t *bookkeeper) {
bookkeeper_list_t	*bookkeeper_list_entry;
uint64_t	seq;

	if ( !bookkeeper )
		return 0;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return 0;
	}

	sem_lock(bookkeeper_list_entry->sem_id);
	seq = bookkeeper->sequence;
	sem_unlock(bookkeeper_list_entry->sem_id);

	return seq;

} // End of BookSequence

void UpdateBooks(bookkeeper_t *bookkeeper, time_t when, uint64_t size) {
bookkeeper_list_t	*bookkeeper_list_entry;

	if ( !bookkeeper )
		return;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return;
	}

	sem_lock(bookkeeper_list_entry->sem_id);
	if ( bookkeeper->first == 0 ) 
		bookkeeper->first = when;

	bookkeeper->last = when;
	bookkeeper->numfiles++;
	bookkeeper->filesize  += size;
	bookkeeper->sequence++;
	sem_unlock(bookkeeper_list_entry->sem_id);

} // End of UpdateBooks

void UpdateBooksParam(bookkeeper_t *bookkeeper, time_t lifetime, uint64_t maxsize) {
bookkeeper_list_t	*bookkeeper_list_entry;

	if ( !bookkeeper )
		return;

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return;
	}

	sem_lock(bookkeeper_list_entry->sem_id);
	bookkeeper->max_lifetime = lifetime;
	bookkeeper->max_filesize = maxsize;
	bookkeeper->sequence++;
	sem_unlock(bookkeeper_list_entry->sem_id);

} // End of UpdateBooksParam

void PrintBooks(bookkeeper_t *bookkeeper) {
bookkeeper_list_t	*bookkeeper_list_entry;
struct tm *ts;
time_t	t;
char	string[32];

	if ( !bookkeeper ) {
		printf("No bookkeeper record available!\n");
		return;
	}

	bookkeeper_list_entry = Get_bookkeeper_list_entry(bookkeeper);
	if ( !bookkeeper_list_entry ) {
		// this should never happen 
		LogError("Software error in %s line %d: %s", __FILE__, __LINE__, "Entry not found in list");
		return;
	}

	sem_lock(bookkeeper_list_entry->sem_id);
	printf("Collector process: %lu\n", (unsigned long)bookkeeper->nfcapd_pid);
	if ( bookkeeper->launcher_pid ) 
		printf("Launcher process: %lu\n", (unsigned long)bookkeeper->launcher_pid);
	else
		printf("Launcher process: <none>\n");
	printf("Record sequence : %llu\n", (unsigned long long)bookkeeper->sequence);

	t = bookkeeper->first;
    ts = localtime(&t);
    strftime(string, 31, "%Y-%m-%d %H:%M:%S", ts);
	string[31] = '\0';
	printf("First           : %s\n", bookkeeper->first ? string : "<not set>");

	t = bookkeeper->last;
    ts = localtime(&t);
    strftime(string, 31, "%Y-%m-%d %H:%M:%S", ts);
	string[31] = '\0';
	printf("Last            : %s\n", bookkeeper->last ? string : "<not set>");
	printf("Number of files : %llu\n", (unsigned long long)bookkeeper->numfiles);
	printf("Total file size : %llu\n", (unsigned long long)bookkeeper->filesize);
	printf("Max file size   : %llu\n", (unsigned long long)bookkeeper->max_filesize);
	printf("Max life time   : %llu\n", (unsigned long long)bookkeeper->max_lifetime);
	sem_unlock(bookkeeper_list_entry->sem_id);
		
} // End of PrintBooks