[systemd-commits] 6 commits - .gitignore Makefile.am man/systemctl.xml man/systemd-analyze.xml shell-completion/systemd-bash-completion.sh shell-completion/systemd-zsh-completion.zsh src/analyze src/shared src/systemctl TODO

Auke-Jan Kok auke at kemper.freedesktop.org
Wed Feb 13 14:59:42 PST 2013


 .gitignore                                  |    1 
 Makefile.am                                 |   21 
 TODO                                        |    2 
 man/systemctl.xml                           |   44 -
 man/systemd-analyze.xml                     |   40 +
 shell-completion/systemd-bash-completion.sh |    4 
 shell-completion/systemd-zsh-completion.zsh |    8 
 src/analyze/systemd-analyze.c               |  804 ++++++++++++++++++++++++++++
 src/analyze/systemd-analyze.in              |  328 -----------
 src/shared/dbus-common.c                    |   28 
 src/shared/dbus-common.h                    |   15 
 src/systemctl/systemctl.c                   |  238 --------
 12 files changed, 906 insertions(+), 627 deletions(-)

New commits:
commit 3e37b970b5454863ca34bd96506c4f14804b2580
Author: Auke Kok <auke-jan.h.kok at intel.com>
Date:   Wed Feb 13 14:51:12 2013 -0800

    Add systemd-analyze to .gitignore

diff --git a/.gitignore b/.gitignore
index d27cce7..9afbb10 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,7 @@
 /systemctl
 /systemd
 /systemd-ac-power
+/systemd-analyze
 /systemd-ask-password
 /systemd-binfmt
 /systemd-bootchart

commit 1700761b0678a5f5b43dc5224a97cc1922f74fad
Author: Simon Peeters <peeters.simon at gmail.com>
Date:   Wed Feb 13 14:17:28 2013 -0800

    Move systemctl dot to systemd-analyze dot

diff --git a/TODO b/TODO
index b89e3ea..f6fbb53 100644
--- a/TODO
+++ b/TODO
@@ -80,8 +80,6 @@ Features:
 
 * introduce ExecCondition= in services
 
-* if we have systemd-analyze in C "systemctl dot" should move there too
-
 * EFI:
   - fsck hookup for the ESP mount is missing
   - write man page for efi boot generator
diff --git a/man/systemctl.xml b/man/systemctl.xml
index bf11cc3..7f70642 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -272,32 +272,6 @@
                         </varlistentry>
 
                         <varlistentry>
-                                <term><option>--order</option></term>
-                                <term><option>--require</option></term>
-
-                                <listitem><para>When used in
-                                conjunction with the
-                                <command>dot</command> command (see
-                                below), selects which dependencies are
-                                shown in the dependency graph. If
-                                <option>--order</option> is passed
-                                only dependencies of type
-                                <varname>After=</varname> or
-                                <varname>Before=</varname> are
-                                shown. If <option>--require</option>
-                                is passed only dependencies of type
-                                <varname>Requires=</varname>,
-                                <varname>RequiresOverridable=</varname>,
-                                <varname>Requisite=</varname>,
-                                <varname>RequisiteOverridable=</varname>,
-                                <varname>Wants=</varname> and
-                                <varname>Conflicts=</varname> are
-                                shown. If neither is passed, shows
-                                dependencies of all these
-                                types.</para></listitem>
-                        </varlistentry>
-
-                        <varlistentry>
                                 <term><option>--no-wall</option></term>
 
                                 <listitem><para>Don't send wall
@@ -979,24 +953,6 @@
                                 applications.</para></listitem>
                         </varlistentry>
                         <varlistentry>
-                                <term><command>dot</command></term>
-
-                                <listitem><para>Generate textual
-                                dependency graph description in dot
-                                format for further processing with the
-                                GraphViz
-                                <citerefentry><refentrytitle>dot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
-                                tool. Use a command line like
-                                <command>systemctl dot | dot -Tsvg >
-                                systemd.svg</command> to generate a
-                                graphical dependency tree. Unless
-                                <option>--order</option> or
-                                <option>--require</option> is passed
-                                the generated graph will show both
-                                ordering and requirement
-                                dependencies.</para></listitem>
-                        </varlistentry>
-                        <varlistentry>
                                 <term><command>list-dependencies [NAME]</command></term>
 
                                 <listitem><para> Shows required and
diff --git a/man/systemd-analyze.xml b/man/systemd-analyze.xml
index c2ff9cc..533bc42 100644
--- a/man/systemd-analyze.xml
+++ b/man/systemd-analyze.xml
@@ -57,6 +57,9 @@
                 <cmdsynopsis>
                         <command>systemd-analyze <arg choice="opt" rep="repeat">OPTIONS</arg> plot <arg choice="opt">> file.svg</arg></command>
                 </cmdsynopsis>
+                <cmdsynopsis>
+                        <command>systemd-analyze <arg choice="opt" rep="repeat">OPTIONS</arg> dot </command>
+                </cmdsynopsis>
         </refsynopsisdiv>
 
         <refsect1>
@@ -90,6 +93,17 @@
                 been started at what time, highlighting the time they
                 spent on initialization.</para>
 
+                <para><command>systemd-analyze dot</command>
+                Generate textual dependency graph description in dot
+                format for further processing with the GraphViz
+                <citerefentry><refentrytitle>dot</refentrytitle><manvolnum>1</manvolnum></citerefentry>
+                tool. Use a command line like <command>systemd-analyze
+                dot | dot -Tsvg > systemd.svg</command> to generate
+                a graphical dependency tree. Unless
+                <option>--order</option> or <option>--require</option>
+                is passed the generated graph will show both ordering
+                and requirement dependencies.</para>
+
                 <para>If no command is passed <command>systemd-analyze
                 time</command> is implied.</para>
 
@@ -116,6 +130,32 @@
                                 of user sessions instead of the system
                                 manager.</para></listitem>
                         </varlistentry>
+
+                        <varlistentry>
+                                <term><option>--order</option></term>
+                                <term><option>--require</option></term>
+
+                                <listitem><para>When used in
+                                conjunction with the
+                                <command>dot</command> command (see
+                                above), selects which dependencies are
+                                shown in the dependency graph. If
+                                <option>--order</option> is passed
+                                only dependencies of type
+                                <varname>After=</varname> or
+                                <varname>Before=</varname> are
+                                shown. If <option>--require</option>
+                                is passed only dependencies of type
+                                <varname>Requires=</varname>,
+                                <varname>RequiresOverridable=</varname>,
+                                <varname>Requisite=</varname>,
+                                <varname>RequisiteOverridable=</varname>,
+                                <varname>Wants=</varname> and
+                                <varname>Conflicts=</varname> are
+                                shown. If neither is passed, shows
+                                dependencies of all these
+                                types.</para></listitem>
+                        </varlistentry>
                 </variablelist>
 
         </refsect1>
diff --git a/shell-completion/systemd-bash-completion.sh b/shell-completion/systemd-bash-completion.sh
index 52dc72b..1132b3c 100644
--- a/shell-completion/systemd-bash-completion.sh
+++ b/shell-completion/systemd-bash-completion.sh
@@ -60,7 +60,7 @@ _systemctl () {
         local -A OPTS=(
                [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
                              --help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
-                             --order --require --quiet -q --privileged -P --system --user --version --runtime'
+                             --quiet -q --privileged -P --system --user --version --runtime'
                       [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
         )
 
@@ -113,7 +113,7 @@ _systemctl () {
                      [JOBS]='cancel'
                 [SNAPSHOTS]='delete'
                      [ENVS]='set-environment unset-environment'
-               [STANDALONE]='daemon-reexec daemon-reload default dot dump
+               [STANDALONE]='daemon-reexec daemon-reload default dump
                              emergency exit halt hibernate hybrid-sleep kexec list-jobs
                              list-units list-unit-files poweroff reboot rescue
                              show-environment suspend'
diff --git a/shell-completion/systemd-zsh-completion.zsh b/shell-completion/systemd-zsh-completion.zsh
index d5fb850..177a564 100644
--- a/shell-completion/systemd-zsh-completion.zsh
+++ b/shell-completion/systemd-zsh-completion.zsh
@@ -27,8 +27,6 @@ _ctls()
                 '--no-legend[Do not print a legend, i.e. the column headers and the footer with hints]' \
                 '--no-pager[Do not pipe output into a pager]' \
                 '--no-ask-password[Do not ask for system passwords]' \
-                '--order[When generating graph for dot, show only order]' \
-                '--require[When generating graph for dot, show only requirement]' \
                 '--system[Connect to system manager]' \
                 '--user[Connect to user service manager]' \
                 '--global[Enable/disable unit files globally]' \
@@ -136,6 +134,8 @@ _ctls()
             _arguments \
                 {-h,--help}'[Show help text.]' \
                 '--user[Shows performance data of user sessions instead of the system manager.]' \
+                '--order[When generating graph for dot, show only order]' \
+                '--require[When generating graph for dot, show only requirement]' \
                 '*::systemd-analyze commands:_systemd_analyze_command'
         ;;
         systemd-ask-password)
@@ -293,6 +293,7 @@ _systemd_analyze_command(){
         'time:Print the time taken to start'
         'blame:prints a list of all running units, ordered by the time they took to initialize'
         'plot:prints an SVG graphic detailing which system services have been started at what time'
+        'dot:Dump dependency graph for dot(1)'
     )
 
     if (( CURRENT == 1 )); then
@@ -352,7 +353,6 @@ _outputmodes() {
     "list-jobs:List jobs"
     "cancel:Cancel all, one, or more jobs"
     "dump:Dump server status"
-    "dot:Dump dependency graph for dot(1)"
     "snapshot:Create a snapshot"
     "delete:Remove one or more snapshots"
     "show-environment:Dump environment"
@@ -575,7 +575,7 @@ done
 (( $+functions[_systemctl_link] )) || _systemctl_link() { _files }
 
 # no systemctl completion for:
-#    [STANDALONE]='daemon-reexec daemon-reload default dot dump
+#    [STANDALONE]='daemon-reexec daemon-reload default dump
 #                  emergency exit halt kexec list-jobs list-units
 #                  list-unit-files poweroff reboot rescue show-environment'
 #         [NAME]='snapshot load'
diff --git a/src/analyze/systemd-analyze.c b/src/analyze/systemd-analyze.c
index 1ea56c6..88fb406 100644
--- a/src/analyze/systemd-analyze.c
+++ b/src/analyze/systemd-analyze.c
@@ -46,6 +46,11 @@
         } while(false)
 
 static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
+static enum dot {
+        DEP_ALL,
+        DEP_ORDER,
+        DEP_REQUIRE
+} arg_dot = DEP_ALL;
 
 double scale_x = 0.1;   // pixels per ms
 double scale_y = 20.0;
@@ -532,6 +537,166 @@ static int analyze_time(DBusConnection *bus)
         return 0;
 }
 
+static int graph_one_property(const char *name, const char *prop, DBusMessageIter *iter) {
+
+        static const char * const colors[] = {
+                "Requires",              "[color=\"black\"]",
+                "RequiresOverridable",   "[color=\"black\"]",
+                "Requisite",             "[color=\"darkblue\"]",
+                "RequisiteOverridable",  "[color=\"darkblue\"]",
+                "Wants",                 "[color=\"grey66\"]",
+                "Conflicts",             "[color=\"red\"]",
+                "ConflictedBy",          "[color=\"red\"]",
+                "After",                 "[color=\"green\"]"
+        };
+
+        const char *c = NULL;
+        unsigned i;
+
+        assert(name);
+        assert(prop);
+        assert(iter);
+
+        for (i = 0; i < ELEMENTSOF(colors); i += 2)
+                if (streq(colors[i], prop)) {
+                        c = colors[i+1];
+                        break;
+                }
+
+        if (!c)
+                return 0;
+
+        if (arg_dot != DEP_ALL)
+                if ((arg_dot == DEP_ORDER) != streq(prop, "After"))
+                        return 0;
+
+        if (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_ARRAY &&
+            dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING) {
+                DBusMessageIter sub;
+
+                dbus_message_iter_recurse(iter, &sub);
+
+                for (dbus_message_iter_recurse(iter, &sub);
+                     dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID;
+                     dbus_message_iter_next(&sub)) {
+                        const char *s;
+
+                        assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING);
+                        dbus_message_iter_get_basic(&sub, &s);
+                        printf("\t\"%s\"->\"%s\" %s;\n", name, s, c);
+                }
+        }
+
+        return 0;
+}
+
+static int graph_one(DBusConnection *bus, const struct unit_info *u) {
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+        const char *interface = "org.freedesktop.systemd1.Unit";
+        int r;
+        DBusMessageIter iter, sub, sub2, sub3;
+
+        assert(bus);
+        assert(u);
+
+        r = bus_method_call_with_reply(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        u->unit_path,
+                        "org.freedesktop.DBus.Properties",
+                        "GetAll",
+                        &reply,
+                        NULL,
+                        DBUS_TYPE_STRING, &interface,
+                        DBUS_TYPE_INVALID);
+        if (r < 0)
+                return r;
+
+        if (!dbus_message_iter_init(reply, &iter) ||
+            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
+            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_DICT_ENTRY)  {
+                log_error("Failed to parse reply.");
+                return -EIO;
+        }
+
+        for (dbus_message_iter_recurse(&iter, &sub);
+             dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID;
+             dbus_message_iter_next(&sub)) {
+                const char *prop;
+
+                assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_DICT_ENTRY);
+                dbus_message_iter_recurse(&sub, &sub2);
+
+                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &prop, true) < 0 ||
+                    dbus_message_iter_get_arg_type(&sub2) != DBUS_TYPE_VARIANT) {
+                        log_error("Failed to parse reply.");
+                        return -EIO;
+                }
+
+                dbus_message_iter_recurse(&sub2, &sub3);
+                r = graph_one_property(u->id, prop, &sub3);
+                if (r < 0)
+                        return r;
+        }
+
+        return 0;
+}
+
+static int dot(DBusConnection *bus) {
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+        DBusMessageIter iter, sub;
+        int r;
+
+        r = bus_method_call_with_reply(
+                        bus,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "ListUnits",
+                        &reply,
+                        NULL,
+                        DBUS_TYPE_INVALID);
+        if (r < 0)
+                return r;
+
+        if (!dbus_message_iter_init(reply, &iter) ||
+            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
+            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT)  {
+                log_error("Failed to parse reply.");
+                return -EIO;
+        }
+
+        printf("digraph systemd {\n");
+
+        for (dbus_message_iter_recurse(&iter, &sub);
+             dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID;
+             dbus_message_iter_next(&sub)) {
+                struct unit_info u;
+
+                r = bus_parse_unit_info(&sub, &u);
+                if (r < 0)
+                        return -EIO;
+
+                r = graph_one(bus, &u);
+                if (r < 0)
+                        return r;
+        }
+
+        printf("}\n");
+
+        log_info("   Color legend: black     = Requires\n"
+                 "                 dark blue = Requisite\n"
+                 "                 dark grey = Wants\n"
+                 "                 red       = Conflicts\n"
+                 "                 green     = After\n");
+
+        if (on_tty())
+                log_notice("-- You probably want to process this output with graphviz' dot tool.\n"
+                           "-- Try a shell pipeline like 'systemd-analyze dot | dot -Tsvg > systemd.svg'!\n");
+
+        return 0;
+}
+
 static void analyze_help(void)
 {
         printf("%s [OPTIONS...] {COMMAND} ...\n\n"
@@ -539,11 +704,14 @@ static void analyze_help(void)
                "  -h --help           Show this help\n"
                "     --version        Show package version\n"
                "     --system         Connect to system manager\n"
-               "     --user           Connect to user service manager\n\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\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"
-               "  plot      output SVG graphic showing service initialization\n\n",
+               "  time                Print time spent in the kernel before reaching userspace\n"
+               "  blame               Print list of running units ordered by time to init\n"
+               "  plot                Output SVG graphic showing service initialization\n"
+               "  dot                 Dump dependency graph (in dot(1) format)\n\n",
                program_invocation_short_name);
 }
 
