summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-login
Commit message (Collapse)AuthorAge
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* fileio: accept FILE* in addition to path in parse_env_file()Lennart Poettering2018-08-24
| | | | | | | Most our other parsing functions do this, let's do this here too, internally we accept that anyway. Also, the closely related load_env_file() and load_env_file_pairs() also do this, so let's be systematic.
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* macro: introduce TAKE_PTR() macroLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This macro will read a pointer of any type, return it, and set the pointer to NULL. This is useful as an explicit concept of passing ownership of a memory area between pointers. This takes inspiration from Rust: https://doc.rust-lang.org/std/option/enum.Option.html#method.take and was suggested by Alan Jenkins (@sourcejedi). It drops ~160 lines of code from our codebase, which makes me like it. Also, I think it clarifies passing of ownership, and thus helps readability a bit (at least for the initiated who know the new macro)
* sd-login: make use of _cleanup_close_ where possibleLennart Poettering2018-05-30
|
* io-util: make flush_fd() return how many bytes where flushedLennart Poettering2018-05-30
| | | | | | | | | | | This is useful so that callers know whether anything at all and how much was flushed. This patches through users of this functions to ensure that the return values > 0 which may be returned now are not propagated in public APIs. Also, users that ignore the return value are changed to do so explicitly now.
* Prep v236 : Add missing SPDX-License-Identifier (4/9) src/libelogindSven Eden2018-03-26
|
* Prep 235: Make cgroups2 available, hybrid mode already works.Sven Eden2018-01-10
|
* Prep 235: Enabled sd_peer_get_session() and sd_peer_get_owner_uid() to try ↵Sven Eden2018-01-09
| | | | to work with eloginds session id to user mapping.
* Prep 235: Enabled sd_bus_creds_get_slice(), sd_bus_creds_get_user_slice(), ↵Sven Eden2018-01-09
| | | | sd_peer_get_user_slice() and sd_pid_get_user_slice() to try to work with eloginds session id to user mapping.
* Prep 235: Enabled sd_peer_get_slice() and sd_pid_get_slice() to at least try ↵Sven Eden2018-01-09
| | | | to work. This is considered experimental.
* Prep 235: Implement an alternative approach for sd_pid_get_owner_uid(), ↵Sven Eden2017-12-13
| | | | making test-login to no longer fail.
* Add abstraction model for BPF programsDaniel Mack2017-11-20
| | | | | This object takes a number of bpf_insn members and wraps them together with the in-kernel reference id. Will be needed by the firewall code.
* Prep v235: Update test-login.cshwsh2017-09-07
| | | | * Merge pull request #29 from shwsh/master
* sd-login: test - fix failure when run from non-graphical seatAlan Jenkins2017-08-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Observed when running from the console of a elogind nspawn container (see failure below). The value of r was tested, when r was last set by sd_session_can_graphical(). This did not correspond to the value expected. Fix the code, so we compare relevant values now. Hopefully :). Test failure ------------ /* Information printed is from the live system */ sd_pid_get_unit(0, …) → "session-13.scope" sd_pid_get_user_unit(0, …) → "n/a" sd_pid_get_slice(0, …) → "user-1000.slice" sd_pid_get_session(0, …) → "13" sd_pid_get_owner_uid(0, …) → 1000 sd_pid_get_cgroup(0, …) → "/user.slice/user-1000.slice/session-13.scope" sd_uid_get_display(1000, …) → "13" sd_uid_get_sessions(1000, …) → [2] "15 13" sd_uid_get_seats(1000, …) → [1] "seat0" sd_session_is_active("13") → yes sd_session_is_remote("13") → no sd_session_get_state("13") → "active" sd_session_get_uid("13") → 1000 sd_session_get_type("13") → "tty" sd_session_get_class("13") → "user" sd_session_get_display("13") → "n/a" sd_session_get_remote_user("13") → "n/a" sd_session_get_remote_host("13") → "n/a" sd_session_get_seat("13") → "seat0" sd_session_can_multi_seat("seat0") → no sd_session_can_tty("seat0") → no sd_session_can_graphical("seat0") → no sd_uid_get_state(1000, …) → active Assertion '!!k == !!r' failed at ../src/libelogind/sd-login/test-login.c:191, function test_login(). Aborting.
* sd-login: test - fix function name in outputAlan Jenkins2017-08-10
|
* General: Update build system to upstream support of meson+ninja.Sven Eden2017-08-04
| | | | | | | | Upstream thinks, that the auto tools are too 'legacy', or that they are at least no longer fitting. We follow, as the classic auto tools files have been removed, so no other choice here...
* sd_uid_get_state: do not return -ENOENT if state is "offline" (#6302)Yu, Li-Yu2017-07-25
|
* sd-login: fix memleak when output argument is NULLZbigniew Jędrzejewski-Szmek2017-07-25
|
* sd-login: sd_get_machine_names(): do not return -EINVAL when output ↵Yu Watanabe2017-07-25
| | | | | | | | parameter is NULL Other functions in sd-login generally allow the output parameter to be NULL, in which case only the number of items that would be stored in the array is returned. Be nice and do the same here.
* sd-login: treat missing /run/elogind/{seats,sessions,users} the same as emptyYu Watanabe2017-07-25
| | | | | | | C.f. 0543105b0fb13e4243b71a78f62f81fb9dde5d51. This makes if /run/elogind/{seats,sessions,users} are missing, then sd_get_seats(), sd_get_sessions() and sd_get_uids() return 0, that is, an empty list, instead of -ENOENT.
* sd-login: translate -ENOMEDIUM to -ENODATAZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | | | | | | The -ENOMEDIUM return value was introduced in v232-1001-g2977724b09, ('core: make hybrid cgroup unified mode keep compat /sys/fs/cgroup/elogind hierarchy'), and would be returned by cg_pid_get_path_shifted(), but the documented and expected return value is -ENODATA. Let's just catch ENXIO/ENOMEDIUM and translate it to ENODATA in all cases. Complements 171f8f591ff27ebb5ff475b7a9d1f13a846c9331, fixes #6012.
* logn: tests - don't compare signed with unsignedTom Gundersen2017-07-25
|
* sd-login: fix querying machines when machined is not runningZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | We should not leak the internal error from missing directory and treat that case the same as no machines.
* sd-login,test-login: return -ENODATA from sd_pid_get_unit tooZbigniew Jędrzejewski-Szmek2017-07-25
| | | | After all, we might be running on a non-elogind system.
* sd-login: fix return value of sd_pid_get_user_unitZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | E.g. "/user.slice/user-1000.slice/session-15.scope" would cause -ENXIO to be returned.
* sd-login: fix return value of sd_pid_get_sessionZbigniew Jędrzejewski-Szmek2017-07-25
| | | | We'd return -ENXIO, even thoug -ENODATA is documented.
* sd-login: read list of uids of sessions from UIDS not ACTIVE_SESSIONSZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | | | | | | | | | | As described by Luke Shumaker: sd_seat_get_sessions looks at /run/elogind/seats/${seat_name}:SESSIONS to get the list of sessions (which I believe is correct), and at /run/elogind/seats/${seat_name}:ACTIVE_SESSIONS for the list of users (which I believe is incorrect); I believe that it should look at the UIDS field for the list of users. As far as I can tell, the ACTIVE_SESSIONS field is never even present in the seats file. I also believe that this has been broken since the function was first committed almost 6 years ago. Fixes #5743.
* sd-login: always return two arrays of same length from sd_seat_get_sessionsZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | | | | sd_seat_get_sessions returns two arrays, that in principle should always match: the session names and corresponding uids. The second array could be shorter only if parsing or uid conversion fails. But in that case there is no way to tell *which* uid is wrong, so they are *all* useless. It's better to simplify things and just return an error if parsing fails.
* test-login: make the test non-manualZbigniew Jędrzejewski-Szmek2017-07-25
| | | | | | | | | | | | | | | | | | | | test-login.c is largely rewritten to use _cleanup_ and give more meaningful messages (function names are used instead of creative terms like "active session", so that when something unexpected is returned, it's much easier to see what function is responsible). The monitoring part is only activated if '-m' is passed on the command line. It runs against the information from /run/elogind/ in the live system, but that should be OK: logind/sd-login interface is supposed to be stable and both backwards and forwards compatible. If not running in a login session, some tests are skipped. Those two changes together mean that it's possible to run test-login in the test suite. Tests for sd_pid_get_{unit,user_unit,slice} are added.
* tree-wide: replace all readdir cycles with FOREACH_DIRENT{,_ALL} (#4853)Reverend Homer2017-07-17
|
* Rename formats-util.h to format-util.hZbigniew Jędrzejewski-Szmek2017-07-17
| | | | | | We don't have plural in the name of any other -util files and this inconsistency trips me up every time I try to type this file name from memory. "formats-util" is even hard to pronounce.
* Various fixes for typos found by lintian (#3705)Michael Biebl2017-06-16
|
* Prep v230: Move musl_missing and parse-printf-format to libshared.Sven Eden2017-06-16
|
* Prep v230: Apply missing upstream fixes and updates (5/8) src/libelogind.Sven Eden2017-06-16
|
* Prep v229: Remove remaining emacs settings [3/6] src/libelogindSven Eden2017-05-17
|
* tree-wide: check if errno is greater than zero (2)Zbigniew Jędrzejewski-Szmek2017-05-17
| | | | | Compare errno with zero in a way that tells gcc that (if the condition is true) errno is positive.
* tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easyLennart Poettering2017-05-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GLIB has recently started to officially support the gcc cleanup attribute in its public API, hence let's do the same for our APIs. With this patch we'll define an xyz_unrefp() call for each public xyz_unref() call, to make it easy to use inside a __attribute__((cleanup())) expression. Then, all code is ported over to make use of this. The new calls are also documented in the man pages, with examples how to use them (well, I only added docs where the _unref() call itself already had docs, and the examples, only cover sd_bus_unrefp() and sd_event_unrefp()). This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we tend to call our destructors these days. Note that this defines no public macro that wraps gcc's attribute and makes it easier to use. While I think it's our duty in the library to make our stuff easy to use, I figure it's not our duty to make gcc's own features easy to use on its own. Most likely, client code which wants to make use of this should define its own: #define _cleanup_(function) __attribute__((cleanup(function))) Or similar, to make the gcc feature easier to use. Making this logic public has the benefit that we can remove three header files whose only purpose was to define these functions internally. See #2008.
* Prep v228: Condense elogind source masks (5/5)Sven Eden2017-04-26
|
* Prep v228: Add remaining updates from upstream (3/3)Sven Eden2017-04-26
| | | | | Apply remaining fixes and the performed move of utility functions into their own foo-util.[hc] files on the rest of elogind.
* [3/5] Apply missing fixes from upstreamSven Eden2017-03-29
|
* sd-login: rework error handlingLennart Poettering2017-03-29
| | | | | | Makre sure we always return sensible errors for the various, following the same rules, and document them in a comment in sd-login.c. Also, update all relevant man pages accordingly.
* sd-login: improve error handlingLennart Poettering2017-03-29
| | | | | | | let's return ENXIO whenever we don't know something rather than ENOENT. ENOENT suggests this was really about a file or directory, while ENXIO is a more generic "not found" indicator.
* Rename ELOGIND_CGROUP_CONTROLLER back to SYSTEMD_CGROUP_CONTROLLERSven Eden2017-03-14
| | | | | Although it is nice to have it read ELOGIND instead of SYSTEMD, all diffs just show too many irrelevant (false) positives.
* Major cleanup of all leftovers after rebasing on master.Sven Eden2017-03-14
| | | | | | | | The patching of elogind in several steps with only partly rebasing on a common commit with upstream, left the tree in a state, that was unmergeable with master. By rebasing on master and manually cleaning up all commits, this merge is now possible. However, this process left some orphans, that are cleanup now.
* Add support for building elogind against musl libcSven Eden2017-03-14
| | | | | | | | | | | | | | | | | | | * Check whether printf.h is available and define/undef HAVE_PRINTF_H accordingly. * Added src/shared/parse-printf-format.[hc] by Emil Renner Berthing <systemd@esmil.dk> that provides parse_printf_format() if printf.h is unavailable * Added src/basic/musl_missing.h by Juergen Buchmueller <pullmoll@t-online.de> that implements glibc functions missing in musl libc as macros. * Extended src/basic/musl_missing.h and added src/basic/musl_missing.c providing - program_invocation_name - program_invocation_short_name and - elogind_set_program_name() to set the two where appropriate. * Added calls to elogind_set_program_name() to all main() functions where needed. * A few other fixes to work nicely with musl libc.
* Classify processes from sessions into cgroupsSven Eden2017-03-14
| | | | | | | Create a private cgroup tree associated with no controllers, and use it to map PIDs to sessions. Since we use our own path structure, remove internal cgroup-related helpers that interpret the cgroup path structure to pull out users, slices, and scopes.