Commit f3a128aa authored by Chris Wedgwood's avatar Chris Wedgwood Committed by Linus Torvalds

[PATCH] uml: mconsole_proc rewrite

This is an update/resync of kraxel's mconsole_proc rewrite from about
two months ago and IMO it should be merged as-is (yes, it means /proc
has to be mounted but the current code crashes so this is better IMO).
Signed-off-by: default avatarChris Wedgwood <cw@f00f.org>
Acked-by: default avatarJeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 9b58dd15
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "linux/fs.h" #include "linux/fs.h"
#include "linux/namei.h" #include "linux/namei.h"
#include "linux/proc_fs.h" #include "linux/proc_fs.h"
#include "linux/syscalls.h"
#include "asm/irq.h" #include "asm/irq.h"
#include "asm/uaccess.h" #include "asm/uaccess.h"
#include "user_util.h" #include "user_util.h"
...@@ -120,77 +121,50 @@ void mconsole_log(struct mc_request *req) ...@@ -120,77 +121,50 @@ void mconsole_log(struct mc_request *req)
void mconsole_proc(struct mc_request *req) void mconsole_proc(struct mc_request *req)
{ {
struct nameidata nd; char path[64];
struct file_system_type *proc; char *buf;
struct super_block *super; int len;
struct file *file; int fd;
int n, err; char *ptr = req->request.data;
char *ptr = req->request.data, *buf;
ptr += strlen("proc"); ptr += strlen("proc");
while(isspace(*ptr)) ptr++; while(isspace(*ptr)) ptr++;
snprintf(path, sizeof(path), "/proc/%s", ptr);
proc = get_fs_type("proc"); fd = sys_open(path, 0, 0);
if(proc == NULL){ if (fd < 0) {
mconsole_reply(req, "procfs not registered", 1, 0);
goto out;
}
super = (*proc->get_sb)(proc, 0, NULL, NULL);
put_filesystem(proc);
if(super == NULL){
mconsole_reply(req, "Failed to get procfs superblock", 1, 0);
goto out;
}
up_write(&super->s_umount);
nd.dentry = super->s_root;
nd.mnt = NULL;
nd.flags = O_RDONLY + 1;
nd.last_type = LAST_ROOT;
err = link_path_walk(ptr, &nd);
if(err){
mconsole_reply(req, "Failed to look up file", 1, 0);
goto out_kill;
}
file = dentry_open(nd.dentry, nd.mnt, O_RDONLY);
if(IS_ERR(file)){
mconsole_reply(req, "Failed to open file", 1, 0); mconsole_reply(req, "Failed to open file", 1, 0);
goto out_kill; printk("open %s: %d\n",path,fd);
goto out;
} }
buf = kmalloc(PAGE_SIZE, GFP_KERNEL); buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if(buf == NULL){ if(buf == NULL){
mconsole_reply(req, "Failed to allocate buffer", 1, 0); mconsole_reply(req, "Failed to allocate buffer", 1, 0);
goto out_fput; goto out_close;
} }
if((file->f_op != NULL) && (file->f_op->read != NULL)){ for (;;) {
do { len = sys_read(fd, buf, PAGE_SIZE-1);
n = (*file->f_op->read)(file, buf, PAGE_SIZE - 1, if (len < 0) {
&file->f_pos); mconsole_reply(req, "Read of file failed", 1, 0);
if(n >= 0){ goto out_free;
buf[n] = '\0'; } else if (len == PAGE_SIZE-1) {
mconsole_reply(req, buf, 0, (n > 0)); buf[len] = '\0';
} mconsole_reply(req, buf, 0, 1);
else { } else {
mconsole_reply(req, "Read of file failed", buf[len] = '\0';
1, 0); mconsole_reply(req, buf, 0, 0);
goto out_free; break;
} }
} while(n > 0);
} }
else mconsole_reply(req, "", 0, 0);
out_free: out_free:
kfree(buf); kfree(buf);
out_fput: out_close:
fput(file); sys_close(fd);
out_kill: out:
deactivate_super(super); /* nothing */;
out: ;
} }
#define UML_MCONSOLE_HELPTEXT \ #define UML_MCONSOLE_HELPTEXT \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment