Commit a3d52a18 authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov

This tries to address two issues:

(1) mkostemp with O_DIRECT in flags can fail, leaving a temporary file:

Apparently, O_DIRECT is not working on top of LVM. The problem is
in this case mkostemp() creates the temporary file but still returns
an error, and the temp file is not removed:

 $ ls
 ioping  ioping.1  ioping.c  ioping.o  ioping.spec  Makefile
 $ strace ./ioping -D .
 ....
 open("./ioping.UFuMHz", O_RDWR|O_CREAT|O_EXCL|O_DIRECT, 0600) = -1 EINVAL (Invalid argument)
 ....
 $ ls
 ioping  ioping.1  ioping.c  ioping.o  ioping.UFuMHz  ioping.spec  Makefile

Solution -- do not use flags, apply those later using fcntl()

(2) While trying to rebuild on centos5:

 cc -c -o ioping.o ioping.c -std=c99 -g -Wall -Wextra -pedantic -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
 ioping.c: In function 'main':
 ioping.c:369: warning: implicit declaration of function 'mkostemp'
Signed-off-by: default avatarKir Kolyshkin <kir@openvz.org>
parent 0e36b374
......@@ -366,11 +366,13 @@ int main (int argc, char **argv)
if (!temp)
err(1, NULL);
sprintf(temp, "%s%s", path, tmpl);
fd = mkostemp(temp, flags);
fd = mkstemp(temp);
if (fd < 0)
err(1, "failed to create temporary file at \"%s\"", path);
if (unlink(temp))
err(1, "unlink \"%s\" failed", temp);
if (fcntl(fd, F_SETFL, flags))
err("fcntl failed, please retry without -D");
for (woffset = 0 ; woffset + size <= wsize ; woffset += size) {
if (pwrite(fd, buf, size, offset + woffset) != size)
err(1, "write failed");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment