Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
450a9a4c
Commit
450a9a4c
authored
Aug 18, 2009
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't rely on terrible dup2 trick, use proper infrastructure for external agent.
parent
91ddc0b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
16 deletions
+21
-16
ccan/tdb/test/external-transaction.c
ccan/tdb/test/external-transaction.c
+15
-10
ccan/tdb/test/external-transaction.h
ccan/tdb/test/external-transaction.h
+2
-2
ccan/tdb/test/run-nested-traverse.c
ccan/tdb/test/run-nested-traverse.c
+2
-2
ccan/tdb/test/run-traverse-in-transaction.c
ccan/tdb/test/run-traverse-in-transaction.c
+2
-2
No files found.
ccan/tdb/test/external-transaction.c
View file @
450a9a4c
...
...
@@ -51,9 +51,12 @@ maybe_alarmed:
return
-
3
;
}
struct
agent
{
int
cmdfd
,
responsefd
;
};
/* Do this before doing any tdb stuff. Return handle, or
-1
. */
int
prepare_external_agent
(
void
)
/* Do this before doing any tdb stuff. Return handle, or
NULL
. */
struct
agent
*
prepare_external_agent
(
void
)
{
int
pid
;
int
command
[
2
],
response
[
2
];
...
...
@@ -61,18 +64,20 @@ int prepare_external_agent(void)
char
name
[
PATH_MAX
];
if
(
pipe
(
command
)
!=
0
||
pipe
(
response
)
!=
0
)
return
-
1
;
return
NULL
;
pid
=
fork
();
if
(
pid
<
0
)
return
-
1
;
return
NULL
;
if
(
pid
!=
0
)
{
struct
agent
*
agent
=
malloc
(
sizeof
(
*
agent
));
close
(
command
[
0
]);
close
(
response
[
1
]);
/* FIXME: Make fds consective. */
dup2
(
command
[
1
]
+
1
,
response
[
1
])
;
return
command
[
1
]
;
agent
->
cmdfd
=
command
[
1
];
agent
->
responsefd
=
response
[
0
]
;
return
agent
;
}
close
(
command
[
1
]);
...
...
@@ -89,15 +94,15 @@ int prepare_external_agent(void)
}
/* Ask the external agent to try to do a transaction. */
bool
external_agent_transaction
(
int
handle
,
const
char
*
tdbname
)
bool
external_agent_transaction
(
struct
agent
*
agent
,
const
char
*
tdbname
)
{
int
res
;
if
(
write
(
handle
,
tdbname
,
strlen
(
tdbname
)
+
1
)
if
(
write
(
agent
->
cmdfd
,
tdbname
,
strlen
(
tdbname
)
+
1
)
!=
strlen
(
tdbname
)
+
1
)
err
(
1
,
"Writing to agent"
);
if
(
read
(
handle
+
1
,
&
res
,
sizeof
(
res
))
!=
sizeof
(
res
))
if
(
read
(
agent
->
responsefd
,
&
res
,
sizeof
(
res
))
!=
sizeof
(
res
))
err
(
1
,
"Reading from agent"
);
if
(
res
>
1
)
...
...
ccan/tdb/test/external-transaction.h
View file @
450a9a4c
...
...
@@ -3,9 +3,9 @@
#include <stdbool.h>
/* Do this before doing any tdb stuff. Return handle, or -1. */
int
prepare_external_agent
(
void
);
struct
agent
*
prepare_external_agent
(
void
);
/* Ask the external agent to try to do a transaction. */
bool
external_agent_transaction
(
int
handle
,
const
char
*
tdbname
);
bool
external_agent_transaction
(
struct
agent
*
handle
,
const
char
*
tdbname
);
#endif
/* TDB_TEST_EXTERNAL_TRANSACTION_H */
ccan/tdb/test/run-nested-traverse.c
View file @
450a9a4c
...
...
@@ -14,7 +14,7 @@
#include <err.h>
#include "external-transaction.h"
static
int
agent
;
static
struct
agent
*
agent
;
static
bool
correct_key
(
TDB_DATA
key
)
{
...
...
@@ -56,7 +56,7 @@ int main(int argc, char *argv[])
plan_tests
(
15
);
agent
=
prepare_external_agent
();
if
(
agent
<
0
)
if
(
!
agent
)
err
(
1
,
"preparing agent"
);
tdb
=
tdb_open
(
"/tmp/test3.tdb"
,
1024
,
TDB_CLEAR_IF_FIRST
,
...
...
ccan/tdb/test/run-traverse-in-transaction.c
View file @
450a9a4c
...
...
@@ -14,7 +14,7 @@
#include <err.h>
#include "external-transaction.h"
static
int
agent
;
static
struct
agent
*
agent
;
static
bool
correct_key
(
TDB_DATA
key
)
{
...
...
@@ -43,7 +43,7 @@ int main(int argc, char *argv[])
plan_tests
(
13
);
agent
=
prepare_external_agent
();
if
(
agent
<
0
)
if
(
!
agent
)
err
(
1
,
"preparing agent"
);
tdb
=
tdb_open
(
"/tmp/test2.tdb"
,
1024
,
TDB_CLEAR_IF_FIRST
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment