Add simple test for the read/write/lseek on posix shm filedescriptor.
Tested by: pho Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
940cb0e2bb
commit
7291e2a320
@ -21,7 +21,7 @@
|
|||||||
* Signal handler which does nothing.
|
* Signal handler which does nothing.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
ignoreit(int sig)
|
ignoreit(int sig __unused)
|
||||||
{
|
{
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -29,13 +29,13 @@ ignoreit(int sig)
|
|||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char buf[1024], *cp;
|
char buf[1024], *cp, c;
|
||||||
int desc, rv;
|
int error, desc, rv;
|
||||||
long scval;
|
long scval;
|
||||||
sigset_t ss;
|
sigset_t ss;
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
void *region;
|
void *region;
|
||||||
size_t psize;
|
size_t i, psize;
|
||||||
|
|
||||||
#ifndef _POSIX_SHARED_MEMORY_OBJECTS
|
#ifndef _POSIX_SHARED_MEMORY_OBJECTS
|
||||||
printf("_POSIX_SHARED_MEMORY_OBJECTS is undefined\n");
|
printf("_POSIX_SHARED_MEMORY_OBJECTS is undefined\n");
|
||||||
@ -118,14 +118,29 @@ main(int argc, char **argv)
|
|||||||
sigemptyset(&ss);
|
sigemptyset(&ss);
|
||||||
sigsuspend(&ss);
|
sigsuspend(&ss);
|
||||||
|
|
||||||
for (cp = region; cp < (char *)region + psize; cp++)
|
for (cp = region; cp < (char *)region + psize; cp++) {
|
||||||
if (*cp != '\151')
|
if (*cp != '\151')
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
}
|
||||||
|
if (lseek(desc, 0, SEEK_SET) == -1)
|
||||||
|
_exit(1);
|
||||||
|
for (i = 0; i < psize; i++) {
|
||||||
|
error = read(desc, &c, 1);
|
||||||
|
if (c != '\151')
|
||||||
|
_exit(1);
|
||||||
|
}
|
||||||
_exit(0);
|
_exit(0);
|
||||||
} else {
|
} else {
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
memset(region, '\151', psize);
|
memset(region, '\151', psize - 2);
|
||||||
|
error = pwrite(desc, region, 2, psize - 2);
|
||||||
|
if (error != 2) {
|
||||||
|
if (error >= 0)
|
||||||
|
errx(1, "short write %d", error);
|
||||||
|
else
|
||||||
|
err(1, "shmfd write");
|
||||||
|
}
|
||||||
kill(rv, SIGUSR1);
|
kill(rv, SIGUSR1);
|
||||||
waitpid(rv, &status, 0);
|
waitpid(rv, &status, 0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user