finish self exctracting executable

This commit is contained in:
FArthur-cmd 2022-03-30 22:01:50 +00:00
parent 7f0c6fb103
commit 6c1d04710f
3 changed files with 15 additions and 9 deletions

View File

@ -45,8 +45,8 @@ int compress(int in_fd, int out_fd, int level=5)
// 6402520 is size of stripped decompressor
size_t start = 6405000ull;
// 22550744 size of decompressor
// size_t start = 22550780ull;
// 22558008ull size of decompressor
// size_t start = 22558008ull;
/// As experiments showed, size of compressed file is 4 times less than clickhouse executable
/// Get a little bit more memory to prevent errors with size.

View File

@ -31,7 +31,7 @@ int decompress(int in_fd, int out_fd)
fstat(in_fd, &info_in);
/// NOTE: next parametrs depend on binary size
// 22550780ull for full, 6405000ull for stripped;
// 22558008ull for full, 6405000ull for stripped;
off_t in_offset = 6405000ull /*size of decompressor*/, out_offset = 0;
/// mmap files
@ -82,16 +82,16 @@ int decompress(int in_fd, int out_fd)
return 0;
}
int main()
int main(int /*argc*/, char* argv[])
{
int input_fd = open("decompressor", O_RDONLY);
int input_fd = open(argv[0], O_RDONLY);
if (input_fd == -1)
{
perror(nullptr);
return 0;
}
int output_fd = open("clickhouse_decompressed", O_RDWR | O_CREAT, 0775);
int output_fd = open("clickhouse.decompressed", O_RDWR | O_CREAT, 0775);
if (output_fd == -1)
{
perror(nullptr);
@ -103,7 +103,12 @@ int main()
return 1;
}
close(input_fd);
fsync(output_fd);
close(output_fd);
close(input_fd);
/// NOTE: This command should not depend from any variables.
/// It should be changed if file changes.
execl("/usr/bin/bash", "bash", "-c", "mv ./clickhouse.decompressed ./clickhouse", NULL);
return 0;
}

View File

@ -2,8 +2,9 @@
# Put this script near compressor and decompressor
strip decompressor
cp decompressor clickhouse
strip clickhouse
# TODO use env variables
./compressor ../../programs/clickhouse decompressor
./compressor ../../programs/clickhouse clickhouse