[CRIU] [PATCH 14/15 v2] criu --help: print a proper list of features
Kir Kolyshkin
kir at openvz.org
Wed Aug 31 11:56:27 PDT 2016
Remove that weird special case from check_add_feature() function, making
it a separate pr_check_features(), which prints a SEP-separated list of
feature names, obeying the max WIDTH, and prepending each line with
OFFSET. That way, we have a decept --help output:
--feature FEAT only check a particular feature, one of:
mnt_id, mem_dirty_track, aio_remap, timerfd, tun,
userns, fdinfo_lock, seccomp_suspend,
seccomp_filters, loginuid, cgroupns, autofs
Alternatively, we could just drop the functionality of showing all the
individual features to check.
[v2: use %s in pr_msg to fix a -Wformat-security warning]
Signed-off-by: Kir Kolyshkin <kir at openvz.org>
---
criu/cr-check.c | 29 +++++++++++++++++++++++------
criu/crtools.c | 2 +-
criu/include/crtools.h | 1 +
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/criu/cr-check.c b/criu/cr-check.c
index 2bee096..bb4d978 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -1113,16 +1113,33 @@ static struct feature_list feature_list[] = {
{ NULL, NULL },
};
-int check_add_feature(char *feat)
+void pr_check_features(const char *offset, const char *sep, int width)
{
struct feature_list *fl;
+ int pos = width + 1;
+ int sep_len = strlen(sep);
+ int offset_len = strlen(offset);
+
+ for (fl = feature_list; fl->name; fl++) {
+ int len = strlen(fl->name);
- if (!strcmp(feat, "list")) {
- for (fl = feature_list; fl->name; fl++)
- pr_msg("%s ", fl->name);
- pr_msg("\n");
- return 1;
+ if (pos + len + sep_len > width) {
+ pr_msg("\n%s", offset);
+ pos = offset_len;
+ }
+ pr_msg("%s", fl->name);
+ pos += len;
+ if ((fl + 1)->name) { // not the last item
+ pr_msg("%s", sep);
+ pos += sep_len;
+ }
}
+ pr_msg("\n");
+}
+
+int check_add_feature(char *feat)
+{
+ struct feature_list *fl;
for (fl = feature_list; fl->name; fl++) {
if (!strcmp(feat, fl->name)) {
diff --git a/criu/crtools.c b/criu/crtools.c
index 344c5e0..bcae557 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -918,7 +918,7 @@ usage:
" --all same as --extra --experimental\n"
" --feature FEAT only check a particular feature, one of:"
);
- check_add_feature("list");
+ pr_check_features(" ", ", ", 80);
pr_msg(
"\n"
"* Logging:\n"
diff --git a/criu/include/crtools.h b/criu/include/crtools.h
index 878e6a1..2aa5e4a 100644
--- a/criu/include/crtools.h
+++ b/criu/include/crtools.h
@@ -26,5 +26,6 @@ extern int cr_dedup(void);
extern int cr_lazy_pages(void);
extern int check_add_feature(char *arg);
+extern void pr_check_features(const char *offset, const char *sep, int width);
#endif /* __CR_CRTOOLS_H__ */
--
2.7.4
More information about the CRIU
mailing list