chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sd-login: fix return value of sd_pid_get_session
[elogind.git]
/
src
/
libelogind
/
sd-login
/
sd-login.c
diff --git
a/src/libelogind/sd-login/sd-login.c
b/src/libelogind/sd-login/sd-login.c
index ac22fa3454ce57a5fc757c5726c3309752d67acd..3adbb34ad5d63bba09e1f194b5864d4612681df0 100644
(file)
--- 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.
/***
This file is part of systemd.
@@
-33,7
+31,7
@@
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
-#include "format
s
-util.h"
+#include "format-util.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "io-util.h"
#include "fs-util.h"
#include "hostname-util.h"
#include "io-util.h"
@@
-58,11
+56,13
@@
*/
_public_ int sd_pid_get_session(pid_t pid, char **session) {
*/
_public_ int sd_pid_get_session(pid_t pid, char **session) {
+ int r;
assert_return(pid >= 0, -EINVAL);
assert_return(session, -EINVAL);
assert_return(pid >= 0, -EINVAL);
assert_return(session, -EINVAL);
- return cg_pid_get_session(pid, session);
+ r = cg_pid_get_session(pid, session);
+ return r == -ENXIO ? -ENODATA : r;
}
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
}
_public_ int sd_pid_get_unit(pid_t pid, char **unit) {
@@
-150,7
+150,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
/* 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 ambig
i
ous for people to grok. */
+ * that's easier and less ambig
u
ous for people to grok. */
if (isempty(c)) {
free(c);
c = strdup("/");
if (isempty(c)) {
free(c);
c = strdup("/");
@@
-380,7
+380,7
@@
static int file_of_seat(const char *seat, char **_p) {
if (!filename_is_valid(seat))
return -EINVAL;
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;
} else {
_cleanup_free_ char *buf = NULL;
@@
-444,10
+444,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))) {
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;
if (r < 0)
return r;
@@
-741,7
+741,7
@@
_public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
r = parse_env_file(p, NEWLINE,
"SESSIONS", &s,
r = parse_env_file(p, NEWLINE,
"SESSIONS", &s,
- "
ACTIVE_SESSION
S", &t,
+ "
UID
S", &t,
NULL);
if (r == -ENOENT)
return -ENXIO;
NULL);
if (r == -ENOENT)
return -ENXIO;
@@
-777,7
+777,7
@@
_public_ int sd_seat_get_sessions(const char *seat, char ***sessions, uid_t **ui
r = parse_uid(k, b + i);
if (r < 0)
r = parse_uid(k, b + i);
if (r < 0)
-
continue
;
+
return r
;
i++;
}
i++;
}
@@
-847,6
+847,7
@@
_public_ int sd_get_sessions(char ***sessions) {
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d;
_public_ int sd_get_uids(uid_t **users) {
_cleanup_closedir_ DIR *d;
+ struct dirent *de;
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;
int r = 0;
unsigned n = 0;
_cleanup_free_ uid_t *l = NULL;
@@
-855,19
+856,10
@@
_public_ int sd_get_uids(uid_t **users) {
if (!d)
return -errno;
if (!d)
return -errno;
- for (;;) {
- struct dirent *de;
+ FOREACH_DIRENT_ALL(de, d, return -errno) {
int k;
uid_t uid;
int k;
uid_t uid;
- errno = 0;
- de = readdir(d);
- if (!de && errno != 0)
- return -errno;
-
- if (!de)
- break;
-
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
dirent_ensure_type(d, de);
if (!dirent_is_file(de))
@@
-1069,7
+1061,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;
_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);
fd = MONITOR_TO_FD(m);
close_nointr(fd);