Exemplo n.º 1
0
/*** shlWrite - Write data to the shell's stdin
 ***/
int
shlWrite(void* inf_v, char* buffer, int cnt, int offset, int flags, pObjTrxTree* oxt)
    {
    pShlData inf = SHL(inf_v);
    int i=-1;
    int waitret;
    int retval;

    if(SHELL_DEBUG & SHELL_DEBUG_IO)
	printf("%s -- %p, %p, %i, %i, %i, %p\n",__FUNCTION__,inf_v,buffer,cnt,offset,flags,oxt);

    /** launch the program if it's not running already **/
    if(inf->shell_pid == -1)
	if(shl_internal_Launch(inf) < 0)
	    return -1;

    /** seek is _not_ allowed (obviously) **/
    if(flags & FD_U_SEEK && offset!=inf->curWrite)
	return -1;

    /** can't write to a dead child :) **/
    if(!inf->shell_pid)
	return -1;

    while(i < 0)
	{
	i=fdWrite(inf->shell_fd,buffer,cnt,0,flags & ~FD_U_SEEK);
	if(i < 0)
	    {
	    /** user doesn;t want us to block **/
	    if(flags & FD_U_NOBLOCK)
		return -1;

	    /** check and make sure the child process is still alive... **/
	    shl_internal_UpdateStatus(inf);
	    if(inf->shell_pid>0)
		{
		/** child is alive, it just isn't ready for data yet -- wait a bit **/
		thSleep(200);
		}
	    else if(inf->shell_pid==0)
		{
		/** child died :( **/
		return -1;
		}
	    }
	}
    inf->curWrite+=i;
    return i;
    }
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
//	gc_init(&argc);
	dy_init(&argc);
	thSleep(0);

	tst_initclass();
	tst_basics();

	tst_methods();

	printf("Slot: %d/%d\n", BGBDYC_SlotHashUsed(), BGBDYC_SlotHashSize());
	BGBDYC_DumpSlotHash();

	printf("Minf: %d/%d\n", BGBDYC_MinfHashUsed(), BGBDYC_MinfHashSize());
	BGBDYC_DumpMinfHash();

//	*(int *)-1=-1;

	return(0);
}
Exemplo n.º 3
0
int main(){
    physics ph(7, 0.5, 0);
    ph.addItem(1,1, sf::Color(255,0,0));
    ph.addItem(20,20, sf::Color(0,0,255));
    ph.addItem(800,200, sf::Color(0,255,255));
    ph.addItem(300,2, sf::Color(255,0,255));
    ph.addItem(99,40, sf::Color(255,255,0));
    ph.addItem(500,230);
    sf::RenderWindow window;
    window.create(sf::VideoMode(800,600), "Titulo");
    sf::Texture t;
    sf::Sprite s;
    sf::Vector2f last(0,0);
    while (window.isOpen()){
        ph.moveTo(last.x, last.y);
        t.loadFromImage(ph.get(800,600));
        window.draw(sf::Sprite(t));
        window.display();
        sf::Event event;
        if (window.pollEvent(event)){
            switch (event.type) {

            case sf::Event::Closed:
                window.close();
            break;

            case sf::Event::MouseMoved:
                last = sf::Vector2f(event.mouseMove.x, event.mouseMove.y);
            break;

            default:
            break;
            }

        }
        thSleep(50);
    }
    return 0;
}
Exemplo n.º 4
0
/*** shlRead - Read data from the shell's stdout
 ***/
int
shlRead(void* inf_v, char* buffer, int maxcnt, int offset, int flags, pObjTrxTree* oxt)
    {
    pShlData inf = SHL(inf_v);
    int i=-1;
    int waitret;
    int retval;

    if(SHELL_DEBUG & SHELL_DEBUG_IO)
	printf("%s -- %p, %p, %i, %i, %i, %p\n",__FUNCTION__,inf_v,buffer,maxcnt,offset,flags,oxt);

    /** launch the program if it's not running already **/
    if(inf->shell_pid == -1)
	if(shl_internal_Launch(inf) < 0)
	    return -1;
    
    /** can't seek backwards on a stream :) **/
    if(flags & FD_U_SEEK)
	{
	if(offset>inf->curRead)
	    {
	    /** scroll forward to point in the stream to read from **/
	    while(offset>inf->curRead)
		{
		char buf[1024];
		int i;
		int readlen = offset-inf->curRead>1024?1024:offset-inf->curRead;
		/** call shlRead instead of fdRead directly, as it has extra protection and this
		 **   will only ever go to one level of recursion **/
		i=shlRead(inf,buf,readlen,0,flags & ~FD_U_SEEK,oxt);
		if(i==-1)
		    return -1;
		inf->curRead+=i;
		}
	    }
	/** this'll also catch if we scroll too far forward... **/
	if(offset<inf->curRead)
	    return -1;
	}

    while(i < 0)
	{
	i=fdRead(inf->shell_fd,buffer,maxcnt,0,flags & ~FD_U_SEEK);
	if(i < 0)
	    {
	    /** if we get EIO, set the done flag **/
	    if(errno == EIO)
		{
		inf->done = 1;
		return -1;
		}

	    /** user doesn't want us to block **/
	    if(flags & FD_U_NOBLOCK)
		return -1;

	    /** if there is no more child process, that's probably why we can't read :) **/
	    if(inf->shell_pid==0)
		return -1;

	    shl_internal_UpdateStatus(inf);

	    if(inf->shell_pid>0)
		{
		/** child is alive, it just doesn't have any data yet -- wait for some **/
		thSleep(200);
		}
	    else
		{
		/** child just died -- retry the read **/
		}
	    }
	}
    inf->curRead+=i;
    return i;
    }
Exemplo n.º 5
0
/*** shlClose - close an open object.
 ***/
int
shlClose(void* inf_v, pObjTrxTree* oxt)
    {
    pShlData inf = SHL(inf_v);
    int childstat=0;
    int waitret;
    int i;

	if(SHELL_DEBUG & SHELL_DEBUG_OPEN)
	    printf("SHELL: closing object: %p\n",inf);

	if(inf->shell_pid>0)
	    {
	    waitret=waitpid(inf->shell_pid,&childstat,WNOHANG);
	    if(waitret==0)
		{
		if(!kill(inf->shell_pid,SIGINT))
		    {
		    /** give it a second to respond to SIGINT **/
		    thSleep(1000);
		    waitret=waitpid(inf->shell_pid,&childstat,WNOHANG);
		    if(waitret==0)
			{
			kill(inf->shell_pid,SIGKILL);
			while(!waitpid(inf->shell_pid,&childstat,WNOHANG))
			    {
			    /** wait for it to die in 1 second intervals **/
			    thSleep(1000);
			    }
			}
		    }
		}
	    if(waitret<0)
		mssError(0,"SHL","Error while trying to reap process %i: %i\n",inf->shell_pid,errno);

	    if(SHELL_DEBUG & SHELL_DEBUG_FORK)
		printf("child (%i) returned: %i\n",inf->shell_pid,childstat);
	    }
#if 0
	if(inf->args)
	    {
	    /** free memory for argument array **/
	    nmFree(inf->args,(inf->nArgs+1)*sizeof(char*));
	    }

	if(inf->envs)
	    {
	    /** free memory for environment array **/
	    nmFree(inf->envs,(inf->nEnvs+1)*sizeof(char*));
	    }

	xhClear(&inf->envHash,free_wrapper,NULL);
	xhDeInit(&inf->envHash);
#endif
	

	xaDeInit(&inf->argArray);
	for(i=0;i<xaCount(&inf->envArray);i++)
	    {
	    if (xaGetItem(&inf->envArray,i))
		nmSysFree(xaGetItem(&inf->envArray,i));
	    }
	xaDeInit(&inf->envList);
	xhClear(&inf->envHash,free_EnvVar,NULL);
	xhDeInit(&inf->envHash);



	if(inf->Node)
	    {
	    /** Write the node first, if need be. **/
	    snWriteNode(inf->Obj->Prev,inf->Node);
	    
	    /** Release the memory **/
	    inf->Node->OpenCnt --;
	    }	

	nmFree(inf,sizeof(ShlData));

    return 0;
    }