Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Darwin, fd_pwrite should respect offset even with append flag #3389

Open
yagehu opened this issue May 7, 2024 · 0 comments · May be fixed by #3390
Open

On Darwin, fd_pwrite should respect offset even with append flag #3389

yagehu opened this issue May 7, 2024 · 0 comments · May be fixed by #3390
Labels
bug Something isn't working

Comments

@yagehu
Copy link
Contributor

yagehu commented May 7, 2024

Summary

I reported this issue with WasmEdge on Linux in #3062. Because of the pwrite/append bug on Linux, other runtimes behave similar to WasmEdge (with the exception of Wasmtime). However, WasmEdge behavior diverges on Darwin.

Specifically, Darwin does not have the Linux pwrite/append bug, so pwrite should write to the specified offset even with append flag.

Current State

No response

Expected State

No response

Reproduction steps

This repro is taken from #3062. Compare the produced file between WasmEdge and some other runtime, e.g. Wasmtime.

#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
    int f = open("tmp/a", O_CREAT | O_WRONLY);
    if (f == -1) {
        perror("open");
	return 1;
    }

    char buf[67];

    int written = write(f, buf, 67);
    printf("written %d\n", written);

    int ret = fcntl(f, F_SETFL, O_APPEND);
    if (ret == -1) {
	perror("fcntl");
	return 1;
    }


    char buf2[102];

    int written2 = pwrite(f, buf2, 102, 0);
    printf("written %d\n", written2);
}

Screenshots

DESCRIPTION

Any logs you want to share for showing the specific issue

No response

Components

CLI

WasmEdge Version or Commit you used

0f11476

Operating system information

Mac OS Darwin Kernel Version 23.4.0

Hardware Architecture

amd64

Compiler flags and options

No response

@yagehu yagehu added the bug Something isn't working label May 7, 2024
yagehu added a commit to yagehu/WasmEdge that referenced this issue May 7, 2024
This commit makes the `fd_pwrite` behave as specified by POSIX when the
fd was opened with the `append` flag.  Specifically, [POSIX][1] says
that `pwrite` should write to the specified offset "regardless of
whether O_APPEND is set".

fixes WasmEdge#3389

[1]: https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/
@yagehu yagehu linked a pull request May 7, 2024 that will close this issue
yagehu added a commit to yagehu/WasmEdge that referenced this issue May 7, 2024
This commit makes the `fd_pwrite` behave as specified by POSIX when the
fd was opened with the `append` flag.  Specifically, [POSIX][1] says
that `pwrite` should write to the specified offset "regardless of
whether O_APPEND is set".

fixes WasmEdge#3389

[1]: https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

Signed-off-by: Yage Hu <me@huyage.dev>
yagehu added a commit to yagehu/WasmEdge that referenced this issue May 7, 2024
This commit makes the `fd_pwrite` behave as specified by POSIX when the
fd was opened with the `append` flag.  Specifically, [POSIX][1] says
that `pwrite` should write to the specified offset "regardless of
whether O_APPEND is set".

fixes WasmEdge#3389

[1]: https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

Signed-off-by: Yage Hu <me@huyage.dev>
yagehu added a commit to yagehu/WasmEdge that referenced this issue May 8, 2024
This commit makes the `fd_pwrite` behave as specified by POSIX when the
fd was opened with the `append` flag.  Specifically, [POSIX][1] says
that `pwrite` should write to the specified offset "regardless of
whether O_APPEND is set".

fixes WasmEdge#3389

[1]: https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

Signed-off-by: Yage Hu <me@huyage.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant