bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] Implement some (global) symlinks.


From: Jeremie Koenig
Subject: [PATCH 2/2] Implement some (global) symlinks.
Date: Fri, 13 Aug 2010 06:06:42 +0200

* /proc/cmdline -> /proc/2/cmdline (pid 2 is usually gnumach)
  This is not perfect, as the format of /proc/cmdline and /proc/*/cmdline are
  different on Linux.  Namely, the latter includes NUL bytes to separate
  subsequent arguments, while the former contains only spaces.

* /proc/mounts -> /etc/mtab
  libext2fs and some other stuff sometimes insists that this file must exist.

Signed-off-by: Jeremie Koenig <jk@jk.fr.eu.org>
---
 procfs_dir.c          |    6 ++++++
 procfs_nonpid_files.c |   26 ++++++++++++++++++++++++++
 procfs_pid_files.c    |   10 +++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/procfs_dir.c b/procfs_dir.c
index f76e6a4..f99f402 100644
--- a/procfs_dir.c
+++ b/procfs_dir.c
@@ -654,6 +654,12 @@ procfs_fill_root_dir(struct procfs_dir *dir, time_t 
timestamp)
   if ((err = procfs_create_loadavg (dir, &node, timestamp)) != 0)
     return err;
 
+  if ((err = procfs_create_cmdline (dir, &node, timestamp)) != 0)
+    return err;
+
+  if ((err = procfs_create_mounts (dir, &node, timestamp)) != 0)
+    return err;
+
   return 0;
 }
 
diff --git a/procfs_nonpid_files.c b/procfs_nonpid_files.c
index 2c1209e..8e88cf3 100644
--- a/procfs_nonpid_files.c
+++ b/procfs_nonpid_files.c
@@ -166,6 +166,32 @@ error_t procfs_create_loadavg (struct procfs_dir *dir,
   return err;
 }
 
+error_t procfs_create_cmdline (struct procfs_dir *dir, 
+                           struct node **node,
+                           time_t timestamp)
+{
+  struct procfs_dir_entry *dir_entry;
+  int err;
+
+  dir_entry = update_pid_entries (dir, "cmdline", timestamp, "2/cmdline");
+  err = procfs_create_node (dir_entry, "cmdline", node);
+
+  return err;
+}
+
+error_t procfs_create_mounts (struct procfs_dir *dir, 
+                           struct node **node,
+                           time_t timestamp)
+{
+  struct procfs_dir_entry *dir_entry;
+  int err;
+
+  dir_entry = update_pid_entries (dir, "mounts", timestamp, "/etc/mtab");
+  err = procfs_create_node (dir_entry, "mounts", node);
+
+  return err;
+}
+
 error_t get_uptime (struct timeval *uptime)
 {
   struct timeval boot_time, now;
diff --git a/procfs_pid_files.c b/procfs_pid_files.c
index 30194c1..b319b95 100644
--- a/procfs_pid_files.c
+++ b/procfs_pid_files.c
@@ -47,10 +47,14 @@ update_pid_entries (struct procfs_dir *dir, const char 
*name,
                           const char *symlink_target)
 {
   struct procfs_dir_entry *dir_entry;
-  struct stat *stat = (struct stat *) malloc (sizeof (struct stat));
-  stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
+  struct stat stat;
 
-  dir_entry = update_entries_list (dir, name, stat, 
+  memset (&stat, 0, sizeof stat);
+  stat.st_size = symlink_target ? strlen (symlink_target) : 0;
+  stat.st_mode = symlink_target ? S_IFLNK : S_IFREG;
+  stat.st_mode |= S_IRUSR | S_IRGRP | S_IROTH;
+
+  dir_entry = update_entries_list (dir, name, &stat,
                                  timestamp, symlink_target);
 
   return dir_entry;
-- 
1.7.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]