@@ -551,6 +719,8 @@ static int parse_argv(int argc, char *argv[])
 {
         enum {
                 ARG_VERSION = 0x100,
+                ARG_ORDER,
+                ARG_REQUIRE,
                 ARG_USER,
                 ARG_SYSTEM
         };
@@ -558,6 +728,8 @@ static int parse_argv(int argc, char *argv[])
         static const struct option options[] = {
                 { "help",      no_argument,       NULL, 'h'           },
                 { "version",   no_argument,       NULL, ARG_VERSION   },
+                { "order",     no_argument,       NULL, ARG_ORDER     },
+                { "require",   no_argument,       NULL, ARG_REQUIRE   },
                 { "user",      no_argument,       NULL, ARG_USER      },
                 { "system",    no_argument,       NULL, ARG_SYSTEM    },
                 { NULL,        0,                 NULL, 0             }
@@ -580,6 +752,12 @@ static int parse_argv(int argc, char *argv[])
                         case ARG_SYSTEM:
                                 arg_scope = UNIT_FILE_SYSTEM;
                                 break;
+                        case ARG_ORDER:
+                                arg_dot = DEP_ORDER;
+                                break;
+                        case ARG_REQUIRE:
+                                arg_dot = DEP_REQUIRE;
+                                break;
                         case -1:
                                 return 1;
                         case '?':
@@ -614,6 +792,8 @@ int main(int argc, char *argv[]) {
                 r = analyze_blame(bus);
         else if (streq(argv[optind], "plot"))
                 r = analyze_plot(bus);
+        else if (streq(argv[optind], "dot"))
+                r = dot(bus);
         else
                 log_error("Unknown operation '%s'.", argv[optind]);
 
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 54c8ebc..12e343e 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -116,11 +116,6 @@ static enum action {
         ACTION_CANCEL_SHUTDOWN,
         _ACTION_MAX
 } arg_action = ACTION_SYSTEMCTL;
-static enum dot {
-        DOT_ALL,
-        DOT_ORDER,
-        DOT_REQUIRE
-} arg_dot = DOT_ALL;
 static enum transport {
         TRANSPORT_NORMAL,
         TRANSPORT_SSH,
@@ -891,176 +886,6 @@ static int list_dependencies(DBusConnection *bus, char **args) {
         return list_dependencies_one(bus, u, 0, NULL, 0);
 }
 
-static int dot_one_property(const char *name, const char *prop, DBusMessageIter *iter) {
-
-        static const char * const colors[] = {
-                "Requires",              "[color=\"black\"]",
-                "RequiresOverridable",   "[color=\"black\"]",
-                "Requisite",             "[color=\"darkblue\"]",
-                "RequisiteOverridable",  "[color=\"darkblue\"]",
-                "Wants",                 "[color=\"grey66\"]",
-                "Conflicts",             "[color=\"red\"]",
-                "ConflictedBy",          "[color=\"red\"]",
-                "After",                 "[color=\"green\"]"
-        };
-
-        const char *c = NULL;
-        unsigned i;
-
-        assert(name);
-        assert(prop);
-        assert(iter);
-
-        for (i = 0; i < ELEMENTSOF(colors); i += 2)
-                if (streq(colors[i], prop)) {
-                        c = colors[i+1];
-                        break;
-                }
-
-        if (!c)
-                return 0;
-
-        if (arg_dot != DOT_ALL)
-                if ((arg_dot == DOT_ORDER) != streq(prop, "After"))
-                        return 0;
-
-        switch (dbus_message_iter_get_arg_type(iter)) {
-
-        case DBUS_TYPE_ARRAY:
-
-                if (dbus_message_iter_get_element_type(iter) == DBUS_TYPE_STRING) {
-                        DBusMessageIter sub;
-
-                        dbus_message_iter_recurse(iter, &sub);
-
-                        while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
-                                const char *s;
-
-                                assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRING);
-                                dbus_message_iter_get_basic(&sub, &s);
-                                printf("\t\"%s\"->\"%s\" %s;\n", name, s, c);
-
-                                dbus_message_iter_next(&sub);
-                        }
-
-                        return 0;
-                }
-        }
-
-        return 0;
-}
-
-static int dot_one(DBusConnection *bus, const struct unit_info *u) {
-        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-        const char *interface = "org.freedesktop.systemd1.Unit";
-        int r;
-        DBusMessageIter iter, sub, sub2, sub3;
-
-        assert(bus);
-        assert(u);
-
-        r = bus_method_call_with_reply(
-                        bus,
-                        "org.freedesktop.systemd1",
-                        u->unit_path,
-                        "org.freedesktop.DBus.Properties",
-                        "GetAll",
-                        &reply,
-                        NULL,
-                        DBUS_TYPE_STRING, &interface,
-                        DBUS_TYPE_INVALID);
-        if (r < 0)
-                return r;
-
-        if (!dbus_message_iter_init(reply, &iter) ||
-            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
-            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_DICT_ENTRY)  {
-                log_error("Failed to parse reply.");
-                return -EIO;
-        }
-
-        dbus_message_iter_recurse(&iter, &sub);
-
-        while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
-                const char *prop;
-
-                assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_DICT_ENTRY);
-                dbus_message_iter_recurse(&sub, &sub2);
-
-                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &prop, true) < 0 ||
-                    dbus_message_iter_get_arg_type(&sub2) != DBUS_TYPE_VARIANT) {
-                        log_error("Failed to parse reply.");
-                        return -EIO;
-                }
-
-                dbus_message_iter_recurse(&sub2, &sub3);
-                r = dot_one_property(u->id, prop, &sub3);
-                if (r < 0)
-                        return r;
-
-                dbus_message_iter_next(&sub);
-        }
-
-        return 0;
-}
-
-static int dot(DBusConnection *bus, char **args) {
-        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-        DBusMessageIter iter, sub;
-        int r;
-
-        r = bus_method_call_with_reply(
-                        bus,
-                        "org.freedesktop.systemd1",
-                        "/org/freedesktop/systemd1",
-                        "org.freedesktop.systemd1.Manager",
-                        "ListUnits",
-                        &reply,
-                        NULL,
-                        DBUS_TYPE_INVALID);
-        if (r < 0)
-                return r;
-
-        if (!dbus_message_iter_init(reply, &iter) ||
-            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
-            dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT)  {
-                log_error("Failed to parse reply.");
-                return -EIO;
-        }
-
-        printf("digraph systemd {\n");
-
-        dbus_message_iter_recurse(&iter, &sub);
-        while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
-                struct unit_info u;
-
-                r = bus_parse_unit_info(&sub, &u);
-                if (r < 0)
-                        return -EIO;
-
-                r = dot_one(bus, &u);
-                if (r < 0)
-                        return r;
-
-                /* printf("\t\"%s\";\n", u.id); */
-                dbus_message_iter_next(&sub);
-        }
-
-        printf("}\n");
-
-        log_info("   Color legend: black     = Requires\n"
-                 "                 dark blue = Requisite\n"
-                 "                 dark grey = Wants\n"
-                 "                 red       = Conflicts\n"
-                 "                 green     = After\n");
-
-        if (on_tty())
-                log_notice("-- You probably want to process this output with graphviz' dot tool.\n"
-                           "-- Try a shell pipeline like 'systemctl dot | dot -Tsvg > systemd.svg'!\n");
-
-        return 0;
-}
-
 static int list_jobs(DBusConnection *bus, char **args) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         DBusMessageIter iter, sub, sub2;
