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

unpack: use cextras for semaphore #285

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion subprojects/cextras.wrap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[wrap-git]
directory = cextras
revision = f3478d1e00d38846af03bd776d92336fbcf6e1f7
revision = d063e11e5e3dd6fb1f9486f2ffa29c6b4e4a00be
url = https://github.com/Gottox/cextras.git
depth = 1

Expand Down
11 changes: 8 additions & 3 deletions tools/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ tool_sources = [
'src/unpack.c',
]

tool_dependencies = [
libsqsh_dep,
cextras_dep,
]

c_args = ['-DVERSION="@0@"'.format(meson.project_version())]

tools = {}
Expand All @@ -21,7 +26,7 @@ foreach src : tool_sources
c_args: c_args,
include_directories: tools_private_include,
install: not meson.is_subproject(),
dependencies: libsqsh_dep,
dependencies: tool_dependencies,
)
tools += {tool_name: tool}
endforeach
Expand All @@ -33,7 +38,7 @@ if fuse3_dep.found()
c_args: c_args,
include_directories: tools_private_include,
install: not meson.is_subproject(),
dependencies: [libsqsh_dep, fuse3_dep],
dependencies: tool_dependencies + [fuse3_dep],
)
tools += {'sqshfs': tool}
endif
Expand All @@ -50,7 +55,7 @@ if fuse2_dep.found()
c_args: c_args,
include_directories: tools_private_include,
install: not meson.is_subproject() and not fuse3_dep.found(),
dependencies: [libsqsh_dep, fuse2_dep],
dependencies: tool_dependencies + [fuse2_dep],
)
tools += {'sqshfs2': tool}
endif
14 changes: 7 additions & 7 deletions tools/src/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@

#include <sqshtools_common.h>

#include <cextras/concurrency.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -48,7 +48,7 @@
typedef int (*extract_fn)(
const char *, enum SqshFileType, const struct SqshFile *);

sem_t file_descriptor_sem;
struct CxSemaphore file_descriptor_sem;
size_t extracted_files = 0;
bool do_chown = false;
bool verbose = false;
Expand Down Expand Up @@ -189,7 +189,7 @@ extract_file_after(
fclose(stream);
rv = update_metadata(data->path, file);
out:
sem_post(&file_descriptor_sem);
cx_semaphore_post(&file_descriptor_sem);
if (rv < 0) {
sqsh_perror(rv, data->path);
}
Expand All @@ -214,7 +214,7 @@ extract_file(const char *path, const struct SqshFile *file) {
}
strcpy(data->tmp_filename, ".sqsh-unpack-XXXXXX");

rv = sem_wait(&file_descriptor_sem);
rv = cx_semaphore_wait(&file_descriptor_sem);
if (rv < 0) {
rv = -errno;
perror(path);
Expand Down Expand Up @@ -508,9 +508,9 @@ main(int argc, char *argv[]) {
goto out;
}
// Leave some file descriptors for the rest of the system
rv = sem_init(&file_descriptor_sem, 0, limits.rlim_cur - 32);
rv = cx_semaphore_init(&file_descriptor_sem, limits.rlim_cur - 32);
if (rv < 0) {
perror("sem_init");
perror("cx_semaphore_init");
rv = EXIT_FAILURE;
goto out;
}
Expand Down Expand Up @@ -552,7 +552,7 @@ main(int argc, char *argv[]) {
rv = extract_all(target_path, src_root, extract_second_pass);
}
out:
sem_destroy(&file_descriptor_sem);
cx_semaphore_destroy(&file_descriptor_sem);
sqsh_threadpool_free(threadpool);
sqsh_close(src_root);
sqsh_archive_close(sqsh);
Expand Down
Loading