Commit graph

108 commits

Author SHA1 Message Date
Daniel J Walsh
2bac4d8a47 Setup LISTEN_PID to point to new child process
In order to get systemd socket passing to work properly
the listen PID needs to match the process ID of the OCI runtime.
This match modifies the LISTEN_PID if it is set to the new runtime.

conmon will check that the LISTEN_PID the pid that conmon is running as and
will ignore it if they are different.  But, if the caller specifies the
--replace-listen-pid flag, then the LISTEN_PID/LISTEN_FDS will always be used.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-03-07 22:06:57 +00:00
Daniel J Walsh
c189b8d147
Merge pull request #1409 from giuseppe/conmon-catch-signals
conmon: catch SIGTERM, SIGINT and SIGQUIT
2018-03-07 21:28:35 +00:00
Giuseppe Scrivano
7036d1c0c2
conmon: catch SIGTERM, SIGINT and SIQUIT
and forward them to the watched process.  A side effect is that we can
correctly invoke the exit command if conmon receives them.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-03-07 07:27:09 +01:00
W. Trevor King
f3c9a6c4ab cmsg: Use do/while for error and errorf
Avoid:

  $ make clean && make CFLAGS='-Wpedantic' cmsg.o 2>&1 | head -n5
  rm -f conmon.o cmsg.o ../bin/conmon
  cc -Wpedantic -std=c99 -Os -Wall -Wextra -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include   -c -o cmsg.o cmsg.c
  cmsg.c: In function ‘recvfd’:
  cmsg.c:30:2: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
    ({         \
    ^

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-03-03 14:58:35 -08:00
W. Trevor King
9356aa9dd8 conmon/cmsg: Distinguish error(s) from errorf(fmt, ...) and replace %m
The same as the last two commits, except for cmsg.c instead of
conmon.c.

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-03-03 14:58:35 -08:00
W. Trevor King
f67d6ed25c conmon: Use strerror(errno) instead of %m
Avoid:

  $ make clean && make CFLAGS=-Wpedantic 2>&1 | head -n5
  rm -f conmon.o cmsg.o ../bin/conmon
  cc -Wpedantic -std=c99 -Os -Wall -Wextra -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include   -c -o conmon.o conmon.c
  conmon.c: In function ‘write_k8s_log’:
  conmon.c:32:19: warning: ISO C does not support the ‘%m’ gnu_printf format [-Wformat=]
     fprintf(stderr, "[conmon:e]: %s %m\n", s);     \
                     ^

from printf(3) [1]:

  m (Glibc extension; supported by uClibc and musl.)  Print output of
    strerror(errno).  No argument is required.

strerror, on the other hand, is in POSIX [2].

[1]: http://man7.org/linux/man-pages/man3/printf.3.html
[2]: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-03-03 14:58:35 -08:00
W. Trevor King
9583581280 conmon: Distinguish pexit(s) from pexitf(fmt, ...) and similar
Avoid:

  $ make clean && make CFLAGS=-Wpedantic 2>&1 | head -n 5
  rm -f conmon.o cmsg.o ../bin/conmon
  cc -Wpedantic -std=c99 -Os -Wall -Wextra -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include   -c -o conmon.o conmon.c
  conmon.c: In function ‘write_k8s_log’:
  conmon.c:342:33: warning: ISO C99 requires at least one argument for the "..." in a variadic macro
      ninfo("Creating new log file");
                                   ^

by distinguishing between calls with and without user-supplied
formatting.

Also remove some user-supplied newlines from the following

* nwarn for "Could not find newline in entire buffer"
* ninfo for "Got ctl message..."
* ninfo for "container %d exited with status..."
* nexitf for "Failed to write %s to exit file..."

because the macros add their own trailing newlines.

Also drop some redundant user-specified strerror() arguments from the
following:

* pexit for "Failed to open log file..."
* pexit for "Runtime path %s is not valid..."

because the pexit* macros add strerror on their own.

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-03-03 14:58:35 -08:00
Daniel J Walsh
1d89b897f7
Merge pull request #1366 from giuseppe/conmon-additional-command-atexit
conmon: add new option to call cleanup program at exit
2018-03-02 13:23:52 -05:00
Daniel J Walsh
0b736bb43f
Merge pull request #1365 from giuseppe/log-file-always-present
conmon: open+rename the log file instead of unlink+open
2018-03-01 12:50:22 -08:00
Daniel J Walsh
0caee670a0
Merge pull request #1371 from wking/respect-start-pipe-read-errors
conmon: Respect start-pipe read errors
2018-03-01 04:04:45 -08:00
Giuseppe Scrivano
a62b39ffa4
conmon: open+rename the log file instead of unlink+open
at no time the log file is not accessible by its path.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-02-26 10:09:12 +01:00
W. Trevor King
1390740df2 conmon: Make --exit-dir optional
CRI-O's server relies on this for creation attempts, but it can set
the option.  conmon itself doesn't need to care one way or the other.
Perhaps it is being called by a process that doesn't care about the
container exit code or has another way to access that information.
With this commit, we trust callers to set --exit-dir if they want it,
instead of requiring non-exec callers to set it.

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-02-24 20:48:42 -08:00
Giuseppe Scrivano
e6145b3596
conmon: add new option to call cleanup program at exit
add the possibility to run a custom command, and optionally provide
additional arguments to it, when conmon exits.

For example, it could be possible to delete the terminated container
with:

conmon [...] --exit-command /usr/bin/runc \
             --exit-command-arg delete \
             --exit-command-arg $CONTAINER_UUID

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-02-24 13:11:08 +01:00
W. Trevor King
1262234531 conmon: Respect start-pipe read errors
Avoid:

  $ make clean && make conmon.o 2>&1
  rm -f conmon.o cmsg.o ../bin/conmon
  cc -std=c99 -Os -Wall -Wextra -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -DVERSION=\"1.9.0-dev\" -DGIT_COMMIT=\""74cd1ec97c13a9784ce5e67a9e50e8977b5d2f38"\"   -c -o conmon.o conmon.c
  conmon.c: In function ‘main’:
  conmon.c:1175:3: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result]
     read(start_pipe_fd, buf, BUF_SIZE);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

by catching and exiting on any read errors.  A read error here would
be because the caller died before writing to the start pipe, and we
don't want to continue in those cases because it would reopen the
cgroup race discussed in af4fbcd9 (conmon: Don't leave zombies and fix
cgroup race, 2017-06-09, #583).  af4fbcd9 is where this line
originally landed, and it didn't have error checking then.

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-02-23 11:25:29 -08:00
Giuseppe Scrivano
6a23a293d7
conmon: add new option --version
Print the version and exit immediately.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-02-23 09:41:48 +01:00
Daniel J Walsh
a19ab49f44 Fix typo in options defition
The options should be no-new-keyring, mistakenly written as no-new_keyring.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-02-06 08:14:40 -05:00
Daniel J Walsh
680e62a459 Add no-new-keyring flag to conmon
We want to pass the no-new-keyring through conmon down to the OCI
Runtime.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-02-05 16:51:35 -05:00
Mrunal Patel
a480b20652 Support stdin once
We leave the stdin open on first client disconnect if stdin once
is not set in the container configuration.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2018-01-30 15:24:51 -08:00
Daniel J Walsh
a85f3127d8 Improve error messages on missing runtime
Also stat.h is included twice,
Add more info on log file name and error when failing to open.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2017-12-18 16:46:19 -05:00
Mrunal Patel
4cf4137be0 conmon: Add support for partial/newline log tags
This is for ttps://github.com/kubernetes/kubernetes/pull/55922

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2017-11-28 18:57:21 -08:00
Antonio Murdaca
63b1706de8
Makefile: output binaries under bin/
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2017-10-30 17:48:29 +01:00
Matthew Heon
e66da6046d Rename conmon argument to socket-dir-path
Signed-off-by: Matthew Heon <mheon@redhat.com>
2017-10-24 18:28:53 -04:00
Matthew Heon
042f31fe68 Add default CRI-O socket path back to conmon
Signed-off-by: Matthew Heon <mheon@redhat.com>
2017-10-24 15:42:23 -04:00
Matthew Heon
ae5fc471ea Make attach sockets directory an argument in Conmon
This is required to enable ongoing work in libpod

Signed-off-by: Matthew Heon <mheon@redhat.com>
2017-10-24 15:42:23 -04:00
d6a44bf111
*: allow to not use pivot_root
runc has a `--no-pivot` flag, that uses MS_MOVE instead.

This patch set bubbles up a runtime config to enable using no-pivot
globally.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2017-09-26 11:35:00 -04:00
Mrunal Patel
c7d33e1899 conmon: Re-open the log file to not exceed max log file size
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2017-09-25 15:36:14 -07:00
Mrunal Patel
82899bdb4e conmon: Track the number of bytes written to the container log file
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2017-09-25 15:35:25 -07:00
Mrunal Patel
48d0706a49 Add log size max flag to conmon and pass it on container create
Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2017-09-25 15:31:31 -07:00
Mrunal Patel
30ded83096 Add inotify watcher for container exits
This allows the container list API to return updated status
for exited container without having to call container status first.

Signed-off-by: Mrunal Patel <mpatel@redhat.com>
2017-08-13 08:01:48 -07:00
Lorenzo Fontana
e9e40c9df2
Using g_get_tmp_dir to build the console socket name
Signed-off-by: Lorenzo Fontana <lo@linux.com>
2017-08-06 17:26:14 +02:00
Giuseppe Scrivano
595b0557f3 conmon: use waitpid to wait for terminated processes
During my testing in OpenShift I've noticed that conmon leaves some
zombies processes.  The reason is that we are using
PR_SET_CHILD_SUBREAPER in conmon and runC forks a new process (runc
init) each time we start a container.  Using g_child_watch_add only on
the main runc process and on the container process is not enough as we
do not cleanup any other zombie process.

Since glib doesn't allow to catch SIGCHLD and to better integrate in the
existing code, catch it with signal(2) then raise a SIGUSR1 that glib
handles.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2017-07-24 14:50:50 +02:00
Giuseppe Scrivano
55310f9a95 conmon: do not fail if waitpid is interrupted
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2017-07-23 18:55:16 +02:00
Alexander Larsson
3cf86e25a8 fixup! conmon: Change how we detect container exit
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-29 23:20:12 +02:00
Alexander Larsson
c00f0dd848 conmon: Change how we detect container exit
Instead of waiting until stderr/out is closed and then waiting for
the container to exit we wait for the container to exit in the
gmainloop, in addition to everything else, exiting only when
the child dies.

We then drain any output in stderr/out after the child has exited.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-29 12:19:34 +02:00
Alexander Larsson
c39868ad55 conmon: Add fds to mainloop where they are created
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
7b91005b36 conmon: Rename global fd variables to longer names
Since these are global, its nice if they are a bit more descriptive.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
4cb4de6cda conmon: Move OOM setup to helper function
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
34b75c20c2 conmon: Move terminal control fifo setup to a helper function
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
640ebeafb3 conmon: Break out attach socket setup to helper function
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
cc3a1615fb conmon: Break out connection socket setup to a separate function
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
b269969216 conmon: Don't use fixed size string buffers
We build paths using g_build_filename and g_strdup_printf() instead
which means we don't have any arbitrary pathname lenght issue, and
the code becomes cleaner.

We also convert asprintf to g_strdup_printf so that we can use
the glib OOM checker instead of open coding it everywhere.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
a7c61e4f9f conmon: Remove unused variables
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
215ef485df conmon: Add add_argv() helper
This makes adding the arguments to runtime_argv somewhat nicer.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
6aa1075ab6 conmon: Add (and use) get_pipe_fd_from_env helper
This avoids duplicating this code in two places.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
4838d6eb80 conmon: Rename all commandline option variables opt_*
This makes it easier to figure out where they come from

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-22 16:09:27 +02:00
Alexander Larsson
81cb788004 conmon: Clean up execsync
This moves the timeout handling from the go code to conmon, whic
removes some of the complexity from criod, and additionally it will
makes it possible to do the double-fork in the exec case too.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-21 21:03:17 +02:00
Mrunal Patel
88037b143b Merge pull request #583 from alexlarsson/conmon-reap-zombies
conmon: Don't leave zombies and fix cgroup race
2017-06-20 07:53:52 -07:00
Alexander Larsson
72686c78b4 fixup! conmon: Don't leave zombies and fix cgroup race
Signed-off-by: Alexander Larsson <alexl@redhat.com>
2017-06-20 12:18:07 +02:00
Antonio Murdaca
2014f0e14f Merge pull request #568 from mrunalp/fix_terminal_settings
conmon: Set ONLCR for console
2017-06-16 10:17:15 +02:00
Mrunal Patel
bfd1b83f51 conmon: Modify console terminal settings to match kube settings
We enable ONLCR on the console to match kube's terminal settings.

Signed-off-by: Mrunal Patel <mpatel@redhat.com>
2017-06-15 07:54:12 -07:00