void
init_daemon()
{
	int status;

	status = fork();
	switch (status)
	{
		case -1:
			syslog(LOG_ERR, "Fork failed exiting...");
			doexit(errno);
		case 0:
			/* Child */
			break;
		default:
			/* Parent */
			exit(EXIT_SUCCESS);
	}

	close(0);
	close(1);
	close(2);
	status = setsid();
	if (status == -1)
	{
		syslog(LOG_ERR, "setsid failed. Client exiting...");
		doexit(errno);
	}
	return;
}
Esempio n. 2
0
File: quine.c Progetto: kahrs/cda
int
main(int argc, char *argv[])
{
	int i, j;

 	stin= stdin;
	warn = 1000;
	buildclass();
	while(argc > 1 && argv[1][0] == '-') {
		for(i=1; j = argv[1][i]; i++) {
			switch(j) {
			default:
				fprintf(stderr, "unknown flag -%c\n", j);
				continue;

			case 'q':
				qflag = 1;
				break;

			case 'w':
				warn = atoi(&argv[1][i+1]);
				break;
			}
			break;
		}
		argc--;
		argv++;
	}
	if(argc > 2)
		fprintf(stderr, "Too many arguments -- ignored\n");
	if(argc > 1) {
		stin = fopen(argv[1], "r");
		if(stin == 0) {
			fprintf(stderr, "cannot open %s\n", argv[1]);
			doexit(1);
		}
	}

readmore:
	nterm = 0;
	itmpp = 0;
	peekc = opeekc;
	peeks = opeeks;
	numb = onumb;
	if(rdata())
		doexit(0);
	opeeks = peeks;
	opeekc = peekc;
	onumb = numb;
	if(qflag)
		doimpq(itmp, &itmp[itmpp], mask, 1L);
	else
		doimp(itmp, &itmp[itmpp], mask, 1L);
	if(nterm % PERLINE)
		fprintf(stdout, "\n");
	goto readmore;
}
Esempio n. 3
0
/*
 Simple Unix-style command line parser, conforming with 'A Proposed Command
 Syntax Standard for Unix Systems', Hemenway & Armitage, Unix/World, Vol.1,
 No.3, 1984.
*/
cmdlin() {
    char x;				/* Local general-purpose int */
    cmarg = "";				/* Initialize globals */
    cmarg2 = "";
    action = cflg = 0;
 
    while (--xargc > 0) {		/* Go through command line words */
	xargv++;
	debug(F111,"xargv",*xargv,xargc);
    	if (**xargv == '-') {		/* Got an option (begins with dash) */
	    x = *(*xargv+1);		/* Get the option letter */
	    x = doarg(x);		/* Go handle the option */
	    if (x < 0) doexit(BAD_EXIT);
    	} else {			/* No dash where expected */
	    usage();
	    doexit(BAD_EXIT);
	}
    }
    debug(F101,"action","",action);
    if (!local) {
	if ((action == 'g') || (action == 'r') ||
	    (action == 'c') || (cflg != 0))
	    fatal("-l and -b required");
    }
    if (*cmarg2 != 0) {
	if ((action != 's') && (action != 'r') &&
	    (action != 'v'))
	    fatal("-a without -s, -r, or -g");
    }
    if ((action == 'v') && (stdouf) && (!local)) {
    	if (isatty(1))
	    fatal("unredirected -k can only be used in local mode");
    }
    if ((action == 's') || (action == 'v') ||
    	(action == 'r') || (action == 'x')) {
	if (local) displa = 1;
	if (stdouf) { displa = 0; quiet = 1; }
    }
 
    if (quiet) displa = 0;		/* No display if quiet requested */
 
    if (cflg) {
	conect();			/* Connect if requested */
	if (action == 0) {
	    if (cnflg) conect();	/* And again if requested */
	    doexit(GOOD_EXIT);		/* Then exit indicating success */
	}
    }
    if (displa) concb(escape);		/* (for console "interrupts") */
    return(action);			/* Then do any requested protocol */
}
static void conescape(void)
{
	char b;

	if (G.gotsig)	/* came from line  mode... go raw */
		rawmode();

	WriteCS(1, "\r\nConsole escape. Commands are:\r\n\n"
			" l	go to line mode\r\n"
			" c	go to character mode\r\n"
			" z	suspend telnet\r\n"
			" e	exit telnet\r\n");

	if (read(0, &b, 1) <= 0)
		doexit(1);

	switch (b)
	{
	case 'l':
		if (!G.gotsig)
		{
			do_linemode();
			goto rrturn;
		}
		break;
	case 'c':
		if (G.gotsig)
		{
			will_charmode();
			goto rrturn;
		}
		break;
	case 'z':
		cookmode();
		kill(0, SIGTSTP);
		rawmode();
		break;
	case 'e':
		doexit(0);
	}

	WriteCS(1, "continuing...\r\n");

	if (G.gotsig)
		cookmode();

 rrturn:
	G.gotsig = 0;

}
Esempio n. 5
0
void main(int argc,char **argv)
{
	short filenum=(-1);
	char *warnmessage=NULL;
	char *module=NULL,*mtnname=NULL;

	module="FINMGT";
	mtnname="MTN FINRACT";
	if(InitializeSubsystems(argc,argv,module,mtnname))
	{
		RDAAPPMAINLOOP();
		return;
	}
	MASTER=MaintainMasterNew(module,mtnname);
	if(findMaintainMaster(MASTER))
	{
		warnmessage=Rmalloc(300+RDAstrlen(MASTER->module)+RDAstrlen(mtnname));
		sprintf(warnmessage,"Error Maintain Master Definition not found, this process cannot be executed without it's definition [%s] in the [%s.MTN] library.",mtnname,MASTER->module);
		ERRORDIALOG("MAINTAIN MASTER NOT FOUND.",warnmessage,NULL,TRUE);
		prterr("%s",warnmessage);
		if(warnmessage!=NULL) Rfree(warnmessage);
		doexit(NULL);
	} else {
		if((filenum=APPOPNNRDEDITABLE(MASTER->module,MASTER->mainfile,&editable))==(-1))
		{
			doexit(NULL);
			return;
		}
		SetSupportingWritable(MASTER,MASTER->module,"FINRYR",1,TRUE,&editable);
		if(!OPEN_MASTER_FILES(MASTER))
		{
			doexit(NULL);
			return;
		}
		ryrnum=APPReturnSupportingFileno(MASTER,"FINMGT","FINRYR",1);
		MASTER->passkey=READPassKey(filenum);
		MASTER->inheritrsrcs=TRUE;
		switch(MASTER->start_with)
		{
			default:
			case 0:
				finractm(1,NULL);
				break;
			case 1:
				browse_finract(NULL,NULL);
				break;
		}
	}
	RDAAPPMAINLOOP();
}
Esempio n. 6
0
int main(int argc,char **argv)
#endif
{
	if(InitializeSubsystems(argc,argv,module,"MTN SCNNOT")) 
	{
		return;
	}
	if((filenum=APPOPNNRDEDITABLE(module,"SCNNOT",&editable))==(-1)) return;
	MASTER=MaintainMasterNew(module,"MTN SCNNOT");
	if(findMaintainMaster(MASTER))
	{
		ERRORDIALOG("MAINTAIN MASTER NOT FOUND.","The Maintain Master function wasn't found.",NULL,TRUE);
		prterr("Error Maintain Master Definition not found, this process cannot be executed without it's definition [%s] in the [%s.MTN] library.","MTN SCNNOT",module);
		doexit(NULL);
	} else {
		MASTER->passkey=READPassKey(filenum);
		switch(MASTER->start_with)
		{
			default:
			case 0:
				mtnscnnot(1,NULL);
				break;
			case 1:
				browse_scn(NULL,NULL);
				break;
		}
	}
}
Esempio n. 7
0
File: quine.c Progetto: kahrs/cda
void
expect(char *s)
{

	fprintf(stderr, "%s expected\n", s);
	doexit(1);
}
void
usage() {
	xSerialxPrintf_P(&xSerialPort,PSTR("E-Kermit %s\r\n"),VERSION);
	xSerialxPrintf_P(&xSerialPort,PSTR("Usage: %s <options>\r\n"),xname);
    xSerialxPrint_P(&xSerialPort,PSTR("Options:\r\n"));
    xSerialxPrint_P(&xSerialPort,PSTR(" -r           Receive files\r\n"));
#ifndef RECVONLY
    xSerialxPrint_P(&xSerialPort,PSTR(" -s <files>   Send files\r\n"));
#endif /* RECVONLY */
    xSerialxPrint_P(&xSerialPort,PSTR(" -p [neoms]   Parity: none, even, odd, mark, space\r\n"));
#ifdef F_CRC
    xSerialxPrint_P(&xSerialPort,PSTR(" -b [1235]    Block check type: 1, 2, 3, or 5\r\n"));
#endif /* F_CRC */
    xSerialxPrint_P(&xSerialPort,PSTR(" -k           Keep incompletely received files\r\n"));
    xSerialxPrint_P(&xSerialPort,PSTR(" -B           Force binary mode\r\n"));
    xSerialxPrint_P(&xSerialPort,PSTR(" -T           Force text mode\r\n"));
    xSerialxPrint_P(&xSerialPort,PSTR(" -R           Remote mode (vs local)\r\n"));
    xSerialxPrint_P(&xSerialPort,PSTR(" -L           Local mode (vs remote)\r\n"));
#ifdef DEBUG
    xSerialxPrint_P(&xSerialPort,PSTR(" -E <number>  Simulated error rate (0-100)\r\n"));
    xSerialxPrint_P(&xSerialPort,PSTR(" -d           Create debug.log\r\n"));
#endif /* DEBUG */
    xSerialxPrint_P(&xSerialPort,PSTR(" -h           Help (this message)\r\n"));
    doexit(FAILURE);
}
Esempio n. 9
0
void main(int argc,char **argv)
{
	short filenum=(-1);

	if(InitializeSubsystems(argc,argv,"POSTRK","MTN POSPER")) 
	{
		RDAAPPMAINLOOP();
		return;
	}
	MASTER=MaintainMasterNew("POSTRK","MTN POSPER");
	if(findMaintainMaster(MASTER))
	{
		ERRORDIALOG("MAINTAIN MASTER NOT FOUND.","The Maintain Master function wasn't found.",NULL,TRUE);
		prterr("Error Maintain Master Definition not found, this process cannot be executed without it's definition [%s] in the [%s.MTN] library.","MTN POSPER",MASTER->module);
		doexit(NULL);
	} else {
		if((filenum=APPOPNNRDEDITABLE(MASTER->module,MASTER->mainfile,
			&editable))==(-1))
		{
			doexit(NULL);
			return;
		}
		SetSupportingWritable(MASTER,"PAYROLL","PAYJMST",1,TRUE,&editable);
		SetSupportingWritable(MASTER,MASTER->module,"POSMSTR",1,TRUE,&editable);
		if(!OPEN_MASTER_FILES(MASTER))
		{
			doexit(NULL);
			return;
		}
		jmstnum=APPReturnSupportingFileno(MASTER,"PAYROLL","PAYJMST",1);
		msrnum=APPReturnSupportingFileno(MASTER,MASTER->module,"POSMSTR",1);
		MASTER->passkey=READPassKey(filenum);
		MASTER->inheritrsrcs=TRUE;
		switch(MASTER->start_with)
		{
			default:
			case 0:
				posperm(1,NULL);
				break;
			case 1:
				browse_posper(NULL,NULL);
				break;
		}
	}
	RDAAPPMAINLOOP();
}
Esempio n. 10
0
static void con_escape(void)
{
	char b;

	if (bb_got_signal) /* came from line mode... go raw */
		rawmode();

	write_str(1, "\r\nConsole escape. Commands are:\r\n\n"
			" l	go to line mode\r\n"
			" c	go to character mode\r\n"
			" z	suspend telnet\r\n"
			" e	exit telnet\r\n");

	if (read(STDIN_FILENO, &b, 1) <= 0)
		doexit(EXIT_FAILURE);

	switch (b) {
	case 'l':
		if (!bb_got_signal) {
			do_linemode();
			goto ret;
		}
		break;
	case 'c':
		if (bb_got_signal) {
			will_charmode();
			goto ret;
		}
		break;
	case 'z':
		cookmode();
		kill(0, SIGTSTP);
		rawmode();
		break;
	case 'e':
		doexit(EXIT_SUCCESS);
	}

	write_str(1, "continuing...\r\n");

	if (bb_got_signal)
		cookmode();
 ret:
	bb_got_signal = 0;

}
Esempio n. 11
0
void main(int argc,char **argv)
{
	short filenum=(-1);
	char *module=NULL,*mtnname=NULL;

	module="LVEMGT";
	mtnname="MTN LVEMSTR";
	if(InitializeSubsystems(argc,argv,module,mtnname))
	{
		RDAAPPMAINLOOP();
		return;
	}
	MASTER=MaintainMasterNew(module,mtnname);
	if(findMaintainMaster(MASTER))
	{
		ERRORDIALOG("MAINTAIN MASTER NOT FOUND.","The Maintain Master function wasn't found.",NULL,TRUE);
		prterr("Error Maintain Master Definition not found, this process can not be executed without it's definition [%s] in the [%s.MTN] library.",mtnname,MASTER->module);
		doexit(NULL);
	} else {
		if((filenum=APPOPNNRDEDITABLE(MASTER->module,MASTER->mainfile,&editable))==(-1))
		{
			doexit(NULL);
			return;
		}
		if(!OPEN_MASTER_FILES(MASTER))
		{
			doexit(NULL);
			return;
		}
		dscnum=APPReturnSupportingFileno(MASTER,MASTER->module,"LVEDSC",1);
		lvetyp=APPReturnSupportingFileno(MASTER,MASTER->module,"LVETPMS",1);
		MASTER->passkey=READPassKey(filenum);
		MASTER->inheritrsrcs=FALSE;
		switch(MASTER->start_with)
		{
			default:
			case 0:
				lvemstm(1,NULL);
				break;
			case 1:
				browse_mst(NULL,NULL);
				break;
		}
	}
	RDAAPPMAINLOOP();
}
Esempio n. 12
0
File: process.c Progetto: 8l/FUZIX
/* This sees if the current process has any signals set, and handles them.
 */
void chksigs(void)
{
	uint8_t j;
	uint32_t pending = udata.u_ptab->p_pending & ~udata.u_ptab->p_held;
	int (**svec)(int) = &udata.u_sigvec[0];
	uint32_t m;

	/* Fast path - no signals pending means no work
	   Also don't do signal processing if we are in P_STOPPED. This
	   isn't quite right but will paper over the holes for the moment
	   FIXME */
	if (!pending || udata.u_ptab->p_status == P_STOPPED)
		return;

	/* Dispatch the lowest numbered signal */
	for (j = 1; j < NSIGS; ++j) {
		svec++;
		m = sigmask(j);
		if (!(m & pending))
			continue;
	        /* SIGSTOP can't be ignored and puts the process into
	           P_STOPPED state when it is ready to handle the signal.
	           Annoyingly right now we have to context switch to the task
	           in order to stop it in the right place. That would be nice
	           to fix */
	        if (j == SIGSTOP || j == SIGTTIN || j == SIGTTOU) {
			udata.u_ptab->p_status = P_STOPPED;
			udata.u_ptab->p_event = j;
			psleep(NULL);
                }
		/* This is more complex than in V7 - we have multiple
		   behaviours (plus the unimplemented as yet core dump) */
		if (*svec == SIG_DFL) {
			/* SIGCONT is subtle - we woke the process to handle
			   the signal so ignoring here works fine */
			if (j == SIGCHLD || j == SIGURG || j == SIGSTOP ||
                            j == SIGTTIN || j == SIGTTOU ||
			    j == SIGIO || j == SIGCONT || udata.u_ptab->p_pid == 1) {
				udata.u_ptab->p_pending &= ~m;	// unset the bit
				continue;
			}
			/* FIXME: core dump on some signals */
#ifdef DEBUG
			kprintf("process terminated by signal %d\n", j);
#endif
                        doexit(dump_core(j));
		} else if (*svec != SIG_IGN) {
			/* Arrange to call the user routine at return */
			udata.u_ptab->p_pending &= ~m;	// unset the bit
#ifdef DEBUG
			kprintf("about to process signal %d\n", j);
#endif
			udata.u_cursig = j;
			break;
		}
	}
}
Esempio n. 13
0
inline size_t add2(size_t a, size_t b)
{
  size_t sum = a + b;
  if (sum < a) {
    fprintf(stderr, "\nInteger overflow\n");
    doexit(5);
  }
  return sum;
}
void
fatal(char *msg1, char *msg2, char *msg3) { /* Not to be called except */
    if (msg1) {				    /* from this module */
    	xSerialxPrintf_P(&xSerialPort,PSTR("%s: %s"),xname,msg1);
	if (msg2) xSerialxPrintf_P(&xSerialPort,PSTR("%s"),msg2);
	if (msg3) xSerialxPrintf_P(&xSerialPort,PSTR("%s"),msg3);
	xSerialxPrint_P(&xSerialPort,PSTR("\n"));
    }
    doexit(FAILURE);
}
Esempio n. 15
0
void growstr(dynstr *str, size_t newlen)
{
  if (newlen < str->alloc)
    return;
  str->buf = realloc(str->buf, str->alloc = add2(newlen, 1));
  if (!str->buf) {
    fprintf(stderr, "\nOut of memory 4\n");
    doexit(4);
  }
}
Esempio n. 16
0
int main(int argc,char **argv)
#endif
{
	short filenum=(-1);

	RDA_SOFTWARE_TYPE=RDA_XPERT_AND_LITE_APP;
	if(InitializeSubsystems(argc,argv,"BFTMGT","MTN BFTMDAC")) 
	{
		RDAAPPMAINLOOP();
		return;
	}
	MTNMASTER=MaintainMasterNew("BFTMGT","MTN BFTMDAC");
	if(findMaintainMaster(MTNMASTER))
	{
		ERRORDIALOG("MAINTAIN MTNMASTER NOT FOUND.","The Maintain Master function wasn't found.",NULL,TRUE);
		prterr("Error Maintain Master Definition not found, this process cannot be executed without it's definition [%s] in the [%s.MTN] library.","MTN BFTMDAC",MTNMASTER->module);
		doexit(NULL);
	} else {
		if((filenum=APPOPNNRDEDITABLE(MTNMASTER->module,"BFTMDAC",&editable))==(-1))
		{
			doexit(NULL);
			return;
		}
		if(!OPEN_MASTER_FILES(MTNMASTER))
		{
			doexit(NULL);
			return;
		}
		MTNMASTER->passkey=READPassKey(filenum);
		MTNMASTER->inheritrsrcs=FALSE;
		switch(MTNMASTER->start_with)
		{
			default:
			case 0:
				bftmdacm(1,NULL);
				break;
			case 1:
				browse_bftmdac(NULL,NULL);
				break;
		}
	}
	RDAAPPMAINLOOP();
}
Esempio n. 17
0
void main(int argc,char **argv)
{
	short filenum=(-1);

	if(InitializeSubsystems(argc,argv,"POSTRK","MTN POSGRAT")) 
	{
		RDAAPPMAINLOOP();
		return;
	}
	MASTER=MaintainMasterNew("POSTRK","MTN POSGRAT");
	PAYROLL_SETUP=RDApayrollNEW();
	getpayrollbin(PAYROLL_SETUP);
	if(findMaintainMaster(MASTER))
	{
		ERRORDIALOG("MAINTAIN MASTER NOT FOUND.","The Maintain Master function wasn't found.",NULL,TRUE);
		prterr("Error Maintain Master Definition not found, this process cannot be executed without it's definition [%s] in the [%s.MTN] library.","MTN POSGRAT",MASTER->module);
		doexit(NULL);
	} else {
		if((filenum=APPOPNNRDEDITABLE(MASTER->module,"POSGRAT",&editable))==(-1))
		{
			doexit(NULL);
			return;
		}
		if(!OPEN_MASTER_FILES(MASTER))
		{
			doexit(NULL);
			return;
		}
		MASTER->passkey=READPassKey(filenum);
		MASTER->inheritrsrcs=TRUE;
		switch(MASTER->start_with)
		{
			default:
			case 0:
				posgratm(1,NULL);
				break;
			case 1:
				browse_posgrat(NULL,NULL);
				break;
		}
	}
	RDAAPPMAINLOOP();
}
Esempio n. 18
0
int main(int argc,char **argv)
#endif
{
	short filenum=(-1);
	char *warnmessage=NULL,*module=NULL,*mtnname=NULL;

	RDA_SOFTWARE_TYPE=RDA_XPERT_AND_LITE_APP;
	module="APPMGT";
	mtnname="ADD APPLICANTS";
	if(InitializeSubsystems(argc,argv,module,mtnname))
	{
		RDAAPPMAINLOOP();
		return;
	}
	MTNMASTER=MaintainMasterNew(module,mtnname);
	if(findMaintainMaster(MTNMASTER))
	{
		warnmessage=Rmalloc(300+RDAstrlen(MTNMASTER->module)+RDAstrlen(mtnname));
		sprintf(warnmessage,"Error Maintain Master Definition not found, this process cannot be executed without it's definition [%s] in the [%s.MTN] library.",mtnname,MTNMASTER->module);
		ERRORDIALOG("MAINTAIN MTNMASTER NOT FOUND.",warnmessage,NULL,TRUE);
		prterr("%s",warnmessage);
		if(warnmessage!=NULL) Rfree(warnmessage);
		doexit(NULL);
	} else {
		if((filenum=APPOPNNRDEDITABLE(MTNMASTER->module,"APPCNT",&editable))==(-1))
		{
			doexit(NULL);
			return;
		}
		if(!OPEN_MASTER_FILES(MTNMASTER))
		{
			doexit(NULL);
			return;
		}
		MTNMASTER->passkey=READPassKey(filenum);
		MTNMASTER->inheritrsrcs=FALSE;
		mtndmg(NULL);
	}
	RDAAPPMAINLOOP();
}
Esempio n. 19
0
void usage(bool isHelp)
{
    printf("Usage:\n");
    printf("   copyexp <file>                     -- returns compress type\n");
    printf("   copyexp <file> <destination>       -- copies file to destination\n");
    printf("                                         (expanding as needed)\n");
    printf("   copyexp -z <file> <dest>           -- compresses file (LZW)\n");
    printf("   copyexp -f <file> <dest>           -- compresses file (FastLZ)\n");
    printf("   copyexp -r <recsz> <file> <dest>   -- compresses file (RowDif)\n");
    printf("   copyexp -fs <file> <dest>          -- compresses file (FastLZ stream)\n");
    printf("           -s                         -- timing stats\n");
    doexit(isHelp ? 0 : 2);
}
Esempio n. 20
0
/* This sees if the current process has any signals set, and handles them.
 */
void chksigs(void)
{
	uint8_t j;
	uint32_t pending = udata.u_ptab->p_pending & ~udata.u_ptab->p_held;
	int (**svec)(int) = &udata.u_sigvec[0];
	uint32_t m;

	// any signals pending?
	if (!pending)
		return;

	// dispatch the lowest numbered signal
	for (j = 1; j < NSIGS; ++j) {
		svec++;
		m = sigmask(j);
		if (!(m & pending))
			continue;
		/* This is more complex than in V7 - we have multiple
		   behaviours (plus the unimplemented as yet core dump) */
		if (*svec == SIG_DFL) {
			/* SIGCONT is subtle - we woke the process to handle
			   the signal so ignoring here works fine */
			if (j == SIGCHLD || j == SIGURG ||
			    j == SIGIO || j == SIGCONT || udata.u_ptab->p_pid == 1) {
				udata.u_ptab->p_pending &= ~m;	// unset the bit
				continue;
			}
			/* FIXME: core dump on some signals */
#ifdef DEBUG
			kputs("process terminated by signal: ");
#endif
			doexit(0, j);
		} else if (*svec != SIG_IGN) {
			/* Arrange to call the user routine at return */
			udata.u_ptab->p_pending &= ~m;	// unset the bit
#ifdef DEBUG
			kprintf("about to process signal %d\n", j);
#endif
			udata.u_cursig = j;
			break;
		}
	}
}
Esempio n. 21
0
void signal_frame(uint8_t *trapframe, uint32_t d0, uint32_t d1, uint32_t a0,
	uint32_t a1)
{
	extern void *udata_shadow;
	uint8_t *usp = get_usp();
	udata_ptr = udata_shadow;
	uint16_t ccr = *(uint16_t *)trapframe;
	uint32_t addr = *(uint32_t *)(trapframe + 2);
	int err = 0;

	/* Build the user stack frame */

	/* FIXME: eventually we should put the trap frame details and trap
	   info into the frame */
	usp -= 4;
	err |= uputl(addr, usp);
	usp -= 4;
	err |= uputw(ccr, usp);
	usp -= 2;
	err |=uputl(a1, usp);
	usp -= 4;
	err |= uputl(a0, usp);
	usp -= 4;
	err |= uputl(d1, usp);
	usp -= 4;
	err |= uputl(d0, usp);
	usp -= 4;
	err |= uputl(udata.u_codebase + 4, usp);
	set_usp(usp);

	if (err) {
		kprintf("%d: stack fault\n", udata.u_ptab->p_pid);
		doexit(dump_core(SIGKILL));
	}
	/* Now patch up the kernel frame */
	*(uint16_t *)trapframe = 0;
	*(uint32_t *)(trapframe + 2) = (uint32_t)udata.u_sigvec[udata.u_cursig];
	udata.u_sigvec[udata.u_cursig] = SIG_DFL;
	udata.u_cursig = 0;
}
Esempio n. 22
0
int telnet_main(int argc, char **argv)
{
	char *host;
	int port;
	int len;
#ifdef USE_POLL
	struct pollfd ufds[2];
#else
	fd_set readfds;
	int maxfd;
#endif

	INIT_G();

#if ENABLE_FEATURE_AUTOWIDTH
	get_terminal_width_height(0, &G.win_width, &G.win_height);
#endif

#if ENABLE_FEATURE_TELNET_TTYPE
	G.ttype = getenv("TERM");
#endif

	if (tcgetattr(0, &G.termios_def) >= 0) {
		G.do_termios = 1;
		G.termios_raw = G.termios_def;
		cfmakeraw(&G.termios_raw);
	}

	if (argc < 2)
		bb_show_usage();

#if ENABLE_FEATURE_TELNET_AUTOLOGIN
	if (1 & getopt32(argv, "al:", &G.autologin))
		G.autologin = getenv("USER");
	argv += optind;
#else
	argv++;
#endif
	if (!*argv)
		bb_show_usage();
	host = *argv++;
	port = bb_lookup_port(*argv ? *argv++ : "telnet", "tcp", 23);
	if (*argv) /* extra params?? */
		bb_show_usage();

	G.netfd = create_and_connect_stream_or_die(host, port);

	setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &const_int_1, sizeof(const_int_1));

	signal(SIGINT, fgotsig);

