Thread (18 messages) flat view 18 messages, 5 authors, 2016-06-15

Re: [PATCH] git-daemon server

From: Linus Torvalds <torvalds@osdl.org>
Date: 2016-06-15 22:41:59


On Fri, 3 Jun 2005, McMullan, Jason wrote:
1) I used the stdin/stdout stuff as debugging

2) It works with xinetd

3) Because I can't figure out how to get /bin/sh to give me two pipes
   that hook together two processes. What I really want:

ssh user@remote git server --db /my/git.git <|> git server request HEAD
Ok, so a ssh connection _would_ work per se, and the only real issue is
the pipe itself is one-directional as done by the shell?
Where 'xxx <|>  yyy' means:

	Take process xxx's stdin, hook it to yyy's stdout,
	Take process yyy's stdin, hook it to xxx's stdout,
	Run till they both die.

If you know how to do that, I'd be grateful.
Yeah, you're right, you can't do bi-directional piping with shell, and 
you'd need to do it inside your program. It should be easy enough to do 
with something like adding a new flag that says "--exec", and when seeing 
that, doing something like

	if (!strcmp(argv[i], "--exec")) {
		int fd[2][2];
		pid_t pid;

		if (pipe(fd[0]) < 0 || pipe(fd[1]) < 0)
			die("unable to create pipes");
		pid = fork();
		if (pid < 0)
			die("unable to fork exec process");

		if (!pid) {
			dup2(fd[0][0], 0);
			dup2(fd[1][1], 1);
			close_pipes(fd);
			exit(system(argv[i+1]));
		}
		dup2(fd[1][0], 0);
		dup2(fd[0][1], 1);
		close_pipes(fd);
	}

where "close_pipes()" just looks like

	void close_pipes(int *fd)
	{
		int i;
		for (i = 0; i < 3; i++)
			close(fd[i]);
	}

and as usual, the above is totally and utterly untested. And using 
"system()" is cheezy and does an extra unnecessary fork(), so if you want 
to, it could be better done with just a "execve(/bin/sh -c 'string')" 
approach by hand.

Anyway, with _something_ like the above you could do something like

	git-sync --exec "ssh master.kernel.org git-sync" ....

and it would do the obvious thing.

What do you think?

		Linus
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help