Commit graph

41 commits

Author SHA1 Message Date
Chris Kuehl
a43367c164
Merge pull request #210 from Villemoes/chdir
chdir to / in parent
2020-12-10 10:53:36 -08:00
suve
7b838007ab Use "%.*s" when printing VERSION
Commit 7bb2fef0e2 attempted to fix
the "missing NUL-terminator in VERSION" issue by replacing the "%s"
conversion specifier with "%*s". However, this fix itself was wrong,
as "%*s" specifies the field width, i.e. _minimum_ number of characters
to print. The proper solution is to use "%.*s", which specifies the
precision, i.e. the _maximum_ number of printed characters.
2020-12-03 13:45:03 +01:00
suve
7bb2fef0e2 Use "%*s" when printing VERSION
The "%s" conversion specifier expects a NUL-terminated string.
However, the VERSION variable does not contain a NUL-terminator,
so formatting it using "%s" may lead to printing whatever happens
to be in memory next to VERSION.

Using "%*s" allows to specify how many characters to print,
thus making sure we don't go off the array.
2020-12-01 19:59:14 +01:00
Rasmus Villemoes
6c2cf1d06d chdir to / in parent
There's no reason the dumb-init process should hold on to a reference
to the original cwd (but of course the child must be spawned with that
cwd). One example where that can be problematic:

# Terminal 1
$ mkdir -p /tmp/d/e
$ sudo mount --make-shared -t tmpfs tmpfs /tmp/d/e

# Terminal 2
$ docker run -v /tmp/d:/tmp/d:rshared --rm -ti --workdir /tmp/d/e some-image-with-dumb-init bash
root@922ef180b49a:/tmp/d/e# cd ..
root@922ef180b49a:/tmp/d# ls -l /proc/*/cwd
lrwxrwxrwx 1 root root 0 Oct  1 11:25 /proc/1/cwd -> /tmp/d/e
lrwxrwxrwx 1 root root 0 Oct  1 11:25 /proc/6/cwd -> /tmp/d
lrwxrwxrwx 1 root root 0 Oct  1 11:25 /proc/self/cwd -> /tmp/d
lrwxrwxrwx 1 root root 0 Oct  1 11:25 /proc/thread-self/cwd -> /tmp/d

# Terminal 1
$ sudo umount /tmp/d/e
umount: /tmp/d/e: target is busy.

i.e., the application inside the container has already let go of its
reference, but the host is not able to unmount /tmp/d/e because the
container's pid 1 still has one.

As for a test case, the 'docker run --workdir' could be emulated by
something like

  sh -c "cd /tmp/d/e; exec $PWD/dumb-init bash -i"

but one would still need root to do the mount and umount.
2020-10-01 13:55:24 +02:00
hellerve
93e076ae18 nit 2: add braces around for 2018-08-09 15:43:01 +02:00
hellerve
341a453731 nit: add braces around if 2018-08-09 10:59:00 +02:00
Chris Kuehl
7d3aa2fc2b Fix SIGHUP/SIGCONT race condition 2018-08-01 16:20:16 -07:00
kpengboy
7623fb4271 Fix ignored signal (non-)forwarding behavior 2017-10-10 17:28:21 -07:00
Chris Kuehl
e4e2dd0503 Fix ioctl arguments 2016-10-10 12:23:19 -07:00
Chris Kuehl
fff4226b17 Hand controlling TTY to child, if we have one 2016-10-10 11:17:31 -07:00
Chris Kuehl
f854583872 Fixes for FreeBSD kernel 2016-08-01 10:32:31 -07:00
Chris Kuehl
d17ab8ac18 Set the signal mask before forking
Fixes #102
2016-07-25 22:30:22 -07:00
Mike McClurg
d57a38b0c1 Print debug output when translating signal 2016-06-19 15:24:34 -07:00
Chris Kuehl
b678dbf4b3 Fix segfault on invalid arguments 2016-06-17 10:20:05 -07:00
Chris Kuehl
1a7c635071 Add ability to ignore signals 2016-06-14 11:34:52 -07:00
Chris Kuehl
554760fda6 Use signal rewriting for TTY signal special cases 2016-06-14 11:08:33 -07:00
Chris Kuehl
9e456addb7 Add signal translation tests 2016-06-13 14:33:51 -07:00
Mike McClurg
6f6b51f869 Rewrite arbitrary signals, and update tests
We've decided to allow arbitrary signal rewriting, not just SIGTERM
rewriting. To use, call dumb-init with the '-r s:r' option, which will
rewrite signum s to signum r. Only signals 1-31 are allowed to be
rewritten, which should cover all the signals we need to cover.

