2007-11-17 19:34:05 +05:30
|
|
|
/* Author: Peter Vrabec <pvrabec@redhat.com> */
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-11-17 19:34:05 +05:30
|
|
|
/* because of TEMP_FAILURE_RETRY */
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
|
|
|
#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>
|
2008-01-06 19:27:17 +05:30
|
|
|
#include "nscd.h"
|
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
|
|
|
{
|
2007-11-17 19:34:05 +05:30
|
|
|
pid_t pid, termpid;
|
|
|
|
int err, status;
|
|
|
|
char *spawnedArgs[] = {"/usr/sbin/nscd", "nscd", "-i", service, NULL};
|
|
|
|
char *spawnedEnv[] = {NULL};
|
|
|
|
|
|
|
|
/* spawn process */
|
|
|
|
if( (err=posix_spawn(&pid, spawnedArgs[0], NULL, NULL,
|
|
|
|
spawnedArgs, spawnedEnv)) !=0 )
|
|
|
|
{
|
|
|
|
fprintf(stderr, "posix_spawn() error=%d\n", err);
|
2007-10-07 17:15:23 +05:30
|
|
|
return -1;
|
2007-11-17 19:34:05 +05:30
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-11-17 19:34:05 +05:30
|
|
|
/* Wait for the spawned process to exit */
|
|
|
|
termpid = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
|
|
|
|
if (termpid == -1)
|
|
|
|
{
|
|
|
|
perror("waitpid");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else if (termpid != pid)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "waitpid returned %ld != %ld\n",
|
|
|
|
(long int) termpid, (long int) pid);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-10-07 17:15:23 +05:30
|
|
|
|
2007-11-17 19:34:05 +05:30
|
|
|
return 0;
|
2007-10-07 17:15:23 +05:30
|
|
|
}
|
2007-11-17 19:34:05 +05:30
|
|
|
|