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
57d7208e
Commit
57d7208e
authored
Oct 20, 2010
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
read_write_all: don't rely on write to pipe blocking in tests.
Instead, directly control write().
parent
5a02610c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
44 deletions
+42
-44
ccan/read_write_all/test/run-write_all.c
ccan/read_write_all/test/run-write_all.c
+42
-44
No files found.
ccan/read_write_all/test/run-write_all.c
View file @
57d7208e
/* FIXME: Do something tricky to ensure we really do loop in write_all. */
#include <ccan/read_write_all/read_write_all.h>
#include <ccan/read_write_all/read_write_all.c>
#include <ccan/tap/tap.h>
#include <unistd.h>
#include <sys/types.h>
...
...
@@ -13,57 +10,58 @@
#include <string.h>
#include <stdio.h>
static
volatile
int
sigcount
;
static
void
got_signal
(
int
sig
)
static
ssize_t
test_write
(
int
fd
,
const
void
*
buf
,
size_t
count
);
#define write test_write
#include <ccan/read_write_all/read_write_all.c>
#undef write
static
ssize_t
write_return
;
static
ssize_t
test_write
(
int
fd
,
const
void
*
buf
,
size_t
count
)
{
sigcount
++
;
if
(
write_return
==
0
)
{
errno
=
ENOSPC
;
return
0
;
}
if
(
write_return
<
0
)
{
errno
=
-
write_return
;
/* Don't return EINTR more than once! */
if
(
errno
==
EINTR
)
write_return
=
count
;
return
-
1
;
}
if
(
write_return
<
count
)
return
write_return
;
return
count
;
}
/* < PIPE_BUF *will* be atomic. But > PIPE_BUF only *might* be non-atomic. */
#define BUFSZ (1024*1024)
#define BUFSZ 1024
int
main
(
int
argc
,
char
*
argv
[])
{
char
*
buffer
;
int
p2c
[
2
];
int
status
;
pid_t
child
;
buffer
=
calloc
(
BUFSZ
,
1
);
plan_tests
(
4
);
buffer
=
malloc
(
BUFSZ
);
plan_tests
(
8
);
/* We fork and torture parent. */
if
(
pipe
(
p2c
)
!=
0
)
err
(
1
,
"pipe"
);
child
=
fork
();
write_return
=
-
ENOSPC
;
ok1
(
!
write_all
(
100
,
buffer
,
BUFSZ
));
ok1
(
errno
==
ENOSPC
);
if
(
!
child
)
{
close
(
p2c
[
1
]);
/* Make sure they started writing. */
if
(
read
(
p2c
[
0
],
buffer
,
1
)
!=
1
)
exit
(
1
);
if
(
kill
(
getppid
(),
SIGUSR1
)
!=
0
)
exit
(
2
);
if
(
!
read_all
(
p2c
[
0
],
buffer
+
1
,
BUFSZ
-
1
))
exit
(
3
);
if
(
memchr
(
buffer
,
0
,
BUFSZ
))
{
fprintf
(
stderr
,
"buffer has 0 at offset %ti
\n
"
,
memchr
(
buffer
,
0
,
BUFSZ
)
-
(
void
*
)
buffer
);
exit
(
4
);
}
exit
(
0
);
}
if
(
child
==
-
1
)
err
(
1
,
"forking"
);
write_return
=
-
EINTR
;
ok1
(
write_all
(
100
,
buffer
,
BUFSZ
));
ok1
(
errno
==
EINTR
);
write_return
=
1
;
errno
=
0
;
ok1
(
write_all
(
100
,
buffer
,
BUFSZ
));
ok1
(
errno
==
0
);
write_return
=
BUFSZ
;
ok1
(
write_all
(
100
,
buffer
,
BUFSZ
));
ok1
(
errno
==
0
);
close
(
p2c
[
0
]);
memset
(
buffer
,
0xff
,
BUFSZ
);
signal
(
SIGUSR1
,
got_signal
);
ok1
(
write_all
(
p2c
[
1
],
buffer
,
BUFSZ
));
ok1
(
sigcount
==
1
);
ok1
(
wait
(
&
status
)
==
child
);
ok
(
WIFEXITED
(
status
)
&&
WEXITSTATUS
(
status
)
==
0
,
"WIFEXITED(status) = %u, WEXITSTATUS(status) = %u"
,
WIFEXITED
(
status
),
WEXITSTATUS
(
status
));
return
exit_status
();
}
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