From 104f3121f8005b426d4df77b2420cfe5837033d1 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 8 Jan 2018 23:00:37 +0100 Subject: Implement /proc//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. --- procfs/process.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'procfs') diff --git a/procfs/process.c b/procfs/process.c index ece37b70..59653b24 100644 --- a/procfs/process.c +++ b/procfs/process.c @@ -94,6 +94,19 @@ static int args_filename_length (const char *name) /* Actual content generators */ +static ssize_t +process_file_gc_exe (struct proc_stat *ps, char **contents) +{ + if (proc_stat_exe_len (ps) == 0) + { + *contents = "-"; + return 1; + } + + *contents = proc_stat_exe(ps); + return proc_stat_exe_len(ps); +} + static ssize_t process_file_gc_cmdline (struct proc_stat *ps, char **contents) { @@ -410,6 +423,14 @@ process_file_make_node (void *dir_hook, const void *entry_hook) return np; } +static struct node * +process_file_symlink_make_node (void *dir_hook, const void *entry_hook) +{ + struct node *np = process_file_make_node (dir_hook, entry_hook); + if (np) procfs_node_chtype (np, S_IFLNK); + return np; +} + /* Stat needs its own constructor in order to set its mode according to the --stat-mode command-line option. */ static struct node * @@ -424,6 +445,17 @@ process_stat_make_node (void *dir_hook, const void *entry_hook) /* Implementation of the process directory per se. */ static struct procfs_dir_entry entries[] = { + { + .name = "exe", + .hook = & (struct process_file_desc) { + .get_contents = process_file_gc_exe, + .needs = PSTAT_EXE, + .no_cleanup = 1, + }, + .ops = { + .make_node = process_file_symlink_make_node, + }, + }, { .name = "cmdline", .hook = & (struct process_file_desc) { -- cgit v1.2.3