Note that this commit does not add new tests, it only fixes the existing
broken test.
2016-06-09 16:05:27 -06:00
Mike McClurg
3b6e9f256f Add '--signal' option to replace SIGTERM
Many servers respond to other signals than SIGTERM for their "soft
shutdown" option, such as Unicorn which requires SIGQUIT to wait on
outstanding connections. The 'docker stop' command sends the SIGTERM
signal to the container, and provides no option for modifying this
behavior. The 'docker kill' command has an '-s' option which allows one
to modify the signal sent to the container, but orchestration frameworks
such as Mesos don't provide a way to use this functionality.

This commit adds the '-s/--signal' option to dumb-init, which provides a
replacement signal for SIGTERM. For instance, running dumb-init like so:

  dumb-init -s 3 <command>

Will send SIGQUIT (3) to the <command> process it spawns when it
receives a SIGTERM. This allows Docker image writers the freedom to
specify how SIGTERM will behave in their containers.

A further improvement to this option could be to provide an arbirary
mapping from signal to signal, but that would greatly complicate the
code for a probably minor use case.
2016-06-08 16:20:57 -06:00
Chris Kuehl
b7aee39721 Fix incorrect error on bad exec when passing args 2016-05-28 02:03:19 -04:00
Chris Kuehl
256edaef74 Simplify dumb-init behavior using sigwait 2016-04-29 17:13:52 -07:00
Chris Kuehl
d626878a0c Fix exit status when process exits via signal
This fixes https://github.com/Yelp/dumb-init/issues/59
2016-03-11 13:42:00 -08:00
Chris Kuehl
3582a92402 Fix typo in error message 2015-11-20 09:31:45 -08:00
Chris Kuehl
01f6064164 Fix typo in help message 2015-10-26 10:20:18 -07:00
Anthony Sottile
d0c28bd03e Descendants not ancestors 2015-10-02 22:28:40 -07:00
Chris Kuehl
6b7f0ce3fa Add standard command-line flags 2015-10-02 15:53:07 -07:00
Chris Kuehl
316f6b0d93 Prefix output with [dumb-init] 2015-10-02 10:51:09 -07:00
Chris Kuehl
2aa56d6aab Merge pull request #25 from chriskuehl/background-support
Properly respond to job control signals
2015-09-29 13:44:28 -07:00
Chris Kuehl
d178fbaf52 Print better error message when exec fails 2015-09-29 10:49:08 -07:00
Chris Kuehl
a78ac8fe23 Exit nonzero if exec fails 2015-09-29 10:43:45 -07:00
Chris Kuehl
b39643dcbc Properly respond to job control signals 2015-09-25 18:19:23 -07:00
Chris Kuehl
d59a190a5d Send TERM to all children when the main child exists in setsid mode 2015-09-16 20:00:15 -07:00
Chris Kuehl
6e2b2eee00 Properly reap zombie processes 2015-09-10 17:28:39 -07:00
Kent Wills
d5f0be96d3 update docstrings, fix itest, add to dockerignore 2015-09-10 15:34:09 -07:00
Kent Wills
1b816df1b6 change setpgid to setsid 2015-09-10 15:34:09 -07:00
Chris Kuehl
4bc0d0abd6 README: update for process group support 2015-09-04 13:14:00 -07:00
Buck Golemon
d0e9a8d02a buck review 2015-08-28 18:21:51 -07:00
Chris Kuehl
807db9be27 Add process group support 2015-08-28 09:25:10 -07:00
Chris Kuehl
129e39af34 Whitespace cleanup 2015-08-10 09:32:56 -07:00
Chris Kuehl
2c3b93a86e Fix return code, add better help, add more tests 2015-08-06 14:31:49 -07:00
Chris Kuehl
ad20525ad9 Initial commit 2015-08-04 16:38:35 -07:00