* net.cc (getdomainname): Change second argument of getdomainname to size_t.

* fhandler_proc.cc (proc_listing): Add '.' and '..' to directory listing.
(fhandler_proc::open): Change use of mode to flags.  If the file does not exist
already, fail with EROFS if O_CREAT flag is set.  Change EROFS error to EACCES
error when writing to a file.  Use cmalloc to allocate memory for filebuf.
(fhandler_proc::close): Use cfree to free filebuf.
(fhandler_proc::get_proc_fhandler): Properly detect attempts to access unknown
subdir.
* fhandler_process.cc (process_listing): Add '.' and '..' to directory listing.
(fhandler_process::open): Use cmalloc to allocate memory for filebuf.
(fhandler_process::close): Use cfree to free filebuf.
* fhandler_registry.cc (registry_listing): Add .  and '..' to directory
listing.
(fhandler_registry::open): Move check for open for writing before open_key.
Use cmalloc to allocate memory for filebuf.
(fhandler_registry::close): Use cfree to free filebuf.
(fhandler_registry::telldir): Use lower 16 bits of __d_position as position in
directory.
(fhandler_registry::seekdir): Ditto.
* fhandler_virtual.cc (fhandler_virtual::write): Change EROFS error to EACCES
error.
(fhandler_virtual::open): Set the NOHANDLE flag.
(fhandler_virtual::dup): Add call to fhandler_base::dup.  Allocate child's
filebuf using cmalloc.  Copy filebuf from parent to child.
(fhandler_virtual::close): Use cfree to free filebuf.
(fhandler_virtual::~fhandler_virtual): Ditto.
(from Chris Faylor <cgf@redhat.com>).
(fhandler_registry::readdir): Add support for '.' and '..' files in
subdirectories of /proc/registry.
* path.cc (path_conv::check): Do not return ENOENT if a file is not found in
/proc.
This commit is contained in:
Christopher Faylor
2002-05-04 03:24:35 +00:00
parent 4b3f6588fb
commit 8761c1dcf7
7 changed files with 167 additions and 65 deletions

View File

@ -20,6 +20,8 @@ details. */
#include "path.h"
#include "sigproc.h"
#include "pinfo.h"
#include "dtable.h"
#include "cygheap.h"
#include <assert.h>
#include <sys/utsname.h>
@ -27,12 +29,14 @@ details. */
#include <dirent.h>
/* offsets in proc_listing */
static const int PROC_REGISTRY = 0; // /proc/registry
static const int PROC_VERSION = 1; // /proc/version
static const int PROC_UPTIME = 2; // /proc/uptime
static const int PROC_REGISTRY = 2; // /proc/registry
static const int PROC_VERSION = 3; // /proc/version
static const int PROC_UPTIME = 4; // /proc/uptime
/* names of objects in /proc */
static const char *proc_listing[] = {
".",
"..",
"registry",
"version",
"uptime",
@ -45,6 +49,8 @@ static const int PROC_LINK_COUNT = (sizeof(proc_listing) / sizeof(const char *))
* fhandler_proc.
*/
static const DWORD proc_fhandlers[] = {
FH_PROC,
FH_PROC,
FH_REGISTRY,
FH_PROC,
FH_PROC
@ -92,7 +98,22 @@ fhandler_proc::get_proc_fhandler (const char *path)
if (p->pid == pid)
return FH_PROCESS;
}
return FH_BAD;
bool has_subdir = false;
while (*path)
if (SLASH_P (*path++))
{
has_subdir = true;
break;
}
if (has_subdir)
/* The user is trying to access a non-existent subdirectory of /proc. */
return FH_BAD;
else
/* Return FH_PROC so that we can return EROFS if the user is trying to create
a file. */
return FH_PROC;
}
/* Returns 0 if path doesn't exist, >0 if path is a directory,
@ -203,13 +224,13 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode)
if (!*path)
{
if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
{
set_errno (EEXIST);
res = 0;
goto out;
}
else if (mode & O_WRONLY)
else if (flags & O_WRONLY)
{
set_errno (EISDIR);
res = 0;
@ -229,13 +250,13 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode)
proc_file_no = i;
if (proc_fhandlers[i] != FH_PROC)
{
if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
if ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
{
set_errno (EEXIST);
res = 0;
goto out;
}
else if (mode & O_WRONLY)
else if (flags & O_WRONLY)
{
set_errno (EISDIR);
res = 0;
@ -251,7 +272,7 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode)
if (proc_file_no == -1)
{
if ((mode & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL))
if (flags & O_CREAT)
{
set_errno (EROFS);
res = 0;
@ -264,7 +285,7 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode)
goto out;
}
}
if (mode & O_WRONLY)
if (flags & O_WRONLY)
{
set_errno (EROFS);
res = 0;
@ -278,7 +299,7 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode)
uname (&uts_name);
filesize = bufalloc = strlen (uts_name.sysname) + 1 +
strlen (uts_name.release) + 1 + strlen (uts_name.version) + 2;
filebuf = new char[bufalloc];
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc);
__small_sprintf (filebuf, "%s %s %s\n", uts_name.sysname,
uts_name.release, uts_name.version);
break;
@ -290,7 +311,7 @@ fhandler_proc::open (path_conv *pc, int flags, mode_t mode)
* NT only dependancies.
*/
DWORD ticks = GetTickCount ();
filebuf = new char[bufalloc = 40];
filebuf = (char *) cmalloc (HEAP_BUF, bufalloc = 40);
__small_sprintf (filebuf, "%d.%02d\n", ticks / 1000,
(ticks / 10) % 100);
filesize = strlen (filebuf);