summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-02-21 16:34:32 +0100
committerJeremy Allison <jra@samba.org>2014-05-22 21:05:15 +0200
commit1cb1b13cc954f2e40796a8db96f7ab9bf4fffc79 (patch)
tree2de0c71c013dca1f774544d2b30b3df3c7f29f66
parent417489a214757055ab95c98180c5ce960bdbe632 (diff)
downloadsamba-1cb1b13cc954f2e40796a8db96f7ab9bf4fffc79.tar.gz
tdb/test: add shutdown_agent() helper function
Signed-off-by: Volker Lendecke <vl@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--lib/tdb/test/external-agent.c26
-rw-r--r--lib/tdb/test/external-agent.h1
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/tdb/test/external-agent.c b/lib/tdb/test/external-agent.c
index 8710b478320..0aca081fc69 100644
--- a/lib/tdb/test/external-agent.c
+++ b/lib/tdb/test/external-agent.c
@@ -99,29 +99,29 @@ static enum agent_return do_operation(enum operation op, const char *name)
struct agent {
int cmdfd, responsefd;
+ pid_t pid;
};
/* Do this before doing any tdb stuff. Return handle, or NULL. */
struct agent *prepare_external_agent(void)
{
- int pid, ret;
+ int ret;
int command[2], response[2];
char name[1+PATH_MAX];
+ struct agent *agent = malloc(sizeof(*agent));
if (pipe(command) != 0 || pipe(response) != 0) {
fprintf(stderr, "pipe failed: %s\n", strerror(errno));
exit(1);
}
- pid = fork();
- if (pid < 0) {
+ agent->pid = fork();
+ if (agent->pid < 0) {
fprintf(stderr, "fork failed: %s\n", strerror(errno));
exit(1);
}
- if (pid != 0) {
- struct agent *agent = malloc(sizeof(*agent));
-
+ if (agent->pid != 0) {
close(command[0]);
close(response[1]);
agent->cmdfd = command[1];
@@ -146,6 +146,20 @@ struct agent *prepare_external_agent(void)
exit(0);
}
+void shutdown_agent(struct agent *agent)
+{
+ pid_t p;
+
+ close(agent->cmdfd);
+ close(agent->responsefd);
+ p = waitpid(agent->pid, NULL, WNOHANG);
+ if (p == 0) {
+ kill(agent->pid, SIGKILL);
+ }
+ waitpid(agent->pid, NULL, 0);
+ free(agent);
+}
+
/* Ask the external agent to try to do an operation. */
enum agent_return external_agent_operation(struct agent *agent,
enum operation op,
diff --git a/lib/tdb/test/external-agent.h b/lib/tdb/test/external-agent.h
index dffdca962f6..354f5b9352b 100644
--- a/lib/tdb/test/external-agent.h
+++ b/lib/tdb/test/external-agent.h
@@ -17,6 +17,7 @@ enum operation {
/* Do this before doing any tdb stuff. Return handle, or -1. */
struct agent *prepare_external_agent(void);
+void shutdown_agent(struct agent *agent);
enum agent_return {
SUCCESS,