9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] Why isn't there a newline character after the first line of /dev/wsys/wctl?
@ 2010-01-15  1:21 Andrés
  2010-01-15  2:54 ` erik quanstrom
  0 siblings, 1 reply; 2+ messages in thread
From: Andrés @ 2010-01-15  1:21 UTC (permalink / raw)
  To: 9fans

rio(4) says:

wctl may be read. When read, it returns the location of the window as
four decimal integers formatted in the usual 12–character style: upper
left x and y, lower right x and y. Following these numbers are strings
describing the window's state: hidden  or visible; current or
notcurrent. A subsequent read will block until the window changes
size, location, or state.

I'm new to Plan 9, but isn't:

term% read /mnt/wsys/wctl

Supposed to just print the first line?, instead, it prints:

read: error reading /mnt/wsys/wctl: buffer too small

Several guys from #plan9 in Freenode told me that that was happening
because of a missing newline.

olegfink told me how to work around this, with:
dd -count 1 -quiet 1 -if /mnt/wsys/wctl

But, is the current behavior correct? Or is it erroneous?

Greetings.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9fans] Why isn't there a newline character after the first line of /dev/wsys/wctl?
  2010-01-15  1:21 [9fans] Why isn't there a newline character after the first line of /dev/wsys/wctl? Andrés
@ 2010-01-15  2:54 ` erik quanstrom
  0 siblings, 0 replies; 2+ messages in thread
From: erik quanstrom @ 2010-01-15  2:54 UTC (permalink / raw)
  To: 9fans

> Supposed to just print the first line?, instead, it prints:
>
> read: error reading /mnt/wsys/wctl: buffer too small
>
> Several guys from #plan9 in Freenode told me that that was happening
> because of a missing newline.

not correct.  it is happening because rio thinks the read
requests too few bytes.  sys/src/cmd/rio/xfid.c:791,796.
read reads 1 byte at a time.  it's not clear that read(5)
expressly allows rio to error here, but it seems reasonable enough.
read(1) uses realloc to allocate its buffer and would hang
looking for a newline if rio allowed 1 byte reads.  if
/mnt/wsys/wctl produced a stream of output with no
newlines, read would eventually fail like this

; time read</dev/zero
read: malloc error: virtual memory allocation failed
156.51u 757.95s 916.67r 	 read  # status= malloc

> But, is the current behavior correct? Or is it erroneous?

while correct and consistent, a newline might have made life
a tad easier for shell scripts.

- erik



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-01-15  2:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-15  1:21 [9fans] Why isn't there a newline character after the first line of /dev/wsys/wctl? Andrés
2010-01-15  2:54 ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).