chiark / gitweb /
build-sys: link most internal libraries statically
[elogind.git] / src / analyze / analyze.c
index b596cadf2f1527651500acb2a24aa176b170cd87..22bf07670ecab41992d741438387bc1ba74156fc 100644 (file)
@@ -62,7 +62,6 @@
                 svg("</text>\n");                                       \
         } while(false)
 
-static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
 static enum dot {
         DEP_ALL,
         DEP_ORDER,
@@ -72,6 +71,9 @@ static char** arg_dot_from_patterns = NULL;
 static char** arg_dot_to_patterns = NULL;
 static usec_t arg_fuzz = 0;
 static bool arg_no_pager = false;
+static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
+static char *arg_host = NULL;
+static bool arg_user = false;
 
 struct boot_times {
         usec_t firmware_time;
@@ -1083,6 +1085,7 @@ static int dot(sd_bus *bus, char* patterns[]) {
 
         return 0;
 }
+
 static int dump(sd_bus *bus, char **args) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
@@ -1123,7 +1126,6 @@ static int dump(sd_bus *bus, char **args) {
 static int set_log_level(sd_bus *bus, char **args) {
         _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         int r;
-        const char* value;
 
         assert(bus);
         assert(args);
@@ -1133,8 +1135,6 @@ static int set_log_level(sd_bus *bus, char **args) {
                 return -E2BIG;
         }
 
-        value = args[0];
-
         r = sd_bus_set_property(
                         bus,
                         "org.freedesktop.systemd1",
@@ -1143,7 +1143,7 @@ static int set_log_level(sd_bus *bus, char **args) {
                         "LogLevel",
                         &error,
                         "s",
-                        value);
+                        args[0]);
         if (r < 0) {
                 log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
                 return -EIO;
@@ -1152,44 +1152,46 @@ static int set_log_level(sd_bus *bus, char **args) {
         return 0;
 }
 
-static void analyze_help(void) {
+static int help(void) {
 
         pager_open_if_enabled();
 
         printf("%s [OPTIONS...] {COMMAND} ...\n\n"
-               "Process systemd profiling information\n\n"
-               "  -h --help           Show this help\n"
-               "     --version        Show package version\n"
-               "     --system         Connect to system manager\n"
-               "     --user           Connect to user service manager\n"
-               "     --order          When generating a dependency graph, show only order\n"
-               "     --require        When generating a dependency graph, show only requirement\n"
+               "Process systemd profiling information.\n\n"
+               "  -h --help               Show this help\n"
+               "     --version            Show package version\n"
+               "     --system             Connect to system manager\n"
+               "     --user               Connect to user manager\n"
+               "  -H --host=[USER@]HOST   Operate on remote host\n"
+               "  -M --machine=CONTAINER  Operate on local container\n"
+               "     --order              When generating a dependency graph, show only order\n"
+               "     --require            When generating a dependency graph, show only requirement\n"
                "     --from-pattern=GLOB, --to-pattern=GLOB\n"
-               "                      When generating a dependency graph, filter only origins\n"
-               "                      or destinations, respectively\n"
-               "     --fuzz=TIMESPAN  When printing the tree of the critical chain, print also\n"
-               "                      services, which finished TIMESPAN earlier, than the\n"
-               "                      latest in the branch. The unit of TIMESPAN is seconds\n"
-               "                      unless specified with a different unit, i.e. 50ms\n"
-               "     --no-pager       Do not pipe output into a pager\n\n"
+               "                          When generating a dependency graph, filter only origins\n"
+               "                          or destinations, respectively\n"
+               "     --fuzz=TIMESPAN      When printing the tree of the critical chain, print also\n"
+               "                          services, which finished TIMESPAN earlier, than the\n"
+               "                          latest in the branch. The unit of TIMESPAN is seconds\n"
+               "                          unless specified with a different unit, i.e. 50ms\n"
+               "     --no-pager           Do not pipe output into a pager\n\n"
                "Commands:\n"
-               "  time                Print time spent in the kernel before reaching userspace\n"
-               "  blame               Print list of running units ordered by time to init\n"
-               "  critical-chain      Print a tree of the time critical chain of units\n"
-               "  plot                Output SVG graphic showing service initialization\n"
-               "  dot                 Output dependency graph in dot(1) format\n"
-               "  set-log-level LEVEL Set logging threshold for systemd\n"
-               "  dump                Output state serialization of service manager\n",
+               "  time                    Print time spent in the kernel before reaching userspace\n"
+               "  blame                   Print list of running units ordered by time to init\n"
+               "  critical-chain          Print a tree of the time critical chain of units\n"
+               "  plot                    Output SVG graphic showing service initialization\n"
+               "  dot                     Output dependency graph in dot(1) format\n"
+               "  set-log-level LEVEL     Set logging threshold for systemd\n"
+               "  dump                    Output state serialization of service manager\n",
                program_invocation_short_name);
 
         /* When updating this list, including descriptions, apply
          * changes to shell-completion/bash/systemd and
          * shell-completion/systemd-zsh-completion.zsh too. */
+
+        return 0;
 }
 
 static int parse_argv(int argc, char *argv[]) {
-        int r;
-
         enum {
                 ARG_VERSION = 0x100,
                 ARG_ORDER,
@@ -1213,29 +1215,32 @@ static int parse_argv(int argc, char *argv[]) {
                 { "to-pattern",   required_argument, NULL, ARG_DOT_TO_PATTERN   },
                 { "fuzz",         required_argument, NULL, ARG_FUZZ             },
                 { "no-pager",     no_argument,       NULL, ARG_NO_PAGER         },
-                { NULL,           0,                 NULL, 0                    }
+                {}
         };
 
+        int r, c;
+
         assert(argc >= 0);
         assert(argv);
 
-        for (;;) {
-                switch (getopt_long(argc, argv, "h", options, NULL)) {
+        while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0) {
+
+                switch (c) {
 
                 case 'h':
-                        analyze_help();
-                        return 0;
+                        return help();
 
                 case ARG_VERSION:
-                        puts(PACKAGE_STRING "\n" SYSTEMD_FEATURES);
+                        puts(PACKAGE_STRING);
+                        puts(SYSTEMD_FEATURES);
                         return 0;
 
                 case ARG_USER:
-                        arg_scope = UNIT_FILE_USER;
+                        arg_user = true;
                         break;
 
                 case ARG_SYSTEM:
-                        arg_scope = UNIT_FILE_SYSTEM;
+                        arg_user = false;
                         break;
 
                 case ARG_ORDER:
@@ -1268,8 +1273,15 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_no_pager = true;
                         break;
 
-                case -1:
-                        return 1;
+                case 'H':
+                        arg_transport = BUS_TRANSPORT_REMOTE;
+                        arg_host = optarg;
+                        break;
+
+                case 'M':
+                        arg_transport = BUS_TRANSPORT_CONTAINER;
+                        arg_host = optarg;
+                        break;
 
                 case '?':
                         return -EINVAL;
@@ -1278,6 +1290,8 @@ static int parse_argv(int argc, char *argv[]) {
                         assert_not_reached("Unhandled option");
                 }
         }
+
+        return 1;
 }
 
 int main(int argc, char *argv[]) {
@@ -1293,13 +1307,9 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 goto finish;
 
-        if (arg_scope == UNIT_FILE_SYSTEM)
-                r = sd_bus_open_system(&bus);
-        else
-                r = sd_bus_open_user(&bus);
-
+        r = bus_open_transport(arg_transport, arg_host, arg_user, &bus);
         if (r < 0) {
-                log_error("Failed to connect to bus: %s", strerror(-r));
+                log_error("Failed to create bus connection: %s", strerror(-r));
                 goto finish;
         }