Date: Tue, 23 Jan 2007 10:46:46 GMT From: Terry Vernon<tvernon24@comcast.net> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/108238: the tail command acts weird when reading from a file that's being simultaneously written to Message-ID: <200701231046.l0NAkkhj079655@www.freebsd.org> Resent-Message-ID: <200701231050.l0NAoIrt042588@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 108238 >Category: bin >Synopsis: the tail command acts weird when reading from a file that's being simultaneously written to >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Jan 23 10:50:17 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Terry Vernon >Release: 6.2-STABLE >Organization: NerdNOS >Environment: FreeBSD nerdnos 6.2-STABLE FreeBSD 6.2-STABLE #2: Tue Jan 23 00:50:47 CST 2007 root@nerdnos:/usr/obj/usr/src/sys/STREAMLINE i386 >Description: I wrote a simple program in C to make a list of IP style addresses for fun. I wanted to time it piping output to a file and periodically check the file with tail to see how it was coming along. Tail starts acting erratically and eventually latches on to the file being written but is showing incorrect values in the numbers and won't end when you told it to. similar to this: (window 1) time ./ipgen > outfile (window 2) tail -20 outfile The first few times you issue the tail command it does what you would expect but hit your up arrow to repeat the command a few times in succession and you'll see the anomoly. I don't know how or why it does it but thought I'd bring it up in case there's the chance some 0-day security hole could be prepared to exploit it somehow or another. I'll include my make.conf file, and my kernel conf file so you can see how my system is setup, including dmesg.boot output. I've done the make buildworld process using this make.conf file so possibly the optimization flags could play a role but again I'm unsure. [make.conf] CFLAGS=-march=pentium3 -O2 -pipe MAKEOPTS=-j16 CXXFLAGS=${CFLAGS} # added by use.perl 2006-11-22 23:52:34 PERL_VER=5.8.8 PERL_VERSION=5.8.8 [dmesg.boot] Copyright (c) 1992-2007 The FreeBSD Project. Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994 The Regents of the University of California. All rights reserved. FreeBSD is a registered trademark of The FreeBSD Foundation. FreeBSD 6.2-STABLE #2: Tue Jan 23 00:50:47 CST 2007 root@nerdnos:/usr/obj/usr/src/sys/STREAMLINE MPTable: <IBM ENSW Osceola SMP > Timecounter "i8254" frequency 1193182 Hz quality 0 CPU: Pentium III/Pentium III Xeon/Celeron (549.98-MHz 686-class CPU) Origin = "GenuineIntel" Id = 0x673 Stepping = 3 Features=0x383fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE> real memory = 2415865856 (2303 MB) avail memory = 2364243968 (2254 MB) FreeBSD/SMP: Multiprocessor System Detected: 4 CPUs cpu0 (BSP): APIC ID: 3 cpu1 (AP): APIC ID: 0 cpu2 (AP): APIC ID: 1 cpu3 (AP): APIC ID: 2 ioapic0: Assuming intbase of 0 ioapic1: Assuming intbase of 24 ioapic1 <Version 1.1> irqs 24-47 on motherboard ioapic0 <Version 1.1> irqs 0-23 on motherboard kbd1 at kbdmux0 cpu0 on motherboard cpu1 on motherboard cpu2 on motherboard cpu3 on motherboard pcib0: <MPTable Host-PCI bridge> pcibus 0 on motherboard pci0: <PCI bus> on pcib0 isab0: <PCI-ISA bridge> at device 0.0 on pci0 isa0: <ISA bus> on isab0 atapci0: <Intel PIIX4 UDMA33 controller> port 0x1f0-0x1f7,0x3f6,0x170-0x177,0x376,0x450-0x45f at device 0.1 on pci0 ata0: <ATA channel 0> on atapci0 ata1: <ATA channel 1> on atapci0 uhci0: <Intel 82371AB/EB (PIIX4) USB controller> port 0x460-0x47f irq 18 at device 0.2 on pci0 uhci0: [GIANT-LOCKED] usb0: <Intel 82371AB/EB (PIIX4) USB controller> on uhci0 usb0: USB revision 1.0 uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1 uhub0: 2 ports with 2 removable, self powered piix0: <PIIX Timecounter> port 0x440-0x44f at device 0.3 on pci0 Timecounter "PIIX" frequency 3579545 Hz quality 0 pcib1: <MPTable PCI-PCI bridge> at device 1.0 on pci0 pci1: <PCI bus> on pcib1 pci1: <bridge> at device 2.0 (no driver attached) ahc0: <Adaptec aic7895 Ultra SCSI adapter> port 0x3100-0x31ff mem 0xa7010000-0xa7010fff irq 15 at device 4.0 on pci1 ahc0: [GIANT-LOCKED] aic7895C: Ultra Wide Channel A, SCSI Id=7, 32/253 SCBs ahc1: <Adaptec aic7895 Ultra SCSI adapter> port 0x3200-0x32ff mem 0xa7011000-0xa7011fff irq 16 at device 4.1 on pci1 ahc1: [GIANT-LOCKED] aic7895C: Ultra Wide Channel B, SCSI Id=7, 32/253 SCBs pci0: <display, VGA> at device 10.0 (no driver attached) tx0: <SMC EtherPower II 10/100> port 0x2000-0x20ff mem 0xa78ff000-0xa78fffff irq 34 at device 11.0 on pci0 miibus0: <MII bus> on tx0 qsphy0: <QS6612 10/100 media interface> on miibus0 qsphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto type SMC9432TX tx0: [GIANT-LOCKED] tx0: Ethernet address: 00:e0:29:3e:d1:3a tx0: if_start running deferred for Giant pcib4: <MPTable Host-PCI bridge> pcibus 4 on motherboard pci4: <PCI bus> on pcib4 ips0: <IBM ServeRAID Adapter> port 0x6000-0x60ff mem 0xd3100000-0xd31fffff irq 33 at device 10.0 on pci4 pcib10: <MPTable Host-PCI bridge> pcibus 10 on motherboard pci10: <PCI bus> on pcib10 bge0: <Broadcom BCM5701 B5, ASIC rev. 0x105> mem 0xfebf0000-0xfebfffff irq 25 at device 2.0 on pci10 miibus1: <MII bus> on bge0 brgphy0: <BCM5701 10/100/1000baseTX PHY> on miibus1 brgphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseTX, 1000baseTX-FDX, auto bge0: Ethernet address: 00:02:a5:e7:66:a0 bge1: <Broadcom BCM5701 B5, ASIC rev. 0x105> mem 0xfebe0000-0xfebeffff irq 26 at device 3.0 on pci10 miibus2: <MII bus> on bge1 brgphy1: <BCM5701 10/100/1000baseTX PHY> on miibus2 brgphy1: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseTX, 1000baseTX-FDX, auto bge1: Ethernet address: 00:02:a5:e7:69:47 pmtimer0 on isa0 orm0: <ISA Option ROMs> at iomem 0xc0000-0xc7fff,0xc8000-0xc87ff on isa0 atkbdc0: <Keyboard controller (i8042)> at port 0x60,0x64 on isa0 atkbd0: <AT Keyboard> irq 1 on atkbdc0 kbd0 at atkbd0 atkbd0: [GIANT-LOCKED] psm0: <PS/2 Mouse> irq 12 on atkbdc0 psm0: [GIANT-LOCKED] psm0: model IntelliMouse, device ID 3 ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0 ppc0: Generic chipset (NIBBLE-only) in COMPATIBLE mode ppbus0: <Parallel port bus> on ppc0 ppi0: <Parallel I/O> on ppbus0 lpt0: <Printer> on ppbus0 lpt0: Interrupt-driven port sc0: <System console> at flags 0x100 on isa0 sc0: VGA <16 virtual consoles, flags=0x300> sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0 sio0: type 16550A sio1 at port 0x2f8-0x2ff irq 3 on isa0 sio1: type 16550A vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0 unknown: <PNP0501> can't assign resources (port) unknown: <PNP0501> can't assign resources (port) unknown: <PNP0401> can't assign resources (port) unknown: <PNP0f13> can't assign resources (irq) unknown: <PNP0c01> can't assign resources (memory) unknown: <PNP0303> can't assign resources (port) Timecounters tick every 1.000 msec ad0: 78167MB <Maxtor 6Y080L0 YAR41VW0> at ata0-master UDMA33 Waiting 5 seconds for SCSI devices to settle ips0: reinitializing adapter, this could take several minutes. ips0: adapter type: ServeRAID 3L (clarinet lite) ips0: logical drives: 1 ips0: Logical Drive 0: RAID5 sectors: 35545088, state OK ipsd0: <Logical Drive> on ips0 ipsd0: Logical Drive (17356MB) SMP: AP CPU #3 Launched! SMP: AP CPU #2 Launched! SMP: AP CPU #1 Launched! Trying to mount root from ufs:/dev/ipsd0s1a [KERNCONF] machine i386 cpu I686_CPU ident STREAMLINE # To statically compile in device wiring instead of /boot/device.hints #hints "GENERIC.hints" # Default places to look for devices. options SCHED_4BSD # scheduler, ULE is slow right now options PREEMPTION # Enable kernel thread preemption options EXT2FS options INET # InterNETworking options INET6 # IPv6 communications protocols options FFS # Berkeley Fast Filesystem options SOFTUPDATES # Enable FFS soft updates support options UFS_ACL # Support for access control lists options UFS_DIRHASH # Improve performance on big directories options MD_ROOT # MD is a potential root device options NFSCLIENT # Network Filesystem Client options NFSSERVER # Network Filesystem Server options NFS_ROOT # NFS usable as /, requires NFSCLIENT options MSDOSFS # MSDOS Filesystem options CD9660 # ISO 9660 Filesystem options PROCFS # Process filesystem (requires PSEUDOFS) options PSEUDOFS # Pseudo-filesystem framework options GEOM_GPT # GUID Partition Tables. options COMPAT_43 # Compatible with BSD 4.3 [KEEP THIS!] options COMPAT_FREEBSD4 # Compatible with FreeBSD4 options COMPAT_FREEBSD5 # Compatible with FreeBSD5 options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI options SYSVSHM # SYSV-style shared memory options SYSVMSG # SYSV-style message queues options SYSVSEM # SYSV-style semaphores options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time options KBD_INSTALL_CDEV # install a CDEV entry in /dev options ADAPTIVE_GIANT # Giant mutex is adaptive. device apic # I/O APIC # Bus support. device eisa device pci # ATA and ATAPI devices device ata device atadisk # ATA disk drives device atapicd # ATAPI CDROM drives options ATA_STATIC_ID # Static device numbering # SCSI Controllers device ahc # AHA2940 and onboard AIC7xxx devices device aic # Adaptec 15[012]x SCSI adapters, AIC-6[23]60. # SCSI peripherals device scbus # SCSI bus (required for SCSI) device da # Direct Access (disks) device cd # CD device pass # Passthrough device (direct SCSI access) device ses # SCSI Environmental Services (and SAF-TE) # RAID controllers interfaced to the SCSI subsystem device ips # IBM (Adaptec) ServeRAID # atkbdc0 controls both the keyboard and the PS/2 mouse device atkbdc # AT keyboard controller device atkbd # AT keyboard device psm # PS/2 mouse device kbdmux # keyboard multiplexer device vga # VGA video card driver device splash # Splash screen and screen saver support # syscons is the default console driver, resembling an SCO console device sc device agp # support several AGP chipsets # Power management support (see NOTES for more options) device apm # Add suspend/resume support for the i8254. device pmtimer # Serial (COM) ports device sio # 8250, 16[45]50 based serial ports # Parallel port device ppc device ppbus # Parallel port bus (required) device lpt # Printer device ppi # Parallel port interface device # PCI Ethernet NICs that use the common MII bus controller code. # NOTE: Be sure to keep the 'device miibus' line in order to use these NICs! device miibus # MII bus support device bge # Broadcom BCM570xx Gigabit Ethernet device tx # SMC EtherPower II (83c170 ``EPIC'') # Pseudo devices. device loop # Network loopback device random # Entropy device device ether # Ethernet support device sl # Kernel SLIP device ppp # Kernel PPP device tun # Packet tunnel. device pty # Pseudo-ttys (telnet etc) device md # Memory "disks" device gif # IPv6 and IPv4 tunneling device faith # IPv6-to-IPv4 relaying (translation) # The `bpf' device enables the Berkeley Packet Filter. # Be aware of the administrative consequences of enabling this! # Note that 'bpf' is required for DHCP. device bpf # Berkeley packet filter # USB support device uhci # UHCI PCI->USB interface device usb # USB Bus (required) options SMP >How-To-Repeat: here's the code to my script that I wrote that helped me see the issue. [ipgen.c]++++++++++++++++++++CUT/PASTE+++++++++++++++++++++++++ #include <stdio.h> int main() { int a,b,c,d; a = b = c = d = 0; while (a != 255){ d++; if (d == 255){ c++; d = 0;} if (c == 255){ b++; c = 0;} if (b == 255){ a++; b = 0;} printf("%d.%d.%d.%d\n", a, b, c, d); }return 0;} ++++++++++++++++++++++++CUT/PASTE++++++++++++++++++++++++++++ Compile this with: gcc -march=pentium3 -O2 ipgen.c -o ipgen Then run the program: time ./ipgen > outfile Then try to view 20 lines of output with tail at another console window: tail -20 outfile This is when all the weirdness begins on my system. I'm viewing through an ssh connection from putty on a windows 2k machine over a wifi network. Sometimes it does it on the first try and sometimes it takes up to 6 tries but eventually the numbers aren't right in what the screen shows and the last stage just keeps scrolling as if you had used tail -f. The numbers appear to be earlier in the sequence than where they really are. >Fix: I don't know where to even start. Could be my compiler flags and architecture, could be ssh is somehow omitting the -20 flag for tail by means of network related screwup. >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200701231046.l0NAkkhj079655>