Commit Graph

24 Commits

Author SHA1 Message Date
agnostic-apollo 7b9b9b6224 fix(run-docker.sh): Fix docker exec not passing kill signals (ctrl+c) to commands in some cases leaving processes still running
If `--tty` is not passed to `docker exec` because stdout is not available (`[ ! -t 1 ]`), like due to redirection to file (`&> build.log`) or if stdin is not available (`< /dev/null`), then docker does not forward kill signals to the process started and they remain running.

To fix the issue, the `DOCKER_EXEC_PID_FILE_PATH` env variable with the value `/tmp/docker-exec-pid-<timestamp>` is passed to the process called with `docke exec` and the process started stores its pid in the file path passed. Traps are set in `run-docker.sh` that runs the `docker exec` command to receive any kills signals, and if it does, it runs another `docker exec` command to read the pid of the process previously started from `DOCKER_EXEC_PID_FILE_PATH` and then kills it and all its children.

See Also:

https://github.com/docker/cli/issues/2607
https://github.com/moby/moby/issues/9098
https://github.com/moby/moby/pull/41548
https://stackoverflow.com/questions/41097652/how-to-fix-ctrlc-inside-a-docker-container

Also passing `--init` to `docker run` to "Run an init inside the container that forwards signals and reaps processes", although it does not work for above cases, but may helpful in others. The `--init` flag changes will only engage on new container creation.

https://docs.docker.com/engine/reference/run/#specify-an-init-process

https://docs.docker.com/engine/reference/commandline/run/

```
./scripts/run-docker.sh ./build-package.sh -f libjpeg-turbo  &> build.log
^C
$ ./scripts/run-docker.sh ps -efww
Running container 'termux-package-builder' from image 'termux/package-builder'...
UID          PID    PPID  C STIME TTY          TIME CMD
builder        1       0  0 05:48 pts/0    00:00:00 bash
builder     9243       0  0 06:01 pts/1    00:00:00 bash
builder    28127       0  0 06:12 ?        00:00:00 /bin/bash ./build-package.sh -f libjpeg-turbo
builder    28141   28127  0 06:12 ?        00:00:00 /bin/bash ./build-package.sh -f libjpeg-turbo
builder    28449   28141  1 06:12 ?        00:00:00 ninja -w dupbuild=warn -j 8
builder    28656   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28657   28656 79 06:12 ?        00:00:01 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28694   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28695   28694 89 06:12 ?        00:00:00 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28728   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28729   28728  0 06:12 ?        00:00:00 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28731   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28734   28731  0 06:12 ?        00:00:00 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28740   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28741   28740  0 06:12 ?        00:00:00 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28744       0  0 06:12 pts/2    00:00:00 ps -efww
builder    28748   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28752   28748  0 06:12 ?        00:00:00 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28753   28449  0 06:12 ?        00:00:00 /bin/sh -c /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28754   28753  0 06:12 ?        00:00:00 /home/builder/.termux-build/_cache/android-r23c-api-24-v0/bin/clang
builder    28755   28449  0 06:12 ?        00:00:00 ninja -w dupbuild=warn -j 8
$ ./scripts/run-docker.sh ./build-package.sh -f libjpeg-turbo  &> build.log
$ ./scripts/run-docker.sh ./build-package.sh -f libjpeg-turbo
Running container 'termux-package-builder' from image 'termux/package-builder'...
ERROR: Another build is already running within same environment.
```
2022-07-28 15:27:20 +05:00
Leonid Pliushch 07852c874b
build-package.sh: allow to select package formats between debian and pacman 2021-09-10 19:55:28 +03:00
Henrik Grimler 2c70621a98 build-package: rename TERMUX_DEBUG to TERMUX_DEBUG_BUILD
To make it more self-explanatory.
2021-08-21 20:55:57 +02:00
Henrik Grimler 55ab8e5839 build-all.sh: Fix error message
${PKG} should be expanded.
2021-02-03 17:30:12 +01:00
vlad doster 380dad2460 (maint) update build-all.sh
- quote bash vars
- handle unknown flags in `getopts`
- add `-r` flag in `read` to avoid mangling `\`
- remove `$` in arithmetic which gives it PEMDAS characteristic
- single quote trap to expand when signaled vs. when defined
2021-01-23 22:54:18 +02:00
Leonid Pliushch e303212ae5 enable on-device builds
Partial compatibility for on-device builds.

There is no guarantee that it will be possible to build all available
packages and built packages will have same reliability that cross-compiled
but should solve "self-hosting" problems as much as possible.
2019-08-08 16:58:34 +03:00
Henrik Grimler 10fdf172d5 build-package: download dependencies recursively when fast-building
Use scripts/buildorder.py with a new -i flag to get all dependencies
(including subpackages). The script now also spits out both package
name and package dir, to make it easier to build packages from another
repo.
2019-03-03 01:40:22 +02:00
Leonid Pliushch cc61b933ac build-all.sh: don't use tabs in script usage info 2019-02-15 18:01:09 +02:00
Wetitpig 7ddcce5701 No backticks 2019-02-15 18:01:09 +02:00
Wetitpig d50c847f11 Shell script compliance 2019-02-15 18:01:09 +02:00
Henrik Grimler 2fbb868cdb build-all.sh: don't set -s if -i is set 2019-01-28 14:20:45 +00:00
Henrik Grimler 4c9ff7b336 build-all.sh: add -i option to build and download dependencies 2019-01-28 14:20:45 +00:00
Henrik Grimler 80b8055538 build-{package,all}.sh: fix -d and add -o to build-all
-d didn't work for build-package.sh -d -a all before.
2018-09-15 21:20:28 +02:00
monoidic a94a538588 Fix building with "all" architecture (#2465) 2018-05-29 11:04:34 +02:00
Henrik Grimler 8b230f9e55 build-all.sh: add option for debug builds 2018-03-05 11:29:53 +01:00
Fredrik Fornwall 41cc3653aa Enable dependency checks for out-of-tree packages
When building an out-of-tree package, as in
	./build-package.sh path/to/my-package.sh
dependency checks now works.
2017-11-04 01:18:32 +01:00
Fredrik Fornwall 75a13474e6 build-all.sh: Add support for specifying arch 2017-01-19 14:38:16 +01:00
Fredrik Fornwall fc89df4deb build-package.sh: Automatically build dependencies
We now automatically build dependencies unless the -s option is
used, so running scripts/buildorder.py shouldn't be necessary now.
2017-01-03 19:04:37 -05:00
Fredrik Fornwall a005794323 Tweak build script and docker setup
- Output deb files to debs/ folder by default.
- Use $HOME/.termux-build for build folder by default (changed
  from previous $HOME/termux).
- Make scripts/run-docker.sh re-use a single container instead of
  creating new ones for each run.
- Avoid mounting the whole Termux build folder in docker. This
  fixes #294, mmap not supported host folders under OS X.
- Add a scripts/update-docker.sh utility for checking for an
  updated docker image..
- Make build-package.sh support the [-a ARCH] flag to specify arch.
- Make aarch64 the default arch (from previous arm).
- Try to improve the README a bit.
2016-06-03 18:41:30 -04:00
Fredrik Fornwall 88183689ef Build and docker updates 2016-05-27 18:24:50 -04:00
Fredrik Fornwall 658bba67c0 Introduce a scripts/ folder 2016-01-14 22:45:50 -05:00
Gert Scholten 12622a9590 build-all.sh status messages and ability to resume previous run.
Enhanced build-all.sh to:
- Print the messages logged to ALL.out, to keep track of progress
- Print an error message when it fails, with a hint to what failed
- Keep track of packaged that build successfully, and if build-all failed:
- Skip packages that were build successfully in the previous run.
2015-12-28 12:49:23 +01:00
Fredrik Fornwall 0c6bde0a53 Do not take path as argument for buildorder.py 2015-07-04 09:00:46 -04:00
Fredrik Fornwall 59f0d218a6 Initial push 2015-06-13 01:03:31 +02:00