void oph_signal_handler(int sig)
{
	pmesg(LOG_DEBUG, __FILE__, __LINE__, "CALLED oph_signal_handler; catched signal nr %d (%s)\n", sig, sys_siglist[sig] ? sys_siglist[sig] : "");
	cleanup();
	exit(1);
}
Example #2
0
void finish() {
  cleanup();
  sqlite3_close(db);
  free(sql_cmd);
  free(all_classes.classes);
}
int WINAPI WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR     lpCmdLine,
                    int       nCmdShow )
{

	// local
    WNDCLASSEX	winClass;
    MSG			uMsg;
	char*		winClassName = "rtvsD3dWinLite";

	// initialise message
    memset(&uMsg,0,sizeof(uMsg));

	// init
    winClass.lpszClassName = winClassName;
    winClass.cbSize        = sizeof(WNDCLASSEX);
    winClass.style         = CS_HREDRAW | CS_VREDRAW;
    winClass.lpfnWndProc   = WindowProc;
    winClass.hInstance     = hInstance;
    winClass.hIcon         = LoadIcon(hInstance, (LPCTSTR)IDI_ICON1);
    winClass.hIconSm       = LoadIcon(hInstance, (LPCTSTR)IDI_ICON2);
    winClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    winClass.lpszMenuName  = NULL;
    winClass.cbClsExtra    = 0;
    winClass.cbWndExtra    = 0;

	// IF register class fails THEN end
    if( !RegisterClassEx(&winClass) )
        return E_FAIL;

	// create window
    g_hWnd = CreateWindowEx( NULL, winClassName, 
                             "JGamlin Ocean Waves",
                             WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                             0, 0, 1200, 800, NULL, NULL, hInstance, NULL );

	// IF create window fails THEN end
    if( g_hWnd == NULL )
        return E_FAIL;

	// housekeeping
    ShowWindow( g_hWnd, nCmdShow );
    UpdateWindow( g_hWnd );

	// create application
	g_app = new rtvsD3dApp(0);

	// non-device one time application setup 
	g_app->setup();

	// non-device one time setup
    setup();

	// device dependent setup
    setupDX();

	// WHILE NOT quit, handle messages and display
    while( uMsg.message != WM_QUIT )
    {
        if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
        { 
            TranslateMessage( &uMsg );
            DispatchMessage( &uMsg );
        }
        else
            display();
    }

	// device dependent cleanup
    cleanupDX();

	// non-device dependant one time cleanup
	cleanup();

	// non-device one time application cleanup
	g_app->cleanup();


	// unregister windows class
    UnregisterClass(
		winClassName,
		winClass.hInstance
		);

    return uMsg.wParam;
}
Example #4
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	pid_t pid1, pid2;
	int exno, status, nsig, i;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping */
		Tst_count = 0;
		status = 1;
		exno = 1;

		/* Fork a process and set the process group so that */
		/* it is different from this one.  Fork 5 more children. */

		pid1 = FORK_OR_VFORK();
		if (pid1 < 0) {
			tst_brkm(TBROK, cleanup, "Fork of first child failed");
		} else if (pid1 == 0) {
			setpgrp();
			for (i = 0; i < 5; i++) {
				pid2 = FORK_OR_VFORK();
				if (pid2 < 0) {
					tst_brkm(TBROK, cleanup, "Fork failed");
				} else if (pid2 == 0) {
#ifdef UCLINUX
					if (self_exec(av[0], "") < 0) {
						tst_brkm(TBROK, cleanup,
							 "self_exec of "
							 "child failed");
					}
#else
					do_child();
#endif
				}
			}
			/* Kill all processes in this process group */
			TEST(kill(0, TEST_SIG));
			pause();
			  exit(exno);
		} else {
			waitpid(pid1, &status, 0);
			if (TEST_RETURN != 0) {
				tst_brkm(TFAIL, cleanup, "%s failed - errno = "
					 "%d : %s", TCID, TEST_ERRNO,
					 strerror(TEST_ERRNO));
			}
		}

		if (STD_FUNCTIONAL_TEST) {
			/*
			 * Check to see if the process was terminated with the
			 * expected signal.
			 */
			nsig = WTERMSIG(status);
			if (nsig == TEST_SIG) {
				tst_resm(TPASS, "received expected signal %d",
					 nsig);
			} else {
				tst_resm(TFAIL,
					 "expected signal %d received %d",
					 TEST_SIG, nsig);
			}
		} else {
			tst_resm(TPASS, "call succeeded");
		}
	}
	cleanup();

	tst_exit();
}
Example #5
0
TimeZoneNamesImpl::~TimeZoneNamesImpl() {
    cleanup();
}
Example #6
0
// -----------------------------------------------------------------------------
WiimoteManager::~WiimoteManager()
{
    cleanup();
}   // ~WiimoteManager
Example #7
0
int main(int ac, char **av)
{
	int lc;
	char *msg;

	struct flock flock;

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

	setup();

	/* check for looping state if -i option is given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset tst_count in case we are looping */
		tst_count = 0;

/* //block1: */
		tst_resm(TINFO, "Enter block 1");
		tst_resm(TINFO, "Test for errno EINVAL");
		fail = 0;

		if (fcntl(1, F_BADCMD, 1) != -1) {
			tst_resm(TFAIL, "fcntl(2) failed to FAIL");
			fail = 1;
		} else if (errno != EINVAL) {
			tst_resm(TFAIL, "Expected EINVAL got %d", errno);
			fail = 1;
		}

		if (fail) {
			tst_resm(TINFO, "block 1 FAILED");
		} else {
			tst_resm(TINFO, "block 1 PASSED");
		}
		tst_resm(TINFO, "Exit block 1");

/* //block2: */
#ifndef UCLINUX
		/* Skip since uClinux does not implement memory protection */
		tst_resm(TINFO, "Enter block 2");
		tst_resm(TINFO, "Test for errno EFAULT");
		fail = 0;

		/* case 1: F_SETLK */
		if (fcntl(1, F_SETLK, (void *)-1) != -1) {
			tst_resm(TFAIL, "F_SETLK: fcntl(2) failed to FAIL");
			fail = 1;
		} else if (errno != EFAULT) {
			tst_resm(TFAIL, "F_SETLK: Expected EFAULT got %d",
				 errno);
			fail = 1;
		}

		/* case 2: F_SETLKW */
		if (fcntl(1, F_SETLKW, (void *)-1) != -1) {
			tst_resm(TFAIL, "F_SETLKW: fcntl(2) failed to FAIL");
			fail = 1;
		} else if (errno != EFAULT) {
			tst_resm(TFAIL, "F_SETLKW: Expected EFAULT got %d",
				 errno);
			fail = 1;
		}

		/* case 3: F_GETLK */
		if (fcntl(1, F_GETLK, (void *)-1) != -1) {
			tst_resm(TFAIL, "F_GETLK: fcntl(2) failed to FAIL");
			fail = 1;
		} else if (errno != EFAULT) {
			tst_resm(TFAIL, "F_GETLK: Expected EFAULT got %d",
				 errno);
			fail = 1;
		}

		if (fail) {
			tst_resm(TINFO, "blcok 2 FAILED");
		} else {
			tst_resm(TINFO, "block 2 PASSED");
		}
		tst_resm(TINFO, "Exit block 2");
#else
		tst_resm(TINFO, "Skip block 2 on uClinux");
#endif

/* //block3: */
		tst_resm(TINFO, "Enter block 3");
		tst_resm(TINFO, "Test for errno EINVAL");
		fail = 0;

		flock.l_whence = -1;
		flock.l_type = F_WRLCK;
		flock.l_start = 0L;
		flock.l_len = 0L;

		if (fcntl(1, F_SETLK, &flock) != -1) {
			tst_resm(TFAIL, "fcntl(2) failed to FAIL");
			fail = 1;
		} else if (errno != EINVAL) {
			tst_resm(TFAIL, "Expected EINVAL, got %d", errno);
			fail = 1;
		}

		if (fail) {
			tst_resm(TINFO, "block 3 FAILED");
		} else {
			tst_resm(TINFO, "block 3 PASSED");
		}
		tst_resm(TINFO, "Exit block 3");

/* //block4: */
		tst_resm(TINFO, "Enter block 4");
		tst_resm(TINFO, "Test for errno EBADF");
		fail = 0;

		if (fcntl(-1, F_GETLK, &flock) != -1) {
			tst_resm(TFAIL, "fcntl(2) failed to FAIL");
			fail = 1;
		} else if (errno != EBADF) {
			tst_resm(TFAIL, "Expected EBADF, got %d", errno);
			fail = 1;
		}

		if (fail) {
			tst_resm(TINFO, "block 4 FAILED");
		} else {
			tst_resm(TINFO, "block 4 PASSED");
		}
		tst_resm(TINFO, "Exit block 4");
	}
	cleanup();
	tst_exit();
}
Example #8
0
int main(int argc, char *argv[])
{
	pid_t cpid2;
	char path[BUFSIZ];
	int lc;
	int fd;
	int ret;

	tst_parse_opts(argc, argv, NULL, NULL);
	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {
		tst_count = 0;

		parentuid = geteuid();
		parentgid = getegid();

		cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
			(void *)child_fn1, NULL);
		if (cpid1 < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				"cpid1 clone failed");

		cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
			(void *)child_fn2, NULL);
		if (cpid2 < 0)
			tst_brkm(TBROK | TERRNO, cleanup,
				"cpid2 clone failed");

		if (access("/proc/self/setgroups", F_OK) == 0) {
			sprintf(path, "/proc/%d/setgroups", cpid1);
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
			SAFE_CLOSE(cleanup, fd);
			/* If the setgroups file has the value "deny",
			 * then the setgroups(2) system call can't
			 * subsequently be reenabled (by writing "allow" to
			 * the file) in this user namespace.  (Attempts to
			 * do so will fail with the error EPERM.)
			*/

			/* test that setgroups can't be re-enabled */
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			ret = write(fd, "allow", 5);

			if (ret != -1) {
				tst_brkm(TBROK | TERRNO, cleanup,
					"write action should fail");
			} else if (errno != EPERM) {
				tst_brkm(TBROK | TERRNO, cleanup,
					"unexpected error: \n");
			}
			SAFE_CLOSE(cleanup, fd);
			tst_resm(TPASS, "setgroups can't be re-enabled");

			sprintf(path, "/proc/%d/setgroups", cpid2);
			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
			SAFE_CLOSE(cleanup, fd);
		}

		updatemap(cpid1, UID_MAP, CHILD1UID, parentuid, cleanup);
		updatemap(cpid2, UID_MAP, CHILD2UID, parentuid, cleanup);

		updatemap(cpid1, GID_MAP, CHILD1GID, parentgid, cleanup);
		updatemap(cpid2, GID_MAP, CHILD2GID, parentgid, cleanup);

		TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 1);

		tst_record_childstatus(cleanup, cpid1);
		tst_record_childstatus(cleanup, cpid2);
	}
	cleanup();
	tst_exit();
}
Example #9
0
k8s::~k8s()
{
	stop_watch();
	cleanup();
}
/* main loop */
static void mainLoop(void)
{
    ARUint8         *dataPtr;
    ARMarkerInfo    *marker_info;
    int             marker_num;
	float curPaddlePos[3];
    int             i;
    double          err;
    double			angle;

	err=0.;
    /* grab a video frame */
    if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
        arUtilSleep(2); 
        return;
    }
	
    if( count == 0 ) arUtilTimerReset();  
    count++;
   
	/* detect the markers in the video frame */
    if( arDetectMarkerLite(dataPtr, thresh, &marker_info, &marker_num) < 0 ) {
        cleanup();
        exit(0);
    }

    argDrawMode2D();
    if( !arDebug ) {
        argDispImage( dataPtr, 0,0 );
    }
    else {
        argDispImage( dataPtr, 1, 1 );
        if( arImageProcMode == AR_IMAGE_PROC_IN_HALF )
            argDispHalfImage( arImage, 0, 0 );
        else
            argDispImage( arImage, 0, 0);

        glColor3f( 1.0, 0.0, 0.0 );
        glLineWidth( 1.0 );
        for( i = 0; i < marker_num; i++ ) {
            argDrawSquare( marker_info[i].vertex, 0, 0 );
        }
        glLineWidth( 1.0 );
    }

    arVideoCapNext();

	for( i = 0; i < marker_num; i++ ) 
		marker_flag[i] = 0;
  
	/* get the paddle position */
	paddleGetTrans(paddleInfo, marker_info, marker_flag, 
				marker_num, &cparam);
	/* draw the 3D models */
	glClearDepth( 1.0 );
	glClear(GL_DEPTH_BUFFER_BIT);


	/* get the translation from the multimarker pattern */
	if( (err=arMultiGetTransMat(marker_info, marker_num, config)) < 0 ) {
        argSwapBuffers();
        return;
    }	
	
	//    printf("err = %f\n", err);
    if(err > 100.0 ) {
        argSwapBuffers();
        return;
    }
	
	//draw a red ground grid
	drawGroundGrid( config->trans, 15, 150.0, 110.0, 0.0);

	/* find the paddle position relative to the base */
	if (paddleInfo->active)
		findPaddlePosition(curPaddlePos,paddleInfo->trans,config->trans);

	/* checking for paddle gesture */
	if( paddleInfo->active) 
	  {
	    int findItem=-1;
	    if (myPaddleItem.item!=-1)
	      {

		  if( check_incline(paddleInfo->trans, config->trans, &angle) ) {
		      myPaddleItem.x += 2.0 * cos(angle);
		      myPaddleItem.y += 2.0 * sin(angle);
		      if( myPaddleItem.x*myPaddleItem.x + 
			  myPaddleItem.y*myPaddleItem.y > 900.0 ) {
			  myPaddleItem.x -= 2.0 * cos(angle);
			  myPaddleItem.y -= 2.0 * sin(angle);
			  myListItem.item[myPaddleItem.item].onpaddle=0;		     
			  myListItem.item[myPaddleItem.item].pos[0]=curPaddlePos[0]; 
			  myListItem.item[myPaddleItem.item].pos[1]=curPaddlePos[1];  
			  myPaddleItem.item = -1;
			}
		  }
	      }
	    else
	      {
		if ((findItem=check_pickup(paddleInfo->trans, config->trans,&myListItem, &angle))!=-1)  {
		    
		    myPaddleItem.item=findItem;
		    myPaddleItem.x =0.0;
		    myPaddleItem.y =0.0;
		    myPaddleItem.angle = 0.0;
		    myListItem.item[myPaddleItem.item].onpaddle=1;
		  }
	      }
	  }

	/* draw the item */
	drawItems(config->trans,&myListItem);

	/* draw the paddle */
	if( paddleInfo->active ){ 
	  draw_paddle(paddleInfo,&myPaddleItem);
	}
	
	argSwapBuffers();
}
KinectManager::~KinectManager(void)
{
	cleanup();
}
/***********************************************************************
 * Main
 ***********************************************************************/
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	char *fname;
	char *desc;
	int ind;
	struct stat *stbuf;
	struct sigaction sa, osa;

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

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {

			fname = Test_cases[ind].pathname;
			desc = Test_cases[ind].desc;
			stbuf = Test_cases[ind].stbuf;

			if (stbuf == (struct stat *)-1) {
				/* special sig11 case */
				sa.sa_handler = &sig11_handler;
				sigemptyset(&sa.sa_mask);
				sa.sa_flags = 0;

				sigaction(SIGSEGV, NULL, &osa);
				sigaction(SIGSEGV, &sa, NULL);

				if (setjmp(sig11_recover)) {
					TEST_RETURN = -1;
					TEST_ERRNO = EFAULT;
				} else {
					TEST(stat(fname, stbuf));
				}
				sigaction(SIGSEGV, &osa, NULL);
			} else {
				/*
				 *  Call stat(2)
				 */

				TEST(stat(fname, stbuf));
			}

			/* check return code */
			if (TEST_RETURN == -1) {
				if (STD_FUNCTIONAL_TEST) {
					if (TEST_ERRNO ==
					    Test_cases[ind].exp_errno)
						tst_resm(TPASS,
							 "stat(<%s>, &stbuf) Failed, errno=%d",
							 desc, TEST_ERRNO);
					else
						tst_resm(TFAIL,
							 "stat(<%s>, &stbuf) Failed, errno=%d, expected errno:%d",
							 desc, TEST_ERRNO,
							 Test_cases[ind].
							 exp_errno);
				} else
					Tst_count++;
			} else {
				tst_resm(TFAIL,
					 "stat(<%s>, &stbuf) returned %ld, expected -1, errno:%d",
					 desc, TEST_RETURN,
					 Test_cases[ind].exp_errno);
			}
		}

	}			/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();

	return 0;
}				/* End main */
Example #13
0
int main(int ac, char **av)
{
	int lc;
	char *msg;
	char read_buffer[BUFSIZ];	/* buffer used to read data from file */

	/* Parse standard options given to run the test. */
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/*
		 * Call sync(2) to commit buffer data to disk.
		 */
		TEST_VOID(sync());

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "%s, Failed, errno=%d : %s",
				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/*
			 * Perform functional verification if test
			 * executed without (-f) option.
			 */
			if (STD_FUNCTIONAL_TEST) {
				/* Set the file ptr to b'nning of file */
				if (lseek(fildes, 0, SEEK_SET) < 0) {
					tst_brkm(TFAIL, cleanup, "lseek() "
						 "failed on %s, error=%d",
						 TEMP_FILE, errno);
				}

				/* Read the contents of file */
				if (read(fildes, read_buffer,
					 sizeof(read_buffer)) > 0) {
					if (strcmp(read_buffer, write_buffer)) {
						tst_resm(TFAIL, "Data read "
							 "from %s doesn't match "
							 "with witten data",
							 TEMP_FILE);
					} else {
						tst_resm(TPASS, "Functionality "
							 "of sync() successful");
					}
				} else {
					tst_brkm(TFAIL, cleanup,
						 "read() Fails on %s, error=%d",
						 TEMP_FILE, errno);
				}
			} else {
				tst_resm(TPASS, "call succeeded");
			}
		}
		Tst_count++;	/* incr. TEST_LOOP counter */
	}

	cleanup();
	tst_exit();

}
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

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

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset Tst_count in case we are looping. */
		Tst_count = 0;

		/*
		 * Call fcntl(2) with F_DUPFD argument on fname
		 */
		TEST(fcntl(fd, F_DUPFD, 0));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "fcntl(%s, F_DUPFD, 0) Failed, errno=%d : %s",
				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {

	    /***************************************************************
	     * only perform functional verification if flag set (-f not given)
	     ***************************************************************/
			if (STD_FUNCTIONAL_TEST) {
				/* No Verification test, yet... */
				tst_resm(TPASS,
					 "fcntl(%s, F_DUPFD, 0) returned %ld",
					 fname, TEST_RETURN);
			}
			if (close(TEST_RETURN) == -1) {
				tst_resm(TWARN | TERRNO,
					 "close(%s) Failed",
					 fname);
			}
		}

	}			/* End for TEST_LOOPING */

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();

	return 0;
}				/* End main */
Example #15
0
int main(int argc, char **argv)
{
	char *msg;		/* message returned from parse_opts */

	/* parse standard options */
	msg = parse_opts(argc, argv, NULL, NULL);
	if (msg != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
		tst_exit();

	}

	setup();

#if HAVE_NUMA_MOVE_PAGES
	unsigned int i;
	int lc;			/* loop counter */
	unsigned int from_node;
	unsigned int to_node;
	int ret;

	ret = get_allowed_nodes(NH_MEMS, 2, &from_node, &to_node);
	if (ret < 0)
		tst_brkm(TBROK|TERRNO, cleanup, "get_allowed_nodes: %d", ret);

	/* check for looping state if -i option is given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {
		void *pages[N_TEST_PAGES] = { 0 };
		int nodes[N_TEST_PAGES];
		int status[N_TEST_PAGES];
		pid_t cpid;
		sem_t *sem;

		/* reset Tst_count in case we are looping */
		Tst_count = 0;

		ret = alloc_shared_pages_on_node(pages + SHARED_PAGE,
						 N_SHARED_PAGES, from_node);
		if (ret == -1)
			continue;

		ret = alloc_pages_on_node(pages + UNSHARED_PAGE,
					  N_UNSHARED_PAGES, from_node);
		if (ret == -1)
			goto err_free_shared;

		for (i = 0; i < N_TEST_PAGES; i++) {
			nodes[i] = to_node;
		}

		sem = alloc_sem(MAX_SEMS);
		if (sem == NULL) {
			goto err_free_unshared;
		}

		/*
		 * Fork a child process so that the shared pages are
		 * now really shared between two processes.
		 */
		cpid = fork();
		if (cpid == -1) {
			tst_resm(TBROK, "forking child failed");
			goto err_free_sem;
		} else if (cpid == 0) {
			child(pages, sem);
		}

		/* Wait for child to setup and signal. */
		if (sem_wait(&sem[SEM_CHILD_SETUP]) == -1)
			tst_resm(TWARN | TERRNO, "error wait semaphore");

		ret = numa_move_pages(0, N_TEST_PAGES, pages, nodes,
				      status, MPOL_MF_MOVE);
		TEST_ERRNO = errno;
		if (ret == -1) {
			tst_resm(TFAIL | TERRNO, "move_pages unexpectedly failed");
			goto err_kill_child;
		}

		if (status[SHARED_PAGE] == -EACCES)
			tst_resm(TPASS, "status[%d] set to expected -EACCES",
				 SHARED_PAGE);
		else
			tst_resm(TFAIL, "status[%d] is %d",
				 SHARED_PAGE, status[SHARED_PAGE]);

	      err_kill_child:
		/* Test done. Ask child to terminate. */
		if (sem_post(&sem[SEM_PARENT_TEST]) == -1)
			tst_resm(TWARN | TERRNO, "error post semaphore");
		/* Read the status, no zombies! */
		wait(NULL);
	      err_free_sem:
		free_sem(sem, MAX_SEMS);
	      err_free_unshared:
		free_pages(pages + UNSHARED_PAGE, N_UNSHARED_PAGES);
	      err_free_shared:
		free_shared_pages(pages + SHARED_PAGE, N_SHARED_PAGES);
	}
#else
	tst_resm(TCONF, "move_pages support not found.");
#endif

	cleanup();

	tst_exit();
}
Example #16
0
CGDISimpleThread::~CGDISimpleThread(void) {
	cleanup();
}
 void run() {
     initWindow();
     initVulkan();
     mainLoop();
     cleanup();
 }
Example #18
0
void CGDISimpleThread::run() {
	emit setIsRunning( true );
	init();

	delayTime = 10;	// initial delay time
	frameCounter = 0;
	frameTimer.start();
	
	while( !*stopThread ) {
		if ( *readyToProcess == true ) {
			// Check for resolution changes
			int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
			int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

			if ( nScreenWidth != ScreenWidth || nScreenHeight != ScreenHeight )	{
				ScreenWidth = nScreenWidth;
				ScreenHeight = nScreenHeight;

				cleanupBuffers();
				initBuffers();
			}  

			// Creating and filling regions data
			CRegions * regions = new CRegions( settings->getHorizontalSegmentWidth( ScreenWidth ), settings->getHorizontalHeight( ScreenHeight ),
				settings->getVerticalWidth( ScreenWidth ), settings->getVerticalSegmentHeight( ScreenHeight ) );

			// Horizontals
			SelectObject( hCaptureDC, hCaptureBitmapH );
			// Top
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->hWidth, regions->hHeight, hDesktopDC, x * regions->hWidth, 0, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapH, bufHSize, bufH );

				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, bufH, bufHSize );

				regions->regionHTop.push_back( bufH_tmp );
			}
			
			// Bottom
			for ( unsigned short x = 0; x < settings->LEDnumH; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->hWidth, regions->hHeight, hDesktopDC, x * regions->hWidth, ScreenHeight - regions->hHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapH, bufHSize, bufH );

				unsigned char * bufH_tmp = new unsigned char[ bufHSize ];
				memcpy( bufH_tmp, bufH, bufHSize );

				regions->regionHBottom.push_back( bufH_tmp );			
			}

			// Verticals
			SelectObject(hCaptureDC,hCaptureBitmapV);
			// Left
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->vWidth, regions->vHeight, hDesktopDC, 0, x * regions->vHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapV, bufVSize, bufV );

				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, bufV, bufVSize );

				regions->regionVLeft.push_back( bufV_tmp );
			}
			
			// Right
			for ( int x = 0; x < settings->LEDnumV; x++ ) {
				BitBlt( hCaptureDC, 0, 0, regions->vWidth, regions->vHeight, hDesktopDC, ScreenWidth - regions->vWidth, x * regions->vHeight, SRCCOPY|CAPTUREBLT );
				GetBitmapBits( hCaptureBitmapV, bufVSize, bufV );

				unsigned char * bufV_tmp = new unsigned char[ bufVSize ];
				memcpy( bufV_tmp, bufV, bufVSize );

				regions->regionVRight.push_back( bufV_tmp );			
			}

			*readyToProcess = false;
			emit onImageCaptured( regions );
			++frameCounter;
			updateDelayTime();
		}		
		usleep( delayTime );
	}
	cleanup();
	emit setIsRunning( false );
	//*stopThread = true;
}
Example #19
0
/**
 * Launch wiimote detection and add the corresponding gamepad devices to the
 * device manager.
 * TODO: this should be done in a separate thread, to not block the UI...
 */
void WiimoteManager::launchDetection(int timeout)
{
    // Stop WiiUse, remove wiimotes, gamepads, gamepad configs.
    cleanup();

    m_all_wiimote_handles =  wiiuse_init(MAX_WIIMOTES);

    // Detect wiimotes
    int nb_found_wiimotes = wiiuse_find(m_all_wiimote_handles, MAX_WIIMOTES, timeout);

    // Couldn't find any wiimote?
    if(nb_found_wiimotes == 0)
        return;

    // Try to connect to all found wiimotes
    int nb_wiimotes = wiiuse_connect(m_all_wiimote_handles, nb_found_wiimotes);

    // Couldn't connect to any wiimote?
    if(nb_wiimotes == 0)
        return;

    // ---------------------------------------------------
    // Create or find a GamepadConfig for all wiimotes
    DeviceManager* device_manager = input_manager->getDeviceList();
    GamepadConfig* gamepad_config = NULL;

    device_manager->getConfigForGamepad(WIIMOTE_START_IRR_ID, "Wiimote",
                                        &gamepad_config);
    int num_buttons = (int)( log((float)WIIMOTE_BUTTON_ALL) / log(2.0f))+1;
    gamepad_config->setNumberOfButtons(num_buttons);
    gamepad_config->setNumberOfAxis(1);

    setWiimoteBindings(gamepad_config);

    // Initialize all Wiimotes, which in turn create their
    // associated GamePadDevices
    for(int i=0 ; i < nb_wiimotes ; i++)
    {
        m_wiimotes.push_back(new Wiimote(m_all_wiimote_handles[i], i,
                                         gamepad_config              ));
    } // end for

    // ---------------------------------------------------
    // Set the LEDs and rumble for 0.2s
    int leds[] = {WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, WIIMOTE_LED_4};
    for(unsigned int i=0 ; i < m_wiimotes.size(); i++)
    {
        wiimote_t*  wiimote_handle = m_wiimotes[i]->getWiimoteHandle();
        wiiuse_set_leds(wiimote_handle, leds[i]);
        wiiuse_rumble(wiimote_handle, 1);
    }

    StkTime::sleep(200);

    for(unsigned int i=0 ; i < m_wiimotes.size(); i++)
    {
        wiimote_t*  wiimote_handle = m_wiimotes[i]->getWiimoteHandle();
        wiiuse_rumble(wiimote_handle, 0);
    }

    // TODO: only enable accelerometer during race
    enableAccelerometer(true);

    // ---------------------------------------------------
    // Launch the update thread
#ifdef WIIMOTE_THREADING
    m_shut = false;
    pthread_create(&m_thread, NULL, &threadFuncWrapper, this);
#endif
}   // launchDetection
Example #20
0
 ~OgreRenderer() { cleanup(); }
void keyDown(unsigned char key, int x, int y)
{
  switch(key)
  {
      // Exit if esc or q is pressed
      case 27:
      case 'q':
            glutDestroyWindow(win);
            cleanup();
            exit(0);
      break;

      /* change shape */
      case 'o':
            if (options[OPT_SHADER_GEN_SHAPE] == FALSE) {
                currentShape = (currentShape + 1) % 6;
           }
            else {
                currentShape = ((currentShape + 1) % 3) + 6;
            }
            strcpy(drawMethodString, currentDrawingMethod[currentShape][0]);
            updateBuffer = TRUE;
            updateRandering();

      break;

      /* increase tessellation */
      case 't':
      case 'T':
          if (key == 'T') {
              uTessellation = min(GEOMETRY_BASE_MAX, uTessellation * 2);
              updateRandering();
              updateBuffer = TRUE;
          }
          else {
              uTessellation = max(GEOMETRY_BASE, uTessellation / 2);
              updateRandering();
              updateBuffer = TRUE;
          }
          sprintf(tessString,"Tessellation: %d x %d",uTessellation,uTessellation);
      break;

      /* toggle light */
      case 'l':
            options[OPT_LIGHTENING] = !options[OPT_LIGHTENING];
          if  (options[OPT_LIGHTENING])
              glEnable(GL_LIGHTING);
          else
              glDisable(GL_LIGHTING);
      break;

      /* display normal */
      case 'n':
            if (options[OPT_SHADER_GEN_SHAPE]   == FALSE &&
                options[OPT_SHADER_BUMPMAP] == FALSE &&
                options[OPT_SHADER_DISPMAP] == FALSE ) {

                options[OPT_DRAW_NORMAL] = !options[OPT_DRAW_NORMAL];
            }
      break;

      /* toggle flat and smooth shading */
      case 'f':
            options[OPT_SHADING_SMOOTH_FLAT] =
                               !options[OPT_SHADING_SMOOTH_FLAT];
            if (options[OPT_SHADING_SMOOTH_FLAT])
                glShadeModel(GL_FLAT);
            else
                glShadeModel(GL_SMOOTH);
      break;

      /* increase and decrease specular */
      case 'h':
      case 'H':
          if (key == 'H')
              shininess += 1.0;
          else
              shininess -= 1.0;
              shininess = fmin(fmax(shininess, 0.0), SHININESS_MAX);
      break;

      /* local view toggle */
      case 'v':
            options[OPT_LOCAL_VIEWER] = !options[OPT_LOCAL_VIEWER];

            if (options[OPT_LOCAL_VIEWER] == TRUE) {
                uLocalViewer = true;
                glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
                strcpy(localViewString,"LocalView:  ON");
            }
            else {
                uLocalViewer = false;
                glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
                strcpy(localViewString,"LocalView: OFF");
            }
      break;

      /* display all settings or only frame rate */
      case 'x':
      case 'X':
           options[OPT_OSP_SHORT_LONG] = !options[OPT_OSP_SHORT_LONG];
      break;

      case 'z':
      case 'Z':
            options[OPT_STDOUT_TEXT] = !options[OPT_STDOUT_TEXT];
      break;

      /* increase and decrease bumps */
      case 'r':
      case 'R':
           if (key == 'R')
               uNumOfBumps = min(BUMPS_BASE_MAX, uNumOfBumps * 2);
           else
               uNumOfBumps = max(BUMPS_BASE, uNumOfBumps / 2);
           sprintf(bumpSizeString,"Number Of Bumps: %d x %d",uNumOfBumps,uNumOfBumps);
      break;

      /* switch between per-vertex and per-pixel lighting */
      case 'p':
          if (options[OPT_SHADING_TOGG]   == TRUE  &&
              options[OPT_SHADER_BUMPMAP] == FALSE &&
              options[OPT_SHADER_DISPMAP] == FALSE) {

              options[OPT_SHADING_VERTEX_PIXEL] =
                                 !options[OPT_SHADING_VERTEX_PIXEL];

              /* per vextex blinn phong and phong */
              if (options[OPT_SHADING_VERTEX_PIXEL] == TRUE) {
                 if (options[OPT_SHADING_BLINN_PHONG] == TRUE) {
                     strcpy(infoString, "Shader: per-vertex blinn phong ");
                     currentShader = shaderProgramHandles[SHADER_VERTEX_BLINN];
                 }
                 else {
                     strcpy(infoString, "Shader: per-vertex phong ");
                     currentShader = shaderProgramHandles[SHADER_VERTEX_PHONG];
                 }
              }

              /* per pixel blinn phong and phong */
              else if (options[OPT_SHADING_VERTEX_PIXEL] == FALSE) {

                  if (options[OPT_SHADING_BLINN_PHONG] == TRUE) {
                      strcpy(infoString, "Shader: per-pixel blinn phong ");
                      currentShader = shaderProgramHandles[SHADER_PIXEL_BLINN];
                  }
                  else {
                      strcpy(infoString, "Shader: per-pixel phong ");
                      currentShader = shaderProgramHandles[SHADER_PIXEL_PHONG];
                  }
              }
          }
      break;
      /* switch between blinn-phong and phong lighting model*/
      case 'm':
          if (options[OPT_SHADING_TOGG]   == TRUE  &&
              options[OPT_SHADER_BUMPMAP] == FALSE &&
              options[OPT_SHADER_DISPMAP] == FALSE) {

              options[OPT_SHADING_BLINN_PHONG] =
                                 !options[OPT_SHADING_BLINN_PHONG];

              /* blinn phong lighting model */
              if( options[OPT_SHADING_BLINN_PHONG] == TRUE) {
                if (options[OPT_SHADING_VERTEX_PIXEL] == TRUE) {
                    strcpy(infoString, "Shader: per-vertex blinn phong ");
                    currentShader = shaderProgramHandles[SHADER_VERTEX_BLINN];
                 }
                else {
                    strcpy(infoString, "Shader: per-pixel blinn phong ");
                    currentShader = shaderProgramHandles[SHADER_PIXEL_BLINN];
                }
              }
              /* phong lighting model */
              else if(options[OPT_SHADING_BLINN_PHONG] == FALSE) {
                if (options[OPT_SHADING_VERTEX_PIXEL] == TRUE) {
                    strcpy(infoString, "Shader: per-vertex phong ");
                    currentShader = shaderProgramHandles[SHADER_VERTEX_PHONG];
                  }
                else {
                    strcpy(infoString, "Shader: per-pixel phong ");
                    currentShader = shaderProgramHandles[SHADER_PIXEL_PHONG];
                }
              }
          }
      break;

      /* switch between gpu and cpu shape generation */
      case 'g':
          if (options[OPT_SHADING_TOGG]   == TRUE  &&
              options[OPT_SHADER_BUMPMAP] == FALSE &&
              options[OPT_SHADER_DISPMAP] == FALSE) {

              options[OPT_SHADER_GEN_SHAPE] = !options[OPT_SHADER_GEN_SHAPE];

              if (options[OPT_SHADER_GEN_SHAPE] == TRUE ) {

                  options[OPT_DRAW_NORMAL] = FALSE;
                  currentShape = SHAPE_INNER_GRID;
                  strcpy(drawMethodString,currentDrawingMethod[currentShape][0]);
                  uGpuGenShape  = true;
                  updateRandering();
              }
              else {

                  uGpuGenShape  = false;
                  currentShape = SHAPE_GRID;
                  strcpy(drawMethodString, currentDrawingMethod[currentShape][0]);
                  updateRandering();
              }
          }
      break;

      /* toggle bump-map */
      case 'b':
            options[OPT_SHADER_BUMPMAP] = !options[OPT_SHADER_BUMPMAP];

          if (options[OPT_SHADER_BUMPMAP] == TRUE) {
              /* set default setting */
              currentShape = SHAPE_INNER_GRID;

              options[OPT_DRAW_NORMAL]      = FALSE;
              options[OPT_SHADER_DISPMAP]   = FALSE;
              options[OPT_SHADER_GEN_SHAPE] = TRUE;
              options[OPT_SHADING_TOGG]     = TRUE;
              currentShader = shaderProgramHandles[SHADER_BUMP_MAP];

              /* update display settings */
            strcpy(infoString,"Shader: bump-map using per-vertex blinn phong ");
            strcpy(drawMethodString, currentDrawingMethod[currentShape][0]);

            updateRandering();
          }
          else {
              options[OPT_SHADER_BUMPMAP]   = FALSE;
              options[OPT_SHADER_GEN_SHAPE] = FALSE;

              /* set default setting */
              currentShape = SHAPE_GRID;
              currentShader = shaderProgramHandles[SHADER_VERTEX_BLINN];

              /* update display settings */
              strcpy(infoString,"Shader: per-vertex blinn phong ");
              strcpy(drawMethodString, currentDrawingMethod[currentShape][0]);

              glUseProgram(currentShader);
              updateRandering();
          }
          uCurrBumpSize = MAX_BUMP_SIZE;
      break;

      /* toggle bump-map */
      case 'd':
            options[OPT_SHADER_DISPMAP] = !options[OPT_SHADER_DISPMAP];

          if (options[OPT_SHADER_DISPMAP] == TRUE) {

              options[OPT_DRAW_NORMAL]      = FALSE;
              options[OPT_SHADER_BUMPMAP]   = FALSE;
              options[OPT_SHADER_GEN_SHAPE] = TRUE;
              options[OPT_SHADING_TOGG]     = TRUE;

              currentShape = SHAPE_INNER_GRID;
              currentShader = shaderProgramHandles[SHADER_DISP_MAP];

              /* update display settings */
              strcpy(infoString,"Shader: displace-map using per-vertex phong ");
              strcpy(drawMethodString, currentDrawingMethod[currentShape][0]);

              updateRandering();
          }
          else {
              /* restore previous setting */
              options[OPT_SHADER_DISPMAP]   = FALSE;
              options[OPT_SHADER_GEN_SHAPE] = FALSE;
              currentShader = shaderProgramHandles[SHADER_VERTEX_BLINN];

              currentShape = SHAPE_GRID;

              glUseProgram(currentShader);
              strcpy(infoString,"Shader: using per-vertex blinn phong ");
              strcpy(drawMethodString, currentDrawingMethod[currentShape][0]);

              updateRandering();
          }
          uCurrBumpSize = MAX_BUMP_SIZE;
      break;

      /* start stop animation  */
      case 'a':
          if (options[OPT_SHADER_DISPMAP] == TRUE ||
              options[OPT_SHADER_BUMPMAP] == TRUE ) {

              options[OPT_SHADER_ANIMATION] =! options[OPT_SHADER_ANIMATION];
              if (options[OPT_SHADER_ANIMATION]== FALSE )
              {
                 uCurrBumpSize = MAX_BUMP_SIZE;
              }
          }
      break;

      /* toggle fixed pipeline and user define shader */
      case 's':

          if (options[OPT_SHADER_BUMPMAP] == FALSE &&
              options[OPT_SHADER_DISPMAP] == FALSE) {

              options[OPT_SHADING_TOGG] = !options[OPT_SHADING_TOGG];

            if (!options[OPT_SHADING_TOGG]) {
                //currentShader = 0;
                strcpy(infoString, "Shader: Fixed pipeline");
                options[OPT_SHADER_GEN_SHAPE] = FALSE;
                uGpuGenShape  = false;
                currentShape = SHAPE_GRID;
                glUseProgram(0);
                updateRandering();
            }
            else {
                strcpy(infoString, "Shader: per-vertex blinn phong ");

                glUseProgram(currentShader);
                updateRandering();
            }
          }
      break;
      default:
      break;
  }
}
Example #22
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

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

	}

    /***************************************************************
     * perform global setup for test
     ***************************************************************/
	setup();

    /***************************************************************
     * check looping state if -c option given
     ***************************************************************/
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/*
		 * TEST CASE:
		 *  Set the effective user ID to the current real uid
		 */
		uid = getuid();

		/* Call setuid(2) */
		TEST(setuid(uid));

		/* check return code */
		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "setuid -  Set the effective user ID to the current real uid failed, errno=%d : %s",
				 TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
	    /***************************************************************
	     * only perform functional verification if flag set (-f not given)
	     ***************************************************************/
			if (STD_FUNCTIONAL_TEST) {
				/* No Verification test, yet... */
				tst_resm(TPASS,
					 "setuid -  Set the effective user ID to the current real uid returned %ld",
					 TEST_RETURN);
			}
		}

	}

    /***************************************************************
     * cleanup and exit
     ***************************************************************/
	cleanup();
	tst_exit();
	tst_exit();

}
static void jpg_process(MSFilter *f){
	JpegWriter *s=(JpegWriter*)f->data;
	if (s->file!=NULL && s->codec!=NULL){
		MSPicture yuvbuf, yuvjpeg;
		mblk_t *m=ms_queue_peek_last(f->inputs[0]);
		if (ms_yuv_buf_init_from_mblk(&yuvbuf,m)==0){
			int error;
			int comp_buf_sz=msgdsize(m);
			uint8_t *comp_buf=(uint8_t*)alloca(comp_buf_sz);
			AVFrame pict;
			mblk_t *jpegm;
			struct SwsContext *sws_ctx;
			
			AVCodecContext *avctx=avcodec_alloc_context();
			
			avctx->width=yuvbuf.w;
			avctx->height=yuvbuf.h;
			avctx->time_base.num = 1;
			avctx->time_base.den =1;
			avctx->pix_fmt=PIX_FMT_YUVJ420P;

			error=avcodec_open(avctx,s->codec);
			if (error!=0) {
				ms_error("avcodec_open() failed: %i",error);
				cleanup(s,NULL);
				av_free(avctx);
				return;
			}
			sws_ctx=sws_getContext(avctx->width,avctx->height,PIX_FMT_YUV420P,
				avctx->width,avctx->height,avctx->pix_fmt,SWS_FAST_BILINEAR,NULL, NULL, NULL);
			if (sws_ctx==NULL) {
				ms_error(" sws_getContext() failed.");
				cleanup(s,avctx);
				goto end;
			}
			jpegm=ms_yuv_buf_alloc (&yuvjpeg,avctx->width, avctx->height);
			if (sws_scale(sws_ctx,(const uint8_t *const*)yuvbuf.planes,yuvbuf.strides,0,avctx->height,yuvjpeg.planes,yuvjpeg.strides)<0){
				ms_error("sws_scale() failed.");
				sws_freeContext(sws_ctx);
				cleanup(s,avctx);
				freemsg(jpegm);
				goto end;
			}
			sws_freeContext(sws_ctx);
			
			avcodec_get_frame_defaults(&pict);
			avpicture_fill((AVPicture*)&pict,(uint8_t*)jpegm->b_rptr,avctx->pix_fmt,avctx->width,avctx->height);
			error=avcodec_encode_video(avctx, (uint8_t*)comp_buf,comp_buf_sz, &pict);
			if (error<0){
				ms_error("Could not encode jpeg picture.");
			}else{
				fwrite(comp_buf,error,1,s->file);
				ms_message("Snapshot done");
			}
			cleanup(s,avctx);
			freemsg(jpegm);
		}
		goto end;
	}
	end:
	ms_queue_flush(f->inputs[0]);
}
Example #24
0
int main(int ac, char **av)
{
	struct stat stat_buf;	/* stat structure buffer */
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */

	/* Parse standard options given to run the test. */
	msg = parse_opts(ac, av, NULL, NULL);
	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);

	setup();

	/* set the expected errnos... */
	TEST_EXP_ENOS(exp_enos);

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		Tst_count = 0;

		/*
		 * Call stat(2) to get the status of
		 * specified 'file' into stat structure.
		 */
		TEST(stat(TESTFILE, &stat_buf));

		if (TEST_RETURN == -1) {
			TEST_ERROR_LOG(TEST_ERRNO);
			tst_resm(TFAIL,
				 "stat(%s, &stat_buf) Failed, errno=%d : %s",
				 TESTFILE, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/*
			 * Perform functional verification if test
			 * executed without (-f) option.
			 */
			if (STD_FUNCTIONAL_TEST) {
				stat_buf.st_mode &= ~S_IFREG;
				/*
				 * Verify the data returned by stat(2)
				 * aganist the expected data.
				 */
				if ((stat_buf.st_uid != user_id) ||
				    (stat_buf.st_gid != group_id) ||
				    (stat_buf.st_size != FILE_SIZE) ||
				    ((stat_buf.st_mode & MASK) != FILE_MODE)) {
					tst_resm(TFAIL, "Functionality of "
						 "stat(2) on '%s' Failed",
						 TESTFILE);
				} else {
					tst_resm(TPASS, "Functionality of "
						 "stat(2) on '%s' Succcessful",
						 TESTFILE);
				}
			} else {
				tst_resm(TINFO, "Call succeeded");
			}
		}
		Tst_count++;	/* incr. TEST_LOOP counter */
	}

	cleanup();
	tst_exit();
	tst_exit();

}
Example #25
0
File: kill01.c Project: GOEUM/ltp
int main(int ac, char **av)
{
	int lc;
	char *msg;
	pid_t pid;
	int exno, status, nsig;

	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
	}
