BusyBox Bug and Patch Tracking
BusyBox
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0005124 [BusyBox] Documentation minor always 09-23-08 20:43 09-26-08 05:25
Reporter DanLiang View Status public  
Assigned To BusyBox
Priority normal Resolution fixed  
Status closed   Product Version 1.12.x
Summary 0005124: vi in busybox always writes files with length 0
Description I use buildroot to create a rootfs and test it.

My configuration is
uclibc-0.9.29
gcc-4.2.4
busybox-1.12.0

When I try to modify a existing file or create a new one with vi, after I save the contents and exit from vi, the file length is always 0 and all the contents are lost.

In file vi.c, I find if I comment out the line "ftruncate(fd, charcnt);" in function "static int file_write(char *fn, char *first, char *last)", everything is OK.
Additional Information busybox-1.11.2 seems to have the same problem
Attached Files  trace_vi.log [^] (7,172 bytes) 09-25-08 23:36
 trace_test.log [^] (1,697 bytes) 09-25-08 23:36
 local.tar.bz2 [^] (10,318 bytes) 09-26-08 05:24

- Relationships

- Notes
(0011854)
vda
09-24-08 04:14

Please add this debugging code:

        charcnt = full_write(fd, first, cnt);
bb_error_msg("file_write: cnt:%d charcnt:%d", cnt, charcnt);
sleep(5);
        ftruncate(fd, charcnt);

and let me know what do you see when you try to save a file.
 
(0011934)
DanLiang
09-24-08 19:20

Hi vda

when I try to save a file, a message is printed out like this:
vi: file_write: cnt:10 charcnt:10.
Variable 'cnt' always has the same value with 'charcnt'.
which means no matter what value I pass to ftruncate(), it will truncate the file length to 0.

But it's very strange when I wrote a small program:
---------------------------------------------------
#include <unistd.h>
#include <fcntl.h>

int main()
{
        char buf[] = "test";
        int fd, cnt, charcnt;

        fd = open("test.txt", (O_RDWR | O_CREAT), 0666);
        if (fd < 0)
                return -1;
        cnt = sizeof(buf);
        buf[cnt-1] = 0x0A;
        charcnt = write(fd, buf, cnt);
        ftruncate(fd, charcnt);
        if (charcnt == cnt) {
        // good write
        //file_modified = FALSE;
        } else {
                charcnt = 0;
        }
        close(fd);
        return charcnt;
}
---------------------------------------------------
I tested it on my ARM board, and it's ok with string "test" in that file.
 
(0012084)
vda
09-25-08 14:30

Can you strace vi? "strace -o s.log vi ..."
Do the same with your test program.
Look how ftruncate's are different in the logs.
If you can't figure it out, just attach strace logs to this bug.
 
(0012124)
DanLiang
09-25-08 23:39
edited on: 09-26-08 00:35

Hi vda,

trace_vi.log is logged when I tried to write string "abcd" into file abc.txt.

trace_test.log is logged when the samll program is run.

In trace_vi.log, ftruncate64 is called, while in trace_test.log, ftruncate is called.

In source code "vi.c" ftruncate() is called.

If I rewrite the samll test program to explicitly use ftruncate64, a weird file size 21474836485 is seen.

 
(0012134)
vda
09-26-08 02:41

Does it help if you replace

ftruncate(fd, charcnt);

with

ftruncate(fd, (off_t)charcnt);

?
 
(0012144)
DanLiang
09-26-08 03:04

It has the same result. :-(
 
(0012154)
vda
09-26-08 03:43

Looks like your libc or kernel mishandle ftruncate64(). Which version of kernel is it?
 
(0012184)
bernhardf
09-26-08 04:40

What arch (and if arm, which ABI) do you use? How did you build your toolchain?
 
(0012194)
DanLiang
09-26-08 05:20

kernel version: linux-2.6.26.2
ABI: EABI
I configred the buildroot to build an arm cross toolchain. The version for buildroot is 23434.

Here is the config file in the attachment.
 
(0012204)
bernhardf
09-26-08 05:25

ftruncate on ARM EABI was fixed in uClibc trunk a day or two ago.
 

- Issue History
Date Modified Username Field Change
09-23-08 20:43 DanLiang New Issue
09-23-08 20:43 DanLiang Status new => assigned
09-23-08 20:43 DanLiang Assigned To  => BusyBox
09-24-08 01:14 DanLiang Issue Monitored: DanLiang
09-24-08 04:14 vda Note Added: 0011854
09-24-08 19:20 DanLiang Note Added: 0011934
09-25-08 14:30 vda Note Added: 0012084
09-25-08 23:36 DanLiang File Added: trace_vi.log
09-25-08 23:36 DanLiang File Added: trace_test.log
09-25-08 23:39 DanLiang Note Added: 0012124
09-26-08 00:28 DanLiang Note Edited: 0012124
09-26-08 00:35 DanLiang Note Edited: 0012124
09-26-08 02:41 vda Note Added: 0012134
09-26-08 03:04 DanLiang Note Added: 0012144
09-26-08 03:43 vda Note Added: 0012154
09-26-08 04:40 bernhardf Note Added: 0012184
09-26-08 05:20 DanLiang Note Added: 0012194
09-26-08 05:24 DanLiang File Added: local.tar.bz2
09-26-08 05:25 bernhardf Status assigned => closed
09-26-08 05:25 bernhardf Note Added: 0012204
09-26-08 05:25 bernhardf Resolution open => fixed


Copyright © 2000 - 2006 Mantis Group
Powered by Mantis Bugtracker