@@ -4276,8 +4101,6 @@ static int systemctl_help(void) {
                "     --no-pager       Do not pipe output into a pager\n"
                "     --no-ask-password\n"
                "                      Do not ask for system passwords\n"
-               "     --order          When generating graph for dot, show only order\n"
-               "     --require        When generating graph for dot, show only requirement\n"
                "     --system         Connect to system manager\n"
                "     --user           Connect to user service manager\n"
                "     --global         Enable/disable unit files globally\n"
@@ -4337,7 +4160,6 @@ static int systemctl_help(void) {
                "  cancel [JOB...]                 Cancel all, one, or more jobs\n\n"
                "Status Commands:\n"
                "  dump                            Dump server status\n"
-               "  dot                             Dump dependency graph for dot(1)\n\n"
                "Snapshot Commands:\n"
                "  snapshot [NAME]                 Create a snapshot\n"
                "  delete [NAME...]                Remove one or more snapshots\n\n"
@@ -4460,8 +4282,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 ARG_NO_LEGEND,
                 ARG_NO_PAGER,
                 ARG_NO_WALL,
-                ARG_ORDER,
-                ARG_REQUIRE,
                 ARG_ROOT,
                 ARG_FULL,
                 ARG_NO_RELOAD,
@@ -4491,8 +4311,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                 { "no-pager",  no_argument,       NULL, ARG_NO_PAGER  },
                 { "no-wall",   no_argument,       NULL, ARG_NO_WALL   },
                 { "quiet",     no_argument,       NULL, 'q'           },
-                { "order",     no_argument,       NULL, ARG_ORDER     },
-                { "require",   no_argument,       NULL, ARG_REQUIRE   },
                 { "root",      required_argument, NULL, ARG_ROOT      },
                 { "force",     no_argument,       NULL, ARG_FORCE     },
                 { "no-reload", no_argument,       NULL, ARG_NO_RELOAD },
@@ -4599,14 +4417,6 @@ static int systemctl_parse_argv(int argc, char *argv[]) {
                         arg_no_wall = true;
                         break;
 
-                case ARG_ORDER:
-                        arg_dot = DOT_ORDER;
-                        break;
-
-                case ARG_REQUIRE:
-                        arg_dot = DOT_REQUIRE;
-                        break;
-
                 case ARG_ROOT:
                         arg_root = optarg;
                         break;
@@ -5307,7 +5117,6 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
                 { "status",                MORE,  2, show              },
                 { "help",                  MORE,  2, show              },
                 { "dump",                  EQUAL, 1, dump              },
-                { "dot",                   EQUAL, 1, dot               },
                 { "snapshot",              LESS,  2, snapshot          },
                 { "delete",                MORE,  2, delete_snapshot   },
                 { "daemon-reload",         EQUAL, 1, daemon_reload     },

commit 2265fbf7e5614e9a9e5272937219181290f86e07
Author: Simon Peeters <peeters.simon at gmail.com>
Date:   Wed Feb 6 15:21:03 2013 +0100

    systemd-analyze: rewrite in C.
    
    Written by Peeters Simon <peeters.simon at gmail.com>.
    Makefile stuff and cleaned up a bit by Auke Kok <auke-jan.h.kok at intel.com>.
    Some code inspired by Marc-Antoine Perennou <Marc-Antoine at Perennou.com>.

diff --git a/Makefile.am b/Makefile.am
index 65294a5..403439b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -267,7 +267,8 @@ rootbin_PROGRAMS = \
 	systemd-ask-password \
 	systemd-tty-ask-password-agent \
 	systemd-tmpfiles \
-	systemd-machine-id-setup
+	systemd-machine-id-setup \
+	systemd-analyze
 
 bin_PROGRAMS = \
 	systemd-cgls \
@@ -297,14 +298,16 @@ systemgenerator_PROGRAMS = \
 	systemd-fstab-generator \
 	systemd-system-update-generator
 
-dist_bin_SCRIPTS = \
-	src/analyze/systemd-analyze
+systemd_analyze_SOURCES = \
+	src/analyze/systemd-analyze.c
 
-EXTRA_DIST += \
-	src/analyze/systemd-analyze.in
+systemd_analyze_CFLAGS = \
+	$(AM_CFLAGS) \
+	$(DBUS_CFLAGS)
 
-CLEANFILES += \
-	src/analyze/systemd-analyze
+systemd_analyze_LDADD = \
+	libsystemd-shared.la \
+	libsystemd-dbus.la
 
 dist_bashcompletion_DATA = \
 	shell-completion/systemd-bash-completion.sh
@@ -3465,10 +3468,6 @@ src/%.policy.in: src/%.policy.in.in Makefile
 	$(SED_PROCESS)
 	$(AM_V_GEN)chmod +x $@
 
-src/analyze/systemd-analyze: %: %.in Makefile
-	$(SED_PROCESS)
-	$(AM_V_GEN)chmod +x $@
-
 src/%.c: src/%.gperf
 	$(AM_V_at)$(MKDIR_P) $(dir $@)
 	$(AM_V_GPERF)$(GPERF) < $< > $@
diff --git a/src/analyze/systemd-analyze.c b/src/analyze/systemd-analyze.c
new file mode 100644
index 0000000..1ea56c6
--- /dev/null
+++ b/src/analyze/systemd-analyze.c
@@ -0,0 +1,624 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <locale.h>
+#include <sys/utsname.h>
+
+#include "install.h"
+#include "log.h"
+#include "dbus-common.h"
+#include "build.h"
+#include "util.h"
+#include "strxcpyx.h"
+
+#define compare(a, b) (((a) > (b))? 1 : (((b) > (a))? -1 : 0))
+#define svg(...) printf(__VA_ARGS__)
+#define svg_bar(class, x1, x2, y) \
+        svg("  <rect class=\"%s\" x=\"%.03f\" y=\"%.03f\" width=\"%.03f\" height=\"%.03f\" />\n", \
+                        (class), \
+                        scale_x * (x1), scale_y * (y), \
+                        scale_x * ((x2) - (x1)), scale_y - 1.0)
+#define svg_text(x, y, format, ...) do {\
+        svg("  <text x=\"%.03f\" y=\"%.03f\">", scale_x * (x) + 5.0, scale_y * (y) + 14.0); \
+        svg(format, ## __VA_ARGS__); \
+        svg("</text>\n"); \
+        } while(false)
+
+static UnitFileScope arg_scope = UNIT_FILE_SYSTEM;
+
+double scale_x = 0.1;   // pixels per ms
+double scale_y = 20.0;
+
+struct boot_times {
+        uint64_t firmware_time;
+        uint64_t loader_time;
+        uint64_t kernel_time;
+        uint64_t kernel_done_time;
+        uint64_t initrd_time;
+        uint64_t userspace_time;
+        uint64_t finish_time;
+};
+struct unit_times {
+        char *name;
+        uint64_t ixt;
+        uint64_t iet;
+        uint64_t axt;
+        uint64_t aet;
+        uint64_t time;
+};
+
+static int bus_get_uint64_property (DBusConnection *bus, const char *path, const char *interface, const char *property, uint64_t *val)
+{
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+        int r;
+        DBusMessageIter iter, sub;
+
+        r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.systemd1",
+                        path,
+                        "org.freedesktop.DBus.Properties",
+                        "Get",
+                        &reply,
+                        NULL,
+                        DBUS_TYPE_STRING, &interface,
+                        DBUS_TYPE_STRING, &property,
+                        DBUS_TYPE_INVALID);
+        if (r < 0)
+                return r;
+
+        if (!dbus_message_iter_init(reply, &iter) ||
+            dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)  {
+                log_error("Failed to parse reply.");
+                return -EIO;
+        }
+
+        dbus_message_iter_recurse(&iter, &sub);
+
+        if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_UINT64)  {
+                log_error("Failed to parse reply.");
+                return -EIO;
+        }
+
+        dbus_message_iter_get_basic(&sub, val);
+
+        return 0;
+}
+
+static int compare_unit_time(const void *a, const void *b)
+{
+        return compare(((struct unit_times *)b)->time,
+                       ((struct unit_times *)a)->time);
+}
+
+static int compare_unit_start(const void *a, const void *b)
+{
+        return compare(((struct unit_times *)a)->ixt,
+                       ((struct unit_times *)b)->ixt);
+}
+
+static char *get_os_name(void)
+{
+        char *n = NULL;
+
+        parse_env_file("/etc/os-release", NEWLINE, "PRETTY_NAME", &n, NULL);
+        return n;
+}
+
+static int acquire_time_data(DBusConnection *bus, struct unit_times **out)
+{
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
+        DBusMessageIter iter, sub;
+        int r, c = 0, n_units = 0;
+        struct unit_times *unit_times = NULL;
+
+        r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.systemd1",
+                        "/org/freedesktop/systemd1",
+                        "org.freedesktop.systemd1.Manager",
+                        "ListUnits",
+                        &reply,
+                        NULL,
+                        DBUS_TYPE_INVALID);
+        if (r)
+                goto fail;
+
+        if (!dbus_message_iter_init(reply, &iter) ||
+                        dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
+                        dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT)  {
+                log_error("Failed to parse reply.");
+                r = -EIO;
+                goto fail;
+        }
+
+        for (dbus_message_iter_recurse(&iter, &sub);
+             dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID;
+             dbus_message_iter_next(&sub)) {
+                struct unit_info u;
+                struct unit_times *t;
+
+                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
+                        log_error("Failed to parse reply.");
+                        r = -EIO;
+                        goto fail;
+                }
+
+                if (c >= n_units) {
+                        struct unit_times *w;
+
+                        n_units = MAX(2*c, 16);
+                        w = realloc(unit_times, sizeof(struct unit_times) * n_units);
+
+                        if (!w) {
+                                r = log_oom();
+                                goto fail;
+                        }
+
+                        unit_times = w;
+                }
+                t = unit_times+c;
+                t->name = NULL;
+
+                r = bus_parse_unit_info(&sub, &u);
+                if (r < 0)
+                        goto fail;
+
+                if (bus_get_uint64_property(bus, u.unit_path,
+                                            "org.freedesktop.systemd1.Unit",
+                                            "InactiveExitTimestampMonotonic",
+                                            &t->ixt) < 0 ||
+                    bus_get_uint64_property(bus, u.unit_path,
+                                            "org.freedesktop.systemd1.Unit",
+                                            "ActiveEnterTimestampMonotonic",
+                                            &t->aet) < 0 ||
+                    bus_get_uint64_property(bus, u.unit_path,
+                                            "org.freedesktop.systemd1.Unit",
+                                            "ActiveExitTimestampMonotonic",
+                                            &t->axt) < 0 ||
+                    bus_get_uint64_property(bus, u.unit_path,
+                                            "org.freedesktop.systemd1.Unit",
+                                            "InactiveEnterTimestampMonotonic",
+                                            &t->iet) < 0) {
+                        r = -EIO;
+                        goto fail;
+                }
+
+                t->iet /= 1000;
+                t->ixt /= 1000;
+                t->aet /= 1000;
+                t->axt /= 1000;
+
+                if (t->aet >= t->ixt)
+                        t->time = t->aet - t->ixt;
+                else if (t->iet >= t->ixt)
+                        t->time = t->iet - t->ixt;
+                else
+                        t->time = 0;
+
+                if (t->ixt == 0)
+                        continue;
+
+                t->name = strdup(u.id);
+                if (t->name == NULL) {
+                        r = log_oom();
+                        goto fail;
+                }
+                c++;
+        }
+
+        *out = unit_times;
+        return c;
+fail:
+        for (; c >= 0; c--)
+                free(unit_times[c].name);
+        free(unit_times);
+        return r;
+}
+
+static struct boot_times *acquire_boot_times(DBusConnection *bus)
+{
+        static struct boot_times times;
+        static bool cached = false;
+        if (cached)
+                return ×
+
+        if (bus_get_uint64_property(bus,
+                                    "/org/freedesktop/systemd1",
+                                    "org.freedesktop.systemd1.Manager",
+                                    "FirmwareTimestampMonotonic",
+                                    &times.firmware_time) < 0 ||
+            bus_get_uint64_property(bus,
+                                    "/org/freedesktop/systemd1",
+                                    "org.freedesktop.systemd1.Manager",
+                                    "LoaderTimestampMonotonic",
+                                    &times.loader_time) < 0 ||
+            bus_get_uint64_property(bus,
+                                    "/org/freedesktop/systemd1",
+                                    "org.freedesktop.systemd1.Manager",
+                                    "KernelTimestamp",
+                                    &times.kernel_time) < 0 ||
+            bus_get_uint64_property(bus,
+                                    "/org/freedesktop/systemd1",
+                                    "org.freedesktop.systemd1.Manager",
+                                    "InitRDTimestampMonotonic",
+                                    &times.initrd_time) < 0 ||
+            bus_get_uint64_property(bus,
+                                    "/org/freedesktop/systemd1",
+                                    "org.freedesktop.systemd1.Manager",
+                                    "UserspaceTimestampMonotonic",
+                                    &times.userspace_time) < 0 ||
+            bus_get_uint64_property(bus,
+                                    "/org/freedesktop/systemd1",
+                                    "org.freedesktop.systemd1.Manager",
+                                    "FinishTimestampMonotonic",
+                                    &times.finish_time) < 0)
+                return NULL;
+
+        if (!times.finish_time) {
+                log_error("Bootup is not yet finished. Please try again later.");
+                return NULL;
+        }
+
+        times.firmware_time /= 1000;
+        times.loader_time /= 1000;
+        times.initrd_time /= 1000;
+        times.userspace_time /= 1000;
+        times.finish_time /= 1000;
+
+        if (times.initrd_time)
+                times.kernel_done_time = times.initrd_time;
+        else
+                times.kernel_done_time = times.userspace_time;
+
+        cached = true;
+        return ×
+}
+
+static char *pretty_boot_time(DBusConnection *bus)
+{
+        struct boot_times *t;
+        size_t size = 4096;
+        static char buf[4096];
+        char *ptr = buf;
+
+        t = acquire_boot_times(bus);
+        if (!t)
+                return NULL;
+
+        size = strpcpyf(&ptr, size, "Startup finished in ");
+        if (t->firmware_time)
+                size = strpcpyf(&ptr, size, "%llums (firmware) + ", (unsigned long long)(t->firmware_time - t->loader_time));
+        if (t->loader_time)
+                size = strpcpyf(&ptr, size, "%llums (loader) + ", (unsigned long long)t->loader_time);
+        if (t->kernel_time)
+                size = strpcpyf(&ptr, size, "%llums (kernel) + ", (unsigned long long)t->kernel_done_time);
+        if (t->initrd_time > 0)
+                size = strpcpyf(&ptr, size, "%llums (initrd) + ", (unsigned long long)(t->userspace_time - t->initrd_time));
+
+        size = strpcpyf(&ptr, size, "%llums (userspace) ", (unsigned long long)(t->finish_time - t->userspace_time));
+        if (t->kernel_time > 0)
+                size = strpcpyf(&ptr, size, "= %llums", (unsigned long long)(t->firmware_time + t->finish_time));
+        else
+                size = strpcpyf(&ptr, size, "= %llums", (unsigned long long)(t->finish_time - t->userspace_time));
+
+        return buf;
+}
+
+static void svg_graph_box(int height, int64_t begin, int64_t end)
+{
+        /* outside box, fill */
+        svg("<rect class=\"box\" x=\"0\" y=\"0\" width=\"%.03f\" height=\"%.03f\" />\n",
+            scale_x * (end - begin), scale_y * height);
+
+        for (int i = (begin / 100) * 100; i <= end; i+=100) {
+                /* lines for each second */
+                if (i % 5000 == 0)
+                        svg("  <line class=\"sec5\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
+                            "  <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
+                            scale_x * i, scale_x * i, scale_y * height, scale_x * i, -5.0, 0.001 * i);
+                else if (i % 1000 == 0)
+                        svg("  <line class=\"sec1\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n"
+                            "  <text class=\"sec\" x=\"%.03f\" y=\"%.03f\" >%.01fs</text>\n",
+                            scale_x * i, scale_x * i, scale_y * height, scale_x * i, -5.0, 0.001 * i);
+                else
+                        svg("  <line class=\"sec01\" x1=\"%.03f\" y1=\"0\" x2=\"%.03f\" y2=\"%.03f\" />\n",
+                            scale_x * i, scale_x * i, scale_y * height);
+        }
+}
+
+static int analyze_plot(DBusConnection *bus)
+{
+        struct unit_times *times;
+        struct boot_times *boot;
+        struct utsname name;
+        int n, m = 1, y=0;
+        double width;
+        char *osname;
+        char *pretty_times;
+
+        boot = acquire_boot_times(bus);
+        if (!boot)
+                return -EIO;
+        pretty_times = pretty_boot_time(bus);
+        if (!pretty_times)
+                return -EIO;
+
+        osname = get_os_name();
+
+        n = uname(&name);
+        if (n < 0) {
+                log_error("Cannot get system name: %m");
+                return -errno;
+        }
+
+        n = acquire_time_data(bus, &times);
+        if (n<=0)
+                return n;
+
+        qsort(times, n, sizeof(struct unit_times), compare_unit_start);
+
+        width = scale_x * (boot->firmware_time + boot->finish_time);
+        if (width < 800.0)
+                width = 800.0;
+
+        if (boot->firmware_time > boot->loader_time)
+                m++;
+        if (boot->loader_time) {
+                m++;
+                if (width < 1000.0)
+                        width = 1000.0;
+        }
+        if (boot->initrd_time)
+                m++;
+        if (boot->kernel_time)
+                m++;
+
+        for (struct unit_times *u = times; u < times + n; u++) {
+                double len;
+                if (u->ixt < boot->userspace_time ||
+                    u->ixt > boot->finish_time) {
+                        free(u->name);
+                        u->name = NULL;
+                        continue;
+                }
+                len = ((boot->firmware_time + u->ixt) * scale_x)
+                        + (10.0 * strlen(u->name));
+                if (len > width)
+                        width = len;
+
+                if (u->iet > u->ixt && u->iet <= boot->finish_time
+                                && u->aet == 0 && u->axt == 0)
+                        u->aet = u->axt = u->iet;
+                if (u->aet < u->ixt || u->aet > boot->finish_time)
+                        u->aet = boot->finish_time;
+                if (u->axt < u->aet || u->aet > boot->finish_time)
+                        u->axt = boot->finish_time;
+                if (u->iet < u->axt || u->iet > boot->finish_time)
+                        u->iet = boot->finish_time;
+                m++;
+        }
+
+        svg("<?xml version=\"1.0\" standalone=\"no\"?>\n"
+            "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
+            "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
+
+        svg("<svg width=\"%.0fpx\" height=\"%.0fpx\" version=\"1.1\" "
+            "xmlns=\"http://www.w3.org/2000/svg\">\n\n",
+                        80.0 + width, 150.0 + (m * scale_y));
+
+        /* write some basic info as a comment, including some help */
+        svg("<!-- This file is a systemd-analyze SVG file. It is best rendered in a   -->\n"
+            "<!-- browser such as Chrome, Chromium or Firefox. Other applications     -->\n"
+            "<!-- that render these files properly but much slower are ImageMagick,   -->\n"
+            "<!-- gimp, inkscape, etc. To display the files on your system, just      -->\n"
+            "<!-- point your browser to this file.                                    -->\n\n"
+            "<!-- This plot was generated by systemd-analyze version %-16.16s -->\n\n", VERSION);
+
+        /* style sheet */
+        svg("<defs>\n  <style type=\"text/css\">\n    <![CDATA[\n"
+            "      rect       { stroke-width: 1; stroke-opacity: 0; }\n"
+            "      rect.activating   { fill: rgb(255,0,0); fill-opacity: 0.7; }\n"
+            "      rect.active       { fill: rgb(200,150,150); fill-opacity: 0.7; }\n"
+            "      rect.deactivating { fill: rgb(150,100,100); fill-opacity: 0.7; }\n"
+            "      rect.kernel       { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
+            "      rect.initrd       { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
+            "      rect.firmware     { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
+            "      rect.loader       { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
+            "      rect.userspace    { fill: rgb(150,150,150); fill-opacity: 0.7; }\n"
+            "      rect.box   { fill: rgb(240,240,240); stroke: rgb(192,192,192); }\n"
+            "      line       { stroke: rgb(64,64,64); stroke-width: 1; }\n"
+            "//    line.sec1  { }\n"
+            "      line.sec5  { stroke-width: 2; }\n"
+            "      line.sec01 { stroke: rgb(224,224,224); stroke-width: 1; }\n"
+            "      text       { font-family: Verdana, Helvetica; font-size: 10; }\n"
+            "      text.sec   { font-size: 8; }\n"
+            "    ]]>\n   </style>\n</defs>\n\n");
+
+        svg("<text x=\"20\" y=\"50\">%s</text>", pretty_times);
+        svg("<text x=\"20\" y=\"30\">%s %s (%s %s) %s</text>",
+            isempty(osname)? "Linux" : osname,
+            name.nodename, name.release, name.version, name.machine);
+        svg("<text x=\"20\" y=\"%.0f\">Legend: Red = Activating; Pink = Active; Dark Pink = Deactivating</text>",
+                        120.0 + (m *scale_y));
+
+        svg("<g transform=\"translate(%.3f,100)\">\n", 20.0 + (scale_x * boot->firmware_time));
+        svg_graph_box(m, -boot->firmware_time, boot->finish_time);
+
+        if (boot->firmware_time) {
+                svg_bar("firmware", -(int64_t) boot->firmware_time, -(int64_t) boot->loader_time, y);
+                svg_text(-(int64_t) boot->firmware_time, y, "firmware");
+                y++;
+        }
+        if (boot->loader_time) {
+                svg_bar("loader", -(int64_t) boot->loader_time, 0, y);
+                svg_text(-(int64_t) boot->loader_time, y, "loader");
+                y++;
+        }
+        if (boot->kernel_time) {
+                svg_bar("kernel", 0, boot->kernel_done_time, y);
+                svg_text(0, y, "kernel");
+                y++;
+        }
+        if (boot->initrd_time) {
+                svg_bar("initrd", boot->initrd_time, boot->userspace_time, y);
+                svg_text(boot->initrd_time, y, "initrd");
+                y++;
+        }
+        svg_bar("userspace", boot->userspace_time, boot->finish_time, y);
+        svg_text(boot->userspace_time, y, "userspace");
+        y++;
+
+        for (struct unit_times *u = times; u < times + n; u++) {
+                if (!u->name)
+                        continue;
+                svg_bar("activating",   u->ixt, u->aet, y);
+                svg_bar("active",       u->aet, u->axt, y);
+                svg_bar("deactivating", u->axt, u->iet, y);
+                svg_text(u->ixt, y, u->time? "%s (%llums)" : "%s", u->name, (unsigned long long)u->time);
+                y++;
+        }
+        svg("</g>\n\n");
+
+        svg("</svg>");
+        return 0;
+}
+
+static int analyze_blame(DBusConnection *bus)
+{
+        struct unit_times *times;
+        int n = acquire_time_data(bus, &times);
+        if (n<=0)
+                return n;
+
+        qsort(times, n, sizeof(struct unit_times), compare_unit_time);
+
+        for (int i = 0; i < n; i++) {
+                if (times[i].time)
+                        printf("%6llums %s\n", (unsigned long long)times[i].time, times[i].name);
+        }
+        return 0;
+}
+
+static int analyze_time(DBusConnection *bus)
+{
+        char *buf;
+        buf = pretty_boot_time(bus);
+        if (!buf)
+                return -EIO;
+        if (puts(buf) == EOF)
+                return -errno;
+        return 0;
+}
+
+static void analyze_help(void)
+{
+        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\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"
+               "  plot      output SVG graphic showing service initialization\n\n",
+               program_invocation_short_name);
+}
+
+static int parse_argv(int argc, char *argv[])
+{
+        enum {
+                ARG_VERSION = 0x100,
+                ARG_USER,
+                ARG_SYSTEM
+        };
+
+        static const struct option options[] = {
+                { "help",      no_argument,       NULL, 'h'           },
+                { "version",   no_argument,       NULL, ARG_VERSION   },
+                { "user",      no_argument,       NULL, ARG_USER      },
+                { "system",    no_argument,       NULL, ARG_SYSTEM    },
+                { NULL,        0,                 NULL, 0             }
+        };
+
+        assert(argc >= 0);
+        assert(argv);
+
+        while (true) {
+                switch (getopt_long(argc, argv, "h", options, NULL)) {
+                        case 'h':
+                                analyze_help();
+                                return 0;
+                        case ARG_VERSION:
+                                puts(PACKAGE_STRING "\n" SYSTEMD_FEATURES);
+                                return 0;
+                        case ARG_USER:
+                                arg_scope = UNIT_FILE_USER;
+                                break;
+                        case ARG_SYSTEM:
+                                arg_scope = UNIT_FILE_SYSTEM;
+                                break;
+                        case -1:
+                                return 1;
+                        case '?':
+                                return -EINVAL;
+                        default:
+                                assert_not_reached("Unhandled option");
+                }
+        }
+}
+
+int main(int argc, char *argv[]) {
+        int r;
+        DBusConnection *bus = NULL;
+
+        setlocale(LC_ALL, "");
+        log_parse_environment();
+        log_open();
+
+        r = parse_argv(argc, argv);
+        if (r == 0)
+                return 0;
+        if (r < 0)
+                return 1;
+
+        bus = dbus_bus_get(arg_scope == UNIT_FILE_SYSTEM ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, NULL);
+        if (!bus)
+                return 1;
+
+        if (!argv[optind] || streq(argv[optind], "time"))
+                r = analyze_time(bus);
+        else if (streq(argv[optind], "blame"))
+                r = analyze_blame(bus);
+        else if (streq(argv[optind], "plot"))
+                r = analyze_plot(bus);
+        else
+                log_error("Unknown operation '%s'.", argv[optind]);
+
+        dbus_connection_unref(bus);
+        if (r)
+                return 1;
+        return 0;
+}
diff --git a/src/analyze/systemd-analyze.in b/src/analyze/systemd-analyze.in
deleted file mode 100755
index e964bb3..0000000
--- a/src/analyze/systemd-analyze.in
+++ /dev/null
@@ -1,328 +0,0 @@
-#!@PYTHON_BINARY@
-# -*-python-*-
-
-#  This file is part of systemd.
-#
-#  Copyright 2010-2013 Lennart Poettering
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU Lesser General Public License as published by
-#  the Free Software Foundation; either version 2.1 of the License, or
-#  (at your option) any later version.
-#
-#  systemd is distributed in the hope that it will be useful, but
-#  WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#  Lesser General Public License for more details.
-#
-#  You should have received a copy of the GNU Lesser General Public License
-#  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-
-import sys, os
-import argparse
-from gi.repository import Gio
-try:
-        import cairo
-except ImportError:
-        cairo = None
-
-def acquire_time_data():
-        manager = Gio.DBusProxy.new_for_bus_sync(bus, Gio.DBusProxyFlags.NONE,
-                None, 'org.freedesktop.systemd1', '/org/freedesktop/systemd1', 'org.freedesktop.systemd1.Manager', None)
-        units = manager.ListUnits()
-
-        l = []
-
-        for i in units:
-                if i[5] != "":
-                        continue
-
-                properties = Gio.DBusProxy.new_for_bus_sync(bus, Gio.DBusProxyFlags.NONE,
-                        None, 'org.freedesktop.systemd1', i[6], 'org.freedesktop.DBus.Properties', None)
-
-                ixt = properties.Get('(ss)', 'org.freedesktop.systemd1.Unit', 'InactiveExitTimestampMonotonic')
-                aet = properties.Get('(ss)', 'org.freedesktop.systemd1.Unit', 'ActiveEnterTimestampMonotonic')
-                axt = properties.Get('(ss)', 'org.freedesktop.systemd1.Unit', 'ActiveExitTimestampMonotonic')
-                iet = properties.Get('(ss)', 'org.freedesktop.systemd1.Unit', 'InactiveEnterTimestampMonotonic')
-
-                l.append((str(i[0]), ixt, aet, axt, iet))
-
-        return l
-
-def acquire_start_time():
-        properties = Gio.DBusProxy.new_for_bus_sync(bus, Gio.DBusProxyFlags.NONE,
-                None, 'org.freedesktop.systemd1', '/org/freedesktop/systemd1', 'org.freedesktop.DBus.Properties', None)
-
-        # Note that the firmware/loader times are returned as positive
-        # values but are actually considered negative from the point
-        # in time of kernel initialization. Also, the monotonic kernel
-        # time will always be 0 since that's the epoch of the
-        # monotonic clock. Since we want to know whether the kernel
-        # timestamp is set at all we will instead ask for the realtime
-        # clock for this timestamp.
-
-        firmware_time = properties.Get('(ss)', 'org.freedesktop.systemd1.Manager', 'FirmwareTimestampMonotonic')
-        loader_time = properties.Get('(ss)', 'org.freedesktop.systemd1.Manager', 'LoaderTimestampMonotonic')
-        kernel_time = properties.Get('(ss)', 'org.freedesktop.systemd1.Manager', 'KernelTimestamp')
-        initrd_time = properties.Get('(ss)', 'org.freedesktop.systemd1.Manager', 'InitRDTimestampMonotonic')
-        userspace_time = properties.Get('(ss)', 'org.freedesktop.systemd1.Manager', 'UserspaceTimestampMonotonic')
-        finish_time = properties.Get('(ss)', 'org.freedesktop.systemd1.Manager', 'FinishTimestampMonotonic')
-
-        if finish_time == 0:
-                sys.exit("Bootup is not yet finished. Please try again later.")
-
-        assert firmware_time >= loader_time
-        assert initrd_time <= userspace_time
-        assert userspace_time <= finish_time
-
-        return firmware_time, loader_time, kernel_time, initrd_time, userspace_time, finish_time
-
-def draw_box(context, j, k, l, m, r = 0, g = 0, b = 0):
-        context.save()
-        context.set_source_rgb(r, g, b)
-        context.rectangle(j, k, l, m)
-        context.fill()
-        context.restore()
-
-def draw_text(context, x, y, text, size = 12, r = 0, g = 0, b = 0, vcenter = 0.5, hcenter = 0.5):
-        context.save()
-
-        context.set_source_rgb(r, g, b)
-        context.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
-        context.set_font_size(size)
-
-        if vcenter or hcenter:
-                x_bearing, y_bearing, width, height = context.text_extents(text)[:4]
-
-                if hcenter:
-                        x = x - width*hcenter - x_bearing
-
-                if vcenter:
-                        y = y - height*vcenter - y_bearing
-
-        context.move_to(x, y)
-        context.show_text(text)
-
-        context.restore()
-
-def time():
-
-        firmware_time, loader_time, kernel_time, initrd_time, userspace_time, finish_time = acquire_start_time()
-
-        sys.stdout.write("Startup finished in ")
-
-        if firmware_time > 0:
-                sys.stdout.write("%lums (firmware) + " % ((firmware_time - loader_time) / 1000))
-        if loader_time > 0:
-                sys.stdout.write("%lums (loader) + " % (loader_time / 1000))
-        if initrd_time > 0:
-                sys.stdout.write("%lums (kernel) + %lums (initrd) + " % (initrd_time / 1000, (userspace_time - initrd_time) / 1000))
-        elif kernel_time > 0:
-                sys.stdout.write("%lums (kernel) + " % (userspace_time  / 1000))
-
-        sys.stdout.write("%lums (userspace) " % ((finish_time - userspace_time) / 1000))
-
-        if kernel_time > 0:
-                sys.stdout.write("= %lums\n" % ((firmware_time + finish_time) / 1000))
-        else:
-                sys.stdout.write("= %lums\n" % ((finish_time - userspace_time) / 1000))
-
-def blame():
-
-        data = acquire_time_data()
-        s = sorted(data, key = lambda i: i[2] - i[1], reverse = True)
-
-        for name, ixt, aet, axt, iet in s:
-
-                if ixt <= 0 or aet <= 0:
-                        continue
-
-                if aet <= ixt:
-                        continue
-
-                sys.stdout.write("%6lums %s\n" % ((aet - ixt) / 1000, name))
-
-def plot():
-        if cairo is None:
-                sys.exit("Failed to initilize python-cairo required for 'plot' verb.")
-        firmware_time, loader_time, kernel_time, initrd_time, userspace_time, finish_time = acquire_start_time()
-        data = acquire_time_data()
-        s = sorted(data, key = lambda i: i[1])
-
-        # Account for kernel and initramfs bars if they exist
-        if initrd_time > 0:
-                count = 3
-        else:
-                count = 2
-
-        for name, ixt, aet, axt, iet in s:
-
-                if (ixt >= userspace_time and ixt <= finish_time) or \
-                                (aet >= userspace_time and aet <= finish_time) or \
-                                (axt >= userspace_time and axt <= finish_time):
-                        count += 1
-
-        border = 100
-        bar_height = 20
-        bar_space = bar_height * 0.1
-
-        # 1000px = 10s, 1px = 10ms
-        width = finish_time/10000 + border*2
-        height = count * (bar_height + bar_space) + border * 2
-
-        if width < 1000:
-                width = 1000
-
-        surface = cairo.SVGSurface(sys.stdout, width, height)
-        context = cairo.Context(surface)
-
-        draw_box(context, 0, 0, width, height, 1, 1, 1)
-
-        context.translate(border + 0.5, border + 0.5)
-
-        context.save()
-        context.set_line_width(1)
-        context.set_source_rgb(0.7, 0.7, 0.7)
-
-        for x in range(0, int(finish_time/10000) + 100, 100):
-                context.move_to(x, 0)
-                context.line_to(x, height-border*2)
-
-        context.move_to(0, 0)
-        context.line_to(width-border*2, 0)
-
-        context.move_to(0, height-border*2)
-        context.line_to(width-border*2, height-border*2)
-
-        context.stroke()
-        context.restore()
-
-        osrel = "Linux"
-        if os.path.exists("/etc/os-release"):
-                for line in open("/etc/os-release"):
-                        if line.startswith('PRETTY_NAME='):
-                                osrel = line[12:]
-                                osrel = osrel.strip('\"\n')
-                                break
-
-        banner = "{} {} ({} {}) {}".format(osrel, *(os.uname()[1:5]))
-        draw_text(context, 0, -15, banner, hcenter = 0, vcenter = 1)
-
-        for x in range(0, int(finish_time/10000) + 100, 100):
-                draw_text(context, x, -5, "%lus" % (x/100), vcenter = 0, hcenter = 0)
-
-        y = 0
-
-        # draw boxes for kernel and initramfs boot time
-        if initrd_time > 0:
-                draw_box(context, 0, y, initrd_time/10000, bar_height, 0.7, 0.7, 0.7)
-                draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0)
-                y += bar_height + bar_space
-
-                draw_box(context, initrd_time/10000, y, userspace_time/10000-initrd_time/10000, bar_height, 0.7, 0.7, 0.7)
-                draw_text(context, initrd_time/10000 + 10, y + bar_height/2, "initramfs", hcenter = 0)
-                y += bar_height + bar_space
-
-        else:
-                draw_box(context, 0, y, userspace_time/10000, bar_height, 0.6, 0.6, 0.6)
-                draw_text(context, 10, y + bar_height/2, "kernel", hcenter = 0)
-                y += bar_height + bar_space
-
-        draw_box(context, userspace_time/10000, y, finish_time/10000-userspace_time/10000, bar_height, 0.7, 0.7, 0.7)
-        draw_text(context, userspace_time/10000 + 10, y + bar_height/2, "userspace", hcenter = 0)
-        y += bar_height + bar_space
-
-        for name, ixt, aet, axt, iet in s:
-
-                drawn = False
-                left = -1
-
-                if ixt >= userspace_time and ixt <= finish_time:
-
-                        # Activating
-                        a = ixt
-                        b = min(filter(lambda x: x >= ixt, (aet, axt, iet, finish_time))) - ixt
-
-                        draw_box(context, a/10000, y, b/10000, bar_height, 1, 0, 0)
-                        drawn = True
-
-                        if left < 0:
-                                left = a
-
-                if aet >= userspace_time and aet <= finish_time:
-
-                        # Active
-                        a = aet
-                        b = min(filter(lambda x: x >= aet, (axt, iet, finish_time))) - aet
-
-                        draw_box(context, a/10000, y, b/10000, bar_height, .8, .6, .6)
-                        drawn = True
-
-                        if left < 0:
-                                left = a
-
-                if axt >= userspace_time and axt <= finish_time:
-
-                        # Deactivating
-                        a = axt
-                        b = min(filter(lambda x: x >= axt, (iet, finish_time))) - axt
-
-                        draw_box(context, a/10000, y, b/10000, bar_height, .6, .4, .4)
-                        drawn = True
-
-                        if left < 0:
-                                left = a
-
-                if drawn:
-                        x = left/10000
-
-                        if x < width/2-border:
-                                draw_text(context, x + 10, y + bar_height/2, name, hcenter = 0)
-                        else:
-                                draw_text(context, x - 10, y + bar_height/2, name, hcenter = 1)
-
-                        y += bar_height + bar_space
-
-        draw_text(context, 0, height-border*2, "Legend: Red = Activating; Pink = Active; Dark Pink = Deactivating", hcenter = 0, vcenter = -1)
-
-        if initrd_time > 0:
-                draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (initramfs) + %lums (userspace) = %lums" % ( \
-                        initrd_time/1000, \
-                        (userspace_time - initrd_time)/1000, \
-                        (finish_time - userspace_time)/1000, \
-                        finish_time/1000), hcenter = 0, vcenter = -1)
-        else:
-                draw_text(context, 0, height-border*2 + bar_height, "Startup finished in %lums (kernel) + %lums (userspace) = %lums" % ( \
-                        userspace_time/1000, \
-                        (finish_time - userspace_time)/1000, \
-                        finish_time/1000), hcenter = 0, vcenter = -1)
-
-        surface.finish()
-
-parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
-                                 version='systemd-analyze @PACKAGE_VERSION@',
-                                 description='Process systemd profiling information',
-                                 epilog='''\
-time - print time spent in the kernel before reaching userspace
-blame - print list of running units ordered by time to init
-plot - output SVG graphic showing service initialization
-''')
-
-parser.add_argument('action', choices=('time', 'blame', 'plot'),
-                    default='time', nargs='?',
-                    help='action to perform (default: time)')
-parser.add_argument('--user', action='store_true',
-                    help='use the session bus')
-
-args = parser.parse_args()
-
-if args.user:
-        bus = Gio.BusType.SESSION
-else:
-        bus = Gio.BusType.SYSTEM
-
-verb = {'time' : time,
-        'blame': blame,
-        'plot' : plot,
-        }
-verb.get(args.action)()

