Commit Graph

7659 Commits

Author SHA1 Message Date
Lukasz Jagiello
8737e2a8a5
lseek - integer overflow
The issue was introduced in PR (https://github.com/lxc/lxc/pull/1705):

Previous code:
```
  if (lseek(fd, size, SEEK_SET) < 0) {
    SYSERROR("Error seeking to set new loop file size");
    close(fd);
    return -1;
  }
```
New code:
```
  int fd, ret;

  [...]

  ret = lseek(fd, size, SEEK_SET);
  if (ret < 0) {
    SYSERROR("Failed to seek to set new loop file size for loop "
       "file \"%s\"", path);
    close(fd);
    return -1;
  }
```

Based on http://man7.org/linux/man-pages/man2/lseek.2.html:
> Upon successful completion, lseek() returns the resulting offset
> location as measured in bytes from the beginning of the file.

So in this case value of `size` and `size` is `uint64_t`.

This fix change declaration of `ret`, but it can be fixed in other ways.
Let me know what works for you.

This PR fix issues (https://github.com/lxc/lxc/issues/1872).

Signed-off-by: Lukasz Jagiello <lukasz@wikia-inc.com>
2018-08-18 08:32:21 -07:00
Christian Brauner
0044aab02a
tools: fix lxc-execute command parsing
Initialize buf to avoid parsing random data later on.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-18 11:56:05 +02:00
Christian Brauner
2957be64da
Merge pull request #2546 from 2xsec/bugfix
storage_utils: move duplicated function from tools
2018-08-18 11:46:10 +02:00
2xsec
2b670dfeb0 storage_utils: move duplicated function from tools
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 18:05:32 +09:00
Christian Brauner
826a94a587
Merge pull request #2544 from 2xsec/bugfix
tools: add default log priority & cleanups
2018-08-18 09:58:53 +02:00
2xsec
34a10bfa34 tools: lxc-unfreeze: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:42:15 +09:00
2xsec
fe8c37efdb tools: lxc-freeze: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:41:51 +09:00
2xsec
c2a23ef6e4 tools: lxc-stop: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:41:06 +09:00
2xsec
c7013c1303 tools: lxc-start: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:40:29 +09:00
2xsec
e8c0bb81d3 tools: lxc-execute: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:39:20 +09:00
2xsec
9fe1638742 tools: lxc-device: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:38:13 +09:00
2xsec
a53759568a tools: lxc-destroy: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:36:58 +09:00
2xsec
0e9dc035dd tools: lxc-create: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:35:57 +09:00
2xsec
a291ab7859 tools: lxc-console: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:34:28 +09:00
2xsec
c03b298128 tools: lxc-checkpoint: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:33:37 +09:00
2xsec
62ebeb04ef tools: lxc-cgroup: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:31:54 +09:00
2xsec
81b4606580 tools: lxc-attach: add default log priority & cleanups
Signed-off-by: 2xsec <dh48.jeong@samsung.com>
2018-08-18 01:30:52 +09:00
Stéphane Graber
5493a1bf89
Merge pull request #2543 from brauner/2018-08-17/silence_init_umount_failures
lxc_init: s/SYSDEBUG()/SYSERROR()/g in remove_self
2018-08-17 10:48:33 -04:00
Christian Brauner
694756df3a
lxc_init: s/SYSDEBUG()/SYSERROR()/g in remove_self
Since we switched to execveat() whenever possible in
commit 4b5b3a2a29 ("execute: use execveat() syscall if supported")
it is unlikely that remove_self() has any job to do at all. So dumb down the
error levels.

Closes #2536.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-17 11:47:25 +02:00
Christian Brauner
3278fdc26c
Merge pull request #2540 from tcharding/checkatch-cmd
cmd: Fix up checkpatch warnings
2018-08-17 11:41:27 +02:00
Christian Brauner
5246e140b8
Merge pull request #2539 from tcharding/contributing
Clean up contributing and coding stlye docs
2018-08-17 11:27:22 +02:00
Tobin C. Harding
551865932e cmd: Do not use comparison to NULL
checkpatch emits two warnings of type:

    CHECK: Comparison to NULL could be written "!foo"

Prefer `(!foo)` instead of `(foo == NULL)`.

Do not use comparison to NULL, use !foo

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 16:18:27 +10:00
Tobin C. Harding
2115d56671 cmd: Remove typo'd semicolon
checkpatch emits warning:

    WARNING: Statements terminations use 1 semicolon

Remove typo'd semicolon.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 16:14:30 +10:00
Tobin C. Harding
75ca3dc6aa cmd: Put trailing */ on a separate line
checkpatch emits warning:

    WARNING: Block comments use a trailing */ on a separate line

Put trailing */ on a separate line.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 16:14:06 +10:00
Tobin C. Harding
1d9f2743b2 cmd: Remove unnecessary whitespace in string
checkpatch emits warning:

    WARNING: unnecessary whitespace before a quoted newline

Remove unnecessary whitespace before a quoted newline

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 16:10:08 +10:00
Tobin C. Harding
7f5700e6aa cmd: Use 'const' for static string constant.
checkpatch emits warning:

WARNING: static char array declaration should probably be static const char

Use 'const' for static string constant (array of chars).

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 16:10:08 +10:00
Tobin C. Harding
32cf169fab cmd: Fix whitespace issues
checkpatch warns about a bunch of whitespace issues.  Fix the
non-controversial ones.

Fix whitespace issues found by checkpatch.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 16:10:03 +10:00
Tobin C. Harding
24d6fb8a27 cmd: Do not use braces for single statement block
checkpatch emites warning:

    WARNING: braces {} are not necessary for single statement blocks

Do not use braces for single statement block.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 15:52:09 +10:00
Tobin C. Harding
2b360805d0 cmd: Use 'void' instead of empty parameter list
checkpatch warns because of function definitions using empty parameter
list.  We should define these functions with 'void' as the parameter.

Use 'void' instead of empty parameter list for function definitions.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 15:44:25 +10:00
Tobin C. Harding
e8fcdf3db2 cmd: Use parenthesis around complex macro
checkpatch emits error:

    ERROR: Macros with complex values should be enclosed in parentheses

Safeguard macro by use of parenthesis.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 15:42:32 +10:00
Tobin C. Harding
7419c83f44 CODING_STYLE: Update section header format
Currently for section headings we use fourth level markdown heading
level (####).  We do not have levels two or three.

We can use standard incremental levels for heading adornments i.e

1) =========
2) ##
3) ###
ect.

Since this document is likely referenced by maintainers when guiding new
contributors it can save maintainer time to be able to quickly reference
a section in the coding stlye guide.  If we add numbers to each heading
(like the kernel stlye guide) then maintainers can say:

   Nice patch, please see section 3 of the coding style guide and ...

So, this patch makes two changes

- Use incremental level heading adornments
- Add a number to each section heading

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:54:35 +10:00
Tobin C. Harding
efcb7f361b CODING_STYLE: Fix non-uniform heading level
Heading uses only 3 level header (###) but the rest of the file uses
four (####).  We should be uniform.

Use uniform heading level in line with the rest of the file.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:37:15 +10:00
Tobin C. Harding
524440e920 CODING_STLYE: Remove sections implied by 'kernel style'
We explicitly state that LXC uses coding style based on Linux kernel
style.  It is redundant to then document obvious, and well known, kernel
style rules.  Identifier names certainly fall into this category as does
usage of braces.

Remove sections implied by 'kernel style'.  Naming conventions and brace
placement conventions.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:37:15 +10:00
Tobin C. Harding
39a1e1fa19 CODING_STLYE: Simplify explanation for use of 'extern'
Current explanation of rules around usage of 'extern' are overly
verbose.  It is not necessary to state that functions should be declared
in header files, the compiler already enforces this.  These rules are
simple, they are better described with simple statements.  An example is
not necessary for such simple rules and serves only to make the document
longer.

Use two simple statements describing the rules that govern function
declaration and the usage of the 'extern' keyword.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:37:13 +10:00
Tobin C. Harding
cd15ab7a04 CONTRIBUTING: Add 'be' to fix grammar
Fix minor grammatical issue.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:36:58 +10:00
Tobin C. Harding
183d7fa5ce CODING_STYLE: Mention kernel style in introduction
Currently the coding style guide does not mention that we use kernel
coding style as a base style for LXC.  We have just linked to
CODING_STLYE.md from CONTRIBUTING (which mentions use of kernel coding
style).  We can increase documentation congruence and completeness by
mentioning kernel coding style guide in the introduction to our style
guide.

Add heading and introduction to coding style guide informing readers
that we follow kernel coding style as a base before explaining our style
additions.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:36:30 +10:00
Tobin C. Harding
54df5d72ed CONTRIBUTING: Direct readers to CODING_STYLE.md
Currently the 'Coding Style' section mentions only the kernel coding
style.  We have additions on top on this outlined in CODING_STYLE.md.
We should direct readers to this document as well as the kernel docs.

Direct readers to CODING_STLYE.md in the 'Coding Style' section.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:30:54 +10:00
Tobin C. Harding
b6fbcbbb81 CONTRIBUTING: Link to latest online kernel docs
Currently we link to a URL for v4.10 of the kernel docs.  Since we
already mention the kernel tree we should link to the _latest_ kernel
docs online instead of a fixed past version.

Link to latest online kernel docs tracking the mainline instead of past
fixed version.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:29:15 +10:00
Tobin C. Harding
82778d4134 CONTRIBUTING: Update reference to kernel coding style
Kernel coding style guide filename is stale, this file has been renamed
in the kernel tree.  While this file still exists we should use the new
filename.

Update reference to kernel coding style guide to use the new file name.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-17 14:29:07 +10:00
Stéphane Graber
d1bf8af11b
Merge pull request #2535 from brauner/2018-08-16/cmd_fixes
log: add logging tools for commands; lxc-usernsexec: cleanup and bugfixes
2018-08-16 11:44:27 -04:00
Christian Brauner
02af80662d
lxc-usernsexec: cleanup and bugfixes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-16 16:29:17 +02:00
Christian Brauner
20029ee35a
log: add CMD_SYSINFO()
Add a thread-safe and uniform way to retrieve errno values in programs that are
shipped as part of LXC but are not expected to have access to the logging
system.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-16 13:03:21 +02:00
Christian Brauner
bb9623e705
log: add CMD_SYSERROR()
Add a thread-safe and uniform way to retrieve errno values in programs that are
shipped as part of LXC but are not expected to have access to the logging
system.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-08-16 13:01:54 +02:00
Christian Brauner
7a8e91c1fc
Merge pull request #2534 from tcharding/checkpatch
Checkpatch
2018-08-16 10:40:10 +02:00
Christian Brauner
c5aca61506
Merge pull request #2532 from tcharding/unshare-err
usernsexec: Make err out vebose for unshare error
2018-08-16 09:16:10 +02:00
Tobin C. Harding
f0a86c6d1c cmd: Move assignment out of if statement
checkpatch.pl emits error

    ERROR: do not use assignment in if condition

Move assignment out of if statement.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-16 17:06:20 +10:00
Tobin C. Harding
2db65c2187 cmd: Fix whitespace ERRORS
checkpatch.pl emits a bunch of warnings about various whitespace
issues.  Fix all these as a single patch since they are all whitespace
only changes.

Fix whitespace issues found by checkpatch.pl

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-16 17:01:30 +10:00
Tobin C. Harding
3c84faa377 cmd: Do not initialise statics to 0
checkpatch.pl emits error

    ERROR: do not initialise statics to 0

Do not initialise statics to 0.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-16 16:57:36 +10:00
Tobin C. Harding
27fdb6bec5 cmd: Correctly indent switch statement
checkpatch.pl emits error

    ERROR: do not use assignment in if condition

Correctly indent switch statement.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-16 16:55:09 +10:00
Tobin C. Harding
ede912b440 usernsexec: Make err out vebose for unshare error
Currently if lxc-usernsexec is run on a kernel without user namespaces
enabled the error message is

	unshare: Invalid argument
	read pipe: Success

This error message 'Invalid argument' does not point at the root cause
of the error.  We can help the user out by giving a more detailed error
message and also not using perror() if errno==0.

Improve error message by
 - Printing unshare flags
 - Printing suggested cause of failure (user namespace not enabled)
 - Print error message with fprintf() if errno==0 (EOF)

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2018-08-16 16:44:12 +10:00