Skip to content

Commit

Permalink
Merge pull request containers#471 from giuseppe/clang-format
Browse files Browse the repository at this point in the history
src: use clang-format
  • Loading branch information
rhatdan authored Aug 25, 2020
2 parents fb75d09 + ed40d38 commit 8bd4f3e
Show file tree
Hide file tree
Showing 60 changed files with 1,861 additions and 2,078 deletions.
117 changes: 117 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
BasedOnStyle: GNU
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: AllDefinitions
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortBlocksOnASingleLine: false
BreakBeforeBraces: Allman
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
ContinuationIndentWidth: 4
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeIsMainRegex: '(Test)?$'
IncludeIsMainSourceRegex: ''
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: AfterHash
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: Always
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
TabWidth: 8
UseCRLF: false
UseTab: Never
...
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ matrix:
env: TEST=coverity
- arch: amd64
env: TEST=alpine-build
- arch: amd64
env: TEST=clang-format
matrix:
- TEST=make-arm64
- TEST=make-amd64
- TEST=podman
- TEST=containerd
- TEST=oci-validation
- TEST=coverity
- TEST=clang-format
- TEST=alpine-build
global:
- COVERITY_SCAN_PROJECT_NAME="giuseppe/crun"
Expand All @@ -49,7 +52,7 @@ services:
- docker
language: c
sudo: required
dist: bionic
dist: focal
addons:
apt:
packages:
Expand All @@ -67,12 +70,14 @@ addons:
- go-md2man
- libsystemd-dev
- gperf
- clang-format
before_install:
- git submodule update --init --recursive
- if test $TEST = podman; then sudo docker build -t crun-podman tests/podman; fi
- if test $TEST = containerd; then sudo docker build -t crun-containerd tests/containerd; fi
- if test $TEST = oci-validation; then sudo docker build -t crun-oci-validation tests/oci-validation; fi
- if test $TEST = alpine-build; then sudo docker build -t crun-alpine-build tests/alpine-build; fi
- if test $TEST = clang-format; then sudo docker build -t crun-clang-format tests/clang-format; fi
- git clone --depth=1 git://github.com/lloyd/yajl
- "(cd yajl && ./configure -p /usr && make && sudo make install)"
# CRIU supports armhfp, aarch64, ppc64le, s390x and x86_64. The PPA has only packages for x86_64
Expand All @@ -86,3 +91,4 @@ script:
- if test $TEST = oci-validation; then sudo docker run --privileged --rm -v /sys/fs/cgroup:/sys/fs/cgroup:rw,rslave -v $(pwd):/crun crun-oci-validation; fi
- if test $TEST = coverity; then ./autogen.sh && eval "${COVERITY_SCAN_BUILD}"; fi
- if test $TEST = alpine-build; then sudo docker run --privileged --rm -v /sys/fs/cgroup:/sys/fs/cgroup:rw,rslave -v $(pwd):/crun crun-alpine-build; fi
- if test $TEST = clang-format; then ./autogen.sh && ./configure && sudo docker run --rm -w /crun -v $(pwd):/crun crun-clang-format make clang-format; fi
6 changes: 5 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,8 @@ generate-rust-bindings: libcrun.rs
generate-signals.c: src/libcrun/signals.perf
${GPERF} --lookup-function-name libcrun_signal_in_word_set -m 100 --null-strings --pic -tCEG -S1 $< > src/libcrun/signals.c

.PHONY: coverity sync generate-rust-bindings generate-signals.c
clang-format:
# do not format files that were copied into the source directory.
git ls-files src | egrep "\\.[hc]" | grep -v "chroot_realpath.c\|cloned_binary.c\|signals.c" | xargs clang-format -style=file -i

.PHONY: coverity sync generate-rust-bindings generate-signals.c clang-format
39 changes: 17 additions & 22 deletions src/checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ static char doc[] = "OCI runtime";

static libcrun_checkpoint_restore_t cr_options;

static struct argp_option options[] = {
{"image-path", OPTION_IMAGE_PATH, "DIR", 0,
"path for saving criu image files", 0},
{"work-path", OPTION_WORK_PATH, "DIR", 0,
"path for saving work files and logs", 0},
{"leave-running", OPTION_LEAVE_RUNNING, 0, 0,
"leave the process running after checkpointing", 0},
{"tcp-established", OPTION_TCP_ESTABLISHED, 0, 0,
"allow open tcp connections", 0},
{"ext-unix-sk", OPTION_EXT_UNIX_SK, 0, 0, "allow external unix sockets", 0},
{"shell-job", OPTION_SHELL_JOB, 0, 0, "allow shell jobs", 0},
{0,}
};
static struct argp_option options[]
= { { "image-path", OPTION_IMAGE_PATH, "DIR", 0, "path for saving criu image files", 0 },
{ "work-path", OPTION_WORK_PATH, "DIR", 0, "path for saving work files and logs", 0 },
{ "leave-running", OPTION_LEAVE_RUNNING, 0, 0, "leave the process running after checkpointing", 0 },
{ "tcp-established", OPTION_TCP_ESTABLISHED, 0, 0, "allow open tcp connections", 0 },
{ "ext-unix-sk", OPTION_EXT_UNIX_SK, 0, 0, "allow external unix sockets", 0 },
{ "shell-job", OPTION_SHELL_JOB, 0, 0, "allow shell jobs", 0 },
{
0,
} };

