Skip to content

Commit

Permalink
don't save build files in AppHook directory
Browse files Browse the repository at this point in the history
  • Loading branch information
darealshinji committed Nov 30, 2023
1 parent e8f835b commit 126fa22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
17 changes: 7 additions & 10 deletions checkrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ void copy_lib(const char *libname, const char *dirname1, const char *dirname2)
char *src = get_libpath(libname);
if (!src) err(EXIT_FAILURE, "cannot find %s in system", libname);

printf("Copy library: %s\n", src);

/* create target directory */
const size_t len = strlen(dirname1) + strlen(dirname2) + strlen(libname) + 4;
char *target = malloc(len);
char *target = malloc(strlen(dirname1) + strlen(dirname2) + strlen(libname) + 3);
sprintf(target, "%s/%s", dirname1, dirname2);
mkdir(target, 0775);

Expand All @@ -126,8 +127,6 @@ void copy_lib(const char *libname, const char *dirname1, const char *dirname2)
ssize_t nread;
uint8_t buf[512*1024];

DEBUG_PRINT("copy from [[%s]] to: %s", src, target);

while ((nread = read(fd_in, buf, sizeof(buf))) > 0) {
if (write(fd_out, buf, nread) != nread) {
err(EXIT_FAILURE, "error writing to file: %s", target);
Expand All @@ -153,14 +152,14 @@ char *find_symbol(mmap_t *mem, const char *sym_prefix)
/* filesize check */
#define CHECK_FSIZE(x) \
if (x >= mem->size) { \
DEBUG_PRINT("%s", "offset exceeds filesize"); \
fprintf(stderr, "%s\n", "offset exceeds filesize"); \
return NULL; \
}

/* overflow + filesize check */
#define CHECK_OVERFLOW(a, b) \
if (__builtin_add_overflow(a, b, &tmp)) { \
DEBUG_PRINT("%s", "overflow detected"); \
fprintf(stderr, "%s\n", "overflow detected"); \
return NULL; \
} \
CHECK_FSIZE(tmp)
Expand Down Expand Up @@ -208,7 +207,7 @@ char *find_symbol(mmap_t *mem, const char *sym_prefix)
/* do some extra checks to prevent floating-point exceptions
* or similar issues */
if (sh_sz < sh_esz || sh_sz == 0 || sh_esz == 0) {
DEBUG_PRINT("error: problematic math division [%ld/%ld] in section header found: %s",
fprintf(stderr, "problematic math division [%ld/%ld] in section header found: %s\n",
sh_sz, sh_esz, mem->filename);
return NULL;
}
Expand Down Expand Up @@ -291,8 +290,7 @@ char *symbol_version(const char *lib, const char *sym_prefix)
bool use_bundled_library(const char *libname, const char *dirname1, const char *dirname2, const char *sym_prefix)
{
bool rv = false;
size_t len = strlen(dirname1) + strlen(dirname2) + strlen(libname) + 4;
char *lib_bundle = malloc(len);
char *lib_bundle = malloc(strlen(dirname1) + strlen(dirname2) + strlen(libname) + 3);

sprintf(lib_bundle, "%s/%s/%s", dirname1, dirname2, libname);

Expand Down Expand Up @@ -361,7 +359,6 @@ void copy_libraries()
char *dir = get_exe_dir();
copy_lib("libgcc_s.so.1", dir, "gcc");
copy_lib("libstdc++.so.6", dir, "cxx");
fprintf(stderr, "%s\n", "Files copied");
FREE(dir);
}

Expand Down
11 changes: 5 additions & 6 deletions template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ if [ "$APPDIR" == "" ]; then
fi

APPDIR="$(realpath "$APPDIR")"
echo "Installing AppRun hook 'checkrt'"
CHECKRTDIR="$APPDIR/checkrt"

mkdir -p "$APPDIR/apprun-hooks/checkrt"
echo "Installing AppRun hook 'checkrt'"
mkdir -p "$APPDIR/apprun-hooks"

cat > "$APPDIR/apprun-hooks/linuxdeploy-plugin-checkrt.sh" << \EOF
#! /usr/bin/env bash
Expand All @@ -44,8 +45,6 @@ if [ -z "$APPDIR" ]; then
APPDIR="$(dirname "$(realpath "$0")")"
fi
CHECKRTDIR="$APPDIR/apprun-hooks/checkrt"
if [ -x "$CHECKRTDIR/checkrt" ]; then
CHECKRT_LIBS="$($CHECKRTDIR/checkrt)"
Expand All @@ -67,7 +66,8 @@ if [ -n "$CHECKRT_DEBUG" ]; then
fi
EOF

cd "$APPDIR/apprun-hooks/checkrt"
mkdir -p "$CHECKRTDIR"
cd "$CHECKRTDIR"

save_files

Expand All @@ -80,5 +80,4 @@ echo "Compiling exec.so"
cc -shared -O2 -fPIC exec.c -o exec.so $LDFLAGS
rm checkrt.c exec.c

echo "Copy libgcc_s.so.1 and libstdc++.so.6"
./checkrt --copy

0 comments on commit 126fa22

Please sign in to comment.