示例#1
0
void searchdaemon::go() {

	/* let search engine get at logger */
	engine.setlogger(&_log);

	/* fork off listeners */
	_log.lprintf( logger::DEBUG, "Looks good: %d\n", getpid() );
	childunix=0;
	childinet=0;

	/* fork off a unix listener .. */
	if( _options.get_bool( "ListenUnix" ) ) {
		_log.lprintf( logger::DEBUG, "Forking UNIX domain listener\n" );
		if( (childunix=fork())==0 ) {
			listener unix_listen( _log, _options.get_string( "UnixSocket" ) );
			listenloop( unix_listen );
		}
	}

	/* .. and an inet listeneer */
	if( _options.get_bool( "ListenInet" ) ) {
		_log.lprintf( logger::DEBUG, "Forking inet domain listener\n" );
		if( (childinet=fork())==0 ) {
			listener inet_listen( _log, _options.get_string( "BindAddress" ), _options.get_int( "ListenPort" ) );
			listenloop( inet_listen );
		}
	}

	signal( SIGTERM, handler_term );

	/* now just chill for a bit */
   while( childunix != 0 || childinet != 0 ) {
     pid_t child = wait( NULL );
     if( child==childunix ) childunix = 0;
     if( child==childinet ) childinet = 0;
   }
	exit( 0 );
}
int main(int argc, char** argv) {
	int listen_on_port, connect_to_port;
	if (argc<3) {
		usage();
		exit(1);
	}
	listen_on_port=atoi(argv[1]);
	connect_to_port=atoi(argv[2]);
	if (! listen_on_port || ! connect_to_port ) {
		fprintf(stderr, "ports must be "
			"numeric and non-zero\n\n");
		usage();
		exit(2);
	}

	set_child_handler();
	return listenloop(listen_on_port, connect_to_port);
}
示例#3
0
void
main(int argc, char *argv[])
{
	char *listfile;
	int ctlfd, fd, n;
	char buf[Arbpathlen], path[Arbpathlen];

	rfork(RFNOTEG);
	toppid = getpid();
	shell = "/bin/rc -il";
	ARGBEGIN {
	case 'd':
		debug++;
		break;
	case 'i':
		idstring = EARGF(usage());
		break;
	case 'n':
		nsfile = EARGF(usage());
		break;
	case 'R':
		prevent = 1;
		/* fall through */
	case 'r':
		restdir = EARGF(usage());
		break;
	case 's':
		sflag = 1;
		shell = EARGF(usage());
		break;
	case 'S':
		srvpt = EARGF(usage());
		break;
	case 't':
		tflag = 1;
		break;
	default:
		usage();
		break;
	} ARGEND;

	errfd = -1;
	if (debug)
		errfd = 2;

	/* work out network connection's directory */
	if (argc >= 1)
		netdir = argv[0];
	else				/* invoked by listen1 */
		netdir = getenv("net");
	if (netdir == nil) {
		syslog(0, "ssh", "server netdir is nil");
		exits("nil netdir");
	}
	syslog(0, "ssh", "server netdir is %s", netdir);

	uname = getenv("user");
	if (uname == nil)
		uname = "none";

	/* extract dfd and cfd from netdir */
	ctlfd = getctlfd();
	fd = getdatafd(ctlfd);

	n = read(fd, buf, sizeof buf - 1);
	if (n < 0) {
		syslog(0, "ssh", "server read error for data file: %r");
		hangup(ctlfd);
		exits("read cap");
	}
	close(fd);
	authnewns(ctlfd, buf, sizeof buf, n);

	/* get connection number in buf */
	n = read(ctlfd, buf, sizeof buf - 1);
	buf[n >= 0? n: 0] = '\0';

	/* tell netssh our id string */
	fd2path(ctlfd, path, sizeof path);
	if (0 && idstring) {			/* was for coexistence */
		syslog(0, "ssh", "server conn %s, writing \"id %s\" to %s",
			buf, idstring, path);
		fprint(ctlfd, "id %s", idstring);
	}

	/* announce */
	fprint(ctlfd, "announce session");

	/* construct listen file name */
	listfile = smprint("%s/%s/listen", netdir, buf);
	if (listfile == nil) {
		syslog(0, "ssh", "out of memory");
		exits("out of memory");
	}
	syslog(0, "ssh", "server listen is %s", listfile);

	mounttunnel(ctlfd);
	listenloop(listfile, ctlfd, buf, sizeof buf);
	hangup(ctlfd);
	exits(nil);
}