static char args_doc[] = "checkpoint CONTAINER";

Expand Down Expand Up @@ -101,24 +98,23 @@ parse_opt (int key, char *arg arg_unused, struct argp_state *state arg_unused)
return 0;
}

static struct argp run_argp =
{ options, parse_opt, args_doc, doc, NULL, NULL, NULL };
static struct argp run_argp = { options, parse_opt, args_doc, doc, NULL, NULL, NULL };

int
crun_command_checkpoint (struct crun_global_arguments *global_args, int argc,
char **argv, libcrun_error_t *err)
crun_command_checkpoint (struct crun_global_arguments *global_args, int argc, char **argv, libcrun_error_t *err)
{
cleanup_free char *cr_path = NULL;
int first_arg;
int ret;

libcrun_context_t crun_context = { 0, };
libcrun_context_t crun_context = {
0,
};

argp_parse (&run_argp, argc, argv, ARGP_IN_ORDER, &first_arg, &cr_options);
crun_assert_n_args (argc - first_arg, 1, 2);

ret =
init_libcrun_context (&crun_context, argv[first_arg], global_args, err);
ret = init_libcrun_context (&crun_context, argv[first_arg], global_args, err);
if (UNLIKELY (ret < 0))
return ret;

Expand All @@ -134,6 +130,5 @@ crun_command_checkpoint (struct crun_global_arguments *global_args, int argc,
cr_options.image_path = cr_path;
}

return libcrun_container_checkpoint (&crun_context, argv[first_arg],
&cr_options, err);
return libcrun_container_checkpoint (&crun_context, argv[first_arg], &cr_options, err);
}
3 changes: 1 addition & 2 deletions src/checkpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#include "crun.h"

int crun_command_checkpoint (struct crun_global_arguments *global_args,
int argc, char **argv, libcrun_error_t * error);
int crun_command_checkpoint (struct crun_global_arguments *global_args, int argc, char **argv, libcrun_error_t *error);

#endif
44 changes: 22 additions & 22 deletions src/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@
#include "libcrun/utils.h"

enum
{
OPTION_CONSOLE_SOCKET = 1000,
OPTION_PID_FILE,
OPTION_NO_SUBREAPER,
OPTION_NO_NEW_KEYRING,
OPTION_PRESERVE_FDS,
OPTION_NO_PIVOT
};
{
OPTION_CONSOLE_SOCKET = 1000,
OPTION_PID_FILE,
OPTION_NO_SUBREAPER,
OPTION_NO_NEW_KEYRING,
OPTION_PRESERVE_FDS,
OPTION_NO_PIVOT
};

static const char *bundle = NULL;

static libcrun_context_t crun_context;

static struct argp_option options[] =
{
{"bundle", 'b', "DIR", 0, "container bundle (default \".\")", 0},
{"config", 'f', "FILE", 0, "override the config file name", 0},
{"console-socket", OPTION_CONSOLE_SOCKET, "SOCK", 0, "path to a socket that will receive the ptmx end of the tty", 0},
{"preserve-fds", OPTION_PRESERVE_FDS, 0, 0, "pass additional FDs to the container", 0},
{"no-pivot", OPTION_NO_PIVOT, 0, 0, "do not use pivot_root", 0},
{"pid-file", OPTION_PID_FILE, "FILE", 0, "where to write the PID of the container", 0},
{"no-subreaper", OPTION_NO_SUBREAPER, 0, 0, "do not create a subreaper process", 0},
{"no-new-keyring", OPTION_NO_NEW_KEYRING, 0, 0, "keep the same session key", 0},
{ 0, }
};
static struct argp_option options[]
= { { "bundle", 'b', "DIR", 0, "container bundle (default \".\")", 0 },
{ "config", 'f', "FILE", 0, "override the config file name", 0 },
{ "console-socket", OPTION_CONSOLE_SOCKET, "SOCK", 0,
"path to a socket that will receive the ptmx end of the tty", 0 },
{ "preserve-fds", OPTION_PRESERVE_FDS, 0, 0, "pass additional FDs to the container", 0 },
{ "no-pivot", OPTION_NO_PIVOT, 0, 0, "do not use pivot_root", 0 },
{ "pid-file", OPTION_PID_FILE, "FILE", 0, "where to write the PID of the container", 0 },
{ "no-subreaper", OPTION_NO_SUBREAPER, 0, 0, "do not create a subreaper process", 0 },
{ "no-new-keyring", OPTION_NO_NEW_KEYRING, 0, 0, "keep the same session key", 0 },
{
0,
} };

static char doc[] = "OCI runtime";

Expand Down Expand Up @@ -123,9 +124,8 @@ crun_command_create (struct crun_global_arguments *global_args, int argc, char *

crun_assert_n_args (argc - first_arg, 1, 1);


/* Make sure the config is an absolute path before changing the directory. */
if ((strcmp("config.json", config_file) != 0))
if ((strcmp ("config.json", config_file) != 0))
{
if (config_file[0] != '/')
{
Expand Down
4 changes: 2 additions & 2 deletions src/create.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* along with crun. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CREATE_H
# define CREATE_H
#define CREATE_H

# include "crun.h"
#include "crun.h"

int crun_command_create (struct crun_global_arguments *global_args, int argc, char **argv, libcrun_error_t *error);

Expand Down
Loading

0 comments on commit 8bd4f3e

Please sign in to comment.