X-Git-Url: https://git.liburcu.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Futils%2Ftestapp%2Fgen-ns-events%2Fgen-ns-events.cpp;h=dc18e4e9f91f36b630c65db25d36cda4f90a3435;hp=80afdb6d63ed27c99510c7068436a7539d23bcf2;hb=28ab034a2c3582d07d3423d2d746731f87d3969f;hpb=52e345b9ac912d033c2a2c25a170a01cf209839d diff --git a/tests/utils/testapp/gen-ns-events/gen-ns-events.cpp b/tests/utils/testapp/gen-ns-events/gen-ns-events.cpp index 80afdb6d6..dc18e4e9f 100644 --- a/tests/utils/testapp/gen-ns-events/gen-ns-events.cpp +++ b/tests/utils/testapp/gen-ns-events/gen-ns-events.cpp @@ -9,6 +9,13 @@ #define _GNU_SOURCE #endif +#include "signal-helper.hpp" +#include "utils.h" + +#include +#include + +#include #include #include #include @@ -18,13 +25,6 @@ #include #include #include -#include - -#include -#include - -#include "signal-helper.hpp" -#include "utils.h" #define LTTNG_PROC_NS_PATH_MAX 40 @@ -35,28 +35,28 @@ * but that use a libc that doesn't define its associated clone flag. */ #ifndef CLONE_NEWNS -#define CLONE_NEWNS 0x00020000 +#define CLONE_NEWNS 0x00020000 #endif #ifndef CLONE_NEWCGROUP #define CLONE_NEWCGROUP 0x02000000 #endif #ifndef CLONE_NEWUTS -#define CLONE_NEWUTS 0x04000000 +#define CLONE_NEWUTS 0x04000000 #endif #ifndef CLONE_NEWIPC -#define CLONE_NEWIPC 0x08000000 +#define CLONE_NEWIPC 0x08000000 #endif #ifndef CLONE_NEWUSER -#define CLONE_NEWUSER 0x10000000 +#define CLONE_NEWUSER 0x10000000 #endif #ifndef CLONE_NEWPID -#define CLONE_NEWPID 0x20000000 +#define CLONE_NEWPID 0x20000000 #endif #ifndef CLONE_NEWNET -#define CLONE_NEWNET 0x40000000 +#define CLONE_NEWNET 0x40000000 #endif #ifndef CLONE_NEWTIME -#define CLONE_NEWTIME 0x00000080 +#define CLONE_NEWTIME 0x00000080 #endif static int debug = 0; @@ -69,15 +69,31 @@ static struct poptOption opts[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ { "debug", 'd', POPT_ARG_NONE, &debug, 0, "Enable debug output", NULL }, { "ns", 'n', POPT_ARG_STRING, &ns_opt, 0, "Namespace short identifier", NULL }, - { "before", 'b', POPT_ARG_STRING, &before_unshare_wait_file_path, 0, "Wait for file before unshare", NULL }, - { "after", 'a', POPT_ARG_STRING, &after_unshare_wait_file_path, 0, "Wait for file after unshare", NULL }, - { "signal", 's', POPT_ARG_STRING, &after_unshare_signal_file_path, 0, "Create signal file after unshare", NULL }, - POPT_AUTOHELP - { NULL, 0, 0, NULL, 0, NULL, NULL } + { "before", + 'b', + POPT_ARG_STRING, + &before_unshare_wait_file_path, + 0, + "Wait for file before unshare", + NULL }, + { "after", + 'a', + POPT_ARG_STRING, + &after_unshare_wait_file_path, + 0, + "Wait for file after unshare", + NULL }, + { "signal", + 's', + POPT_ARG_STRING, + &after_unshare_signal_file_path, + 0, + "Create signal file after unshare", + NULL }, + POPT_AUTOHELP{ NULL, 0, 0, NULL, 0, NULL, NULL } }; -static ATTR_FORMAT_PRINTF(1, 2) -void debug_printf(const char *format, ...) +static ATTR_FORMAT_PRINTF(1, 2) void debug_printf(const char *format, ...) { va_list args; va_start(args, format); @@ -98,8 +114,7 @@ static int get_ns_inum(const char *ns, ino_t *ns_inum) /* * /proc/thread-self was introduced in kernel v3.17 */ - if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, - "/proc/thread-self/ns/%s", ns) >= 0) { + if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, "/proc/thread-self/ns/%s", ns) >= 0) { if (stat(proc_ns_path, &sb) == 0) { *ns_inum = sb.st_ino; } else { @@ -108,8 +123,11 @@ static int get_ns_inum(const char *ns, ino_t *ns_inum) goto end; } - if (snprintf(proc_ns_path, LTTNG_PROC_NS_PATH_MAX, - "/proc/self/task/%d/%s/net", lttng_gettid(), ns) >= 0) { + if (snprintf(proc_ns_path, + LTTNG_PROC_NS_PATH_MAX, + "/proc/self/task/%d/%s/net", + lttng_gettid(), + ns) >= 0) { if (stat(proc_ns_path, &sb) == 0) { *ns_inum = sb.st_ino; } else { @@ -128,8 +146,7 @@ static int do_the_needful(int ns_flag, const char *ns_str) ret = get_ns_inum(ns_str, &ns1); if (ret) { - debug_printf("Failed to get ns inode number for namespace %s", - ns_str); + debug_printf("Failed to get ns inode number for namespace %s", ns_str); ret = -1; goto end; } @@ -151,8 +168,7 @@ static int do_the_needful(int ns_flag, const char *ns_str) ret = get_ns_inum(ns_str, &ns2); if (ret) { - debug_printf("Failed to get ns inode number for namespace %s", - ns_str); + debug_printf("Failed to get ns inode number for namespace %s", ns_str); ret = -1; goto end; } @@ -205,7 +221,8 @@ int main(int argc, const char **argv) if (opt < -1) { /* an error occurred during option processing */ poptPrintUsage(pc, stderr, 0); - fprintf(stderr, "%s: %s\n", + fprintf(stderr, + "%s: %s\n", poptBadOption(pc, POPT_BADOPTION_NOALIAS), poptStrerror(opt)); ret = EXIT_FAILURE;