[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ProgSoc] Synchronise a file to a remote machine in real time
On Mon, 2006-06-05 at 10:00 +0000, John Elliot wrote:
> Raz suggests:
>
> foo@B $ ssh A tail -f logfile >logfile-copy
>
> So, the best explanation I can conjure so far is that the shell on B
> forks an ssh-client process which establishes an encrypted channel to A
Spot-on, but note that, after calling fork() and, in the child process,
prior to calling exec*("/usr/bin/ssh", ...), the shell on B opens
logfile-copy for writing (with O_CREATE set, thereby creating it if it
wasn't already there) and arranges for it to be file descriptor #1, i.e.
stdout. This could be arranged by careful sequence of close() and open()
calls, but more likely happens with dup2(). Thereafter, ssh-client's
parent (the shell) is not involved in handling stdout, the ssh-client is
writing directly to the file descriptor #1 which the shell helpfully
connected to logfile-copy.
(This is in contrast to the situation on A where tail's parent (sshd)
_is_ involved in processing stdout. In this case, it has arranged for
the child's (tail's) stdout to be connected to one end of a kernel pipe
(see pipe(2)) and is listening on the other end in order to get the
unencrypted data to encrypt and send to ssh-client on B.)
> with a shell on A listening on the other end. "tail -f logfile" is then
> run on A with its stdout picked up by the ssh server on A, which sends
> it over the encrypted channel back to B, where the shell process running
> on B has redirected that stream to the <something> which owns the
Erm, the encrypted stream goes to ssh-client on B which, after
decrypting it, writes it to stdout which, just prior to exec*(), the
shell helpfully connected to the file logfile-copy.
> write-lock required to spit the data to the file system on B where the
> logfile-copy file resides.
What's with all this lock stuff? This is not Windows you know...
- Raz
-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.