Commit Graph

561 Commits

Author SHA1 Message Date
Christian Brauner
f5849fd76f
lxccontainer: remove stack allocations
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-06 11:47:57 +01:00
Christian Brauner
a7547c5c34
compiler: -Wshadow hardening
Warn whenever a local variable or type declaration shadows another
variable, parameter, type, class member (in C++), or instance variable
(in Objective-C) or whenever a built-in function is shadowed.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-02-05 22:36:31 +01:00
Christian Brauner
02f71d7ef0
freezer: non-functional changes
Fix the coding style in a few files.

Fixes: db1228b35f ("Avoid hardcoded string length")
Fixes: 71fc9c0468 ("Avoid risk of "too far memory read"")
Fixes: 2341916a03 ("Avoid double lxc-freeze/unfreeze")
Fixes: 9eb9ce3e47 ("Update freezer.c")
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-01-31 11:34:46 +01:00
Rachid Koucha
2341916a03
Avoid double lxc-freeze/unfreeze
If we call lxc-freeze multiple times for an already frozen container, LXC
triggers useless freezing by writing into the "freezer.state" cgroup file.
This is the same when we call lxc-unfreeze multiple times.
Checking the current state with a LXC_CMD_GET_STATE
(calling c->state) would permit to check if the container is FROZEN
or not.

Signed-off-by: Rachid Koucha <rachid.koucha@gmail.com>
2019-01-26 23:46:34 +01:00
Stéphane Graber
62aad75f9a
Merge pull request #2755 from brauner/2018-12-16/rootfs_managed
storage: do not destroy pre-existing rootfs
2019-01-08 00:34:16 +01:00
Christian Brauner
3d7e738a6b
lxccontainer: fix container copy
We need to strip the prefix from the container's source path before
trying to update the file.

Closes #2380.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2019-01-07 13:37:06 +01:00
S.Çağlar Onur
4bcf92a32e Revert "Set c to NULL after freeing it"
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
2019-01-05 16:28:54 -08:00
S.Çağlar Onur
370c786023 Set c to NULL after freeing it
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
2018-12-26 11:19:13 -08:00
Christian Brauner
4e5a9657ca
lxccontainer: fix mount api (mount_injection_file)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-12-17 11:45:58 +01:00
Christian Brauner
92fa4347d7
storage: do not destroy pre-existing rootfs
Closes #2752.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-12-16 18:40:22 +01:00
Christian Brauner
137da20a4d
Merge pull request #1943 from bhelm/master
Added allowrunning command line option for snapshotting running containers
2018-11-23 11:51:47 +13:00
Christian Brauner
ecce75a68c
lxccontainer: fix temporary path removal
Needed-by: https://github.com/lxc/lxd/issues/5227

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-11-01 11:07:15 -04:00
Josh Soref
3b034c39eb spelling: array
Signed-off-by: Josh Soref <jsoref@gmail.com>
2018-10-30 06:47:57 +00:00
Christian Brauner
b20e0599c6
lxccontainer: remove check from goto target
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-22 16:47:44 +02:00
Bernd Helm
754076f555 added allowrunning command line option for snapshotting alive containers
Signed-off-by: Bernd Helm <bernd.helm@helmundwalter.de>
2018-10-22 09:07:46 +02:00
Christian Brauner
8a22c16838
lxccontainer: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-07 10:01:30 +02:00
Christian Brauner
e8f764b6bc
syscall_wrappers: move unshare()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-10-03 13:03:30 +02:00
Christian Brauner
d7b58715b6
raw_syscalls: add lxc_raw_getpid()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-30 20:20:16 +02:00
Christian Brauner
d38dd64a51
tree-wide: fix includes to fix bionic builds
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-27 01:01:33 +02:00
Christian Brauner
b1e44ed125
tree_wide: switch to netns_getifaddrs()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-23 21:19:35 +02:00
Christian Brauner
6ce39620fd
autotools: support -Wcast-align
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-23 20:22:41 +02:00
Christian Brauner
aafa5f96f6
api_extensions: introduce lxc_has_api_extension()
This is modeled after LXD's API extension checks. This allows API users
to query the given LXC instance whether a given API extension is
supported.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-21 15:17:15 +02:00
Christian Brauner
152508ba09
lxccontainer: remove locks from get_cgroup_item()
The on-disk config file is not altered and the in-memory config isn't
altered so no need for locking.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-20 22:42:55 +02:00
Christian Brauner
03095169ca
lxccontainer: remove locks from set_cgroup_item()
The on-disk config file is not altered and the in-memory config isn't
altered so no need for locking.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-20 22:41:45 +02:00
2xsec
e581b9b5f2
security: fix too wide or inconsistent non-owner permissions
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-09-19 14:30:12 +09:00
Christian Brauner
b07ea13d4a
lxccontainer: use correct pid_t type
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-11 11:18:13 +02:00
2xsec
5106ecd032
lxccontainer: fix dereferenced pointer
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-09-06 16:55:10 +09:00
Christian Brauner
979a0d9354
Revert "Revert "tree-wide: use sizeof on static arrays""
This reverts commit 2fb7cf0b32.

The problem wasn't caused by the reverted commit and was fixed in

commit 0c9b1f826d ("macro: calculate buffer lengths correctly")

The full explanation can be taken from the following irc excerpt from
the #lxc-dev channel:

│19:54:47 brauner | there was a bug in one of the standard macros we used
│19:55:01 brauner | and the changes by INTTYPE_TO_STRLEN() caused the issue to surface
│19:55:03 brauner | which is good
│19:55:16 brauner | i sent a branch and stgraber merged it that fixes it
│19:57:56  Blub\0 | so...
│19:58:31  Blub\0 | still doesn't explain how it was the sizeof() patch
│20:07:14 brauner | Blub\0: so here's the long explanation
│20:07:35 brauner | Blub\0: stgraber bumped pid_max on our jenkins test builders
│20:07:53 brauner | Blub\0: because we're running *a lot* of containers
│20:07:56 brauner | in any case
│20:08:06 brauner | there was a buffer
│20:08:12 brauner | LXC_LSMATTRLEN
│20:08:59 brauner | it used to be
│20:09:03 brauner | -/* /proc/pid-to-str/attr/current = (5 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1) */
│20:09:03 brauner | -#define LXC_LSMATTRLEN (5 + INTTYPE_TO_STRLEN(pid_t) + 7 + 1)
│20:09:14 brauner | which one can see is wrong
│20:09:21 brauner | before the INTTYPE patchset
│20:09:40 brauner | INTTYPE_TO_STRLEN(pid_t) was LXC_NUMSTRLEN64
│20:09:45 brauner | which gave you 21 chars
│20:09:57 brauner | so it accounted for the missing parts
│20:10:03 brauner | because the correct macro should've been
│20:10:17 brauner | +/* /proc/        = 6
│20:10:17 brauner | + *               +
│20:10:17 brauner | + * <pid-as-str>  = INTTYPE_TO_STRLEN(pid_t)
│20:10:17 brauner | + *               +
│20:10:17 brauner | + * /attr/        = 6
│20:10:17 brauner | + *               +
│20:10:17 brauner | + * /current      = 8
│20:10:17 brauner | + *               +
│20:10:17 brauner | + * \0            = 1
│20:10:17 brauner | + */
│20:10:17 brauner | +#define LXC_LSMATTRLEN (6 + INTTYPE_TO_STRLEN(pid_t) + 6 + 8 + 1)
│20:10:24  Blub\0 | still
│20:10:31 brauner | the issue was only seen
│20:10:39 brauner | when the pid number hit a specific maximum
│20:10:50  Blub\0 | the sizeof patch only changed instances of actual char buf[A_FIXED_NUMBER] + snprintf(buf, A_FIXED_NUMBER, ...)
│20:10:54 brauner | aka exceeded the newly shortened buffer
│20:11:42 brauner | your patch was a red herring
│20:12:03  Blub\0 | I guess
│20:12:06 brauner | it didn't cause it
│20:12:14 brauner | it just surfaced at the same time it was merged
│20:12:25  Blub\0 | so we can revert the revert then? :)
│20:12:35 brauner | yes, that was th eplan all along

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-09-01 20:25:07 +02:00
Stéphane Graber
2fb7cf0b32
Revert "tree-wide: use sizeof on static arrays"
This reverts commit 81a3bb64b4.

This commit broke all builders running with pid_max > 32768.

Reverting for now so we can bring the build farm back online.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2018-08-31 11:58:17 -07:00
Wolfgang Bumiller
6b28940591
Merge pull request #2435 from brauner/2018-06-27/storage_managed
[RFC] conf: introduce lxc.rootfs.managed
2018-08-30 08:28:08 +02:00
Wolfgang Bumiller
81a3bb64b4 tree-wide: use sizeof on static arrays
Instead of duplicating their lengths in read/snprintf/...
calls.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-08-29 21:46:39 +02:00
Christian Brauner
da07fe61fc
lxccontainer: s/LXC_NUMSTRLEN64/INTTYPE_TO_STRLEN()/
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-28 20:14:52 +02:00
Christian Brauner
5a087e056f
cgroups: don't escape if lxc.cgroup.keep is true
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Felix Abecassis <fabecassis@nvidia.com>
Cc: Jonathan Calmels <jcalmels@nvidia.com>
2018-08-27 03:16:41 +02:00
Christian Brauner
bafad46888
lxccontainer: minor fixes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-16 00:25:15 +02:00
Christian Brauner
d1bc8d484c
lxccontainer: improve file locking
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-15 00:37:05 +02:00
Christian Brauner
ec74f3f859
lxccontainer: fix F_OFD_GETLK checks
When we check whether an open file description lock has been taken on a file we
need to set the l_pid field to 0 otherwise the kernel will send back EINVAL.
Additionally, the kernel will not do pid translation and simply set the l_pid
value to -1.

Fixes https://discuss.linuxcontainers.org/t/container-deleted-or-stopped-when-lxc-ls-executed-concurrently/2439

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-14 13:00:29 +02:00
2xsec
df05fa0f04
fix thread safe issue(localtime => localtime_r)
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-13 16:53:30 +09:00
Christian Brauner
6e54330c46
conf: introduce lxc.rootfs.managed
This introduces a new config key lxc.rootfs.managed which can be used to
indicate whether this LXC instance is managing the container storage. If LXC is
not managing the storage then LXC will not modify the container storage.
For example, an API call to c->destroy(c) will then run any destroy hooks but
will not destroy the actual rootfs (Unless, of course, the hook does so behind
LXC's back.).

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
CC: Wolfgang Bumiller <w.bumiller@proxmox.com>
CC: Stéphane Graber <stgraber@ubuntu.com>
CC: Serge Hallyn <serge@hallyn.com>
CC: 2xsec <dh48.jeong@samsung.com>
2018-07-31 22:09:34 +02:00
Christian Brauner
3e1e9db834
lxccontainer: s/read()/lxc_read_nointr()/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-30 00:16:26 +02:00
Christian Brauner
2a2a676d04
lxccontainer: s/write()/lxc_write_nointr()/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-30 00:16:25 +02:00
Christian Brauner
0ac84f04d1
lxccontainer: s/pipe()/pipe2()/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-30 00:16:17 +02:00
Christian Brauner
9f4866a6f2
lxccontainer: cleanup do_lxcapi_get_interfaces()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-30 00:16:16 +02:00
Christian Brauner
3c1f04cdfa
lxccontainer: s/strtok_r()/lxc_iterate_parts()/g
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-26 16:38:42 +02:00
Liza Tretyakova
60534030e4
conf, lxccontainer: fix length checks in snprintf
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
2018-07-22 15:35:21 +02:00
Liza Tretyakova
7a41e8578e
conf, confile, lxccontainer, start: nonfunctional changes
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
2018-07-22 15:35:21 +02:00
Christian Brauner
1f5a90f946
lxccontainer: reword create_mount_target()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-22 15:35:21 +02:00
Christian Brauner
3340f44172
lxccontainer: do_lxcapi_mount() coding-style
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-22 15:34:06 +02:00
Liza Tretyakova
c6885c3f24
lxccontainer: add handling of file mounts
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
2018-07-22 15:33:51 +02:00
Liza Tretyakova
d83da817b3
lxccontainer: add the umount API function
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
[christian@brauner.io: minor coding-style changes]
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-07-22 15:32:42 +02:00
Liza Tretyakova
29df56cda5
lxccontainer: add container API function and structs for injecting a mount
Signed-off-by: Liza Tretyakova <elizabet.tretyakova@gmail.com>
2018-07-22 15:25:16 +02:00