From 7d6b27238f5047657c8ebd4314d504e68217c6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Jun 2018 11:59:04 +0200 Subject: [PATCH 1/7] man: xinclude the generic text to talk about libsystemd pkgconfig The only difference is that functions are not individually listed by name, but that seems completely pointless, since all functions that are documented are always exported, so the generic text tells the user all she or he needs to know. --- man/sd_bus_creds_get_pid.xml | 13 ++---------- man/sd_bus_creds_new_from_pid.xml | 13 ++---------- man/sd_bus_default.xml | 13 ++---------- man/sd_bus_error.xml | 12 ++--------- man/sd_bus_message_append.xml | 10 +-------- man/sd_bus_message_append_array.xml | 10 +-------- man/sd_bus_message_append_basic.xml | 12 ++--------- man/sd_bus_message_append_string_memfd.xml | 9 +------- man/sd_bus_message_append_strv.xml | 10 +-------- man/sd_bus_message_get_cookie.xml | 14 +++---------- man/sd_bus_message_get_monotonic_usec.xml | 16 +++----------- man/sd_bus_message_set_destination.xml | 13 ++---------- man/sd_bus_negotiate_fds.xml | 12 ++--------- man/sd_bus_new.xml | 12 ++--------- man/sd_bus_slot_set_floating.xml | 11 ++-------- man/sd_bus_track_add_name.xml | 10 ++------- man/sd_bus_track_new.xml | 10 ++------- man/sd_get_seats.xml | 16 +++----------- man/sd_id128_get_machine.xml | 12 ++--------- man/sd_id128_randomize.xml | 12 ++--------- man/sd_id128_to_string.xml | 13 ++---------- man/sd_journal_add_match.xml | 19 ++--------------- man/sd_journal_enumerate_fields.xml | 7 ++----- man/sd_journal_get_catalog.xml | 9 ++------ man/sd_journal_get_cursor.xml | 9 ++------ man/sd_journal_get_cutoff_realtime_usec.xml | 10 ++------- man/sd_journal_get_data.xml | 17 ++------------- man/sd_journal_get_realtime_usec.xml | 14 +++---------- man/sd_journal_get_usage.xml | 8 ++----- man/sd_journal_has_runtime_files.xml | 7 ++----- man/sd_journal_next.xml | 11 ++-------- man/sd_journal_print.xml | 12 ++--------- man/sd_journal_query_unique.xml | 10 ++------- man/sd_journal_seek_head.xml | 12 ++--------- man/sd_journal_stream_fd.xml | 8 ++----- man/sd_login_monitor_new.xml | 18 +++------------- man/sd_machine_get_class.xml | 13 ++---------- man/sd_pid_get_owner_uid.xml | 22 +++----------------- man/sd_seat_get_active.xml | 17 +++------------ man/sd_session_is_active.xml | 23 +++------------------ man/sd_uid_get_state.xml | 12 +++-------- 41 files changed, 87 insertions(+), 424 deletions(-) diff --git a/man/sd_bus_creds_get_pid.xml b/man/sd_bus_creds_get_pid.xml index c1af00ee0f..f3d198df38 100644 --- a/man/sd_bus_creds_get_pid.xml +++ b/man/sd_bus_creds_get_pid.xml @@ -10,7 +10,7 @@ Copyright 2014 Zbigniew Jędrzejewski-Szmek --> - + sd_bus_creds_get_pid @@ -529,16 +529,7 @@ - - Notes - - sd_bus_creds_get_pid() and the other - functions described here are available as a shared library, which - can be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_creds_new_from_pid.xml b/man/sd_bus_creds_new_from_pid.xml index ed26f4418b..a4edb1fd6a 100644 --- a/man/sd_bus_creds_new_from_pid.xml +++ b/man/sd_bus_creds_new_from_pid.xml @@ -10,7 +10,7 @@ Copyright 2014 Zbigniew Jędrzejewski-Szmek --> - + sd_bus_creds_new_from_pid @@ -315,16 +315,7 @@ - - Notes - - sd_bus_creds_new_from_pid() and the - other calls described here are available as a shared library, - which can be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_default.xml b/man/sd_bus_default.xml index da06fb9cbf..78b836bfef 100644 --- a/man/sd_bus_default.xml +++ b/man/sd_bus_default.xml @@ -10,7 +10,7 @@ Copyright 2014 Zbigniew Jędrzejewski-Szmek --> - + sd_bus_default @@ -281,16 +281,7 @@ by returned. See sd_bus_send3. - - Notes - - sd_bus_open_user() and the other - functions described here are available as a shared library, which - can be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_error.xml b/man/sd_bus_error.xml index 6ca0e8af64..1552405ac4 100644 --- a/man/sd_bus_error.xml +++ b/man/sd_bus_error.xml @@ -10,7 +10,7 @@ Copyright 2014 Zbigniew Jędrzejewski-Szmek --> - + sd_bus_error @@ -352,15 +352,7 @@ - - Notes - - sd_bus_set_error() and other functions - described here are available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_append.xml b/man/sd_bus_message_append.xml index 29a12c4b47..dcabfeaec4 100644 --- a/man/sd_bus_message_append.xml +++ b/man/sd_bus_message_append.xml @@ -251,15 +251,7 @@ sd_bus_message_append(m, "ynqiuxtd", y, n, q, i, u, x, t, d); - - Notes - - sd_bus_open_user() and other functions - described here are available as a shared library, which can be - compiled and linked to with the - libsystemd-bus pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_append_array.xml b/man/sd_bus_message_append_array.xml index a601ba51d0..76e342f716 100644 --- a/man/sd_bus_message_append_array.xml +++ b/man/sd_bus_message_append_array.xml @@ -176,15 +176,7 @@ - - Notes - - sd_bus_append_array() and other - functions described here are available as a shared library, which - can be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_append_basic.xml b/man/sd_bus_message_append_basic.xml index 7e1794dfff..9b1ac34169 100644 --- a/man/sd_bus_message_append_basic.xml +++ b/man/sd_bus_message_append_basic.xml @@ -10,7 +10,7 @@ Copyright 2014 Zbigniew Jędrzejewski-Szmek --> - + sd_bus_message_append_basic @@ -260,15 +260,7 @@ - - Notes - - The sd_bus_append_basic() function - described here is available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_append_string_memfd.xml b/man/sd_bus_message_append_string_memfd.xml index 144a9c2dcb..4616bba71a 100644 --- a/man/sd_bus_message_append_string_memfd.xml +++ b/man/sd_bus_message_append_string_memfd.xml @@ -119,14 +119,7 @@ - - Notes - - The functions described here are available as a shared library, - which can be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_append_strv.xml b/man/sd_bus_message_append_strv.xml index 5ac4ed3423..eb13e63d35 100644 --- a/man/sd_bus_message_append_strv.xml +++ b/man/sd_bus_message_append_strv.xml @@ -80,15 +80,7 @@ - - Notes - - The sd_bus_append_append_strv() function - described here is available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_get_cookie.xml b/man/sd_bus_message_get_cookie.xml index 1b64240766..5bc0d13ed7 100644 --- a/man/sd_bus_message_get_cookie.xml +++ b/man/sd_bus_message_get_cookie.xml @@ -10,7 +10,8 @@ Copyright 2013 Lennart Poettering --> - + sd_bus_message_get_cookie @@ -111,16 +112,7 @@ - - Notes - - The sd_bus_message_get_cookie() and - sd_bus_message_get_reply_cookie() interfaces - are available as a shared library, which can be compiled and - linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_get_monotonic_usec.xml b/man/sd_bus_message_get_monotonic_usec.xml index b00dcf5e20..f3f66cb2bd 100644 --- a/man/sd_bus_message_get_monotonic_usec.xml +++ b/man/sd_bus_message_get_monotonic_usec.xml @@ -10,7 +10,8 @@ Copyright 2013 Lennart Poettering --> - + sd_bus_message_get_monotonic_usec @@ -141,18 +142,7 @@ - - Notes - - The - sd_bus_message_get_monotonic_usec(), - sd_bus_message_get_realtime_usec(), and - sd_bus_message_get_seqnum() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_message_set_destination.xml b/man/sd_bus_message_set_destination.xml index 0bae24b7ea..c255cfe9b5 100644 --- a/man/sd_bus_message_set_destination.xml +++ b/man/sd_bus_message_set_destination.xml @@ -9,7 +9,7 @@ Copyright 2017 Lennart Poettering --> - + sd_bus_message_set_destination @@ -99,16 +99,7 @@ - - Notes - - The sd_bus_message_set_destination() and - sd_bus_message_set_sender() interfaces - are available as a shared library, which can be compiled and - linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_negotiate_fds.xml b/man/sd_bus_negotiate_fds.xml index eae879047f..44865f352c 100644 --- a/man/sd_bus_negotiate_fds.xml +++ b/man/sd_bus_negotiate_fds.xml @@ -10,7 +10,7 @@ Copyright 2014 Lennart Poettering --> - + sd_bus_negotiate_fds @@ -140,15 +140,7 @@ - - Notes - - sd_bus_negotiate_fds() and the other - functions described here are available as a shared library, which - can be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_new.xml b/man/sd_bus_new.xml index dfbdd4a06f..4b6905df99 100644 --- a/man/sd_bus_new.xml +++ b/man/sd_bus_new.xml @@ -10,7 +10,7 @@ Copyright 2014 Zbigniew Jędrzejewski-Szmek --> - + sd_bus_new @@ -152,15 +152,7 @@ - - Notes - - sd_bus_new() and other functions - described here are available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_bus_slot_set_floating.xml b/man/sd_bus_slot_set_floating.xml index 2ac5090193..9cb4b8a441 100644 --- a/man/sd_bus_slot_set_floating.xml +++ b/man/sd_bus_slot_set_floating.xml @@ -4,7 +4,7 @@ - + sd_bus_slot_set_floating @@ -96,14 +96,7 @@ - - Notes - - sd_bus_slot_set_floating() and sd_bus_slot_get_floating() are - available as a shared library, which can be compiled and linked to with the - libsystemd pkg-config1 file. - + See Also diff --git a/man/sd_bus_track_add_name.xml b/man/sd_bus_track_add_name.xml index 3705515aa9..212fa87351 100644 --- a/man/sd_bus_track_add_name.xml +++ b/man/sd_bus_track_add_name.xml @@ -10,7 +10,7 @@ Copyright 2016 Lennart Poettering --> - + sd_bus_track_add_name @@ -229,13 +229,7 @@ - - Notes - - sd_bus_track_add_name() and the other calls described here are available as a shared library, - which can be compiled and linked to with the libsystemd pkg-config1 file. - + See Also diff --git a/man/sd_bus_track_new.xml b/man/sd_bus_track_new.xml index c863962471..8cdecbfe60 100644 --- a/man/sd_bus_track_new.xml +++ b/man/sd_bus_track_new.xml @@ -10,7 +10,7 @@ Copyright 2016 Lennart Poettering --> - + sd_bus_track_new @@ -231,13 +231,7 @@ - - Notes - - sd_bus_track_new() and the other calls described here are available as a shared library, - which can be compiled and linked to with the libsystemd pkg-config1 file. - + See Also diff --git a/man/sd_get_seats.xml b/man/sd_get_seats.xml index 63659f8cd1..f522f75d99 100644 --- a/man/sd_get_seats.xml +++ b/man/sd_get_seats.xml @@ -10,7 +10,8 @@ Copyright 2010 Lennart Poettering --> - + sd_get_seats @@ -121,18 +122,7 @@ - - Notes - - The sd_get_seats(), - sd_get_sessions(), - sd_get_uids() and - sd_get_machine_names() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_id128_get_machine.xml b/man/sd_id128_get_machine.xml index 827756d135..77268da38b 100644 --- a/man/sd_id128_get_machine.xml +++ b/man/sd_id128_get_machine.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_id128_get_machine @@ -123,15 +123,7 @@ empty or all zeros. - - Notes - - The sd_id128_get_machine(), sd_id128_get_machine_app_specific() - sd_id128_get_boot() and sd_id128_get_invocation() interfaces are - available as a shared library, which can be compiled and linked to with the - libsystemd pkg-config1 file. - + Examples diff --git a/man/sd_id128_randomize.xml b/man/sd_id128_randomize.xml index beefc270c0..f9c72780fe 100644 --- a/man/sd_id128_randomize.xml +++ b/man/sd_id128_randomize.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_id128_randomize @@ -78,15 +78,7 @@ errno-style error code. - - Notes - - The sd_id128_randomize() interface is - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_id128_to_string.xml b/man/sd_id128_to_string.xml index c25cd5da36..f4a2097240 100644 --- a/man/sd_id128_to_string.xml +++ b/man/sd_id128_to_string.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_id128_to_string @@ -95,16 +95,7 @@ errno-style error code. - - Notes - - The sd_id128_to_string() and - sd_id128_from_string() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_journal_add_match.xml b/man/sd_journal_add_match.xml index 01fd68add8..d50afec558 100644 --- a/man/sd_journal_add_match.xml +++ b/man/sd_journal_add_match.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_add_match @@ -154,21 +154,7 @@ returns nothing. - - Notes - - All functions listed here are thread-agnostic and only a single thread may operate - on a given sd_journal object. - - The sd_journal_add_match(), - sd_journal_add_disjunction(), - sd_journal_add_conjunction() and - sd_journal_flush_matches() - interfaces are available as a shared library, which can - be compiled and linked to with the - libsystemd pkg-config1 - file. - + Examples @@ -189,7 +175,6 @@ int add_matches(sd_journal *j) { sd_journal_add_disjunction(j); sd_journal_add_match(j, "MESSAGE_ID=03bb1dab98ab4ecfbf6fff2738bdd964", 0); } - diff --git a/man/sd_journal_enumerate_fields.xml b/man/sd_journal_enumerate_fields.xml index fdaaccef93..db39f9bfb5 100644 --- a/man/sd_journal_enumerate_fields.xml +++ b/man/sd_journal_enumerate_fields.xml @@ -10,7 +10,7 @@ Copyright 2016 Lennart Poettering --> - + sd_journal_enumerate_fields @@ -102,10 +102,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The sd_journal_enumerate_fields() and sd_journal_restart_fields() - interfaces are available as a shared library, which can be compiled and linked to with the - libsystemd pkg-config1 file. + diff --git a/man/sd_journal_get_catalog.xml b/man/sd_journal_get_catalog.xml index 85aa189d4f..b095f0cd60 100644 --- a/man/sd_journal_get_catalog.xml +++ b/man/sd_journal_get_catalog.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_get_catalog @@ -104,12 +104,7 @@ single thread may operate on a given sd_journal object. Function sd_journal_get_catalog_for_message_id() is thread-safe. - The sd_journal_get_catalog() and - sd_journal_get_catalog_for_message_id() - interfaces are available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_get_cursor.xml b/man/sd_journal_get_cursor.xml index 0e8244420d..0267609442 100644 --- a/man/sd_journal_get_cursor.xml +++ b/man/sd_journal_get_cursor.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_get_cursor @@ -114,12 +114,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The sd_journal_get_cursor() and - sd_journal_test_cursor() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_get_cutoff_realtime_usec.xml b/man/sd_journal_get_cutoff_realtime_usec.xml index 7f9b863a21..bda21ae35f 100644 --- a/man/sd_journal_get_cutoff_realtime_usec.xml +++ b/man/sd_journal_get_cutoff_realtime_usec.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_get_cutoff_realtime_usec @@ -112,13 +112,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The - sd_journal_get_cutoff_realtime_usec() and - sd_journal_get_cutoff_monotonic_usec() - interfaces are available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_get_data.xml b/man/sd_journal_get_data.xml index 9d2278f4da..505a8bddd4 100644 --- a/man/sd_journal_get_data.xml +++ b/man/sd_journal_get_data.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_get_data @@ -169,19 +169,7 @@ success or a negative errno-style error code. - - Notes - - The sd_journal_get_data(), - sd_journal_enumerate_data(), - sd_journal_restart_data(), - sd_journal_set_data_threshold() and - sd_journal_get_data_threshold() interfaces - are available as a shared library, which can be compiled and - linked to with the - libsystemd pkg-config1 - file. - + Examples @@ -204,7 +192,6 @@ int print_fields(sd_journal *j) { printf("%.*s\n", (int) length, data); } … - diff --git a/man/sd_journal_get_realtime_usec.xml b/man/sd_journal_get_realtime_usec.xml index 49528357c6..9ef719a67e 100644 --- a/man/sd_journal_get_realtime_usec.xml +++ b/man/sd_journal_get_realtime_usec.xml @@ -10,7 +10,8 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_get_realtime_usec @@ -101,16 +102,7 @@ sd_journal_get_monotonic_usec(). - - Notes - - The sd_journal_get_realtime_usec() and - sd_journal_get_monotonic_usec() interfaces - are available as a shared library, which can be compiled and - linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_journal_get_usage.xml b/man/sd_journal_get_usage.xml index fdd7b05a7d..d8eaff1255 100644 --- a/man/sd_journal_get_usage.xml +++ b/man/sd_journal_get_usage.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_get_usage @@ -72,11 +72,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The sd_journal_get_usage() interface is - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_has_runtime_files.xml b/man/sd_journal_has_runtime_files.xml index d9a1e2c3d0..295bc0cc63 100644 --- a/man/sd_journal_has_runtime_files.xml +++ b/man/sd_journal_has_runtime_files.xml @@ -10,7 +10,7 @@ Copyright 2016 Jan Synáček --> - + sd_journal_has_runtime_files @@ -80,10 +80,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - Functions listed here are available as a shared library, which can be compiled and linked - to with the libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_next.xml b/man/sd_journal_next.xml index c90ac80ba9..9385315e2e 100644 --- a/man/sd_journal_next.xml +++ b/man/sd_journal_next.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_next @@ -138,14 +138,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The sd_journal_next(), - sd_journal_previous(), - sd_journal_next_skip() and - sd_journal_previous_skip() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_print.xml b/man/sd_journal_print.xml index e30bbf9b4d..4c7221e557 100644 --- a/man/sd_journal_print.xml +++ b/man/sd_journal_print.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_print @@ -203,15 +203,7 @@ sd_journal_send("MESSAGE=Hello World, this is PID %lu!", (unsigned long) getpid( not async signal safe. - - Notes - - The sd_journal_print(), sd_journal_printv(), - sd_journal_send(), sd_journal_sendv() and - sd_journal_perror() interfaces are available as a shared library, which can be compiled and - linked to with the libsystemd pkg-config1 file. - + See Also diff --git a/man/sd_journal_query_unique.xml b/man/sd_journal_query_unique.xml index d4f55ae475..56480b5718 100644 --- a/man/sd_journal_query_unique.xml +++ b/man/sd_journal_query_unique.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_query_unique @@ -142,13 +142,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The sd_journal_query_unique(), - sd_journal_enumerate_unique() and - sd_journal_restart_unique() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_seek_head.xml b/man/sd_journal_seek_head.xml index a250e74289..7dc9bb439e 100644 --- a/man/sd_journal_seek_head.xml +++ b/man/sd_journal_seek_head.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_seek_head @@ -136,15 +136,7 @@ All functions listed here are thread-agnostic and only a single thread may operate on a given sd_journal object. - The sd_journal_seek_head(), - sd_journal_seek_tail(), - sd_journal_seek_monotonic_usec(), - sd_journal_seek_realtime_usec(), - and sd_journal_seek_cursor() - interfaces are available as a shared library, which can - be compiled and linked to with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_journal_stream_fd.xml b/man/sd_journal_stream_fd.xml index 12bf937944..047991381a 100644 --- a/man/sd_journal_stream_fd.xml +++ b/man/sd_journal_stream_fd.xml @@ -10,7 +10,7 @@ Copyright 2012 Lennart Poettering --> - + sd_journal_stream_fd @@ -108,11 +108,7 @@ Function sd_journal_stream_fd() is thread-safe and may be called from multiple threads. - The sd_journal_stream_fd() interface is - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. + diff --git a/man/sd_login_monitor_new.xml b/man/sd_login_monitor_new.xml index f27c4f8bff..f26d88bc8b 100644 --- a/man/sd_login_monitor_new.xml +++ b/man/sd_login_monitor_new.xml @@ -10,7 +10,8 @@ Copyright 2010 Lennart Poettering --> - + sd_login_monitor_new @@ -246,20 +247,7 @@ else { - - Notes - - The sd_login_monitor_new(), - sd_login_monitor_unref(), - sd_login_monitor_flush(), - sd_login_monitor_get_fd(), - sd_login_monitor_get_events() and - sd_login_monitor_get_timeout() - interfaces are available as a shared library, which can be - compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_machine_get_class.xml b/man/sd_machine_get_class.xml index 9c3baf46ed..f48ddf4f0b 100644 --- a/man/sd_machine_get_class.xml +++ b/man/sd_machine_get_class.xml @@ -10,7 +10,7 @@ Copyright 2014 Lennart Poettering --> - + sd_machine_get_class @@ -116,16 +116,7 @@ - - Notes - - The sd_machine_get_class() and - sd_machine_get_ifindices() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_pid_get_owner_uid.xml b/man/sd_pid_get_owner_uid.xml index a0b906d142..28800b43a4 100644 --- a/man/sd_pid_get_owner_uid.xml +++ b/man/sd_pid_get_owner_uid.xml @@ -10,7 +10,8 @@ Copyright 2010 Lennart Poettering --> - + sd_pid_get_owner_uid @@ -308,24 +309,7 @@ Notes - The sd_pid_get_session(), - sd_pid_get_unit(), - sd_pid_get_user_unit(), - sd_pid_get_owner_uid(), - sd_pid_get_machine_name(), - sd_pid_get_slice(), - sd_pid_get_user_slice(), - sd_peer_get_session(), - sd_peer_get_unit(), - sd_peer_get_user_unit(), - sd_peer_get_owner_uid(), - sd_peer_get_machine_name(), - sd_peer_get_slice() and - sd_peer_get_user_slice() interfaces are - available as a shared library, which can be compiled and linked to - with the libsystemd pkg-config1 - file. + Note that the login session identifier as returned by sd_pid_get_session() diff --git a/man/sd_seat_get_active.xml b/man/sd_seat_get_active.xml index 32a67706d8..98ff2be151 100644 --- a/man/sd_seat_get_active.xml +++ b/man/sd_seat_get_active.xml @@ -10,7 +10,8 @@ Copyright 2010 Lennart Poettering --> - + sd_seat_get_active @@ -175,19 +176,7 @@ - - Notes - - The sd_seat_get_active(), - sd_seat_get_sessions(), - sd_seat_can_multi_session(), - sd_seat_can_tty() and - sd_seat_can_graphical() interfaces are - available as a shared library, which can be compiled and linked to - with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml index d5af6c12ef..b3009dedc6 100644 --- a/man/sd_session_is_active.xml +++ b/man/sd_session_is_active.xml @@ -10,7 +10,8 @@ Copyright 2010 Lennart Poettering --> - + sd_session_is_active @@ -316,25 +317,7 @@ - - Notes - - The sd_session_is_active(), - sd_session_get_state(), - sd_session_get_uid(), - sd_session_get_seat(), - sd_session_get_service(), - sd_session_get_type(), - sd_session_get_class(), - sd_session_get_display(), - sd_session_get_remote_host(), - sd_session_get_remote_user() and - sd_session_get_tty() - interfaces are available as a shared library, which can - be compiled and linked to with the - libsystemd pkg-config1 - file. - + See Also diff --git a/man/sd_uid_get_state.xml b/man/sd_uid_get_state.xml index 925696bd56..317e46a072 100644 --- a/man/sd_uid_get_state.xml +++ b/man/sd_uid_get_state.xml @@ -10,7 +10,8 @@ Copyright 2010 Lennart Poettering --> - + sd_uid_get_state @@ -197,14 +198,7 @@ - - Notes - - Functions described here are available as a shared library, - and can be compiled and linked to using the - libsystemd pkg-config1 - entry. - + See Also From 83b6c1a6b147d42a1077ad589f48ad5cd74ecea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 4 Jun 2018 13:04:40 +0200 Subject: [PATCH 2/7] bus-util: avoid unneeded initalization to zero --- src/shared/bus-util.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index e150c8728e..941a06f68d 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1838,13 +1838,15 @@ static int request_name_handler_may_reload_dbus(sd_bus_message *m, void *userdat int bus_request_name_async_may_reload_dbus(sd_bus *bus, sd_bus_slot **ret_slot, const char *name, uint64_t flags, void *userdata) { struct request_name_data *data; - data = new0(struct request_name_data, 1); + data = new(struct request_name_data, 1); if (!data) return -ENOMEM; - data->name = name; - data->flags = flags; - data->userdata = userdata; + *data = (struct request_name_data) { + .name = name, + .flags = flags, + .userdata = userdata, + }; return sd_bus_request_name_async(bus, ret_slot, name, flags, request_name_handler_may_reload_dbus, data); } From 24924cc959561c0aea09821a1b1d975a2e5f5d52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 4 Jun 2018 15:15:17 +0200 Subject: [PATCH 3/7] test-bus-util: add a simple test for bus_request_name_async_may_reload_dbus() This shows a minor memleak: ==1883== 24 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==1883== at 0x4C2DBAB: malloc (vg_replace_malloc.c:299) ==1883== by 0x4E9D385: malloc_multiply (alloc-util.h:69) ==1883== by 0x4EA2959: bus_request_name_async_may_reload_dbus (bus-util.c:1841) ==1883== by ... The exchange of messages is truncated at two different points: once right after the first callback is requested, and the second time after the full sequence has run (usually resulting in an error because of policy). --- src/test/meson.build | 4 ++++ src/test/test-bus-util.c | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/test/test-bus-util.c diff --git a/src/test/meson.build b/src/test/meson.build index 619f0cd823..29ef733d9b 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -656,6 +656,10 @@ tests += [ 'src/core/umount.h'], [], [libmount]], + + [['src/test/test-bus-util.c'], + [], + []], ] ############################################################ diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c new file mode 100644 index 0000000000..2543fa534f --- /dev/null +++ b/src/test/test-bus-util.c @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ + +#include "bus-util.h" +#include "log.h" + +static void test_name_async(unsigned n_messages) { + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; + int r; + unsigned i; + + log_info("/* %s (%u) */", __func__, n_messages); + + r = bus_open_system_watch_bind_with_description(&bus, "test-bus"); + if (r < 0) { + log_error_errno(r, "Failed to connect to bus: %m"); + return; + } + + r = bus_request_name_async_may_reload_dbus(bus, NULL, "org.freedesktop.systemd.test-bus-util", 0, NULL); + if (r < 0) { + log_error_errno(r, "Failed to request name: %m"); + return; + } + + for (i = 0; i < n_messages; i++) { + r = sd_bus_process(bus, NULL); + log_debug("stage %u: sd_bus_process returned %d", i, r); + if (r < 0) { + log_notice_errno(r, "Processing failed: %m"); + return; + } + + if (r > 0 && i + 1 < n_messages) + (void) sd_bus_wait(bus, USEC_PER_SEC / 3); + } +} + +int main(int argc, char **argv) { + log_set_max_level(LOG_DEBUG); + log_parse_environment(); + log_open(); + + test_name_async(0); + test_name_async(20); + + return 0; +} From e3736e02231dd71b6674091b4db79e2dee800bca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Jun 2018 10:57:30 +0200 Subject: [PATCH 4/7] man: also mention EINVAL in sd_bus_slot_set_floating(3) --- man/sd_bus_slot_set_floating.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/man/sd_bus_slot_set_floating.xml b/man/sd_bus_slot_set_floating.xml index 9cb4b8a441..cae1f5353c 100644 --- a/man/sd_bus_slot_set_floating.xml +++ b/man/sd_bus_slot_set_floating.xml @@ -29,7 +29,7 @@ int sd_bus_slot_set_floating - sd_bus_slot *bus + sd_bus_slot *slot int b @@ -81,6 +81,12 @@ Returned errors may indicate the following problems: + + -EINVAL + + The slot parameter is NULL. + + -ECHILD From fa17b4e8d93c715793e35242829b33fef54bddea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Jun 2018 11:07:02 +0200 Subject: [PATCH 5/7] bus: optionally call a callbacks for cleanup This adds a function sd_bus_slot_set_destroy_callback() to set a function which can free userdata or perform other cleanups. sd_bus_slot_get_destory_callback() queries the callback, and is included for completeness. Without something like this, for floating asynchronous callbacks, which might be called or not, depending on the sequence of events, it's hard to perform resource cleanup. The alternative would be to always perform the cleanup from the caller too, but that requires more coordination and keeping of some shared state. It's nicer to keep the cleanup contained between the callback and the function that requests the callback. --- man/rules/meson.build | 4 + man/sd_bus_slot_set_destroy_callback.xml | 105 +++++++++++++++++++++++ man/sd_bus_slot_set_floating.xml | 1 + src/libsystemd/libsystemd.sym | 2 + src/libsystemd/sd-bus/bus-internal.h | 1 + src/libsystemd/sd-bus/bus-slot.c | 20 +++++ src/systemd/sd-bus.h | 3 + 7 files changed, 136 insertions(+) create mode 100644 man/sd_bus_slot_set_destroy_callback.xml diff --git a/man/rules/meson.build b/man/rules/meson.build index e1e2c5e60d..efbd940fe0 100644 --- a/man/rules/meson.build +++ b/man/rules/meson.build @@ -231,6 +231,10 @@ manpages = [ ['sd_bus_set_connected_signal', '3', ['sd_bus_get_connected_signal'], ''], ['sd_bus_set_sender', '3', ['sd_bus_get_sender'], ''], ['sd_bus_set_watch_bind', '3', ['sd_bus_get_watch_bind'], ''], + ['sd_bus_slot_set_destroy_callback', + '3', + ['sd_bus_slot_get_destroy_callback'], + ''], ['sd_bus_slot_set_floating', '3', ['sd_bus_slot_get_floating'], ''], ['sd_bus_track_add_name', '3', diff --git a/man/sd_bus_slot_set_destroy_callback.xml b/man/sd_bus_slot_set_destroy_callback.xml new file mode 100644 index 0000000000..6334444f9a --- /dev/null +++ b/man/sd_bus_slot_set_destroy_callback.xml @@ -0,0 +1,105 @@ + + + + + + + + + sd_bus_slot_set_destroy_callback + systemd + + + + sd_bus_slot_set_destroy_callback + 3 + + + + sd_bus_slot_set_destroy_callback + sd_bus_slot_get_destroy_callback + + Define the callback function for resource cleanup. + + + + + #include <systemd/sd-bus.h> + + + typedef int (*sd_bus_destroy_t) + void *userdata + + + + int sd_bus_slot_set_destroy_callback + sd_bus_slot *slot + sd_bus_destroy_t callback + + + + int sd_bus_slot_get_destroy_callback + sd_bus_slot *slot + sd_bus_destroy_t *callback + + + + + + Description + + sd_bus_slot_set_destroy_callback() sets + callback as the callback function to be called right before the bus slot + object slot is deallocated. The userdata pointer + from the slot object will be passed as the userdata parameter. This + pointer can be set specified as an argument to the constuctor functions, see + sd_bus_add_match3, + or directly, see + sd_bus_set_userdata3. + This callback function is called even if userdata is + NULL. + + sd_bus_slot_get_destroy_callback() returns the current callback + for slot in the callback parameter. + + + + Return Value + + On success, sd_bus_slot_set_destroy_callback() returns 0 or a + positive integer. On failure, it returns a negative errno-style error code. + + sd_bus_slot_get_destroy_callback() returns 1 if the destroy callback + function is set, 0 if not. On failure, it returns a negative errno-style error code. + + + + Errors + + Returned errors may indicate the following problems: + + + + -EINVAL + + The slot parameter is NULL. + + + + + + + + + See Also + + + systemd1, + sd-bus3, + sd_bus_slot_set_floating3 + + + + diff --git a/man/sd_bus_slot_set_floating.xml b/man/sd_bus_slot_set_floating.xml index cae1f5353c..650b56f8c2 100644 --- a/man/sd_bus_slot_set_floating.xml +++ b/man/sd_bus_slot_set_floating.xml @@ -110,6 +110,7 @@ systemd1, sd-bus3, + sd_bus_slot_set_destroy_callback3, sd_bus_add_match3 diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 1bc70cc1f2..dc9c2d241a 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -563,6 +563,8 @@ global: sd_bus_open_system_with_description; sd_bus_slot_get_floating; sd_bus_slot_set_floating; + sd_bus_slot_get_destroy_callback; + sd_bus_slot_set_destroy_callback; sd_event_add_inotify; sd_event_source_get_inotify_mask; } LIBSYSTEMD_238; diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 4bce0a7e32..05321d4e79 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -127,6 +127,7 @@ struct sd_bus_slot { unsigned n_ref; sd_bus *bus; void *userdata; + sd_bus_destroy_t destroy_callback; BusSlotType type:5; /* Slots can be "floating" or not. If they are not floating (the usual case) then they reference the bus object diff --git a/src/libsystemd/sd-bus/bus-slot.c b/src/libsystemd/sd-bus/bus-slot.c index 34cfdd29e9..db9af9a97e 100644 --- a/src/libsystemd/sd-bus/bus-slot.c +++ b/src/libsystemd/sd-bus/bus-slot.c @@ -203,6 +203,10 @@ _public_ sd_bus_slot* sd_bus_slot_unref(sd_bus_slot *slot) { } bus_slot_disconnect(slot); + + if (slot->destroy_callback) + slot->destroy_callback(slot->userdata); + free(slot->description); return mfree(slot); } @@ -230,6 +234,22 @@ _public_ void *sd_bus_slot_set_userdata(sd_bus_slot *slot, void *userdata) { return ret; } +_public_ int sd_bus_slot_set_destroy_callback(sd_bus_slot *slot, sd_bus_destroy_t callback) { + assert_return(slot, -EINVAL); + + slot->destroy_callback = callback; + return 0; +} + +_public_ int sd_bus_slot_get_destroy_callback(sd_bus_slot *slot, sd_bus_destroy_t *callback) { + assert_return(slot, -EINVAL); + + if (callback) + *callback = slot->destroy_callback; + + return !!slot->destroy_callback; +} + _public_ sd_bus_message *sd_bus_slot_get_current_message(sd_bus_slot *slot) { assert_return(slot, NULL); assert_return(slot->type >= 0, NULL); diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index 740e40439e..b2394763c1 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -111,6 +111,7 @@ typedef int (*sd_bus_property_set_t) (sd_bus *bus, const char *path, const char typedef int (*sd_bus_object_find_t) (sd_bus *bus, const char *path, const char *interface, void *userdata, void **ret_found, sd_bus_error *ret_error); typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *prefix, void *userdata, char ***ret_nodes, sd_bus_error *ret_error); typedef int (*sd_bus_track_handler_t) (sd_bus_track *track, void *userdata); +typedef void (*sd_bus_destroy_t)(void *userdata); #include "sd-bus-protocol.h" #include "sd-bus-vtable.h" @@ -230,6 +231,8 @@ int sd_bus_slot_set_description(sd_bus_slot *slot, const char *description); int sd_bus_slot_get_description(sd_bus_slot *slot, const char **description); int sd_bus_slot_get_floating(sd_bus_slot *slot); int sd_bus_slot_set_floating(sd_bus_slot *slot, int b); +int sd_bus_slot_set_destroy_callback(sd_bus_slot *s, sd_bus_destroy_t callback); +int sd_bus_slot_get_destroy_callback(sd_bus_slot *s, sd_bus_destroy_t *callback); sd_bus_message* sd_bus_slot_get_current_message(sd_bus_slot *slot); sd_bus_message_handler_t sd_bus_slot_get_current_handler(sd_bus_slot *bus); From 200bc75db9f20920462f067272a1573430e03592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Jun 2018 11:12:25 +0200 Subject: [PATCH 6/7] shared/bus-util: use the new cleanup functionality to avoid a memleak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the async callbacks didn't get a chance to finish properly, we'd leak memory. The output from test-bus-util with additional log line in the callbacks to show what is happening: $ build/test-bus-util /* test_name_async (0) */ Bus test-bus: changing state UNSET → OPENING Bus test-bus: changing state OPENING → AUTHENTICATING Bus test-bus: changing state AUTHENTICATING → HELLO Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=2 reply_cookie=0 signature=su error-name=n/a error-message=n/a Got message type=method_return sender=org.freedesktop.DBus destination=:1.732 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a Bus test-bus: changing state HELLO → RUNNING Bus test-bus: changing state RUNNING → CLOSED request_name_destroy_callback n_ref=1 /* test_name_async (20) */ Bus test-bus: changing state UNSET → OPENING Bus test-bus: changing state OPENING → AUTHENTICATING Bus test-bus: changing state AUTHENTICATING → HELLO stage 0: sd_bus_process returned 1 Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=Hello cookie=1 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=2 reply_cookie=0 signature=su error-name=n/a error-message=n/a stage 1: sd_bus_process returned 1 Got message type=method_return sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=1 signature=s error-name=n/a error-message=n/a Bus test-bus: changing state HELLO → RUNNING stage 2: sd_bus_process returned 1 Got message type=signal sender=org.freedesktop.DBus.Local destination=n/a path=/org/freedesktop/DBus/Local interface=org.freedesktop.DBus.Local member=Connected cookie=4294967295 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a stage 3: sd_bus_process returned 1 Got message type=signal sender=org.freedesktop.DBus destination=:1.733 path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameAcquired cookie=4294967295 reply_cookie=0 signature=s error-name=n/a error-message=n/a stage 4: sd_bus_process returned 1 Got message type=error sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=2 signature=s error-name=org.freedesktop.DBus.Error.AccessDenied error-message=Request to own name refused by policy Unable to request name, will retry after reloading DBus configuration: Request to own name refused by policy Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=ReloadConfig cookie=3 reply_cookie=0 signature=n/a error-name=n/a error-message=n/a request_name_destroy_callback n_ref=2 stage 5: sd_bus_process returned 1 Got message type=method_return sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=3 signature= error-name=n/a error-message=n/a Sent message type=method_call sender=n/a destination=org.freedesktop.DBus path=/org/freedesktop/DBus interface=org.freedesktop.DBus member=RequestName cookie=4 reply_cookie=0 signature=su error-name=n/a error-message=n/a request_name_destroy_callback n_ref=1 stage 6: sd_bus_process returned 1 Got message type=error sender=org.freedesktop.DBus destination=:1.733 path=n/a interface=n/a member=n/a cookie=4294967295 reply_cookie=4 signature=s error-name=org.freedesktop.DBus.Error.AccessDenied error-message=Request to own name refused by policy Unable to request name, failing connection: Request to own name refused by policy Bus test-bus: changing state RUNNING → CLOSING stage 7: sd_bus_process returned 1 Bus test-bus: changing state CLOSING → CLOSED stage 8: sd_bus_process returned 1 stage 9: sd_bus_process returned -104 Processing failed: Connection reset by peer --- src/shared/bus-util.c | 62 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index 941a06f68d..bae419d63b 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1729,19 +1729,34 @@ int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *descri } struct request_name_data { + unsigned n_ref; + const char *name; uint64_t flags; void *userdata; }; +static void request_name_destroy_callback(void *userdata) { + struct request_name_data *data = userdata; + + assert(data); + assert(data->n_ref > 0); + + log_info("%s n_ref=%u", __func__, data->n_ref); + + data->n_ref--; + if (data->n_ref == 0) + free(data); +} + static int reload_dbus_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { - _cleanup_free_ struct request_name_data *data = userdata; + struct request_name_data *data = userdata; const sd_bus_error *e; int r; - assert(m); assert(data); assert(data->name); + assert(data->n_ref > 0); e = sd_bus_message_get_error(m); if (e) { @@ -1758,15 +1773,16 @@ static int reload_dbus_handler(sd_bus_message *m, void *userdata, sd_bus_error * } static int request_name_handler_may_reload_dbus(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { - _cleanup_free_ struct request_name_data *data = userdata; + struct request_name_data *data = userdata; uint32_t ret; int r; assert(m); - assert(userdata); + assert(data); if (sd_bus_message_is_method_error(m, NULL)) { const sd_bus_error *e = sd_bus_message_get_error(m); + _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot = NULL; if (!sd_bus_error_has_name(e, SD_BUS_ERROR_ACCESS_DENIED)) { log_debug_errno(sd_bus_error_get_errno(e), @@ -1778,31 +1794,37 @@ static int request_name_handler_may_reload_dbus(sd_bus_message *m, void *userdat } log_debug_errno(sd_bus_error_get_errno(e), - "Unable to request name, retry after reloading DBus configuration: %s", + "Unable to request name, will retry after reloading DBus configuration: %s", e->message); /* If systemd-timesyncd.service enables DynamicUser= and dbus.service * started before the dynamic user is realized, then the DBus policy * about timesyncd has not been enabled yet. So, let's try to reload - * DBus configuration, and after that request name again. Note that it + * DBus configuration, and after that request the name again. Note that it * seems that no privileges are necessary to call the following method. */ r = sd_bus_call_method_async( sd_bus_message_get_bus(m), - NULL, + &slot, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus", "ReloadConfig", reload_dbus_handler, - userdata, NULL); + data, NULL); if (r < 0) { log_error_errno(r, "Failed to reload DBus configuration: %m"); bus_enter_closing(sd_bus_message_get_bus(m)); return 1; } - data = NULL; /* Avoid free() */ + data->n_ref ++; + assert_se(sd_bus_slot_set_destroy_callback(slot, request_name_destroy_callback) >= 0); + + r = sd_bus_slot_set_floating(slot, true); + if (r < 0) + return r; + return 1; } @@ -1836,19 +1858,37 @@ static int request_name_handler_may_reload_dbus(sd_bus_message *m, void *userdat } int bus_request_name_async_may_reload_dbus(sd_bus *bus, sd_bus_slot **ret_slot, const char *name, uint64_t flags, void *userdata) { - struct request_name_data *data; + _cleanup_free_ struct request_name_data *data = NULL; + _cleanup_(sd_bus_slot_unrefp) sd_bus_slot *slot = NULL; + int r; data = new(struct request_name_data, 1); if (!data) return -ENOMEM; *data = (struct request_name_data) { + .n_ref = 1, .name = name, .flags = flags, .userdata = userdata, }; - return sd_bus_request_name_async(bus, ret_slot, name, flags, request_name_handler_may_reload_dbus, data); + r = sd_bus_request_name_async(bus, &slot, name, flags, request_name_handler_may_reload_dbus, data); + if (r < 0) + return r; + + assert_se(sd_bus_slot_set_destroy_callback(slot, request_name_destroy_callback) >= 0); + TAKE_PTR(data); + + if (ret_slot) + *ret_slot = TAKE_PTR(slot); + else { + r = sd_bus_slot_set_floating(slot, true); + if (r < 0) + return r; + } + + return 0; } int bus_reply_pair_array(sd_bus_message *m, char **l) { From 869881a6cb466ed1b9aa63e7e9de233bcf35a0ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Jun 2018 22:58:03 +0200 Subject: [PATCH 7/7] test-bus-util: add a test for destroy callbacks --- src/test/test-bus-util.c | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/test/test-bus-util.c b/src/test/test-bus-util.c index 2543fa534f..791b3928fe 100644 --- a/src/test/test-bus-util.c +++ b/src/test/test-bus-util.c @@ -35,6 +35,48 @@ static void test_name_async(unsigned n_messages) { } } +static int callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { + return 1; +} + +static void destroy_callback(void *userdata) { + int *n_called = userdata; + + (*n_called) ++; +} + +static void test_destroy_callback(void) { + _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; + sd_bus_slot *slot = NULL; + sd_bus_destroy_t t; + + int r, n_called = 0; + + log_info("/* %s */", __func__); + + r = bus_open_system_watch_bind_with_description(&bus, "test-bus"); + if (r < 0) { + log_error_errno(r, "Failed to connect to bus: %m"); + return; + } + + r = sd_bus_request_name_async(bus, &slot, "org.freedesktop.systemd.test-bus-util", 0, callback, &n_called); + assert(r == 1); + + assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 0); + assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 0); + + assert_se(sd_bus_slot_set_destroy_callback(slot, destroy_callback) == 0); + assert_se(sd_bus_slot_get_destroy_callback(slot, NULL) == 1); + assert_se(sd_bus_slot_get_destroy_callback(slot, &t) == 1); + assert_se(t == destroy_callback); + + /* Force cleanup so we can look at n_called */ + assert(n_called == 0); + sd_bus_slot_unref(slot); + assert(n_called == 1); +} + int main(int argc, char **argv) { log_set_max_level(LOG_DEBUG); log_parse_environment(); @@ -42,6 +84,7 @@ int main(int argc, char **argv) { test_name_async(0); test_name_async(20); + test_destroy_callback(); return 0; }