Example #1
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void
cleanup(void)
{
	/* if they exist, remove the shared memory resources */
	rm_shm(shm_id_1);
	rm_shm(shm_id_2);

	if (seteuid(0) == -1) {
		tst_resm(TINFO, "setuid failed to "
				"to set the effective uid to %d",
				ltpuser->pw_uid);
		perror("seteuid");
	}

	/* Remove the temporary directory */
	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

	/* exit with return code appropriate for results */
	tst_exit();
}
Example #2
0
File: shmctl02.c Project: 1587/ltp
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if they exist, remove the shared memory resources */
	rm_shm(shm_id_1);
	rm_shm(shm_id_2);

	tst_rmdir();

}
Example #3
0
void cleanup(void)
{
	rm_shm(shm_id_1);
	rm_shm(shm_id_2);

	set_sys_tune("nr_hugepages", orig_hugepages, 0);

	tst_rmdir();
}
Example #4
0
File: shmt05.c Project: heluxie/LTP
int main(void)
{
	int shmid, shmid1;
	char *cp, *cp1;

	srand48((getpid() << 16) + (unsigned)time(NULL));

	key[0] = (key_t) lrand48();
	key[1] = (key_t) lrand48();

	cp = NULL;
	cp1 = NULL;

/*--------------------------------------------------------*/

	if ((shmid = shmget(key[0], SIZE, IPC_CREAT | 0666)) < 0) {
		perror("shmget");
		tst_resm(TFAIL,
			 "Error: shmget: shmid = %d, errno = %d\n",
			 shmid, errno);
	} else {
		cp = shmat(shmid, NULL, 0);

		if (cp == (char *)-1) {
			tst_resm(TFAIL, "shmat");
			rm_shm(shmid);
		}
	}

	tst_resm(TPASS, "shmget & shmat");

/*--------------------------------------------------------*/

	if ((shmid1 = shmget(key[1], SIZE, IPC_CREAT | 0666)) < 0) {
		perror("shmget2");
		tst_resm(TFAIL,
			 "Error: shmget: shmid1 = %d, errno = %d\n",
			 shmid1, errno);
	} else {
		cp1 = shmat(shmid1, cp + (SIZE / 2), 0);
		if (cp1 != (char *)-1) {
			perror("shmat");
			tst_resm(TFAIL,
				 "Error: shmat: shmid1 = %d, addr= %p, errno = %d\n",
				 shmid1, cp1, errno);
		} else {
			tst_resm(TPASS, "2nd shmget & shmat");
		}
	}

/*------------------------------------------------------*/

	rm_shm(shmid);
	rm_shm(shmid1);

	tst_exit();
}
Example #5
0
int main()
{
	register int shmid;
	char *cp;
	key_t key;

	errno = 0;
	key = (key_t) getpid();

/*----------------------------------------------------------------*/

	if ((shmid = shmget(key, 16 * K_1, IPC_CREAT | 0666)) < 0) {
		perror("shmget");
		tst_resm(TFAIL, "shmget Failed: shmid = %d, errno = %d\n",
			 shmid, errno);
		tst_exit();
	}

	tst_resm(TPASS, "shmget");

/*----------------------------------------------------------------*/

	cp = (char *)shmat(shmid, (void *)NULL, 0);

	if (cp == (char *)-1) {
		perror("shmat");
		tst_resm(TFAIL, "shmat Failed: shmid = %d, errno = %d\n",
			 shmid, errno);
		rm_shm(shmid);
		tst_exit();
	}

	*cp = '1';
	*(cp + 1) = '2';

	tst_resm(TPASS, "shmat");

/*----------------------------------------------------------------*/

	rm_shm(shmid);

	if (*cp != '1' || *(cp + 1) != '2') {
		tst_resm(TFAIL,
			 "Error in shared memory contents: shmid = %d\n",
			 shmid);
	}

	tst_resm(TPASS, "Correct shared memory contents");

/*------------------------------------------------------------------*/

	tst_exit();

/*-------------------- THIS LINE IS NOT REACHED -------------------*/
	return (0);
}
Example #6
0
int main(void)
{
	char	*cp=NULL, *cp1=NULL;
	int	shmid;

	key = (key_t) getpid() ;
	errno = 0 ;
/*-------------------------------------------------------*/


	if ((shmid = shmget(key, 24*K_1, IPC_CREAT|0666)) < 0) {
		perror("shmget");
		tst_resm(TFAIL,"Error: shmget: shmid = %d, errno = %d\n",
		shmid, errno) ;
		tst_exit() ;
	}

	cp = (char *) shmat(shmid, (void *)0, 0);
	if (cp == (char *)-1) {
		tst_resm(TFAIL,"shmat1 Failed");
		rm_shm(shmid) ;
		tst_exit() ;
	}

	cp1 = (char *) shmat(shmid, (void *)0, 0);
	if (cp1 == (char *)-1) {
		perror("shmat2");
		rm_shm(shmid) ;
		tst_exit() ;
	}

	tst_resm(TPASS,"shmget,shmat");

/*--------------------------------------------------------*/


	if (shmdt(cp) < 0) {
		perror("shmdt2");
		tst_resm(TFAIL,"shmdt:cp") ;
	}

	if (shmdt(cp1) < 0 ) {
		perror("shmdt1");
		tst_resm(TFAIL,"shmdt:cp1") ;
	}

	tst_resm(TPASS,"shmdt");

/*---------------------------------------------------------*/
	rm_shm(shmid) ;
	tst_exit() ;

/*---------------------------------------------------------*/
	return(0);
}
Example #7
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if they exist, remove the shared memory resources */
	rm_shm(shm_id_2);
	rm_shm(shm_id_3);

	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

}
Example #8
0
File: shmctl03.c Project: kraj/ltp
int main(int ac, char **av)
{
	int pid;
	void do_child(void);

	tst_parse_opts(ac, av, NULL, NULL);

	setup();		/* global setup */

	if ((pid = FORK_OR_VFORK()) == -1) {
		tst_brkm(TBROK, cleanup, "could not fork");
	}

	if (pid == 0) {		/* child */
		/* set  the user ID of the child to the non root user */
		if (setuid(ltp_uid) == -1) {
			tst_resm(TBROK, "setuid() failed");
			exit(1);
		}

		do_child();
	} else {
		/* wait for the child to return */
		SAFE_WAITPID(cleanup, pid, NULL, 0);

		/* if it exists, remove the shared memory resource */
		rm_shm(shm_id_1);

		tst_rmdir();
	}

	cleanup();
	tst_exit();
}
Example #9
0
File: shmget04.c Project: 1587/ltp
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if it exists, remove the shared memory resource */
	rm_shm(shm_id_1);

	tst_rmdir();

}
Example #10
0
void cleanup(void)
{
	TEST_CLEANUP;

	rm_shm(shmid1);

	tst_rmdir();
}
Example #11
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if they exist, remove the shared memory resources */
	rm_shm(shm_id_2);
	rm_shm(shm_id_3);

	/* Remove the temporary directory */
	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

	/* exit with return code appropriate for results */
	tst_exit();
}
Example #12
0
static void cleanup(void)
{
	int i;

	for (i = 0; i < num_shms; i++)
		rm_shm(shm_id_arr[i]);

	FILE_PRINTF(PATH_SHMMNI, "%ld", orig_shmmni);
	restore_nr_hugepages();
}
Example #13
0
int main(int argc, char const *argv[])
{
	int i;
	int shm_id;
	pid_t pid;
	char *map_buf1;
	char *map_buf2;

	shm_id = get_shm();                      // 创建一个共享内存段,并返回一个id标识符
	pid = fork();

	if(pid < 0)
	{
		perror("Create New Process Error");
		exit(EXIT_FAILURE);
	}else
	if(pid == 0)
	{
		/*在子进程中*/
		map_buf1 = at_shm(shm_id);          // 将共享内存段连接到子进程中,并使map_buf1指向共享内存段
		i = 0;
		while(i < _SHM_SIZE_)
		{
			map_buf1[i] = '8';
			i++;
		}

		map_buf1[_SHM_SIZE_-1] = '\0';
		rm_shm(map_buf1);                  // 分离子进程与共享内存
	}else
	{
		/*在父进程中*/
		map_buf2 = at_shm(shm_id);         // 将共享内存连接到父进程中,并使map_buf2指向共享内存段
		sleep(5);
		printf("In Parent, read Share Memory: %s\n", map_buf2);
		rm_shm(map_buf2);                  // 分离父进程与共享内存

		waitpid(pid, NULL, 0);             // 等待子进程结束
		delete_shm(shm_id);                // 删除共享内存
	}

	return 0;
}
Example #14
0
void buf_dtor(struct buf_s *buf)
{
	if (!buf)
		return;
	if (buf->mapW) {
		detach_shm(buf);
		rm_shm(buf);
	} else
		detach_mal(buf);
}
Example #15
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if it exists, remove the shared memory segment */
	rm_shm(shm_id_1);

	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

}
Example #16
0
void cleanup(void)
{
	int i;
	char buf[BUFSIZ];

	TEST_CLEANUP;

	for (i = 0; i < num_shms; i++)
		rm_shm(shm_id_arr[i]);

	snprintf(buf, BUFSIZ, "%ld", orig_shmmni);
	write_file(PATH_SHMMNI, buf);
	set_sys_tune("nr_hugepages", orig_hugepages, 0);

	tst_rmdir();
}
Example #17
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{

	/* if it exists, remove the shared memory resource */
	rm_shm(shm_id_1);

	if (TC != NULL)
		free(TC);

	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

}
Example #18
0
int main(int ac, char **av)
{
	char *msg;			/* message returned from parse_opts */
	int pid;
	void do_child(void);

	/* parse standard options */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);

        if (get_no_of_hugepages() <= 0 || hugepages_size() <= 0)
             tst_brkm(TCONF, cleanup, "Not enough available Hugepages");
        else
             huge_pages_shm_to_be_allocated = ( get_no_of_hugepages() * hugepages_size() * 1024) / 2 ;

	setup();			/* global setup */

	if ((pid = fork()) == -1) {
		tst_brkm(TBROK, cleanup, "could not fork");
	}

	if (pid == 0) {		/* child */
		/* set  the user ID of the child to the non root user */
		if (setuid(ltp_uid) == -1) {
			tst_resm(TBROK, "setuid() failed");
			exit(1);
		}

		do_child();
	} else {
		/* wait for the child to return */
		if (waitpid(pid, NULL, 0) == -1) {
			tst_brkm(TBROK, cleanup, "waitpid failed");
		}

		/* if it exists, remove the shared memory resource */
		rm_shm(shm_id_1);

		tst_rmdir();
	}

	cleanup ();
	tst_exit();
}
Example #19
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void
cleanup(void)
{
	int i;

	/* remove the shared memory resources that were created */
	for (i=0; i<num_shms; i++) {
		rm_shm(shm_id_arr[i]);
	}

	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

}
Example #20
0
int main(int ac, char **av)
{
	char *msg;			/* message returned from parse_opts */
	int pid;
	void do_child(void);

	/* parse standard options */
	if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){
		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
	}

	setup();			/* global setup */

	if ((pid = FORK_OR_VFORK()) == -1) {
		tst_brkm(TBROK, cleanup, "could not fork");
	}

	if (pid == 0) {		/* child */
		/* set the user ID of the child to the non root user */
		if (setuid(ltp_uid) == -1) {
			tst_resm(TBROK, "setuid() failed");
			exit(1);
		}

		do_child();

	} else {		/* parent */
		/* wait for the child to return */
		if (waitpid(pid, NULL, 0) == -1) {
			tst_brkm(TBROK, cleanup, "waitpid failed");
		}

		/* if it exists, remove the shared memory resource */
		rm_shm(shm_id_1);

		/* Remove the temporary directory */
		tst_rmdir();
	}

	cleanup();
	return(0);
}
Example #21
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void
cleanup(void)
{
	int i;

	/* remove the shared memory resources that were created */
	for(i=0; i<num_shms; i++) {
		rm_shm(shm_id_arr[i]);
	}

	/* Remove the temporary directory */
	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

	/* exit with return code appropriate for results */
	tst_exit();
}
Example #22
0
int main(int ac, char **av)
{
	const char *msg;
	int pid;
	void do_child(void);

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();		/* global setup */

	if ((pid = FORK_OR_VFORK()) == -1) {
		tst_brkm(TBROK, cleanup, "could not fork");
	}

	if (pid == 0) {		/* child */
		/* set the user ID of the child to the non root user */
		if (setuid(ltp_uid) == -1) {
			tst_resm(TBROK, "setuid() failed");
			exit(1);
		}

		do_child();

		cleanup();

	} else {		/* parent */
		/* wait for the child to return */
		if (waitpid(pid, NULL, 0) == -1) {
			tst_brkm(TBROK, cleanup, "waitpid failed");
		}

		/* if it exists, remove the shared memory resource */
		rm_shm(shm_id_1);

		tst_rmdir();
	}
	tst_exit();
}
Example #23
0
int main(void)
{
		 register int		 shmid;
		 char		 		 *cp;
		 key_t		 		 key;

		 errno = 0;
		 key = (key_t)getpid() ;

/*----------------------------------------------------------------*/


		 if ((shmid = shmget(key, 16*K_1, IPC_CREAT|0666)) < 0 ) {
		 		 perror("shmget");
		 		 tst_resm(TFAIL, "shmget Failed: shmid = %d, errno = %d\n",
		 		 shmid, errno) ;
		 		 tst_exit() ;
		 }

		 tst_resm(TPASS, "shmget") ;

/*----------------------------------------------------------------*/


		 /* are we doing with ia64 or arm_arch_4t arch */
#if defined (__ia64__) || defined (__ARM_ARCH_4T__)
		 cp = (char *) shmat(shmid, (void *)NULL, 0);
#else		
 		 cp = (char *) shmat(shmid, (void *)0x80000, 0);
#endif
		 if (cp == (char *)-1) {
		 		 perror("shmat");
		 		 tst_resm(TFAIL, "shmat Failed: shmid = %d, errno = %d\n",
		 		 shmid, errno) ;
		 		 rm_shm(shmid) ;
		 		 tst_exit() ;		 
		 }

		 *cp     = '1';
		 *(cp+1) = '2';

		 tst_resm(TPASS, "shmat") ;

/*----------------------------------------------------------------*/


		 rm_shm(shmid) ;

		 if ( *cp != '1' || *(cp+1) != '2' ) {
		 		 tst_resm(TFAIL, 
		 		 "Error in shared memory contents: shmid = %d\n",
		 		 shmid);
		 }
		 
		 tst_resm(TPASS, "Correct shared memory contents") ;

/*------------------------------------------------------------------*/

		 tst_exit() ; 

/*-------------------- THIS LINE IS NOT REACHED -------------------*/
		 return(0);
}
Example #24
0
int main(void)
{
 int		 shmid, shmid1;
 char		 *cp, *cp1;

 srand48((getpid() << 16) + (unsigned)time((time_t *)NULL));

 key[0] = (key_t) lrand48();
 key[1] = (key_t) lrand48();

/*--------------------------------------------------------*/


 if ((shmid = shmget(key[0], SIZE, IPC_CREAT|0666)) < 0) {
  perror("shmget");
  tst_resm(TFAIL,
  "Error: shmget: shmid = %d, errno = %d\n",
  shmid, errno) ;
 } else {
#ifdef __ia64__ 
  cp = (char *) shmat(shmid, ADDR_IA, 0);
#elif defined(__ARM_ARCH_4T__)
  cp = (char *) shmat(shmid, (void *)NULL, 0);
#else
  cp = (char *) shmat(shmid, ADDR, 0);
#endif
  if (cp == (char *)-1) {
   tst_resm(TFAIL,"shmat");
   rm_shm(shmid) ;
  }
 }

 tst_resm(TPASS,"shmget & shmat");		 

/*--------------------------------------------------------*/


 if ((shmid1 = shmget(key[1], SIZE, IPC_CREAT|0666)) < 0) {
  perror("shmget2");
  tst_resm(TFAIL,
  "Error: shmget: shmid1 = %d, errno = %d\n",
  shmid1, errno) ;
 } else {
#ifdef __ia64__
   cp1 = (char *) shmat(shmid1, ADDR1_IA, 0);
#elif defined(__ARM_ARCH_4T__)
   cp1 = (char *) shmat(shmid1, (void *)NULL, 0);
#else
   cp1 = (char *) shmat(shmid1, ADDR1, 0);
#endif
  if (cp1 != (char *)-1) {
   perror("shmat");
   tst_resm(TFAIL,
     "Error: shmat: shmid1 = %d, addr= %#x, errno = %d\n",
     shmid1, cp1, errno);
  }
 }

 tst_resm(TPASS,"2nd shmget & shmat"); 

/*------------------------------------------------------*/

 rm_shm(shmid) ;
 rm_shm(shmid1) ;

 tst_exit() ;

/*-------------------------------------------------------*/
 return(0);
}
Example #25
0
File: shmctl01.c Project: 1587/ltp
void cleanup(void)
{
	rm_shm(shm_id_1);

	tst_rmdir();
}
Example #26
0
int main()
{
	char *cp = NULL;
	int shmid, pid, status;
	key_t key;

	key = (key_t) getpid();

/*---------------------------------------------------------*/

	errno = 0;

	if ((shmid = shmget(key, SIZE, IPC_CREAT | 0666)) < 0) {
		perror("shmget");
		tst_resm(TFAIL, "Error: shmget: shmid = %d, errno = %d\n",
			 shmid, errno);
		tst_exit();
	}
	cp = (char *)shmat(shmid, NULL, 0);

	if (cp == (char *)-1) {
		perror("shmat");
		tst_resm(TFAIL,
			 "Error: shmat: shmid = %d, errno = %d\n",
			 shmid, errno);
		rm_shm(shmid);
		tst_exit();
	}

	*cp = '1';
	*(cp + 1) = '2';

	tst_resm(TPASS, "shmget,shmat");

/*-------------------------------------------------------*/

	pid = fork();
	switch (pid) {
	case -1:
		tst_resm(TBROK, "fork failed");
		tst_exit();

	case 0:
		if (*cp != '1') {
			tst_resm(TFAIL, "Error: not 1\n");
		}
		if (*(cp + 1) != '2') {
			tst_resm(TFAIL, "Error: not 2\n");
		}
		tst_exit();
	}

	/* parent */
	while (wait(&status) < 0 && errno == EINTR) ;

	tst_resm(TPASS, "cp & cp+1 correct");

/*-----------------------------------------------------------*/
	rm_shm(shmid);
	tst_exit();
/*-----------------------------------------------------------*/
	return (0);
}
Example #27
0
int main()
{
	char *cp = NULL;
	int pid, pid1, shmid;
	int status;

	key = (key_t) getpid();

	sigemptyset(&sigset);
	sigaddset(&sigset, SIGUSR1);
	sigprocmask(SIG_BLOCK, &sigset, NULL);

	pid = fork();
	switch (pid) {
	case -1:
		tst_resm(TBROK, "fork failed");
		tst_exit();
	case 0:
		child();
	}

/*------------------------------------------------------*/

	if ((shmid = shmget(key, SIZE, IPC_CREAT | 0666)) < 0) {
		perror("shmget");
		tst_resm(TFAIL, "Error: shmget: shmid = %d, errno = %d\n",
			 shmid, errno);
		/*
		 * kill the child if parent failed to do the attach
		 */
		(void)kill(pid, SIGINT);
	} else {
		cp = (char *)shmat(shmid, NULL, 0);

		if (cp == (char *)-1) {
			perror("shmat");
			tst_resm(TFAIL,
				 "Error: shmat: shmid = %d, errno = %d\n",
				 shmid, errno);

			/* kill the child if parent failed to do the attch */

			kill(pid, SIGINT);

			/* remove shared memory segment */

			rm_shm(shmid);

			tst_exit();
		}
		*cp = 'A';
		*(cp + 1) = 'B';
		*(cp + 2) = 'C';

		kill(pid, SIGUSR1);
		while ((pid1 = wait(&status)) < 0 && (errno == EINTR)) ;
		if (pid1 != pid) {
			tst_resm(TFAIL, "Waited on the wrong child");
			tst_resm(TFAIL,
				 "Error: wait_status = %d, pid1= %d\n", status,
				 pid1);
		}
	}

	tst_resm(TPASS, "shmget,shmat");

/*---------------------------------------------------------------*/

	if (shmdt(cp) < 0) {
		tst_resm(TFAIL, "shmdt");
	}

	tst_resm(TPASS, "shmdt");

/*-------------------------------------------------------------*/

	rm_shm(shmid);
	tst_exit();

/*-----------------------------------------------------------*/
	return (0);
}
Example #28
0
File: shmt09.c Project: heluxie/LTP
int main()
{
	char *c1 = NULL, *c2 = NULL, *c3 = NULL;
	void *vp;
	int shmid;
	key_t key;

	key = (key_t) getpid();

/*-----------------------------------------------------------*/

	if ((unsigned long)sbrk(16384) >= (-4095UL)) {
		perror("sbrk");
		tst_brkm(TFAIL, NULL, "Error: sbrk failed, errno = %d\n",
			 errno);
	}

	if ((unsigned long)sbrk(-4097) >= (-4095UL)) {
		perror("sbrk");
		tst_brkm(TFAIL, NULL, "Error: sbrk failed, errno = %d\n",
			 errno);
	}

	if ((shmid = shmget(key, 10 * K_1, IPC_CREAT | 0666)) < 0) {
		perror("shmget");
		tst_brkm(TFAIL,
			 NULL,
			 "Error: shmget Failed, shmid = %d, errno = %d\n",
			 shmid, errno);
	}

	c1 = shmat(shmid, NULL, 0);
	if (c1 == (char *)-1) {
		perror("shmat");
		tst_resm(TFAIL,
			 "Error: shmat Failed, shmid = %d, errno = %d\n",
			 shmid, errno);
		rm_shm(shmid);
		tst_exit();
	}

	tst_resm(TPASS, "sbrk, sbrk, shmget, shmat");

/*--------------------------------------------------------*/

	if ((unsigned long)sbrk(32 * K_1) >= (-4095UL)) {
		perror("sbrk");
		tst_resm(TFAIL, "Error: sbrk failed, errno = %d\n", errno);
		rm_shm(shmid);
		tst_exit();
	}
	vp = (void *)((char *)sbrk(0) - 2 * K_1);
	c2 = shmat(shmid, vp, 0);
	if (c2 != (char *)-1) {
		tst_resm(TFAIL,
			 "ERROR: shmat: succeeded!: shmid = %d, shmaddr = %p, "
			 "att_addr = %p", shmid, c2, vp);
		rm_shm(shmid);
		tst_exit();
	}

	tst_resm(TPASS, "sbrk, shmat");

/*---------------------------------------------------------*/

	if ((unsigned long)sbrk(-16000) >= (-4095UL)) {
		perror("sbrk");
		tst_resm(TFAIL, "Error: sbrk failed, errno = %d\n", errno);
		rm_shm(shmid);
		tst_exit();
	}
#ifdef __mips__
	vp = (void *)((char *)sbrk(0) + 256 * K_1);
#elif  defined(__powerpc__) || defined(__powerpc64__)
	vp = (void *)((char *)sbrk(0) + getpagesize());
#else
	/* SHM_RND rounds vp on the nearest multiple of SHMLBA */
	vp = (void *)SHMALIGN((char *)sbrk(0) + 1);
#endif

	c3 = shmat(shmid, vp, SHM_RND);
	if (c3 == (char *)-1) {
		perror("shmat1");
		tst_resm(TFAIL,
			 "Error: shmat Failed, shmid = %d, errno = %d\n",
			 shmid, errno);
		rm_shm(shmid);
		tst_exit();
	}

	tst_resm(TPASS, "sbrk, shmat");

/*--------------------------------------------------------*/
#if defined (__ia64__) || defined(__mips__) || defined(__hppa__) || defined(__arm__) || defined(__aarch64__)
	while ((vp = sbrk(INCREMENT)) != (void *)-1) ;
	if (errno != ENOMEM) {
		tst_resm(TFAIL, "Error: sbrk failed, errno = %d\n", errno);
		rm_shm(shmid);
		tst_exit();
	}
#else
	if ((vp = sbrk(INCREMENT)) != (void *)-1) {
		tst_resm(TFAIL,
			 "Error: sbrk succeeded!  ret = %p, curbrk = %p, ",
			 vp, sbrk(0));
		rm_shm(shmid);
		tst_exit();
	}
#endif

	tst_resm(TPASS, "sbrk");

/*------------------------------------------------------*/

	rm_shm(shmid);
	tst_exit();
}
Example #29
0
File: shmt03.c Project: 1587/ltp
int main(void)
{
	char *cp1, *cp2;
	int shmid;
	key_t key;

	key = (key_t) getpid();
	errno = 0;

/*------------------------------------------------------------*/

	if ((shmid = shmget(key, 16 * K_1, IPC_CREAT | 0666)) < 0) {
		perror("shmget");
		tst_brkm(TFAIL, NULL,
			 "shmget Failed: shmid = %d, errno = %d\n",
			 shmid, errno);
	}

	tst_resm(TPASS, "shmget");

/*------------------------------------------------------------*/

	if ((cp1 = shmat(shmid, NULL, 0)) == (char *)-1) {
		perror("shmat");
		tst_resm(TFAIL, "shmat Failed: shmid = %d, errno = %d\n",
			 shmid, errno);
	} else {
		*cp1 = '1';
		*(cp1 + 5 * K_1) = '2';
		first_attach = SUCCESSFUL;
	}

	tst_resm(TPASS, "1st shmat");

/*------------------------------------------------------------*/

	if ((cp2 = shmat(shmid, NULL, 0)) == (char *)-1) {
		perror("shmat");
		tst_resm(TFAIL, "shmat Failed: shmid = %d, errno = %d\n",
			 shmid, errno);
	} else {
		second_attach = SUCCESSFUL;
		if ((*cp2 != '1' || *(cp2 + 5 * K_1) != '2') &&
		    first_attach == SUCCESSFUL) {
			tst_resm(TFAIL, "Error: Shared memory contents\n");
		}
	}

	tst_resm(TPASS, "2nd shmat");

/*---------------------------------------------------------------*/

	rm_shm(shmid);

	if (first_attach && second_attach) {
		if (*cp2 != '1' || *(cp2 + 5 * K_1) != '2' ||
		    *cp1 != '1' || *(cp1 + 5 * K_1) != '2') {
			tst_resm(TFAIL, "Error: Shared memory contents\n");
		}
	}

	tst_resm(TPASS, "Correct shared memory contents");
/*-----------------------------------------------------------------*/
	tst_exit();
}
Example #30
0
void cleanup(void)
{
	rm_shm(shm_id_1);
	restore_nr_hugepages();
}