1 /* Copyright (c) 1998 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
32 /* We use this to make sure the receiver is the same. */
33 static const char compilation
[21] = __DATE__
" " __TIME__
;
35 /* Statistic data for one database. */
42 unsigned long int postimeout
;
43 unsigned long int negtimeout
;
45 unsigned long int poshit
;
46 unsigned long int neghit
;
47 unsigned long int posmiss
;
48 unsigned long int negmiss
;
51 /* Record for transmitting statistics. */
54 char version
[sizeof (compilation
)];
57 struct dbstat dbs
[lastdb
];
62 send_stats (int fd
, struct database dbs
[lastdb
])
67 memcpy (data
.version
, compilation
, sizeof (compilation
));
68 data
.debug_level
= debug_level
;
71 for (cnt
= 0; cnt
< lastdb
; ++cnt
)
73 data
.dbs
[cnt
].enabled
= dbs
[cnt
].enabled
;
74 data
.dbs
[cnt
].check_file
= dbs
[cnt
].check_file
;
75 data
.dbs
[cnt
].module
= dbs
[cnt
].module
;
76 data
.dbs
[cnt
].postimeout
= dbs
[cnt
].postimeout
;
77 data
.dbs
[cnt
].negtimeout
= dbs
[cnt
].negtimeout
;
78 data
.dbs
[cnt
].poshit
= dbs
[cnt
].poshit
;
79 data
.dbs
[cnt
].neghit
= dbs
[cnt
].neghit
;
80 data
.dbs
[cnt
].posmiss
= dbs
[cnt
].posmiss
;
81 data
.dbs
[cnt
].negmiss
= dbs
[cnt
].negmiss
;
84 if (TEMP_FAILURE_RETRY (write (fd
, &data
, sizeof (data
))) != sizeof (data
))
87 dbg_log (_("cannot write statistics: %s"),
88 strerror_r (errno
, buf
, sizeof (buf
)));
94 receive_print_stats (void)
102 /* Open a socket to the running nscd. */
103 fd
= nscd_open_socket ();
105 error (EXIT_FAILURE
, 0, _("nscd not running!\n"));
107 /* Send the request. */
108 req
.version
= NSCD_VERSION
;
111 nbytes
= TEMP_FAILURE_RETRY (write (fd
, &req
, sizeof (request_header
)));
112 if (nbytes
!= sizeof (request_header
))
116 error (EXIT_FAILURE
, err
, _("write incomplete"));
119 /* Read as much data as we expect. */
120 if (TEMP_FAILURE_RETRY (read (fd
, &data
, sizeof (data
))) != sizeof (data
)
121 || (memcmp (data
.version
, compilation
, sizeof (compilation
)) != 0
122 /* Yes, this is an assignment! */
125 /* Not the right version. */
128 error (EXIT_FAILURE
, err
, _("cannot read statistics data"));
131 printf (_("nscd configuration:\n\n%15d server debug level\n"),
134 for (i
= 0; i
< lastdb
; ++i
)
136 unsigned long int hit
= data
.dbs
[i
].poshit
+ data
.dbs
[i
].neghit
;
137 unsigned long int all
= hit
+ data
.dbs
[i
].posmiss
+ data
.dbs
[i
].negmiss
;
138 const char *enabled
= nl_langinfo (data
.dbs
[i
].enabled
? YESSTR
: NOSTR
);
139 const char *check_file
= nl_langinfo (data
.dbs
[i
].check_file
142 if (enabled
[0] == '\0')
143 /* The locale does not provide this information so we have to
144 translate it ourself. Since we should avoid short translation
145 terms we artifically increase the length. */
146 enabled
= data
.dbs
[i
].enabled
? _(" yes") : _(" no");
147 if (check_file
[0] == '\0')
148 check_file
= data
.dbs
[i
].check_file
? _(" yes") : _(" no");
151 /* If nothing happened so far report a 0% hit rate. */
154 printf (_("\n%s cache:\n\n"
155 "%15s cache is enabled\n"
156 "%15Zd suggested size\n"
157 "%15ld seconds time to live for positive entries\n"
158 "%15ld seconds time to live for negative entries\n"
159 "%15ld cache hits on positive entries\n"
160 "%15ld cache hits on negative entries\n"
161 "%15ld cache misses on positive entries\n"
162 "%15ld cache misses on negative entries\n"
163 "%15ld%% cache hit rate\n"
164 "%15s check /etc/%s for changes\n"),
167 data
.dbs
[i
].postimeout
, data
.dbs
[i
].negtimeout
,
168 data
.dbs
[i
].poshit
, data
.dbs
[i
].neghit
,
169 data
.dbs
[i
].posmiss
, data
.dbs
[i
].negmiss
,
171 check_file
, dbnames
[i
]);