#ifdef UCLINUX
	maybe_run_child(&do_child, "");
#endif

	setup();		/* global setup */

	/* The following loop checks looping state if -i option given */
	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset tst_count in case we are looping */
		tst_count = 0;
		status = 1;
		exno = 1;
		pid = FORK_OR_VFORK();
		if (pid < 0) {
			tst_brkm(TBROK, cleanup, "Fork of child failed");
		} else if (pid == 0) {
#ifdef UCLINUX
			if (self_exec(av[0], "") < 0) {
				tst_brkm(TBROK, cleanup,
					 "self_exec of child failed");
			}
#else
			do_child();
#endif
		} else {
			TEST(kill(pid, TEST_SIG));
			waitpid(pid, &status, 0);
		}

		if (TEST_RETURN == -1) {
			tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s",
				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
		}

		if (STD_FUNCTIONAL_TEST) {
			/*
			 * Check to see if the process was terminated with the
			 * expected signal.
			 */
			nsig = WTERMSIG(status);
			if (nsig == TEST_SIG) {
				tst_resm(TPASS, "received expected signal %d",
					 nsig);
			} else {
				tst_resm(TFAIL,
					 "expected signal %d received %d",
					 TEST_SIG, nsig);
			}
		} else {
			tst_resm(TPASS, "call succeeded");
		}
	}
	cleanup();

	tst_exit();
}
void forwarding_actor_proxy::kill_proxy(uint32_t reason) {
  manager(invalid_actor);
  cleanup(reason);
}
Example #27
0
File: mknod03.c Project: GOEUM/ltp
int main(int ac, char **av)
{
	int lc;
	int fflag;		/* functionality flag variable */
	char *msg;

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

	}

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		tst_count = 0;

		/*
		 *  Attempt to create a filesystem node with group id (sgid)
		 *  bit set on a directory with group id (sgid) bit set
		 *  such that, the node created by mknod(2) should have
		 *  group id (sgid) bit set and node's gid should be equal
		 *  to that of effective gid of the process.
		 */
		TEST(mknod(node_name, MODE_SGID, 0));

		/* Check return code from mknod(2) */
		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "mknod(%s, %#o, 0)  failed, errno=%d : "
				 "%s", node_name, MODE_SGID, TEST_ERRNO,
				 strerror(TEST_ERRNO));
			continue;
		}
		/*
		 * Perform functional verification if test executed
		 * without (-f) option.
		 */
		if (STD_FUNCTIONAL_TEST) {
			/* Set the functionality flag */
			fflag = 1;

			/* Check for node's creation */
			if (stat(node_name, &buf) < 0) {
				tst_resm(TFAIL, "stat() of %s failed, errno:%d",
					 node_name, TEST_ERRNO);
				/* unset functionality flag */
				fflag = 0;
			}

			/* Verify mode permissions of node */
			if (!(buf.st_mode & S_ISGID)) {
				tst_resm(TFAIL,
					 "%s: Incorrect modes, setgid bit not "
					 "set", node_name);
				/* unset flag as functionality fails */
				fflag = 0;
			}

			/* Verify group ID */
			if (buf.st_gid != group2_gid) {
				tst_resm(TFAIL, "%s: Incorrect group",
					 node_name);
				/* unset flag as functionality fails */
				fflag = 0;
			}
			if (fflag) {
				tst_resm(TPASS, "Functionality of mknod(%s, "
					 "%#o, 0) successful",
					 node_name, MODE_SGID);
			}
		} else {
			tst_resm(TPASS, "call succeeded");
		}

		/* Remove the node for the next go `round */
		if (unlink(node_name) == -1) {
			tst_resm(TWARN, "unlink(%s) failed, errno:%d %s",
				 node_name, errno, strerror(errno));
		}
	}

	/* Change the directory back to temporary directory */
	chdir("..");

	/*
	 * Invoke cleanup() to delete the test directories created
	 * in the setup() and exit main().
	 */
	cleanup();

	tst_exit();
}
Example #28
0
MemoryTestHelper::~MemoryTestHelper()
{
  cleanup();
}
Example #29
0
int main(int ac, char **av)
{
	int lc;
	int i;
	char *comp_string;

	comp_string = NULL;

	tst_parse_opts(ac, av, NULL, NULL);

	setup();

	for (lc = 0; TEST_LOOPING(lc); lc++) {

		/* reset tst_count in case we are looping */
		tst_count = 0;

		for (i = 0; i < TST_TOTAL; ++i) {

			osnamelth = SIZE(osname);

			switch (i) {
			case 0:
				comp_string = buf.sysname;
				break;
			case 1:
				comp_string = buf.release;
				break;
			case 2:
				comp_string = buf.version;
				break;
			}

			TEST(sysctl(TC[i].name, TC[i].size, TC[i].oldval,
				    TC[i].oldlen, TC[i].newval, TC[i].newlen));

			if (TEST_RETURN != 0) {
				if (TEST_ERRNO == ENOSYS) {
					tst_resm(TCONF,
						 "You may need to make CONFIG_SYSCTL_SYSCALL=y"
						 " to your kernel config.");
				} else {
					tst_resm(TFAIL,
						 "sysctl(2) failed unexpectedly "
						 "errno:%d", TEST_ERRNO);
				}
				continue;
			}

			if (strcmp(TC[i].oldval, comp_string) != 0) {
				tst_resm(TFAIL, "strings don't match - %s : %s",
					 TC[i].oldval, comp_string);
			} else {
				tst_resm(TPASS, "%s is correct", TC[i].desc);
			}
			if (TC[i].cleanup) {
				(void)TC[i].cleanup();
			}
		}
	}

	cleanup();
	tst_exit();
}
int main(int argc, char *argv[])
{
	SOAP_SOCKET m;
#if defined(_POSIX_THREADS) || defined(_SC_THREADS)
	pthread_t tid;
	pthread_mutex_init(&global_flag, NULL);
	pthread_mutex_init(&libssh2_flag, NULL);
	pthread_cond_init(&termination_flag, NULL);
#endif
	struct soap soap, *tsoap = NULL;
	psoap = &soap;

	int ch, msglevel = LOG_INFO;
	static char *USAGE = "\nUSAGE:\noph_server [-d] [-l <log_file>] [-p <port>] [-v] [-w]\n";

	fprintf(stdout, "%s", OPH_VERSION);
	fprintf(stdout, "%s", OPH_DISCLAIMER);

	set_debug_level(msglevel + 10);

	while ((ch = getopt(argc, argv, "dhl:p:vwxz")) != -1) {
		switch (ch) {
			case 'd':
				msglevel = LOG_DEBUG;
				break;
			case 'h':
				fprintf(stdout, "%s", USAGE);
				return 0;
			case 'l':
				oph_log_file_name = optarg;
				break;
			case 'p':
				oph_server_port = optarg;
				break;
			case 'v':
				return 0;
				break;
			case 'w':
				if (msglevel < LOG_WARNING)
					msglevel = LOG_WARNING;
				break;
			case 'x':
				fprintf(stdout, "%s", OPH_WARRANTY);
				return 0;
			case 'z':
				fprintf(stdout, "%s", OPH_CONDITIONS);
				return 0;
			default:
				fprintf(stdout, "%s", USAGE);
				return 0;
		}
	}

	set_debug_level(msglevel + 10);
	pmesg(LOG_INFO, __FILE__, __LINE__, "Selected log level %d\n", msglevel);

#ifdef OPH_SERVER_LOCATION
	oph_server_location = strdup(OPH_SERVER_LOCATION);
#else
	oph_server_location = getenv(OPH_SERVER_LOCATION_STR);
	if (!oph_server_location) {
		fprintf(stderr, "OPH_SERVER_LOCATION has to be set\n");
		return 1;
	}
#endif
	pmesg(LOG_DEBUG, __FILE__, __LINE__, "Server location '%s'\n", oph_server_location);

	char configuration_file[OPH_MAX_STRING_SIZE];
	snprintf(configuration_file, OPH_MAX_STRING_SIZE, OPH_CONFIGURATION_FILE, oph_server_location);
	set_global_values(configuration_file);

	if (oph_log_file_name) {
		if (logfile)
			fclose(logfile);
		if (!(logfile = fopen(oph_log_file_name, "a"))) {
			fprintf(stderr, "Wrong log file name '%s'\n", oph_log_file_name);
			return 1;
		}
		pmesg(LOG_INFO, __FILE__, __LINE__, "Selected log file '%s'\n", oph_log_file_name);
		if (logfile)
			set_log_file(logfile);
	} else
		oph_log_file_name = hashtbl_get(oph_server_params, OPH_SERVER_CONF_LOGFILE);

	int int_port = strtol(oph_server_port, NULL, 10);

	if (oph_handle_signals()) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "A problem occurred while setting up signal dispositions\n");
		exit(1);
	}

	if (mysql_library_init(0, 0, 0)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Cannot setup MySQL\n");
		exit(1);
	}

	oph_tp_start_xml_parser();
	if (CRYPTO_thread_setup()) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Cannot setup thread mutex for OpenSSL\n");
		exit(1);
	}
	soap_init(&soap);
	soap.fget = oph_http_get;
	if (soap_register_plugin(&soap, oph_plugin)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Cannot register %s plugin\n", OPH_PLUGIN_ID);
		soap_print_fault(&soap, stderr);
		cleanup();
		exit(-1);
	}
	// Register serverid
	struct oph_plugin_data *state = NULL;
	if (!(state = (struct oph_plugin_data *) soap_lookup_plugin(&soap, OPH_PLUGIN_ID))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error on lookup plugin struct\n");
		soap_print_fault(&soap, stderr);
		cleanup();
		exit(-1);
	}
	state->serverid = strdup(oph_web_server);

