Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Aug 2013 17:47:11 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r254604 - head/tools/test/posixshm
Message-ID:  <201308211747.r7LHlBeq086304@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Wed Aug 21 17:47:11 2013
New Revision: 254604
URL: http://svnweb.freebsd.org/changeset/base/254604

Log:
  Add simple test for the read/write/lseek on posix shm filedescriptor.
  
  Tested by:	pho
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/tools/test/posixshm/shm_test.c

Modified: head/tools/test/posixshm/shm_test.c
==============================================================================
--- head/tools/test/posixshm/shm_test.c	Wed Aug 21 17:45:00 2013	(r254603)
+++ head/tools/test/posixshm/shm_test.c	Wed Aug 21 17:47:11 2013	(r254604)
@@ -21,7 +21,7 @@
  * Signal handler which does nothing.
  */
 static void 
-ignoreit(int sig)
+ignoreit(int sig __unused)
 {
 	;
 }
@@ -29,13 +29,13 @@ ignoreit(int sig)
 int
 main(int argc, char **argv)
 {
-	char buf[1024], *cp;
-	int desc, rv;
+	char buf[1024], *cp, c;
+	int error, desc, rv;
 	long scval;
 	sigset_t ss;
 	struct sigaction sa;
 	void *region;
-	size_t psize;
+	size_t i, psize;
 
 #ifndef _POSIX_SHARED_MEMORY_OBJECTS
 	printf("_POSIX_SHARED_MEMORY_OBJECTS is undefined\n");
@@ -118,14 +118,29 @@ main(int argc, char **argv)
 		sigemptyset(&ss);
 		sigsuspend(&ss);
 
-		for (cp = region; cp < (char *)region + psize; cp++)
+		for (cp = region; cp < (char *)region + psize; cp++) {
 			if (*cp != '\151')
 				_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);
 	} else {
 		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);
 		waitpid(rv, &status, 0);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308211747.r7LHlBeq086304>