X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibelogind%2Fsd-login%2Fsd-login.c;h=f41e1a855b37dfbb0a18b94b955f19f0d3afab8c;hb=0d34aec56cd175cb1ac3722e3d9da7c49cf52113;hp=6c81c18d4c27bc4ac79604404a1063ee09c9fc05;hpb=fdff7397c22a853e7e66ec72adb85c3f2f519f32;p=elogind.git
diff --git a/src/libelogind/sd-login/sd-login.c b/src/libelogind/sd-login/sd-login.c
index 6c81c18d4..f41e1a855 100644
--- a/src/libelogind/sd-login/sd-login.c
+++ b/src/libelogind/sd-login/sd-login.c
@@ -1,5 +1,3 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
/***
This file is part of systemd.
@@ -19,21 +17,33 @@
along with systemd; If not, see .
***/
-#include
-#include
#include
-#include
#include
+#include
+#include
+#include
-#include "util.h"
+#include "sd-login.h"
+
+#include "alloc-util.h"
#include "cgroup-util.h"
-#include "macro.h"
-#include "strv.h"
+#include "dirent-util.h"
+#include "escape.h"
+#include "fd-util.h"
#include "fileio.h"
-#include "login-util.h"
#include "formats-util.h"
+#include "fs-util.h"
#include "hostname-util.h"
-#include "sd-login.h"
+#include "io-util.h"
+#include "login-util.h"
+#include "macro.h"
+#include "parse-util.h"
+#include "path-util.h"
+#include "socket-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "user-util.h"
+#include "util.h"
/* Error codes:
*
@@ -58,8 +68,7 @@ _public_ int sd_pid_get_unit(pid_t pid, char **unit) {
assert_return(pid >= 0, -EINVAL);
assert_return(unit, -EINVAL);
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_unit(pid, unit);
#else
return -ESRCH;
@@ -71,8 +80,7 @@ _public_ int sd_pid_get_user_unit(pid_t pid, char **unit) {
assert_return(pid >= 0, -EINVAL);
assert_return(unit, -EINVAL);
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_user_unit(pid, unit);
#else
return -ESRCH;
@@ -84,8 +92,7 @@ _public_ int sd_pid_get_machine_name(pid_t pid, char **name) {
assert_return(pid >= 0, -EINVAL);
assert_return(name, -EINVAL);
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_machine_name(pid, name);
#else
return -ESRCH;
@@ -97,8 +104,7 @@ _public_ int sd_pid_get_slice(pid_t pid, char **slice) {
assert_return(pid >= 0, -EINVAL);
assert_return(slice, -EINVAL);
-/// elogind does not support systemd slices
-#if 0
+#if 0 /// elogind does not support systemd slices
return cg_pid_get_slice(pid, slice);
#else
return -ESRCH;
@@ -110,8 +116,7 @@ _public_ int sd_pid_get_user_slice(pid_t pid, char **slice) {
assert_return(pid >= 0, -EINVAL);
assert_return(slice, -EINVAL);
-/// elogind does not support systemd slices
-#if 0
+#if 0 /// elogind does not support systemd slices
return cg_pid_get_user_slice(pid, slice);
#else
return -ESRCH;
@@ -123,8 +128,7 @@ _public_ int sd_pid_get_owner_uid(pid_t pid, uid_t *uid) {
assert_return(pid >= 0, -EINVAL);
assert_return(uid, -EINVAL);
-/// elogind does not support systemd slices
-#if 0
+#if 0 /// elogind does not support systemd slices
return cg_pid_get_owner_uid(pid, uid);
#else
return -ESRCH;
@@ -144,7 +148,7 @@ _public_ int sd_pid_get_cgroup(pid_t pid, char **cgroup) {
/* The internal APIs return the empty string for the root
* cgroup, let's return the "/" in the public APIs instead, as
- * that's easier and less ambigious for people to grok. */
+ * that's easier and less ambiguous for people to grok. */
if (isempty(c)) {
free(c);
c = strdup("/");
@@ -168,8 +172,7 @@ _public_ int sd_peer_get_session(int fd, char **session) {
if (r < 0)
return r;
-/// elogind does not support systemd scopes
-#if 0
+#if 0 /// elogind does not support systemd scopes
return cg_pid_get_session(ucred.pid, session);
#else
return -ESRCH;
@@ -187,8 +190,7 @@ _public_ int sd_peer_get_owner_uid(int fd, uid_t *uid) {
if (r < 0)
return r;
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_owner_uid(ucred.pid, uid);
#else
return -ESRCH;
@@ -206,8 +208,7 @@ _public_ int sd_peer_get_unit(int fd, char **unit) {
if (r < 0)
return r;
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_unit(ucred.pid, unit);
#else
return -ESRCH;
@@ -225,8 +226,7 @@ _public_ int sd_peer_get_user_unit(int fd, char **unit) {
if (r < 0)
return r;
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_user_unit(ucred.pid, unit);
#else
return -ESRCH;
@@ -244,8 +244,7 @@ _public_ int sd_peer_get_machine_name(int fd, char **machine) {
if (r < 0)
return r;
-/// elogind does not support systemd units
-#if 0
+#if 0 /// elogind does not support systemd units
return cg_pid_get_machine_name(ucred.pid, machine);
#else
return -ESRCH;
@@ -263,8 +262,7 @@ _public_ int sd_peer_get_slice(int fd, char **slice) {
if (r < 0)
return r;
-/// elogind does not support systemd slices
-#if 0
+#if 0 /// elogind does not support systemd slices
return cg_pid_get_slice(ucred.pid, slice);
#else
return -ESRCH;
@@ -282,8 +280,7 @@ _public_ int sd_peer_get_user_slice(int fd, char **slice) {
if (r < 0)
return r;
-/// elogind does not support systemd slices
-#if 0
+#if 0 /// elogind does not support systemd slices
return cg_pid_get_user_slice(ucred.pid, slice);
#else
return -ESRCH;
@@ -381,7 +378,7 @@ static int file_of_seat(const char *seat, char **_p) {
if (!filename_is_valid(seat))
return -EINVAL;
- p = strappend("/run/systemd/seats/", seat);
+ p = strappend("/run/systemd/seats/", seat);
} else {
_cleanup_free_ char *buf = NULL;
@@ -445,10 +442,10 @@ static int uid_get_array(uid_t uid, const char *variable, char ***array) {
r = parse_env_file(p, NEWLINE, variable, &s, NULL);
if (r == -ENOENT || (r >= 0 && isempty(s))) {
- if (array)
- *array = NULL;
- return 0;
- }
+ if (array)
+ *array = NULL;
+ return 0;
+ }
if (r < 0)
return r;
@@ -863,7 +860,7 @@ _public_ int sd_get_uids(uid_t **users) {
errno = 0;
de = readdir(d);
- if (!de && errno != 0)
+ if (!de && errno > 0)
return -errno;
if (!de)
@@ -985,9 +982,7 @@ _public_ int sd_machine_get_ifindices(const char *machine, int **ifindices) {
*(char*) (mempcpy(buf, word, l)) = 0;
- if (safe_atoi(buf, &ifi) < 0)
- continue;
- if (ifi <= 0)
+ if (parse_ifindex(buf, &ifi) < 0)
continue;
if (!GREEDY_REALLOC(ni, allocated, nr+1)) {
@@ -1072,7 +1067,8 @@ _public_ int sd_login_monitor_new(const char *category, sd_login_monitor **m) {
_public_ sd_login_monitor* sd_login_monitor_unref(sd_login_monitor *m) {
int fd;
- assert_return(m, NULL);
+ if (!m)
+ return NULL;
fd = MONITOR_TO_FD(m);
close_nointr(fd);