]> granicus.if.org Git - shadow/blob - lib/nscd.c
* src/faillog.c, src/chage.c, src/newusers.c, src/su.c: The getopt
[shadow] / lib / nscd.c
1 /* Author: Peter Vrabec <pvrabec@redhat.com> */
2
3 #include <config.h>
4 #ifdef USE_NSCD
5
6 #include <stdio.h>
7 #include <sys/wait.h>
8 #include <sys/types.h>
9 #include "exitcodes.h"
10 #include "defines.h"
11 #include "prototypes.h"
12 #include "nscd.h"
13
14 #define MSG_NSCD_FLUSH_CACHE_FAILED "%s: Failed to flush the nscd cache.\n"
15
16 /*
17  * nscd_flush_cache - flush specified service buffer in nscd cache
18  */
19 int nscd_flush_cache (const char *service)
20 {
21         int status, code;
22         const char *cmd = "/usr/sbin/nscd";
23         const char *spawnedArgs[] = {"nscd", "-i", service, NULL};
24         const char *spawnedEnv[] = {NULL};
25
26         if (run_command (cmd, spawnedArgs, spawnedEnv, &status) != 0) {
27                 /* run_command writes its own more detailed message. */
28                 (void) fprintf (stderr, _(MSG_NSCD_FLUSH_CACHE_FAILED), Prog);
29                 return -1;
30         }
31
32         code = WEXITSTATUS (status);
33         if (!WIFEXITED (status)) {
34                 (void) fprintf (stderr,
35                                 _("%s: nscd did not terminate normally (signal %d)\n"),
36                                 Prog, WTERMSIG (status));
37                 return -1;
38         } else if (code == E_CMD_NOTFOUND) {
39                 /* nscd is not installed, or it is installed but uses an
40                    interpreter that is missing.  Probably the former. */
41                 return 0;
42         } else if (code != 0) {
43                 (void) fprintf (stderr, _("%s: nscd exited with status %d"),
44                                 Prog, code);
45                 (void) fprintf (stderr, _(MSG_NSCD_FLUSH_CACHE_FAILED), Prog);
46                 return -1;
47         }
48
49         return 0;
50 }
51 #else                           /* USE_NSCD */
52 extern int errno;               /* warning: ANSI C forbids an empty source file */
53 #endif                          /* USE_NSCD */
54