chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
logind: minor clean-ups
[elogind.git]
/
src
/
basic
/
process-util.c
diff --git
a/src/basic/process-util.c
b/src/basic/process-util.c
index b05591eb866c0fa747f2aa6448312b6fec7fb360..8a1f54db81b61fd6949401cb81b389e4b9942b54 100644
(file)
--- a/
src/basic/process-util.c
+++ b/
src/basic/process-util.c
@@
-43,7
+43,10
@@
int get_process_state(pid_t pid) {
assert(pid >= 0);
p = procfs_file_alloca(pid, "stat");
assert(pid >= 0);
p = procfs_file_alloca(pid, "stat");
+
r = read_one_line_file(p, &line);
r = read_one_line_file(p, &line);
+ if (r == -ENOENT)
+ return -ESRCH;
if (r < 0)
return r;
if (r < 0)
return r;
@@
-87,8
+90,11
@@
int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
p = procfs_file_alloca(pid, "cmdline");
f = fopen(p, "re");
p = procfs_file_alloca(pid, "cmdline");
f = fopen(p, "re");
- if (!f)
+ if (!f) {
+ if (errno == ENOENT)
+ return -ESRCH;
return -errno;
return -errno;
+ }
if (max_length == 0) {
size_t len = 0, allocated = 0;
if (max_length == 0) {
size_t len = 0, allocated = 0;
@@
-175,15
+181,18
@@
int is_kernel_thread(pid_t pid) {
bool eof;
FILE *f;
bool eof;
FILE *f;
- if (pid == 0
)
+ if (pid == 0
|| pid == 1) /* pid 1, and we ourselves certainly aren't a kernel thread */
return 0;
return 0;
- assert(pid >
0
);
+ assert(pid >
1
);
p = procfs_file_alloca(pid, "cmdline");
f = fopen(p, "re");
p = procfs_file_alloca(pid, "cmdline");
f = fopen(p, "re");
- if (!f)
+ if (!f) {
+ if (errno == ENOENT)
+ return -ESRCH;
return -errno;
return -errno;
+ }
count = fread(&c, 1, 1, f);
eof = feof(f);
count = fread(&c, 1, 1, f);
eof = feof(f);
@@
-201,13
+210,18
@@
int is_kernel_thread(pid_t pid) {
#if 0
int get_process_capeff(pid_t pid, char **capeff) {
const char *p;
#if 0
int get_process_capeff(pid_t pid, char **capeff) {
const char *p;
+ int r;
assert(capeff);
assert(pid >= 0);
p = procfs_file_alloca(pid, "status");
assert(capeff);
assert(pid >= 0);
p = procfs_file_alloca(pid, "status");
- return get_status_field(p, "\nCapEff:", capeff);
+ r = get_proc_field(p, "CapEff", WHITESPACE, capeff);
+ if (r == -ENOENT)
+ return -ESRCH;
+
+ return r;
}
#endif // 0
}
#endif // 0
@@
-218,8
+232,10
@@
static int get_process_link_contents(const char *proc_file, char **name) {
assert(name);
r = readlink_malloc(proc_file, name);
assert(name);
r = readlink_malloc(proc_file, name);
+ if (r == -ENOENT)
+ return -ESRCH;
if (r < 0)
if (r < 0)
- return r
== -ENOENT ? -ESRCH : r
;
+ return r;
return 0;
}
return 0;
}
@@
-258,8
+274,11
@@
static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
p = procfs_file_alloca(pid, "status");
f = fopen(p, "re");
p = procfs_file_alloca(pid, "status");
f = fopen(p, "re");
- if (!f)
+ if (!f) {
+ if (errno == ENOENT)
+ return -ESRCH;
return -errno;
return -errno;
+ }
FOREACH_LINE(line, f, return -errno) {
char *l;
FOREACH_LINE(line, f, return -errno) {
char *l;
@@
-321,8
+340,11
@@
int get_process_environ(pid_t pid, char **env) {
p = procfs_file_alloca(pid, "environ");
f = fopen(p, "re");
p = procfs_file_alloca(pid, "environ");
f = fopen(p, "re");
- if (!f)
+ if (!f) {
+ if (errno == ENOENT)
+ return -ESRCH;
return -errno;
return -errno;
+ }
while ((c = fgetc(f)) != EOF) {
if (!GREEDY_REALLOC(outcome, allocated, sz + 5))
while ((c = fgetc(f)) != EOF) {
if (!GREEDY_REALLOC(outcome, allocated, sz + 5))
@@
-334,13
+356,18
@@
int get_process_environ(pid_t pid, char **env) {
sz += cescape_char(c, outcome + sz);
}
sz += cescape_char(c, outcome + sz);
}
+ if (!outcome) {
+ outcome = strdup("");
+ if (!outcome)
+ return -ENOMEM;
+ } else
outcome[sz] = '\0';
outcome[sz] = '\0';
+
*env = outcome;
outcome = NULL;
return 0;
}
*env = outcome;
outcome = NULL;
return 0;
}
-#endif // 0
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
int r;
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
int r;
@@
-358,6
+385,8
@@
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
p = procfs_file_alloca(pid, "stat");
r = read_one_line_file(p, &line);
p = procfs_file_alloca(pid, "stat");
r = read_one_line_file(p, &line);
+ if (r == -ENOENT)
+ return -ESRCH;
if (r < 0)
return r;
if (r < 0)
return r;
@@
-384,6
+413,7
@@
int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
return 0;
}
return 0;
}
+#endif // 0
int wait_for_terminate(pid_t pid, siginfo_t *status) {
siginfo_t dummy;
int wait_for_terminate(pid_t pid, siginfo_t *status) {
siginfo_t dummy;
@@
-481,8
+511,11
@@
int getenv_for_pid(pid_t pid, const char *field, char **_value) {
path = procfs_file_alloca(pid, "environ");
f = fopen(path, "re");
path = procfs_file_alloca(pid, "environ");
f = fopen(path, "re");
- if (!f)
+ if (!f) {
+ if (errno == ENOENT)
+ return -ESRCH;
return -errno;
return -errno;
+ }
l = strlen(field);
r = 0;
l = strlen(field);
r = 0;
@@
-541,7
+574,7
@@
bool pid_is_alive(pid_t pid) {
return false;
r = get_process_state(pid);
return false;
r = get_process_state(pid);
- if (r == -E
NOENT
|| r == 'Z')
+ if (r == -E
SRCH
|| r == 'Z')
return false;
return true;
return false;
return true;