summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhusudan.C.S <madhusudancs@gmail.com>2008-08-30 22:48:00 +0200
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2010-08-01 01:43:05 +0200
commit7a8b315855fc8edba2003fa69cb86cf664f4c2ec (patch)
treeab0e3e62abf07bd01ae9c113451b72ebe6b9d39a
parentfdd74966f222b67aa3161e809c6e9d8aacb16b12 (diff)
2008-08-30 Madhusudan.C.S <madhusudancs@gmail.com>
* procfs_dir.c: (procfs_dir_create): Assign newly created directory to its pointer in netnode. (procfs_dir_remove): Removed function. (free_entry): New function. (ordered_unlink): Likewise. (delete): Likewise. (sweep): Likewise. (procfs_dir_entries_remove): Likewise. (is_in_pid_list): Removed call to make_dir_invalid (). (procfs_fill_root_dir): struct stat *stat -> struct stat stat. Add Read and Execute permissions to all in stat.st_mode. Set stat.st_nlink to 1. Set stat.st_size to 0. Add struct proc_stat *ps definition. Set struct proc_stat data from _proc_stat_create () function and set stat.st_uid and stat.st_gid from the data in that structure. * procfs_pid_files.c: (update_pid_entries): Add Read permissions to all in stat->st_mode.
-rw-r--r--ChangeLog21
-rw-r--r--procfs_dir.c119
-rw-r--r--procfs_pid_files.c2
3 files changed, 126 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index e22887d..0e62b6f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2008-08-30 Madhusudan.C.S <madhusudancs@gmail.com>
+
+ * procfs_dir.c: (procfs_dir_create): Assign newly created directory to
+ its pointer in netnode.
+ (procfs_dir_remove): Removed function.
+ (free_entry): New function.
+ (ordered_unlink): Likewise.
+ (delete): Likewise.
+ (sweep): Likewise.
+ (procfs_dir_entries_remove): Likewise.
+ (is_in_pid_list): Removed call to make_dir_invalid ().
+ (procfs_fill_root_dir): struct stat *stat -> struct stat stat.
+ Add Read and Execute permissions to all in stat.st_mode.
+ Set stat.st_nlink to 1.
+ Set stat.st_size to 0.
+ Add struct proc_stat *ps definition.
+ Set struct proc_stat data from _proc_stat_create () function and
+ set stat.st_uid and stat.st_gid from the data in that structure.
+ * procfs_pid_files.c: (update_pid_entries): Add Read permissions
+ to all in stat->st_mode.
+
2008-08-29 Madhusudan.C.S <madhusudancs@gmail.com>
* AUTHORS: File removed.
diff --git a/procfs_dir.c b/procfs_dir.c
index b9b0410..f76e6a4 100644
--- a/procfs_dir.c
+++ b/procfs_dir.c
@@ -77,6 +77,9 @@ error_t procfs_dir_create (struct procfs *fs, struct node *node,
*dir = new;
+ if (fs->root != 0)
+ node->nn->dir = new;
+
return 0;
}
@@ -343,14 +346,50 @@ procfs_dir_null_lookup (struct procfs_dir *dir, struct node **node)
return err;
}
-/* Remove the specified DIR and free all its allocated
- storage. */
-void procfs_dir_remove (struct procfs_dir *dir)
+/* Free the directory entry DIR_ENTRY and all resources it consumes. */
+void
+free_entry (struct procfs_dir_entry *dir_entry)
{
- /* STUB */
+ assert (! dir_entry->self_p); /* We should only free deleted nodes. */
+ free (dir_entry->name);
+ if (dir_entry->symlink_target)
+ free (dir_entry->symlink_target);
+ free (dir_entry->node->nn->dir);
+ free (dir_entry->node->nn);
+ free (dir_entry->node);
+ free (dir_entry);
+}
+
+/* Remove DIR_ENTRY from its position in the ordered_next chain. */
+static void
+ordered_unlink (struct procfs_dir_entry *dir_entry)
+{
+ if (dir_entry->ordered_self_p)
+ *dir_entry->ordered_self_p = dir_entry->ordered_next;
+ if (dir_entry->ordered_next)
+ dir_entry->ordered_next->self_p = dir_entry->ordered_self_p;
+}
+
+/* Delete DIR_ENTRY from its directory, freeing any resources it holds. */
+static void
+delete (struct procfs_dir_entry *dir_entry, struct procfs_dir *dir)
+{
+ dir->num_entries--;
- return 0;
+ /* Take out of the hash chain. */
+ if (dir_entry->self_p)
+ *dir_entry->self_p = dir_entry->next;
+ if (dir_entry->next)
+ dir_entry->next->self_p = dir_entry->self_p;
+
+ /* Take out of the directory ordered list. */
+ ordered_unlink (dir_entry);
+
+ /* If there's a node attached, we'll delete the entry whenever it goes
+ away, otherwise, just delete it now. */
+ if (! dir_entry->node)
+ free_entry (dir_entry);
}
/* Make all the directory entries invalid */
@@ -373,6 +412,41 @@ make_dir_invalid (struct procfs_dir *dir)
}
}
+/* Delete any entries in DIR which don't have their valid bit set. */
+static void
+sweep (struct procfs_dir *dir)
+{
+ size_t len = dir->htable_len, i;
+ struct procfs_dir_entry **htable = dir->htable, *dir_entry;
+
+ for (i = 0; i < len; i++)
+ {
+ dir_entry = htable[i];
+ while (dir_entry)
+ {
+ if (!dir_entry->valid && !dir_entry->noent && dir->num_entries)
+ delete (dir_entry, dir);
+ dir_entry = dir_entry->next;
+ }
+ if (htable[i])
+ {
+ free (htable[i]);
+ htable[i] = 0;
+ }
+
+ }
+
+}
+
+/* Remove the specified DIR and free all its allocated
+ storage. */
+void procfs_dir_entries_remove (struct procfs_dir *dir)
+{
+ /* Free all entries. */
+ make_dir_invalid (dir);
+ sweep (dir);
+}
+
/* Checks if the DIR name is in list of
Active pids. */
int is_in_pid_list (struct procfs_dir *dir)
@@ -417,7 +491,6 @@ error_t procfs_dir_refresh (struct procfs_dir *dir, int isroot)
error_t err;
int is_parent_pid;
struct node *node;
- make_dir_invalid (dir);
struct timeval tv;
maptime_read (procfs_maptime, &tv);
@@ -513,14 +586,18 @@ procfs_fill_root_dir(struct procfs_dir *dir, time_t timestamp)
char *data;
pid_t *pids;
int pidslen;
- struct stat *stat = (struct stat *) malloc (sizeof (struct stat));
- stat->st_mode = S_IFDIR;
+ struct stat stat;
+ stat.st_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP |
+ S_IROTH | S_IXOTH;
+ stat.st_nlink = 1;
+ stat.st_size = 0;
int count;
char *dir_name_pid;
struct node *node;
struct procfs_dir *new_dir;
struct procfs_dir_entry *dir_entry;
+ struct proc_stat *ps;
pids = NULL;
pidslen = 0;
@@ -540,13 +617,25 @@ procfs_fill_root_dir(struct procfs_dir *dir, time_t timestamp)
if (! node || ! new_dir )
return ENOMEM;
#endif
- dir_entry = update_entries_list (dir, dir_name_pid,
- stat, timestamp, NULL);
- err = procfs_create_node (dir_entry, dir_name_pid, &node);
-
- procfs_dir_create (dir->fs, node,
- dir_name_pid, &new_dir);
- free(dir_name_pid);
+ err = _proc_stat_create (pids[count], ps_context, &ps);
+ if (! err)
+ {
+ err = set_field_value (ps, PSTAT_PROC_INFO);
+ if (! err)
+ {
+ stat.st_uid = proc_stat_proc_info (ps)->owner;
+ stat.st_gid = proc_stat_proc_info (ps)->pgrp;
+
+ dir_entry = update_entries_list (dir, dir_name_pid,
+ &stat, timestamp, NULL);
+ err = procfs_create_node (dir_entry, dir_name_pid, &node);
+
+ procfs_dir_create (dir->fs, node,
+ dir_name_pid, &new_dir);
+ free(dir_name_pid);
+ _proc_stat_free (ps);
+ }
+ }
}
}
diff --git a/procfs_pid_files.c b/procfs_pid_files.c
index ed3a3bd..4686153 100644
--- a/procfs_pid_files.c
+++ b/procfs_pid_files.c
@@ -48,7 +48,7 @@ update_pid_entries (struct procfs_dir *dir, const char *name,
{
struct procfs_dir_entry *dir_entry;
struct stat *stat = (struct stat *) malloc (sizeof (struct stat));
- stat->st_mode = S_IFREG;
+ stat->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
dir_entry = update_entries_list (dir, name, stat,
timestamp, symlink_target);