commit a38694df9c49cb8953e444ff94b1d78239347dfe
Author: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
Date:   Thu Jan 31 09:57:25 2013 +0100

    systemctl: use parse_unit_info
    
    Signed-off-by: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>

diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0d1be19..54c8ebc 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -435,7 +435,7 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
 static int list_units(DBusConnection *bus, char **args) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         _cleanup_free_ struct unit_info *unit_infos = NULL;
-        DBusMessageIter iter, sub, sub2;
+        DBusMessageIter iter, sub;
         unsigned c = 0, n_units = 0;
         int r;
 
@@ -465,8 +465,6 @@ static int list_units(DBusConnection *bus, char **args) {
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
                 struct unit_info *u;
 
-                assert(dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRUCT);
-
                 if (c >= n_units) {
                         struct unit_info *w;
 
@@ -480,21 +478,7 @@ static int list_units(DBusConnection *bus, char **args) {
 
                 u = unit_infos + c;
 
-                dbus_message_iter_recurse(&sub, &sub2);
-
-                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->id, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->description, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->load_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->active_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->sub_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->following, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &u->unit_path, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &u->job_id, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &u->job_type, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &u->job_path, false) < 0) {
-                        log_error("Failed to parse reply.");
-                        return -EIO;
-                }
+                bus_parse_unit_info(&sub, u);
 
                 dbus_message_iter_next(&sub);
                 c++;
@@ -966,19 +950,19 @@ static int dot_one_property(const char *name, const char *prop, DBusMessageIter
         return 0;
 }
 
-static int dot_one(DBusConnection *bus, const char *name, const char *path) {
+static int dot_one(DBusConnection *bus, const struct unit_info *u) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         const char *interface = "org.freedesktop.systemd1.Unit";
         int r;
         DBusMessageIter iter, sub, sub2, sub3;
 
         assert(bus);
-        assert(path);
+        assert(u);
 
         r = bus_method_call_with_reply(
                         bus,
                         "org.freedesktop.systemd1",
-                        path,
+                        u->unit_path,
                         "org.freedesktop.DBus.Properties",
                         "GetAll",
                         &reply,
@@ -1010,7 +994,7 @@ static int dot_one(DBusConnection *bus, const char *name, const char *path) {
                 }
 
                 dbus_message_iter_recurse(&sub2, &sub3);
-                r = dot_one_property(name, prop, &sub3);
+                r = dot_one_property(u->id, prop, &sub3);
                 if (r < 0)
                         return r;
 
@@ -1022,7 +1006,7 @@ static int dot_one(DBusConnection *bus, const char *name, const char *path) {
 
 static int dot(DBusConnection *bus, char **args) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
-        DBusMessageIter iter, sub, sub2;
+        DBusMessageIter iter, sub;
         int r;
 
         r = bus_method_call_with_reply(
@@ -1048,31 +1032,17 @@ static int dot(DBusConnection *bus, char **args) {
 
         dbus_message_iter_recurse(&iter, &sub);
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
-                const char *id, *description, *load_state, *active_state, *sub_state, *following, *unit_path;
-
-                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
-                        log_error("Failed to parse reply.");
-                        return -EIO;
-                }
+                struct unit_info u;
 
-                dbus_message_iter_recurse(&sub, &sub2);
-
-                if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &id, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &description, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &load_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &active_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &sub_state, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &following, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &unit_path, true) < 0) {
-                        log_error("Failed to parse reply.");
+                r = bus_parse_unit_info(&sub, &u);
+                if (r < 0)
                         return -EIO;
-                }
 
-                r = dot_one(bus, id, unit_path);
+                r = dot_one(bus, &u);
                 if (r < 0)
                         return r;
 
-                /* printf("\t\"%s\";\n", id); */
+                /* printf("\t\"%s\";\n", u.id); */
                 dbus_message_iter_next(&sub);
         }
 

commit ddb88cc5b8c5896fc30a86397da6d7e14160801b
Author: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
Date:   Thu Jan 31 09:50:21 2013 +0100

    dbus: introduce parse_unit_info
    
    Signed-off-by: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>

diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c
index 50891a8..2769b2c 100644
--- a/src/shared/dbus-common.c
+++ b/src/shared/dbus-common.c
@@ -988,6 +988,34 @@ int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) {
         return 0;
 }
 
+int bus_parse_unit_info(DBusMessageIter *iter, struct unit_info *u) {
+        DBusMessageIter sub;
+
+        assert(iter);
+        assert(u);
+
+        if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRUCT)
+                return -EINVAL;
+
+        dbus_message_iter_recurse(iter, &sub);
+
+        if (bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->id, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->description, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->load_state, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->active_state, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->sub_state, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->following, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_OBJECT_PATH, &u->unit_path, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_UINT32, &u->job_id, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_STRING, &u->job_type, true) < 0 ||
+            bus_iter_get_basic_and_next(&sub, DBUS_TYPE_OBJECT_PATH, &u->job_path, false) < 0) {
+                log_error("Failed to parse reply.");
+                return -EIO;
+        }
+
+        return 0;
+}
+
 int bus_append_strv_iter(DBusMessageIter *iter, char **l) {
         DBusMessageIter sub;
 
diff --git a/src/shared/dbus-common.h b/src/shared/dbus-common.h
index 800c0ea..f7f614c 100644
--- a/src/shared/dbus-common.h
+++ b/src/shared/dbus-common.h
@@ -212,6 +212,8 @@ struct unit_info {
         const char *job_path;
 };
 
+int bus_parse_unit_info(DBusMessageIter *iter, struct unit_info *u);
+
 int bus_append_strv_iter(DBusMessageIter *iter, char **l);
 
 int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next);