#ifdef USE_POLL
	ufds[0].fd = 0; ufds[1].fd = G.netfd;
	ufds[0].events = ufds[1].events = POLLIN;
#else
	FD_ZERO(&readfds);
	FD_SET(STDIN_FILENO, &readfds);
	FD_SET(G.netfd, &readfds);
	maxfd = G.netfd + 1;
#endif

	while (1) {
#ifndef USE_POLL
		fd_set rfds = readfds;

		switch (select(maxfd, &rfds, NULL, NULL, NULL))
#else
		switch (poll(ufds, 2, -1))
#endif
		{
		case 0:
			/* timeout */
		case -1:
			/* error, ignore and/or log something, bay go to loop */
			if (G.gotsig)
				conescape();
			else
				sleep(1);
			break;
		default:

#ifdef USE_POLL
			if (ufds[0].revents) /* well, should check POLLIN, but ... */
#else
			if (FD_ISSET(STDIN_FILENO, &rfds))
#endif
			{
				len = read(STDIN_FILENO, G.buf, DATABUFSIZE);
				if (len <= 0)
					doexit(EXIT_SUCCESS);
				TRACE(0, ("Read con: %d\n", len));
				handlenetoutput(len);
			}

#ifdef USE_POLL
			if (ufds[1].revents) /* well, should check POLLIN, but ... */
#else
			if (FD_ISSET(G.netfd, &rfds))
#endif
			{
				len = read(G.netfd, G.buf, DATABUFSIZE);
				if (len <= 0) {
					write_str(1, "Connection closed by foreign host\r\n");
					doexit(EXIT_FAILURE);
				}
				TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len));
				handlenetinput(len);
			}
		}
	}
}
Esempio n. 23
0
void rf (const char *name)
{
  struct stat st, st2, st3;
  const size_t namelen = strlen(name);
  nobjects++;
  if (lstat (name, &st))
    return;
  if (st.st_dev != dev && !force) {
    if (dev) {
      fprintf(stderr, "%s is on different filesystem than the rest.\nUse -f option to override.\n", name);
      doexit(6);
    }
    dev = st.st_dev;
  }
  if (S_ISDIR (st.st_mode)) {
    d * dp = malloc(add3(sizeof(d), namelen, 1));
    if (!dp) {
      fprintf(stderr, "\nOut of memory 3\n");
      doexit(3);
    }
    memcpy(dp->name, name, namelen + 1);
    dp->next = dirs;
    dirs = dp;
  } else if (S_ISREG (st.st_mode)) {
    int fd, i;
    f * fp, * fp2;
    h * hp;
    const char *n1, *n2;
    int cksumsize = sizeof(buf);
    unsigned int cksum;
    time_t mtime = content_only ? 0 : st.st_mtime;
    unsigned int hsh = hash (st.st_size, mtime);
    off_t fsize;
    nregfiles++;
    if (verbose > 1)
      fprintf(stderr, "  %s", name);
    fd = open (name, O_RDONLY);
    if (fd < 0) return;
    if (st.st_size < sizeof(buf)) {
      cksumsize = st.st_size;
      memset (((char *)buf) + cksumsize, 0, (sizeof(buf) - cksumsize) % sizeof(buf[0]));
    }
    if (read (fd, buf, cksumsize) != cksumsize) {
      close(fd);
      if (verbose > 1 && namelen <= NAMELEN)
        fprintf(stderr, "\r%*s\r", (int)(namelen + 2), "");
      return;
    }
    cksumsize = (cksumsize + sizeof(buf[0]) - 1) / sizeof(buf[0]);
    for (i = 0, cksum = 0; i < cksumsize; i++) {
      if (cksum + buf[i] < cksum)
        cksum += buf[i] + 1;
      else
        cksum += buf[i];
    }
    for (hp = hps[hsh]; hp; hp = hp->next)
      if (hp->size == st.st_size && hp->mtime == mtime)
        break;
    if (!hp) {
      hp = malloc(sizeof(h));
      if (!hp) {
        fprintf(stderr, "\nOut of memory 1\n");
        doexit(1);
      }
      hp->size = st.st_size;
      hp->mtime = mtime;
      hp->chain = NULL;
      hp->next = hps[hsh];
      hps[hsh] = hp;
    }
    for (fp = hp->chain; fp; fp = fp->next)
      if (fp->cksum == cksum)
        break;
    for (fp2 = fp; fp2 && fp2->cksum == cksum; fp2 = fp2->next)
      if (fp2->ino == st.st_ino && fp2->dev == st.st_dev) {
        close(fd);
        if (verbose > 1 && namelen <= NAMELEN)
          fprintf(stderr, "\r%*s\r", (int)(namelen + 2), "");
        return;
      }
    for (fp2 = fp; fp2 && fp2->cksum == cksum; fp2 = fp2->next)
      if (!lstat (fp2->name, &st2) && S_ISREG (st2.st_mode) &&
          !stcmp (&st, &st2, content_only) &&
          st2.st_ino != st.st_ino &&
          st2.st_dev == st.st_dev) {
        int fd2 = open (fp2->name, O_RDONLY);
        if (fd2 < 0) continue;
        if (fstat (fd2, &st2) || !S_ISREG (st2.st_mode) || st2.st_size == 0) {
          close (fd2);
          continue;
        }
        ncomp++;
	lseek(fd, 0, SEEK_SET);
	for (fsize = st.st_size; fsize > 0; fsize -= NIOBUF) {
	  off_t rsize = fsize >= NIOBUF ? NIOBUF : fsize;
	  if (read (fd, iobuf1, rsize) != rsize || read (fd2, iobuf2, rsize) != rsize) {
	    close(fd);
	    close(fd2);
	    fprintf(stderr, "\nReading error\n");
	    return;
	  }
	  if (memcmp (iobuf1, iobuf2, rsize)) break;
	}
	close(fd2);
	if (fsize > 0) continue;
        if (lstat (name, &st3)) {
          fprintf(stderr, "\nCould not stat %s again\n", name);
          close(fd);
          return;
        }
        st3.st_atime = st.st_atime;
        if (stcmp (&st, &st3, 0)) {
          fprintf(stderr, "\nFile %s changed underneath us\n", name);
          close(fd);
          return;
        }
        n1 = fp2->name;
        n2 = name;
        if (!no_link) {
          const char *suffix = ".$$$___cleanit___$$$";
          const size_t suffixlen = strlen(suffix);
          size_t n2len = strlen(n2);
          dynstr nam2 = {NULL, 0};
          growstr(&nam2, add2(n2len, suffixlen));
          memcpy(nam2.buf, n2, n2len);
          memcpy(&nam2.buf[n2len], suffix, suffixlen + 1);
          if (rename (n2, nam2.buf)) {
            fprintf(stderr, "\nFailed to rename %s to %s\n", n2, nam2.buf);
            free(nam2.buf);
            continue;
          }
          if (link (n1, n2)) {
            fprintf(stderr, "\nFailed to hardlink %s to %s\n", n1, n2);
            if (rename (nam2.buf, n2)) {
              fprintf(stderr, "\nBad bad - failed to rename back %s to %s\n", nam2.buf, n2);
            }
            close(fd);
            free(nam2.buf);
            return;
          }
          unlink (nam2.buf);
          free(nam2.buf);
        }
        nlinks++;
        if (st3.st_nlink > 1) {
	  /* We actually did not save anything this time, since the link second argument
	     had some other links as well.  */
          if (verbose > 1)
            fprintf(stderr, "\r%*s\r%s %s to %s\n", (int)(((namelen > NAMELEN) ? 0 : namelen) + 2), "", (no_link ? "Would link" : "Linked"), n1, n2);
        } else {
          nsaved+=((st.st_size+4095)/4096)*4096;
          if (verbose > 1)
            fprintf(stderr, "\r%*s\r%s %s to %s, %s %ld\n", (int)(((namelen > NAMELEN) ? 0 : namelen) + 2), "", (no_link ? "Would link" : "Linked"), n1, n2, (no_link ? "would save" : "saved"), st.st_size);
	}
        close(fd);
        return;
      }
    fp2 = malloc(add3(sizeof(f), namelen, 1));
    if (!fp2) {
      fprintf(stderr, "\nOut of memory 2\n");
      doexit(2);
    }
    close(fd);
    fp2->ino = st.st_ino;
    fp2->dev = st.st_dev;
    fp2->cksum = cksum;
    memcpy(fp2->name, name, namelen + 1);
    if (fp) {
      fp2->next = fp->next;
      fp->next = fp2;
    } else {
      fp2->next = hp->chain;
      hp->chain = fp2;
    }
    if (verbose > 1 && namelen <= NAMELEN)
      fprintf(stderr, "\r%*s\r", (int)(namelen + 2), "");
    return;
  }
}
Esempio n. 24
0
int main(int argc, char *argv[])
{
    int sockfd;
    //int numbytes;
    //char buf[MAXDATASIZE];
    struct addrinfo hints, *servinfo, *p;
    int rv;
    char s[INET6_ADDRSTRLEN];

    if (argc != 3) {
        fprintf(stderr,"usage: client hostname port\n");
        exit(1);
    }

    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    if ((rv = getaddrinfo(argv[1], argv[2], &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    // loop through all the results and connect to the first we can
    for(p = servinfo; p != NULL; p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("client: socket");
            continue;
        }

        if (connect(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("client: connect");
            continue;
        }

        break;
    }

    if (p == NULL) {
        fprintf(stderr, "client: failed to connect\n");
        return 2;
    }

    inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
            s, sizeof s);
    printf("client: connecting to %s\n", s);

    freeaddrinfo(servinfo); // all done with this structure

    printf("cmd load = %d\n",doload(sockfd));
    printf("cmd uptime= %d\n", douptime(sockfd));
    printf("cmd invalidrc = %d\n", doinvalid(sockfd));
    printf("cmd sleeptimeoutrc = %d\n", dosleep(sockfd));
    printf("cmd exitrc = %d\n ", doexit(sockfd)	);

    close(sockfd);

    return 0;
}
Esempio n. 25
0
File: quine.c Progetto: kahrs/cda
int
rdata(void)
{
	int s, c;
	long v;

	if(ndc < 0)
		ndc = 0;
	if(ndc) {
		for(s=0; s<ndc; s++) {
			itmp[itmpp++] =  dctmp[s];
			if(itmpp >= NTMP) {
				fprintf(stderr, "rdata: no room\n");
#ifdef PLAN9
				exits("rdata no room");
#else
				exit(1);
#endif
			}
		}
		ndc = -1;
		return 0;
	}
	mask = ~0L;

loop:
	s = symb();
	if(s == EON)
		return 1;
	if(s == ITER) {
		fprintf(stdout, ".r");
		for(;;) {
			c = gchar();
			if(c < 0)
				goto loop;
			putchar(c);
			if(c == '\n')
				goto loop;
		}
	}
 	if(s == EXTERN) {
 		fprintf(stdout, ".x");
 		while((c = gchar()) != '\n') putchar(c);
 		putchar(c);
 		goto loop;
 	}
	if(s != OUT)
		expect(".o");
	fflush(stdout);
	fprintf(stdout, ".o");
	for(;;) {
		s = symb();
		if(s == NUMB) {
			fprintf(stdout, " %ld", numb);
			continue;
		}
		if(s == NAME) {
			fprintf(stdout, " %s", name);
			continue;
		}
		break;
	}
	fprintf(stdout, "\n");
	if(s != LINE)
		expect("new line");
	for(;;) {
		s = symb();
		if(s == LINE)
			continue;
		if(s != NUMB)
			break;
		v = numb;
		c = symb();
		if(c != COLON && c != PERC)
			expect(":");
		s = symb();
		if(s != NUMB)
			expect("number");
		if(c == PERC) {
			if(ndc >= NDC) {
				fprintf(stderr, "NDC(%d) too small\n", NDC);
				doexit(1);
			}
			dctmp[ndc++] = v;
		}
		if(mask == ~0L)
			mask = numb;
		else
		if(mask != numb) {
			fprintf(stderr, "whoops, masks different\n");
#ifdef PLAN9
			exits("whoooops, masks different");
#else
			exit(1);
#endif
		}
		v &= mask;
		if((itmpp == 0) || (itmp[itmpp-1] < v)) {
			itmp[itmpp++] = v;
			if(itmpp >= NTMP) {
				fprintf(stderr, "rdata: no room\n");
#ifdef PLAN9
				exits("rdata no room");
#else
				exit(1);
#endif
			}
			continue;
		}
		if(itmp[itmpp-1] > v) {
			fprintf(stderr, "input not sorted\n");
#ifdef PLAN9
				exits("input not sorted");
#else
				exit(1);
#endif
		}
	}
	peeks = s;
	return 0;
}
Esempio n. 26
0
int main(int argc, char **argv)
{
  int ch;
  int i;
  dynstr nam1 = {NULL, 0};
  while ((ch = getopt (argc, argv, "cnvhf")) != -1) {
    switch (ch) {
    case 'n':
      no_link++;
      break;
    case 'v':
      verbose++;
      break;
    case 'c':
      content_only++;
      break;
    case 'f':
      force=1;
      break;
    case 'h':
    default:
      usage(argv[0]);
    }
  }
  if (optind >= argc)
    usage(argv[0]);
  for (i = optind; i < argc; i++)
    rf(argv[i]);
  while (dirs) {
    DIR *dh;
    struct dirent *di;
    d * dp = dirs;
    size_t nam1baselen = strlen(dp->name);
    dirs = dp->next;
    growstr(&nam1, add2(nam1baselen, 1));
    memcpy(nam1.buf, dp->name, nam1baselen);
    free (dp);
    nam1.buf[nam1baselen++] = '/';
    nam1.buf[nam1baselen] = 0;
    dh = opendir (nam1.buf);
    if (dh == NULL)
      continue;
    ndirs++;
    while ((di = readdir (dh)) != NULL) {
      if (!di->d_name[0])
        continue;
      if (di->d_name[0] == '.') {
        char *q;
        if (!di->d_name[1] || !strcmp (di->d_name, "..") || !strncmp (di->d_name, ".in.", 4))
          continue;
        q = strrchr (di->d_name, '.');
        if (q && strlen (q) == 7 && q != di->d_name) {
          nam1.buf[nam1baselen] = 0;
          if (verbose)
            fprintf(stderr, "Skipping %s%s\n", nam1.buf, di->d_name);
          continue;
        }
      }
      {
        size_t subdirlen;
        growstr(&nam1, add2(nam1baselen, subdirlen = strlen(di->d_name)));
        memcpy(&nam1.buf[nam1baselen], di->d_name, add2(subdirlen, 1));
      }
      rf(nam1.buf);
    }
    closedir(dh);
  }
  doexit(0);
  return 0;
}
Esempio n. 27
0
void _exit (int iExCode) 
{
  _TestExit(iExCode);
  doexit(iExCode, 1, 0);	/* quick term, kill process */
}
Esempio n. 28
0
void exit (int iExCode)
{
  _TestExit(iExCode);
  doexit(iExCode, 0, 0);	/* full term, kill process */
}
Esempio n. 29
0
	//--------------------------------------------------------------------------------
	//Deconstruct the bootstrap to clean up at the end of the process
	CModuleBootStrap::~CModuleBootStrap()
	{
		m_bStaticInitialised = false;
		doexit();
	}
extern int telnet_main(int argc, char** argv)
{
	int len;
	struct sockaddr_in s_in;
#ifdef USE_POLL
	struct pollfd ufds[2];
#else
	fd_set readfds;
	int maxfd;
#endif

#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
	int opt;
#endif

#ifdef CONFIG_FEATURE_AUTOWIDTH
	get_terminal_width_height(0, &win_width, &win_height);
#endif

#ifdef CONFIG_FEATURE_TELNET_TTYPE
    ttype = getenv("TERM");
#endif

	memset(&G, 0, sizeof G);

	if (tcgetattr(0, &G.termios_def) < 0)
		exit(1);

	G.termios_raw = G.termios_def;
	cfmakeraw(&G.termios_raw);

	if (argc < 2)
		bb_show_usage();

#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN
	autologin = NULL;
	while ((opt = getopt(argc, argv, "al:")) != EOF) {
		switch (opt) {
			case 'l':
				autologin = optarg;
				break;
			case 'a':
				autologin = getenv("USER");
				break;
			case '?':
				bb_show_usage();
				break;
		}
	}
	if (optind < argc) {
		bb_lookup_host(&s_in, argv[optind++]);
		s_in.sin_port = bb_lookup_port((optind < argc) ? argv[optind++] :
				"telnet", "tcp", 23);
		if (optind < argc)
			bb_show_usage();
	} else
		bb_show_usage();
#else
	bb_lookup_host(&s_in, argv[1]);
	s_in.sin_port = bb_lookup_port((argc == 3) ? argv[2] : "telnet", "tcp", 23);
#endif

	G.netfd = xconnect(&s_in);

	setsockopt(G.netfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof one);

	signal(SIGINT, fgotsig);

#ifdef USE_POLL
	ufds[0].fd = 0; ufds[1].fd = G.netfd;
	ufds[0].events = ufds[1].events = POLLIN;
#else
	FD_ZERO(&readfds);
	FD_SET(0, &readfds);
	FD_SET(G.netfd, &readfds);
	maxfd = G.netfd + 1;
#endif

	while (1)
	{
#ifndef USE_POLL
		fd_set rfds = readfds;

		switch (select(maxfd, &rfds, NULL, NULL, NULL))
#else
		switch (poll(ufds, 2, -1))
#endif
		{
		case 0:
			/* timeout */
		case -1:
			/* error, ignore and/or log something, bay go to loop */
			if (G.gotsig)
				conescape();
			else
				sleep(1);
			break;
		default:

#ifdef USE_POLL
			if (ufds[0].revents) /* well, should check POLLIN, but ... */
#else
			if (FD_ISSET(0, &rfds))
#endif
			{
				len = read(0, G.buf, DATABUFSIZE);

				if (len <= 0)
					doexit(0);

				TRACE(0, ("Read con: %d\n", len));

				handlenetoutput(len);
			}

#ifdef USE_POLL
			if (ufds[1].revents) /* well, should check POLLIN, but ... */
#else
			if (FD_ISSET(G.netfd, &rfds))
#endif
			{
				len = read(G.netfd, G.buf, DATABUFSIZE);

				if (len <= 0)
				{
					WriteCS(1, "Connection closed by foreign host.\r\n");
					doexit(1);
				}
				TRACE(0, ("Read netfd (%d): %d\n", G.netfd, len));

				handlenetinput(len);
			}
		}
	}
}