#ifdef WITH_OPENSSL
	/* init gsoap context and SSL */
	if (soap_ssl_server_context(&soap, SOAP_TLSv1_2, oph_server_cert, oph_server_password, oph_server_ca, NULL, NULL, NULL, NULL)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "SSL Server Context Error\n");
		soap_print_fault(&soap, stderr);
		cleanup();
		exit(1);
	}
#endif

	soap.accept_timeout = oph_server_inactivity_timeout;
	soap.send_timeout = soap.recv_timeout = oph_server_timeout;
	soap.bind_flags |= SO_REUSEADDR;
	m = soap_bind(&soap, NULL, int_port, 100);
	if (!soap_valid_socket(m)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Soap invalid socket\n");
		soap_print_fault(&soap, stderr);
		cleanup();
		exit(1);
	}
	pmesg(LOG_DEBUG, __FILE__, __LINE__, "Bind successful: socket = %d\n", m);

	for (;;) {
		SOAP_SOCKET s = soap_accept(&soap);
		if (!soap_valid_socket(s)) {
			if (soap.errnum) {
				pmesg(LOG_ERROR, __FILE__, __LINE__, "Soap invalid socket\n");
				soap_print_fault(&soap, stderr);
			} else
				pmesg(LOG_ERROR, __FILE__, __LINE__, "Server timed out (timeout set to %d seconds)\n", soap.accept_timeout);
			break;
		}
		tsoap = soap_copy(&soap);
		if (!tsoap) {
			soap_closesock(&soap);
			continue;
		}
#if defined(_POSIX_THREADS) || defined(_SC_THREADS)
		pthread_create(&tid, NULL, (void *(*)(void *)) &process_request, tsoap);
#else
		process_request(tsoap);
#endif
	}
	cleanup();
	return 0;
}