commit cdf3f17bfb20eac2929c8b6a582b988b790f071d
Author: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
Date:   Thu Jan 31 09:49:35 2013 +0100

    dbus: import struct unit_info from systemctl
    
    Signed-off-by: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>

diff --git a/src/shared/dbus-common.h b/src/shared/dbus-common.h
index e141c9e..800c0ea 100644
--- a/src/shared/dbus-common.h
+++ b/src/shared/dbus-common.h
@@ -199,6 +199,19 @@ int bus_parse_strv(DBusMessage *m, char ***_l);
 int bus_parse_strv_iter(DBusMessageIter *iter, char ***_l);
 int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l);
 
+struct unit_info {
+        const char *id;
+        const char *description;
+        const char *load_state;
+        const char *active_state;
+        const char *sub_state;
+        const char *following;
+        const char *unit_path;
+        uint32_t job_id;
+        const char *job_type;
+        const char *job_path;
+};
+
 int bus_append_strv_iter(DBusMessageIter *iter, char **l);
 
 int bus_iter_get_basic_and_next(DBusMessageIter *iter, int type, void *data, bool next);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 5deacbf..0d1be19 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -275,19 +275,6 @@ static bool avoid_bus(void) {
         return false;
 }
 
-struct unit_info {
-        const char *id;
-        const char *description;
-        const char *load_state;
-        const char *active_state;
-        const char *sub_state;
-        const char *following;
-        const char *unit_path;
-        uint32_t job_id;
-        const char *job_type;
-        const char *job_path;
-};
-
 static int compare_unit_info(const void *a, const void *b) {
         const char *d1, *d2;
         const struct unit_info *u = a, *v = b;



More information about the systemd-commits mailing list