From: Michael Tremer Date: Wed, 8 Jan 2025 11:45:25 +0000 (+0000) Subject: stripper: Rename to self X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cac687ea93d40591ffb2a57f28004935922f3ff9;p=people%2Fric9%2Fpakfire.git stripper: Rename to self Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/stripper.c b/src/pakfire/stripper.c index 2d8cece71..bbf2e59cf 100644 --- a/src/pakfire/stripper.c +++ b/src/pakfire/stripper.c @@ -57,16 +57,16 @@ struct pakfire_stripper { int sourcesfd; }; -static int pakfire_stripper_open_sources(struct pakfire_stripper* stripper) { +static int pakfire_stripper_open_sources(struct pakfire_stripper* self) { // Open the source directory - stripper->sourcesfd = pakfire_openat(stripper->pakfire, BUILD_SRC_DIR, O_DIRECTORY|O_PATH); - if (stripper->sourcesfd < 0) { + self->sourcesfd = pakfire_openat(self->pakfire, BUILD_SRC_DIR, O_DIRECTORY|O_PATH); + if (self->sourcesfd < 0) { switch (errno) { case ENOENT: break; default: - ERROR(stripper->ctx, "Could not open %s: %m\n", BUILD_SRC_DIR); + ERROR(self->ctx, "Could not open %s: %m\n", BUILD_SRC_DIR); return -errno; } } @@ -76,92 +76,92 @@ static int pakfire_stripper_open_sources(struct pakfire_stripper* stripper) { int pakfire_stripper_create(struct pakfire_stripper** stripper, struct pakfire* pakfire, struct pakfire_jail* jail, const char* path) { - struct pakfire_stripper* s = NULL; + struct pakfire_stripper* self = NULL; int r; // Allocate a new object - s = calloc(1, sizeof(*s)); - if (!s) + self = calloc(1, sizeof(*self)); + if (!self) return -errno; // Store a reference to the context - s->ctx = pakfire_ctx(pakfire); + self->ctx = pakfire_ctx(pakfire); // Store a reference to Pakfire - s->pakfire = pakfire_ref(pakfire); + self->pakfire = pakfire_ref(pakfire); // Store a reference to the jail - s->jail = pakfire_jail_ref(jail); + self->jail = pakfire_jail_ref(jail); // Initialize the reference counter - s->nrefs = 1; + self->nrefs = 1; // Initialize file descriptors - s->sourcesfd = -EBADF; + self->sourcesfd = -EBADF; // Store the path - r = pakfire_string_set(s->path, path); + r = pakfire_string_set(self->path, path); if (r < 0) goto ERROR; // Create a filelist - r = pakfire_filelist_create(&s->filelist, s->pakfire); + r = pakfire_filelist_create(&self->filelist, self->pakfire); if (r < 0) goto ERROR; // Create a list for the sources - r = pakfire_filelist_create(&s->sources, s->pakfire); + r = pakfire_filelist_create(&self->sources, self->pakfire); if (r < 0) goto ERROR; // Open the source directory - r = pakfire_stripper_open_sources(s); + r = pakfire_stripper_open_sources(self); if (r < 0) goto ERROR; // Return the pointer - *stripper = pakfire_stripper_ref(s); + *stripper = pakfire_stripper_ref(self); ERROR: - if (s) - pakfire_stripper_unref(s); + if (self) + pakfire_stripper_unref(self); return r; } -static void pakfire_stripper_free(struct pakfire_stripper* stripper) { - if (stripper->sources) - pakfire_filelist_unref(stripper->sources); - if (stripper->sourcesfd) - close(stripper->sourcesfd); - if (stripper->filelist) - pakfire_filelist_unref(stripper->filelist); - if (stripper->pakfire) - pakfire_unref(stripper->pakfire); - if (stripper->jail) - pakfire_jail_unref(stripper->jail); - if (stripper->ctx) - pakfire_ctx_unref(stripper->ctx); - free(stripper); +static void pakfire_stripper_free(struct pakfire_stripper* self) { + if (self->sources) + pakfire_filelist_unref(self->sources); + if (self->sourcesfd) + close(self->sourcesfd); + if (self->filelist) + pakfire_filelist_unref(self->filelist); + if (self->pakfire) + pakfire_unref(self->pakfire); + if (self->jail) + pakfire_jail_unref(self->jail); + if (self->ctx) + pakfire_ctx_unref(self->ctx); + free(self); } -struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* stripper) { - ++stripper->nrefs; +struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* self) { + ++self->nrefs; - return stripper; + return self; } -struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* stripper) { - if (--stripper->nrefs > 0) - return stripper; +struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* self) { + if (--self->nrefs > 0) + return self; - pakfire_stripper_free(stripper); + pakfire_stripper_free(self); return NULL; } static int pakfire_stripper_find_elf( struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { - struct pakfire_stripper* stripper = data; + struct pakfire_stripper* self = data; int r; // Never try to strip any firmware @@ -170,7 +170,7 @@ static int pakfire_stripper_find_elf( // Add ELF files to the filelist if (pakfire_file_matches_class(file, PAKFIRE_FILE_ELF)) { - r = pakfire_filelist_add(stripper->filelist, file); + r = pakfire_filelist_add(self->filelist, file); if (r < 0) return r; } @@ -181,22 +181,22 @@ static int pakfire_stripper_find_elf( /* Scan all files in path and identify ELF files */ -static int pakfire_stripper_scan(struct pakfire_stripper* stripper) { +static int pakfire_stripper_scan(struct pakfire_stripper* self) { struct pakfire_filelist* filelist = NULL; int r; // Create a new filelist - r = pakfire_filelist_create(&filelist, stripper->pakfire); + r = pakfire_filelist_create(&filelist, self->pakfire); if (r < 0) goto ERROR; // Scan path for all files - r = pakfire_filelist_scan(filelist, stripper->path, NULL, NULL, 0); + r = pakfire_filelist_scan(filelist, self->path, NULL, NULL, 0); if (r < 0) goto ERROR; // Walk through all files to find ELF files - r = pakfire_filelist_walk(filelist, pakfire_stripper_find_elf, stripper, 0, NULL); + r = pakfire_filelist_walk(filelist, pakfire_stripper_find_elf, self, 0, NULL); if (r < 0) goto ERROR; @@ -209,7 +209,7 @@ ERROR: static int pakfire_stripper_collect_sources( struct pakfire_ctx* ctx, struct pakfire_elf* elf, const char* filename, void* data) { - struct pakfire_stripper* stripper = data; + struct pakfire_stripper* self = data; struct pakfire_file* file = NULL; int r; @@ -218,16 +218,16 @@ static int pakfire_stripper_collect_sources( return 0; // Don't add files more than once - if (pakfire_filelist_contains(stripper->sources, filename)) + if (pakfire_filelist_contains(self->sources, filename)) return 0; // Create a new file object - r = pakfire_file_create(&file, stripper->pakfire, filename); + r = pakfire_file_create(&file, self->pakfire, filename); if (r < 0) goto ERROR; // Add the file to the list - r = pakfire_filelist_add(stripper->sources, file); + r = pakfire_filelist_add(self->sources, file); if (r < 0) goto ERROR; @@ -240,7 +240,7 @@ ERROR: static int pakfire_stripper_copy_sources( struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { - struct pakfire_stripper* stripper = data; + struct pakfire_stripper* self = data; struct stat st = {}; char p[PATH_MAX]; FILE* dst = NULL; @@ -258,7 +258,7 @@ static int pakfire_stripper_copy_sources( goto ERROR; // Open the source file - fd = openat(stripper->sourcesfd, p, O_RDONLY); + fd = openat(self->sourcesfd, p, O_RDONLY); if (fd < 0) { switch (errno) { // If the source file does not exist, we cannot copy anything @@ -266,7 +266,7 @@ static int pakfire_stripper_copy_sources( goto ERROR; default: - ERROR(stripper->ctx, "Could not open /%s: %m\n", p); + ERROR(self->ctx, "Could not open /%s: %m\n", p); r = -errno; goto ERROR; } @@ -275,13 +275,13 @@ static int pakfire_stripper_copy_sources( // Stat the source file r = fstat(fd, &st); if (r < 0) { - ERROR(stripper->ctx, "Could not stat /%s: %m\n", p); + ERROR(self->ctx, "Could not stat /%s: %m\n", p); r = -errno; goto ERROR; } // Add the buildroot - r = pakfire_path_append(p, stripper->path, path); + r = pakfire_path_append(p, self->path, path); if (r < 0) goto ERROR; @@ -293,7 +293,7 @@ static int pakfire_stripper_copy_sources( // Open the destination file dst = fopen(p, "wx"); if (!dst) { - ERROR(stripper->ctx, "Could not open %s: %m\n", p); + ERROR(self->ctx, "Could not open %s: %m\n", p); r = -errno; goto ERROR; } @@ -301,7 +301,7 @@ static int pakfire_stripper_copy_sources( // Copy all content ssize_t bytes_written = sendfile(fileno(dst), fd, 0, st.st_size); if (bytes_written < st.st_size) { - ERROR(stripper->ctx, "Failed to copy source file %s: %m\n", path); + ERROR(self->ctx, "Failed to copy source file %s: %m\n", path); r = -errno; goto ERROR; } @@ -309,7 +309,7 @@ static int pakfire_stripper_copy_sources( // Change permissions r = fchmod(fileno(dst), 0444); if (r < 0) { - ERROR(stripper->ctx, "Could not change permissions of %s: %m\n", path); + ERROR(self->ctx, "Could not change permissions of %s: %m\n", path); r = -errno; goto ERROR; } @@ -323,7 +323,7 @@ ERROR: return r; } -static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* stripper, +static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* self, struct pakfire_file* file, struct pakfire_elf* elf) { const char* build_id = NULL; char build_id_path[PATH_MAX]; @@ -338,14 +338,14 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* stripp // Fetch the Build ID build_id = pakfire_elf_build_id(elf); if (!build_id) { - ERROR(stripper->ctx, "No Build ID\n"); + ERROR(self->ctx, "No Build ID\n"); r = -ENOTSUP; goto ERROR; } // Make Build ID path r = pakfire_string_format(build_id_path, "%s/usr/lib/debug/.build-id/%c%c/%s.debug", - stripper->path, build_id[0], build_id[1], build_id + 2); + self->path, build_id[0], build_id[1], build_id + 2); if (r < 0) goto ERROR; @@ -355,7 +355,7 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* stripp goto ERROR; // Make a path for a new temporary file - r = pakfire_path(stripper->pakfire, tmppath, "%s", PAKFIRE_TMP_DIR "/.pakfire-strip.XXXXXXX"); + r = pakfire_path(self->pakfire, tmppath, "%s", PAKFIRE_TMP_DIR "/.pakfire-strip.XXXXXXX"); if (r < 0) goto ERROR; @@ -382,15 +382,15 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* stripp }; // Run the command - r = pakfire_jail_exec_command(stripper->jail, extract_argv, NULL, 0); + r = pakfire_jail_exec_command(self->jail, extract_argv, NULL, 0); if (r < 0) { - ERROR(stripper->ctx, "Could not extract debug sections from %s: %s\n", + ERROR(self->ctx, "Could not extract debug sections from %s: %s\n", pakfire_file_get_path(file), strerror(-r)); return r; // The command returned an error } else if (r > 0) { - ERROR(stripper->ctx, "Could not extract debug sections from %s: %d\n", + ERROR(self->ctx, "Could not extract debug sections from %s: %d\n", pakfire_file_get_path(file), r); return -ENOTSUP; } @@ -412,20 +412,20 @@ static int pakfire_stripper_strip_debug_sections(struct pakfire_stripper* stripp path, // The stripped output - pakfire_relpath(stripper->pakfire, tmppath), + pakfire_relpath(self->pakfire, tmppath), NULL, }; // Run the command - r = pakfire_jail_exec_command(stripper->jail, strip_argv, NULL, 0); + r = pakfire_jail_exec_command(self->jail, strip_argv, NULL, 0); if (r < 0) { - ERROR(stripper->ctx, "Could not strip debug sections from %s: %s\n", + ERROR(self->ctx, "Could not strip debug sections from %s: %s\n", pakfire_file_get_path(file), strerror(-r)); goto ERROR; // The command returned an error } else if (r > 0) { - ERROR(stripper->ctx, "Could not strip debug sections from %s\n", + ERROR(self->ctx, "Could not strip debug sections from %s\n", pakfire_file_get_path(file)); r = -ENOTSUP; goto ERROR; @@ -447,12 +447,12 @@ ERROR: static int pakfire_stripper_strip( struct pakfire_ctx* ctx, struct pakfire_file* file, void* data) { - struct pakfire_stripper* stripper = data; + struct pakfire_stripper* self = data; struct pakfire_elf* elf = NULL; int r; // Open the ELF file - r = pakfire_elf_open_file(&elf, stripper->ctx, file); + r = pakfire_elf_open_file(&elf, self->ctx, file); if (r < 0) goto ERROR; @@ -460,12 +460,12 @@ static int pakfire_stripper_strip( if (!pakfire_elf_is_stripped(elf)) { // Collect sources r = pakfire_elf_foreach_source_file(elf, - pakfire_stripper_collect_sources, stripper); + pakfire_stripper_collect_sources, self); if (r < 0) goto ERROR; // Strip debug information - r = pakfire_stripper_strip_debug_sections(stripper, file, elf); + r = pakfire_stripper_strip_debug_sections(self, file, elf); if (r < 0) goto ERROR; } @@ -477,27 +477,27 @@ ERROR: return r; } -int pakfire_stripper_run(struct pakfire_stripper* stripper) { +int pakfire_stripper_run(struct pakfire_stripper* self) { int r; // Scan for all ELF files in path - r = pakfire_stripper_scan(stripper); + r = pakfire_stripper_scan(self); if (r < 0) return r; // If the filelist is empty, there is nothing to do - if (pakfire_filelist_is_empty(stripper->filelist)) + if (pakfire_filelist_is_empty(self->filelist)) return 0; // Strip all files - r = pakfire_filelist_walk(stripper->filelist, pakfire_stripper_strip, - stripper, PAKFIRE_FILELIST_SHOW_PROGRESS, _("Stripping Files...")); + r = pakfire_filelist_walk(self->filelist, pakfire_stripper_strip, + self, PAKFIRE_FILELIST_SHOW_PROGRESS, _("Stripping Files...")); if (r < 0) return r; // Copy sources - r = pakfire_filelist_walk(stripper->sources, pakfire_stripper_copy_sources, - stripper, PAKFIRE_FILELIST_SHOW_PROGRESS, _("Copying Sources...")); + r = pakfire_filelist_walk(self->sources, pakfire_stripper_copy_sources, + self, PAKFIRE_FILELIST_SHOW_PROGRESS, _("Copying Sources...")); if (r < 0) return r; diff --git a/src/pakfire/stripper.h b/src/pakfire/stripper.h index 59a0f0050..e6f53eb93 100644 --- a/src/pakfire/stripper.h +++ b/src/pakfire/stripper.h @@ -32,9 +32,9 @@ struct pakfire_stripper; int pakfire_stripper_create(struct pakfire_stripper** stripper, struct pakfire* pakfire, struct pakfire_jail* jail, const char* path); -struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* stripper); -struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* stripper); +struct pakfire_stripper* pakfire_stripper_ref(struct pakfire_stripper* self); +struct pakfire_stripper* pakfire_stripper_unref(struct pakfire_stripper* self); -int pakfire_stripper_run(struct pakfire_stripper* stripper); +int pakfire_stripper_run(struct pakfire_stripper* self); #endif /* PAKFIRE_STRIPPER_H */