usr.bin/rdist/server.c
/*
 * Server routine to read requests and process them.
 * Commands are:
 *	Tname	- Transmit file if out of date
 *	Vname	- Verify if file out of date or not
 *	Qname	- Query if file exists. Return mtime & size if it does.
 */
Server routine to read requests and process them.
Commands are:
Tname   - Transmit file if out of date
Vname   - Verify if file out of date or not
Qname   - Query if file exists. Return mtime & size if it does.
Server routine to read requests and process them . Commands are : Tname - Transmit file if out of date Vname - Verify if file out of date or not Qname - Query if file exists . Return mtime & size if it does .
void
server()
{
	char cmdbuf[BUFSIZ];
	register char *cp;
	signal(SIGHUP, cleanup);
	signal(SIGINT, cleanup);
	signal(SIGQUIT, cleanup);
	signal(SIGTERM, cleanup);
	signal(SIGPIPE, cleanup);
	rem = 0;
	oumask = umask(0);
	(void) sprintf(buf, "V%d\n", VERSION);
	(void) write(rem, buf, strlen(buf));
	for (;;) {
		cp = cmdbuf;
		if (read(rem, cp, 1) <= 0)
			return;
		if (*cp++ == '\n') {
			error("server: expected control record\n");
			continue;
		}
		do {
			if (read(rem, cp, 1) != 1)
				cleanup(0);
		} while (*cp++ != '\n' && cp < &cmdbuf[BUFSIZ]);
		*--cp = '\0';
		cp = cmdbuf;
		switch (*cp++) {
		case 'T':  
			catname = 1;	
			goto dotarget;
		case 't':  
			catname = 0;
		dotarget:
			if (exptilde(target, cp) == NULL)
				continue;
			tp = target;
			while (*tp)
				tp++;
			ack();
			continue;
		case 'R':  
			recvf(cp, S_IFREG);
			continue;
		case 'D':  
			recvf(cp, S_IFDIR);
			continue;
		case 'K':  
			recvf(cp, S_IFLNK);
			continue;
		case 'k':  
			hardlink(cp);
			continue;
		case 'E':  
			*tp = '\0';
			if (catname <= 0) {
				error("server: too many 'E's\n");
				continue;
			}
			tp = stp[--catname];
			*tp = '\0';
			ack();
			continue;
		case 'C':  
			clean(cp);
			continue;
		case 'Q':  
			query(cp);
			continue;
		case 'S':  
			dospecial(cp);
			continue;
#ifdef notdef
		case 'X':  
			except = bp = NULL;
		case 'x':  
			if (*cp == '\0') {
				ack();
				continue;
			}
			if (*cp == '~') {
				if (exptilde(buf, cp) == NULL)
					continue;
				cp = buf;
			}
			if (bp == NULL)
				except = bp = expand(makeblock(NAME, cp), E_VARS);
			else
				bp->b_next = expand(makeblock(NAME, cp), E_VARS);
			while (bp->b_next != NULL)
				bp = bp->b_next;
			ack();
			continue;
		case 'I':  
			opts = 0;
			while (*cp >= '0' && *cp <= '7')
				opts = (opts << 3) | (*cp++ - '0');
			if (*cp++ != ' ') {
				error("server: options not delimited\n");
				return;
			}
			install(cp, opts);
			continue;
		case 'L':  
			log(lfp, cp);
			continue;
#endif
		case '\1':
			nerrs++;
			continue;
		case '\2':
			return;
		default:
			error("server: unknown command '%s'\n", cp);
		case '\0':
			continue;
		}
	}
}
void server ( ) { char cmdbuf [ BUFSIZ ] ; register char * cp ; signal ( SIGHUP , cleanup ) ; signal ( SIGINT , cleanup ) ; signal ( SIGQUIT , cleanup ) ; signal ( SIGTERM , cleanup ) ; signal ( SIGPIPE , cleanup ) ; rem = 0 ; oumask = umask ( 0 ) ; ( void ) sprintf ( buf , " \n " , VERSION ) ; ( void ) write ( rem , buf , strlen ( buf ) ) ; for ( ; ; ) { cp = cmdbuf ; if ( read ( rem , cp , 1 ) <= 0 ) return ; if ( * cp ++ == ' \n ' ) { error ( " \n " ) ; continue ; } do { if ( read ( rem , cp , 1 ) != 1 ) cleanup ( 0 ) ; } while ( * cp ++ != ' \n ' && cp < & cmdbuf [ BUFSIZ ] ) ; * -- cp = ' \0 ' ; cp = cmdbuf ; switch ( * cp ++ ) { case ' ' : catname = 1 ; goto dotarget ; case ' ' : catname = 0 ; dotarget : if ( exptilde ( target , cp ) == NULL ) continue ; tp = target ; while ( * tp ) tp ++ ; ack ( ) ; continue ; case ' ' : recvf ( cp , S_IFREG ) ; continue ; case ' ' : recvf ( cp , S_IFDIR ) ; continue ; case ' ' : recvf ( cp , S_IFLNK ) ; continue ; case ' ' : hardlink ( cp ) ; continue ; case ' ' : * tp = ' \0 ' ; if ( catname <= 0 ) { error ( " \n " ) ; continue ; } tp = stp [ -- catname ] ; * tp = ' \0 ' ; ack ( ) ; continue ; case ' ' : clean ( cp ) ; continue ; case ' ' : query ( cp ) ; continue ; case ' ' : dospecial ( cp ) ; continue ; #ifdef notdef case ' ' : except = bp = NULL ; case ' ' : if ( * cp == ' \0 ' ) { ack ( ) ; continue ; } if ( * cp == ' ' ) { if ( exptilde ( buf , cp ) == NULL ) continue ; cp = buf ; } if ( bp == NULL ) except = bp = expand ( makeblock ( NAME , cp ) , E_VARS ) ; else bp -> b_next = expand ( makeblock ( NAME , cp ) , E_VARS ) ; while ( bp -> b_next != NULL ) bp = bp -> b_next ; ack ( ) ; continue ; case ' ' : opts = 0 ; while ( * cp >= ' ' && * cp <= ' ' ) opts = ( opts << 3 ) | ( * cp ++ - ' ' ) ; if ( * cp ++ != ' ' ) { error ( " \n " ) ; return ; } install ( cp , opts ) ; continue ; case ' ' : log ( lfp , cp ) ; continue ; #endif case ' \1 ' : nerrs ++ ; continue ; case ' \2 ' : return ; default : error ( " \n " , cp ) ; case ' \0 ' : continue ; } } }
Server routine to read requests and process them.
Server routine to read requests and process them .
/* init target file/directory name */ /* target should be directory */ /* init target file/directory name */ /* Transfer a regular file. */ /* Transfer a directory. */ /* Transfer symbolic link. */ /* Transfer hard link. */ /* End. (of directory) */ /* Clean. Cleanup a directory */ /* Query. Does the file/directory exist? */ /* Special. Execute commands */ /*
		 * These entries are reserved but not currently used.
		 * The intent is to allow remote hosts to have master copies.
		 * Currently, only the host rdist runs on can have masters.
		 */ /* start a new list of files to exclude */ /* add name to list of files to exclude */ /* Install. Transfer file if out of date. */ /* Log. save message in log file */