Re: [systemd-devel] sdbus errors and their underlaying int value: unique?
On Wed, 03 Mar 2021 at 13:51:38 +0100, Lennart Poettering wrote: > On Di, 02.03.21 10:40, Carlo Wood (ca...@alinoe.com) wrote: > > In C++ we have std::error_code which stores both a (unique) domain > > and an int that is defined within that domain. The integer values > > do not have to be globally unique. > > Generally: when doing D-Bus focus on the error names, because that's > the native thing. It seems std::error_code is conceptually the same as the domain and code from GLib's GError (convergent evolution, or inspiration from GLib?), so it would probably be useful to look at how GLib's GDBus maps GError to/from D-Bus errors: https://developer.gnome.org/gio/stable/gio-GDBusError.html In GError, the domain is basically a string (it's a GQuark, which is a handle representing an "interned" string), the code is an int defined within that domain, and there is also a human-readable message. So for instance, org.freedesktop.DBus.Error.NoMemory maps to (domain=G_DBUS_ERROR, code=G_DBUS_ERROR_NO_MEMORY), which behind the scenes is the same as (domain=g_quark_from_string("g-dbus-error-quark"), code=1). smcv ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Antw: [EXT] D-bus connection Unknown error
On Wed, 03 Mar 2021 07:59:03 +0100 "Ulrich Windl" wrote: > > Failed to get D-bus connection: Unknown error -1 > > I have no idea, but I think "unknown error" is bad programming style; > it's like "something went wrong; go and figure...". I can't agree more (I always go out of my way to have excellent error reporting in my own code), but I think that what is going on here is that -1 was interpreted as an 'errno' - and strerror was used to print a human readable description. If you pass -1 to strerror it returns "Unknown error -1", because -1 isn't a known errno. Ie if you pass 1 to it, it will say "Unknown error 1". The real problem therefore seems a bug in the code where the return value of a function that is either >= 0 on success and -1 on error is interpreted as errno. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] Antw: Re: Antw: [EXT] D-bus connection Unknown error
>>> Reindl Harald schrieb am 03.03.2021 um 12:39 in Nachricht <35c55fcf-6f7c-0566-ef55-5d7b2fb50...@thelounge.net>: > > Am 03.03.21 um 07:59 schrieb Ulrich Windl: > Shiju Email <994...@gmail.com> schrieb am 02.03.2021 um 22:27 in Nachricht >> : >>> Hi, I am getting an error when any systemctl commands are issued. >>> >>> Failed to get D‑bus connection: Unknown error ‑1 >> >> I have no idea, but I think "unknown error" is bad programming style; it's >> like "something went wrong; go and figure..." > > it's the "you should never reach that" codepath and is at least a better > programming style than crash when something you din't think of happens So it's an "unexpected error condition", and probably details about the condition are available. > ___ > systemd‑devel mailing list > systemd‑de...@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/systemd‑devel ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] sdbus errors and their underlaying int value: unique?
On Di, 02.03.21 10:40, Carlo Wood (ca...@alinoe.com) wrote: > Hello, > > thank you for you previous help; I made a lot of progress. > > I'm not writing my own C++ wrappers around sbus. > > I have the following question: > > A sd_bus_error has a name (and a message). The name is usually something > like "org.freedesktop.DBus.Error.InvalidArgs" or > "com.alinoe.DBus.Error.test_error" - in other words it contains a > domain, "org.freedesktop.DBus.Error" and "com.alinoe.DBus.Error" > respectively. > > In C++ we have std::error_code which stores both a (unique) domain > and an int that is defined within that domain. The integer values > do not have to be globally unique. > > For example, org.freedesktop.DBus.Error.InvalidArgs is mapped to > EINVAL which is 22. But can I use 22 too for > com.alinoe.DBus.Error.test_error? This would be fine with > std::error_code; and I'm trying to support conversion from > DBus errors to std::error_code. D-Bus has no concept of error numbers, only of error names (in reverse domain name notation) and human readable messages. Since sd-bus is a C wrapper around D-Bus, and in C it is more common to deal with 'errno' style error codes there's a bit of infrastructure in place to map names to errors, since quite often it is useful to propagate errno-style error codes on where one receives a D-Bus error, and vice versa. sd_bus_error_get_errno() wraps the error name → errno mapping, and sd_bus_error_set_errno() can be used for the opposite direction. Note however, that D-Bus names are a lot more precise, and thus multiple error names might map to the same error numbers. sd-bus has a bunch of mappings built-in, for well-known errors from the D-Bus spec and from systemd. You can define more such mappings via sd_bus_error_add_map(), to make sd-bus translate things with them too. Generally: when doing D-Bus focus on the error names, because that's the native thing. Use the error numbers only really if you really need to provide C-style errnos instead, and ignore them, and never forget that the mapping logic is not a D-Bus invention but an sd-bus one. Lennart -- Lennart Poettering, Berlin ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] D-bus connection Unknown error
On Mi, 03.03.21 10:27, Shiju Email (994...@gmail.com) wrote: > Hi, I am getting an error when any systemctl commands are issued. > > Failed to get D-bus connection: Unknown error -1 We do not generate such an error string in our entire codebase. This doesn't look like a systemd issue, but more of a D-Bus issue hence. Which systemd version is this? Please contact your distro for help first. Lennart -- Lennart Poettering, Berlin ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Antw: [EXT] D-bus connection Unknown error
Am 03.03.21 um 07:59 schrieb Ulrich Windl: Shiju Email <994...@gmail.com> schrieb am 02.03.2021 um 22:27 in Nachricht : Hi, I am getting an error when any systemctl commands are issued. Failed to get D-bus connection: Unknown error -1 I have no idea, but I think "unknown error" is bad programming style; it's like "something went wrong; go and figure..." it's the "you should never reach that" codepath and is at least a better programming style than crash when something you din't think of happens ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel