@@ -1652,91 +1652,72 @@ static int list_dependencies_print(const char *name, int level, unsigned int bra
16521652
16531653static int list_dependencies_get_dependencies (sd_bus * bus , const char * name , char * * * deps ) {
16541654
1655- static const char * dependencies [_DEPENDENCY_MAX ] = {
1656- [DEPENDENCY_FORWARD ] = "Requires\0"
1657- "Requisite\0"
1658- "Wants\0"
1659- "ConsistsOf\0"
1660- "BindsTo\0" ,
1661- [DEPENDENCY_REVERSE ] = "RequiredBy\0"
1662- "RequisiteOf\0"
1663- "WantedBy\0"
1664- "PartOf\0"
1665- "BoundBy\0" ,
1666- [DEPENDENCY_AFTER ] = "After\0" ,
1667- [DEPENDENCY_BEFORE ] = "Before\0" ,
1655+ struct DependencyStatusInfo {
1656+ char * * dep [5 ];
1657+ } info = {};
1658+
1659+ static const struct bus_properties_map map [_DEPENDENCY_MAX ][6 ] = {
1660+ [DEPENDENCY_FORWARD ] = {
1661+ { "Requires" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [0 ]) },
1662+ { "Requisite" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [1 ]) },
1663+ { "Wants" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [2 ]) },
1664+ { "ConsistsOf" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [3 ]) },
1665+ { "BindsTo" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [4 ]) },
1666+ {}
1667+ },
1668+ [DEPENDENCY_REVERSE ] = {
1669+ { "RequiredBy" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [0 ]) },
1670+ { "RequisiteOf" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [1 ]) },
1671+ { "WantedBy" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [2 ]) },
1672+ { "PartOf" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [3 ]) },
1673+ { "BoundBy" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [4 ]) },
1674+ {}
1675+ },
1676+ [DEPENDENCY_AFTER ] = {
1677+ { "After" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [0 ]) },
1678+ {}
1679+ },
1680+ [DEPENDENCY_BEFORE ] = {
1681+ { "Before" , "as" , NULL , offsetof(struct DependencyStatusInfo , dep [0 ]) },
1682+ {}
1683+ },
16681684 };
16691685
16701686 _cleanup_ (sd_bus_error_free ) sd_bus_error error = SD_BUS_ERROR_NULL ;
1671- _cleanup_ (sd_bus_message_unrefp ) sd_bus_message * reply = NULL ;
16721687 _cleanup_strv_free_ char * * ret = NULL ;
16731688 _cleanup_free_ char * path = NULL ;
1674- int r ;
1689+ int i , r ;
16751690
16761691 assert (bus );
16771692 assert (name );
16781693 assert (deps );
1679- assert_cc (ELEMENTSOF (dependencies ) == _DEPENDENCY_MAX );
16801694
16811695 path = unit_dbus_path_from_name (name );
16821696 if (!path )
16831697 return log_oom ();
16841698
1685- r = sd_bus_call_method (
1686- bus ,
1687- "org.freedesktop.systemd1" ,
1688- path ,
1689- "org.freedesktop.DBus.Properties" ,
1690- "GetAll" ,
1691- & error ,
1692- & reply ,
1693- "s" , "org.freedesktop.systemd1.Unit" );
1699+ r = bus_map_all_properties (bus ,
1700+ "org.freedesktop.systemd1" ,
1701+ path ,
1702+ map [arg_dependency ],
1703+ & error ,
1704+ & info );
16941705 if (r < 0 )
16951706 return log_error_errno (r , "Failed to get properties of %s: %s" , name , bus_error_message (& error , r ));
16961707
1697- r = sd_bus_message_enter_container (reply , SD_BUS_TYPE_ARRAY , "{sv}" );
1698- if (r < 0 )
1699- return bus_log_parse_error (r );
1700-
1701- while ((r = sd_bus_message_enter_container (reply , SD_BUS_TYPE_DICT_ENTRY , "sv" )) > 0 ) {
1702- const char * prop ;
1703-
1704- r = sd_bus_message_read (reply , "s" , & prop );
1705- if (r < 0 )
1706- return bus_log_parse_error (r );
1707-
1708- if (!nulstr_contains (dependencies [arg_dependency ], prop )) {
1709- r = sd_bus_message_skip (reply , "v" );
1710- if (r < 0 )
1711- return bus_log_parse_error (r );
1712- } else {
1713-
1714- r = sd_bus_message_enter_container (reply , SD_BUS_TYPE_VARIANT , "as" );
1715- if (r < 0 )
1716- return bus_log_parse_error (r );
1717-
1718- r = bus_message_read_strv_extend (reply , & ret );
1719- if (r < 0 )
1720- return bus_log_parse_error (r );
1721-
1722- r = sd_bus_message_exit_container (reply );
1723- if (r < 0 )
1724- return bus_log_parse_error (r );
1725- }
1708+ if (IN_SET (arg_dependency , DEPENDENCY_AFTER , DEPENDENCY_BEFORE )) {
1709+ * deps = info .dep [0 ];
1710+ return 0 ;
1711+ }
17261712
1727- r = sd_bus_message_exit_container (reply );
1713+ for (i = 0 ; i < 5 ; i ++ ) {
1714+ r = strv_extend_strv (& ret , info .dep [i ], true);
17281715 if (r < 0 )
1729- return bus_log_parse_error ( r );
1730-
1716+ return log_oom ( );
1717+ info . dep [ i ] = strv_free ( info . dep [ i ]);
17311718 }
1732- if (r < 0 )
1733- return bus_log_parse_error (r );
1734-
1735- r = sd_bus_message_exit_container (reply );
1736- if (r < 0 )
1737- return bus_log_parse_error (r );
17381719
1739- * deps = strv_uniq ( ret ) ;
1720+ * deps = ret ;
17401721 ret = NULL ;
17411722
17421723 return 0 ;
0 commit comments