2007-11-17 19:34:05 +05:30
|
|
|
/* Author: Peter Vrabec <pvrabec@redhat.com> */
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2008-08-31 00:00:36 +05:30
|
|
|
#include <config.h>
|
|
|
|
#ifdef USE_NSCD
|
|
|
|
|
2007-11-17 19:34:05 +05:30
|
|
|
/* because of TEMP_FAILURE_RETRY */
|
2008-08-31 22:57:26 +05:30
|
|
|
#ifndef _GNU_SOURCE
|
2007-11-17 19:34:05 +05:30
|
|
|
#define _GNU_SOURCE
|
2008-08-31 22:57:26 +05:30
|
|
|
#endif
|
2007-11-17 19:34:05 +05:30
|
|
|
|
|
|
|
#include <features.h>
|
2007-10-07 17:15:23 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2007-11-17 19:34:05 +05:30
|
|
|
#include <spawn.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/types.h>
|
2011-08-20 19:03:38 +05:30
|
|
|
#include "exitcodes.h"
|
2008-06-11 01:31:55 +05:30
|
|
|
#include "defines.h"
|
2011-08-20 19:03:38 +05:30
|
|
|
#include "spawn.h"
|
2008-01-06 19:27:17 +05:30
|
|
|
#include "nscd.h"
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2008-06-11 01:31:55 +05:30
|
|
|
#define MSG_NSCD_FLUSH_CACHE_FAILED "Failed to flush the nscd cache.\n"
|
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
/*
|
2007-11-17 19:34:05 +05:30
|
|
|
* nscd_flush_cache - flush specified service buffer in nscd cache
|
2007-10-07 17:15:23 +05:30
|
|
|
*/
|
2008-01-06 19:27:17 +05:30
|
|
|
int nscd_flush_cache (const char *service)
|
2007-10-07 17:15:23 +05:30
|
|
|
{
|
2011-08-20 19:03:38 +05:30
|
|
|
pid_t pid;
|
|
|
|
int err, status, code;
|
|
|
|
const char *spawnedArgs[] = {"/usr/sbin/nscd", "nscd", "-i", service, NULL};
|
|
|
|
const char *spawnedEnv[] = {NULL};
|
2007-11-17 19:34:05 +05:30
|
|
|
|
2011-08-20 19:03:38 +05:30
|
|
|
err = run_command (spawnedArgs[0], spawnedArgs, spawnedEnv, &status);
|
|
|
|
if (0 != err)
|
2007-11-17 19:34:05 +05:30
|
|
|
{
|
2011-08-20 19:03:38 +05:30
|
|
|
/* run_command writes its own more detailed message. */
|
2008-06-11 01:31:55 +05:30
|
|
|
(void) fputs (_(MSG_NSCD_FLUSH_CACHE_FAILED), stderr);
|
2007-10-07 17:15:23 +05:30
|
|
|
return -1;
|
2007-11-17 19:34:05 +05:30
|
|
|
}
|
2011-08-20 19:03:38 +05:30
|
|
|
code = WIFEXITED (status) ? WEXITSTATUS (status)
|
|
|
|
: (WTERMSIG (status) + 128);
|
|
|
|
if (code == E_CMD_NOTFOUND)
|
2007-11-17 19:34:05 +05:30
|
|
|
{
|
2011-08-20 19:03:38 +05:30
|
|
|
/* nscd is not installed, or it is installed but uses an
|
|
|
|
interpreter that is missing. Probably the former. */
|
|
|
|
return 0;
|
2007-11-17 19:34:05 +05:30
|
|
|
}
|
2011-08-20 19:03:38 +05:30
|
|
|
if (code != 0)
|
2007-11-17 19:34:05 +05:30
|
|
|
{
|
2011-08-20 19:03:38 +05:30
|
|
|
(void) fprintf (stderr, "nscd exited with status %d", code);
|
2008-06-11 01:31:55 +05:30
|
|
|
(void) fputs (_(MSG_NSCD_FLUSH_CACHE_FAILED), stderr);
|
2007-11-17 19:34:05 +05:30
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2007-10-07 17:15:23 +05:30
|
|
|
}
|
2008-08-31 00:03:13 +05:30
|
|
|
#else /* USE_NSCD */
|
|
|
|
extern int errno; /* warning: ANSI C forbids an empty source file */
|
|
|
|
#endif /* USE_NSCD */
|
2007-11-17 19:34:05 +05:30
|
|
|
|