Okay, since I notice that io_set_nonblocking() and
io_set_close_on_exec()
set flags without querying the flags that are already set and then
or'ing with the new flags to set I patched my lsh to query flags,
or, and set flags. This fixed the mangled ~/.lsh/captured_keys
problem for me - new keys are now appended correctly. I'm not
sure, however, what other parts of lsh this might also affect. Who
knows, it might create or fix other bugs . . .
PS. I'd send a patch but that would be the equivalent of exporting
a nuclear missle or something similar . . . I'm sure, however,
that everyone can figure out what I'm talking about because, like
I said, I am _not_ a programmer . . . ;^)
Thayne Harbaugh wrote:
>
> I (finally) strace'd my lsh to find out why lsh isn't appending
> keys to the file. It appears to be the same problem that Eric
> mentions:
>
> open("/home/thayne/.lsh/captured_keys", O_WRONLY|O_APPEND|O_CREAT, 0600)
> = 5
> fcntl(5, F_SETFL, O_RDONLY|O_NONBLOCK) = 0
> fcntl(5, F_SETFD, FD_CLOEXEC) = 0
>
> <more stuff>
>
> write(5, "\n; ACL for host foo.northsky"..., 500) = 500
> poll([{fd=7, events=POLLIN|POLLRDNORM}, {fd=5, events=POLLOUT,
> revents=POLLOUT}], 2, 100) = 1
> write(5, "GBzUjTkW4VvQBz0feHbh4LERHVvVmVOF"..., 241) = 241
>
> <more stuff>
>
> And there is no close(5) - Same as what Eric mentions.
>
> seems strange that F_SETFL is trying to set O_RDONLY . . .
>
> I also notice that in io.c there are io_set_nonblocking() and
> io_set_close_on_exec which uses F_SETFL and F_SETFD (respectively)
> without prior doing a F_GETFL and F_GETFD, or'ing the bits with
> the O_NONBLOCK and FD_CLOEXEC, and then using F_SETFL and F_SETFD
> respectively.
>
> seems strange again . . .
>
> What do I know, I'm not a real programmer - I just play one on TV . . .
>
> "Eric J. Schwertfeger" wrote:
> >
> > On Fri, 7 Jan 2000, Thayne Harbaugh wrote:
> >
> > > "Eric J. Schwertfeger" wrote:
> > > >
> > > > On 7 Jan 2000, Niels M�ller wrote:
> > > >
> > > > > Copying keys from captured_keys to known_hosts should work.
> > > >
> > > > It didn't, I'll look into that more this lunch, and maybe this weekend.
> > > >
> > >
> > > Make sure you don't have an extra line of garbage on the end of your
> > > captured key - similar to my problem. No, I haven't spent the moment
> > > to further investigate my problem.
> >
> > That was the problem. I deleted the file, ran lsh, and had no garbage in
> > the file. Ran lsh again, and still no garbage. Replaced captured_keys with
> > 100 lines of "testing\n", this time got garbage at the end of the line.
> >
> > Looked at the truss output:
> >
> > syscall open("/home/ejs/.lsh/captured_keys",521,0600)
> >
> > 521 is O_APPEND|O_CREAT|O_WRONLY so that looks right.
> >
> > syscall fcntl(0x6,0x4,0x4)
> >
> > 0x4 is F_SETFL
> >
> > syscall fcntl(0x6,0x2,0x1)
> >
> > 0x2 is F_SETFD
> >
> > syscall write(6,0x808540c,500)
> >
> > syscall write(6,0x8085600,213)
> >
> > And we never close the file? the F_SETFD is setting close_on_exec though.
> >
> > I've never played with fcntl, but somehow lsh is getting the OS to ignore
> > the O_APPEND flag.