Skip to content

Commit e782565

Browse files
authored
[WasmFS] Ignore fcntl F_SETLK (inter-process file locking) (emscripten-core#23694)
This is the current behaviour of the legacy FS and the flock function so it seems reasonable to do the same thing, at least for now. See emscripten-core#23697 This fixes sqlite which makes use of this fcntl to lock the database when accessing it from multiple different processes. Fixes: emscripten-core#23692
1 parent 5dfe0a2 commit e782565

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

src/lib/libsyscall.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,11 @@ var SyscallsLibrary = {
794794
}
795795
case {{{ cDefs.F_SETLK }}}:
796796
case {{{ cDefs.F_SETLKW }}}:
797-
return 0; // Pretend that the locking is successful.
797+
// Pretend that the locking is successful. These are process-level locks,
798+
// and Emscripten programs are a single process. If we supported linking a
799+
// filesystem between programs, we'd need to do more here.
800+
// See https://github.com/emscripten-core/emscripten/issues/23697
801+
return 0;
798802
#if SYSCALL_DEBUG
799803
case {{{ cDefs.F_GETOWN_EX }}}:
800804
case {{{ cDefs.F_SETOWN }}}:

system/lib/libc/emscripten_libc_stubs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ weak void setgrent(void) {
147147
// ==========================================================================
148148

149149
weak int flock(int fd, int operation) {
150-
// int flock(int fd, int operation);
151-
// Pretend to succeed
150+
// Pretend that the locking is successful. These are process-level locks,
151+
// and Emscripten programs are a single process. If we supported linking a
152+
// filesystem between programs, we'd need to do more here.
153+
// See https://github.com/emscripten-core/emscripten/issues/23697
152154
return 0;
153155
}
154156

system/lib/wasmfs/syscalls.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,8 +1521,11 @@ int __syscall_fcntl64(int fd, int cmd, ...) {
15211521
case F_SETLKW: {
15221522
static_assert(F_SETLK == F_SETLK64);
15231523
static_assert(F_SETLKW == F_SETLKW64);
1524-
// Always error for now, until we implement byte-range locks.
1525-
return -EACCES;
1524+
// Pretend that the locking is successful. These are process-level locks,
1525+
// and Emscripten programs are a single process. If we supported linking a
1526+
// filesystem between programs, we'd need to do more here.
1527+
// See https://github.com/emscripten-core/emscripten/issues/23697
1528+
return 0;
15261529
}
15271530
default: {
15281531
// TODO: support any remaining cmds

test/sqlite/test.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,22 @@ int main(){
3232
NULL
3333
};
3434

35-
rc = sqlite3_open(":memory:", &db);
36-
if( rc ){
37-
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
35+
rc = sqlite3_open("test.db", &db);
36+
if (rc) {
37+
printf("Can't open database: %s\n", sqlite3_errmsg(db));
3838
sqlite3_close(db);
3939
exit(1);
4040
}
41+
4142
for (i = 0; commands[i]; i++) {
4243
rc = sqlite3_exec(db, commands[i], callback, 0, &zErrMsg);
43-
if( rc!=SQLITE_OK ){
44-
fprintf(stderr, "SQL error on %d: %s\n", i, zErrMsg);
44+
if (rc != SQLITE_OK){
45+
printf("SQL error on %d: %s\n", i, zErrMsg);
4546
sqlite3_free(zErrMsg);
4647
exit(1);
4748
}
4849
}
50+
4951
sqlite3_close(db);
5052
return 0;
5153
}

test/sqlite/benchmark.out renamed to test/sqlite/test.out

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
count(*) = 2
22

3-
datetime('2012-04-16 12:35:57', '+1 days') = 2012-04-17 12:35:57
4-
53
a = 1
64
b = 13153
75
c = thirteen thousand one hundred fifty three

test/test_core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6642,6 +6642,7 @@ def test_freetype(self):
66426642
@no_asan('local count too large for VMs')
66436643
@no_ubsan('local count too large for VMs')
66446644
@is_slow_test
6645+
@also_with_wasmfs
66456646
@parameterized({
66466647
'': (False,),
66476648
'pthreads': (True,),
@@ -6651,7 +6652,7 @@ def test_sqlite(self, use_pthreads):
66516652
self.emcc_args.append('-pthread')
66526653
self.setup_node_pthreads()
66536654
self.emcc_args += ['-sUSE_SQLITE3']
6654-
self.do_run_in_out_file_test('sqlite/benchmark.c')
6655+
self.do_run_in_out_file_test('sqlite/test.c')
66556656

66566657
@needs_make('mingw32-make')
66576658
@is_slow_test

0 commit comments

Comments
 (0)