summaryrefslogtreecommitdiff
path: root/proc
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2018-01-08 23:00:37 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-01-08 23:00:37 +0100
commit104f3121f8005b426d4df77b2420cfe5837033d1 (patch)
tree34bb93d3796e7c45dc1c67a5d40fb3bd1604ad9f /proc
parent9d3ba19ddc56ad929f673af23eb87ab07ae30631 (diff)
Implement /proc/<pid>/exe
by adding proc_set/get_exe to the proc server, making exec call proc_set_exe, and libps call proc_get_exe. procfs can then just retrieve the information to make the "exe" symlink. * hurd/process.defs (proc_set_exe, proc_get_exe): New RPCs. * hurd/process_request.defs: Likewise. * hurd/process_reply.defs: Add skips for proc_set_exe and proc_get_exe RPCs. * proc/proc.h (struct proc): Add `exe' field. * proc/info.c (S_proc_set_exe, S_proc_get_exe): New functions. * proc/mgt.c (process_has_exited): Free p->exe. (S_proc_child): Duplicate parent `exe' into child's `exe'. * exec/exec.c (do_exec): Call proc_set_exe when a filename is available. * libps/ps.h (struct proc_stat): Add `exe_vm_alloced', `exe', and `exe_len' field. (PSTAT_EXE): New macro. (PSTAT_USER_BASE): Change value to make room. (proc_stat_exe, proc_stat_exe_len): New macros. * libps/procstat.c (proc_stat_set_flags): Handle PSTAT_EXE case by calling proc_get_exe. * libps/spec.c (ps_get_exe): New function. (ps_exe_getter): New structure. (ps_fmt_spec): Add "Exe" specification. * procfs/process.c (process_file_symlink_make_node, process_file_gc_exe): New functions. (procfs_dir_entry): Add "exe" entry. * startup/startup.c (launch_core_servers): Set exe paths for startup, auth, proc, and fs servers. (frob_kernel_process): Set exe path for kernel task. (S_startup_essential_task): Set exe path for exec server.
Diffstat (limited to 'proc')
-rw-r--r--proc/info.c41
-rw-r--r--proc/mgt.c4
-rw-r--r--proc/proc.h1
3 files changed, 46 insertions, 0 deletions
diff --git a/proc/info.c b/proc/info.c
index 3c1bf6d3a..6ab9f3faa 100644
--- a/proc/info.c
+++ b/proc/info.c
@@ -24,6 +24,7 @@
#include <sys/mman.h>
#include <hurd/hurd_types.h>
#include <stdlib.h>
+#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/resource.h>
@@ -1017,3 +1018,43 @@ S_proc_getnports (struct proc *callerp,
return err;
}
+
+/* Implement proc_set_path as described in <hurd/process.defs>. */
+kern_return_t
+S_proc_set_exe (struct proc *p,
+ char *path)
+{
+ char *copy;
+
+ if (!p)
+ return EOPNOTSUPP;
+
+ copy = strdup(path);
+ if (! copy)
+ return ENOMEM;
+
+ free(p->exe);
+ p->exe = copy;
+ return 0;
+}
+
+/* Implement proc_get_path as described in <hurd/process.defs>. */
+kern_return_t
+S_proc_get_exe (struct proc *callerp,
+ pid_t pid,
+ char *path)
+{
+ struct proc *p = pid_find (pid);
+
+ /* No need to check CALLERP here; we don't use it. */
+
+ if (!p)
+ return ESRCH;
+
+ if (p->exe)
+ snprintf (path, 1024 /* XXX */, "%s", p->exe);
+ else
+ path[0] = 0;
+ return 0;
+}
+
diff --git a/proc/mgt.c b/proc/mgt.c
index 354f37843..d92bf5285 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -223,6 +223,8 @@ S_proc_child (struct proc *parentp,
childp->start_code = parentp->start_code;
childp->end_code = parentp->end_code;
}
+ if (! childp->exe && parentp->exe)
+ childp->exe = strdup (parentp->exe);
if (MACH_PORT_VALID (parentp->p_task_namespace))
{
@@ -860,6 +862,8 @@ process_has_exited (struct proc *p)
if (!--p->p_login->l_refcnt)
free (p->p_login);
+ free (p->exe);
+ p->exe = NULL;
ids_rele (p->p_id);
diff --git a/proc/proc.h b/proc/proc.h
index b33845d96..a974f629e 100644
--- a/proc/proc.h
+++ b/proc/proc.h
@@ -68,6 +68,7 @@ struct proc
pthread_cond_t p_wakeup;
/* Miscellaneous information */
+ char *exe; /* path to binary executable */
vm_address_t p_argv, p_envp;
vm_address_t start_code; /* all executable segments are in this range */
vm_address_t end_code;