All pastes #110799 Raw Edit

Stuff

public text v1 · immutable
·published 2006-08-01 22:48 UTC
rendered paste body
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>

/* Only needed for this test */
#include <stdio.h>

int spawn(char* cmdLine) {
	int sv[2];
	socketpair(AF_UNIX, SOCK_STREAM, 0, sv);
	
	if (!fork()) {
		dup2(sv[1], 0);
		dup2(sv[1], 1);
		execl("/bin/sh", "sh", "-c", cmdLine);
	}
	
	close(sv[1]);
	return sv[0];
}

int main(int argc, char** argv) {
	int done = 0;
	if (argc != 2) {
		printf("Usage: %s \"ssh -options\"\n", argv[0]);
		return 1;
	}
	
	int sshSock = spawn(argv[1]);
	while (!done) {
		/* while (socketNotClosed);
		close(sshSock);
		sshSock = spawn(argv[1]);
		*/
	}
	close(sshSock); /* Program is done (never will happen) */
	return 0;
}