mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-03-03 05:25:24 +08:00
* cygheap.h (class cygheap_fdenum): New class to enumerate used
fhandlers. * dtable.h (class dtable): Add cygheap_fdenum as friend class. * fhandler.h (fhandler_base::get_proc_fd_name): New virtual method to return a name for /proc/<pid>/fd. (fhandler_socket::get_proc_fd_name): Ditto. (fhandler_pipe::get_proc_fd_name): Ditto. (fhandler_virtual::opendir): Make virtual method. (fhandler_process::opendir): New method. * fhandler.cc (fhandler_base::get_proc_fd_name): New method. * fhandler_process.cc: Include ctype.h. (PROCESS_FD): Define. (process_listing): Add "fd". (fhandler_process::exists): Fix comment. Return 1 in case of "fd" directory. Handle files below "fd". (fhandler_process::fstat): Drop "self" handling. Set correct link count for directories. (fhandler_process::opendir): New method to handle "fd" directory. (fhandler_process::readdir): Add "fd" handling. (fhandler_process::open): Drop "self" handling. (fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix "maps" output string. * fhandler_registry.cc (fhandler_registry::fstat): Set correct link count for directories. * fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method. * path.cc (symlink_info::set): Fix thinko. * pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout. Drop local path variable in PICOM_FIFO case. Fix debug output. Close handles as early as possible. Add PICOM_FDS and PICOM_FD handling. (_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling. (_pinfo::fd): New method. (_pinfo::fds): New method. * pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD. (_pinfo::fd): Declare. (_pinfo::fds): Declare. * pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
This commit is contained in:
parent
d0ae095b8c
commit
4f27e288c5
@ -1,3 +1,43 @@
|
|||||||
|
2005-01-31 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* cygheap.h (class cygheap_fdenum): New class to enumerate used
|
||||||
|
fhandlers.
|
||||||
|
* dtable.h (class dtable): Add cygheap_fdenum as friend class.
|
||||||
|
* fhandler.h (fhandler_base::get_proc_fd_name): New virtual method
|
||||||
|
to return a name for /proc/<pid>/fd.
|
||||||
|
(fhandler_socket::get_proc_fd_name): Ditto.
|
||||||
|
(fhandler_pipe::get_proc_fd_name): Ditto.
|
||||||
|
(fhandler_virtual::opendir): Make virtual method.
|
||||||
|
(fhandler_process::opendir): New method.
|
||||||
|
* fhandler.cc (fhandler_base::get_proc_fd_name): New method.
|
||||||
|
* fhandler_process.cc: Include ctype.h.
|
||||||
|
(PROCESS_FD): Define.
|
||||||
|
(process_listing): Add "fd".
|
||||||
|
(fhandler_process::exists): Fix comment. Return 1 in case of "fd"
|
||||||
|
directory. Handle files below "fd".
|
||||||
|
(fhandler_process::fstat): Drop "self" handling. Set correct link
|
||||||
|
count for directories.
|
||||||
|
(fhandler_process::opendir): New method to handle "fd" directory.
|
||||||
|
(fhandler_process::readdir): Add "fd" handling.
|
||||||
|
(fhandler_process::open): Drop "self" handling.
|
||||||
|
(fhandler_process::fill_filebuf): Ditto. Add "fd" handling. Fix
|
||||||
|
"maps" output string.
|
||||||
|
* fhandler_registry.cc (fhandler_registry::fstat): Set correct link
|
||||||
|
count for directories.
|
||||||
|
* fhandler_socket.cc (fhandler_socket::get_proc_fd_name): New method.
|
||||||
|
* path.cc (symlink_info::set): Fix thinko.
|
||||||
|
* pinfo.cc (_pinfo::commune_recv): Rename pathbuf to path throughout.
|
||||||
|
Drop local path variable in PICOM_FIFO case. Fix debug output.
|
||||||
|
Close handles as early as possible. Add PICOM_FDS and PICOM_FD
|
||||||
|
handling.
|
||||||
|
(_pinfo::commune_send): Add PICOM_FDS and PICOM_FD handling.
|
||||||
|
(_pinfo::fd): New method.
|
||||||
|
(_pinfo::fds): New method.
|
||||||
|
* pinfo.h (enum picom): Add PICOM_FDS and PICOM_FD.
|
||||||
|
(_pinfo::fd): Declare.
|
||||||
|
(_pinfo::fds): Declare.
|
||||||
|
* pipe.cc (fhandler_pipe::get_proc_fd_name): New method.
|
||||||
|
|
||||||
2005-01-29 Corinna Vinschen <corinna@vinschen.de>
|
2005-01-29 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* smallprint.c (rn): Change uval to unsigned long long to fix 64 bit
|
* smallprint.c (rn): Change uval to unsigned long long to fix 64 bit
|
||||||
|
@ -384,6 +384,29 @@ class cygheap_fdget : public cygheap_fdmanip
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class cygheap_fdenum : public cygheap_fdmanip
|
||||||
|
{
|
||||||
|
int start_fd;
|
||||||
|
public:
|
||||||
|
cygheap_fdenum (int start_fd = -1, bool lockit = false)
|
||||||
|
{
|
||||||
|
if (lockit)
|
||||||
|
cygheap->fdtab.lock ();
|
||||||
|
this->start_fd = fd = start_fd < 0 ? -1 : start_fd;
|
||||||
|
}
|
||||||
|
int next ()
|
||||||
|
{
|
||||||
|
while (++fd < (int) cygheap->fdtab.size)
|
||||||
|
if (*(fh = cygheap->fdtab + fd) != NULL)
|
||||||
|
return fd;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
void rewind ()
|
||||||
|
{
|
||||||
|
fd = start_fd;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class child_info;
|
class child_info;
|
||||||
void *__stdcall cygheap_setup_for_child (child_info *ci, bool dup_later) __attribute__ ((regparm(2)));
|
void *__stdcall cygheap_setup_for_child (child_info *ci, bool dup_later) __attribute__ ((regparm(2)));
|
||||||
void __stdcall cygheap_setup_for_child_cleanup (void *, child_info *, bool) __attribute__ ((regparm(3)));
|
void __stdcall cygheap_setup_for_child_cleanup (void *, child_info *, bool) __attribute__ ((regparm(3)));
|
||||||
|
@ -88,6 +88,7 @@ public:
|
|||||||
friend class cygheap_fdmanip;
|
friend class cygheap_fdmanip;
|
||||||
friend class cygheap_fdget;
|
friend class cygheap_fdget;
|
||||||
friend class cygheap_fdnew;
|
friend class cygheap_fdnew;
|
||||||
|
friend class cygheap_fdenum;
|
||||||
};
|
};
|
||||||
|
|
||||||
fhandler_base *build_fh_dev (const device&, const char * = NULL);
|
fhandler_base *build_fh_dev (const device&, const char * = NULL);
|
||||||
|
@ -154,6 +154,16 @@ fhandler_base::set_name (path_conv &in_pc)
|
|||||||
pc.set_normalized_path (in_pc.normalized_path, false);
|
pc.set_normalized_path (in_pc.normalized_path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *fhandler_base::get_proc_fd_name (char *buf)
|
||||||
|
{
|
||||||
|
if (get_name ())
|
||||||
|
return strcpy (buf, get_name ());
|
||||||
|
if (dev ().name)
|
||||||
|
return strcpy (buf, dev ().name);
|
||||||
|
__small_sprintf (buf, "device:[%d:%d]", get_major (), get_minor ());
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
/* Detect if we are sitting at EOF for conditions where Windows
|
/* Detect if we are sitting at EOF for conditions where Windows
|
||||||
returns an error but UNIX doesn't. */
|
returns an error but UNIX doesn't. */
|
||||||
static int __stdcall
|
static int __stdcall
|
||||||
|
@ -218,6 +218,8 @@ class fhandler_base
|
|||||||
const char *get_name () const { return pc.normalized_path; }
|
const char *get_name () const { return pc.normalized_path; }
|
||||||
const char *get_win32_name () { return pc.get_win32 (); }
|
const char *get_win32_name () { return pc.get_win32 (); }
|
||||||
__ino64_t get_namehash () { return namehash ?: namehash = hash_path_name (0, get_win32_name ()); }
|
__ino64_t get_namehash () { return namehash ?: namehash = hash_path_name (0, get_win32_name ()); }
|
||||||
|
/* Returns name used for /proc/<pid>/fd in buf. */
|
||||||
|
virtual char *get_proc_fd_name (char *buf);
|
||||||
|
|
||||||
virtual void hclose (HANDLE h) {CloseHandle (h);}
|
virtual void hclose (HANDLE h) {CloseHandle (h);}
|
||||||
virtual void set_no_inheritance (HANDLE &h, int not_inheriting);
|
virtual void set_no_inheritance (HANDLE &h, int not_inheriting);
|
||||||
@ -398,6 +400,7 @@ class fhandler_socket: public fhandler_base
|
|||||||
void fixup_after_fork (HANDLE);
|
void fixup_after_fork (HANDLE);
|
||||||
void fixup_after_exec ();
|
void fixup_after_exec ();
|
||||||
bool need_fixup_before () const {return true;}
|
bool need_fixup_before () const {return true;}
|
||||||
|
char *get_proc_fd_name (char *buf);
|
||||||
|
|
||||||
select_record *select_read (select_record *s);
|
select_record *select_read (select_record *s);
|
||||||
select_record *select_write (select_record *s);
|
select_record *select_write (select_record *s);
|
||||||
@ -432,6 +435,7 @@ public:
|
|||||||
select_record *select_read (select_record *s);
|
select_record *select_read (select_record *s);
|
||||||
select_record *select_write (select_record *s);
|
select_record *select_write (select_record *s);
|
||||||
select_record *select_except (select_record *s);
|
select_record *select_except (select_record *s);
|
||||||
|
char *get_proc_fd_name (char *buf);
|
||||||
void set_close_on_exec (bool val);
|
void set_close_on_exec (bool val);
|
||||||
void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
void __stdcall read (void *ptr, size_t& len) __attribute__ ((regparm (3)));
|
||||||
int close ();
|
int close ();
|
||||||
@ -1105,7 +1109,7 @@ class fhandler_virtual : public fhandler_base
|
|||||||
virtual ~fhandler_virtual();
|
virtual ~fhandler_virtual();
|
||||||
|
|
||||||
virtual int exists();
|
virtual int exists();
|
||||||
DIR *opendir ();
|
virtual DIR *opendir ();
|
||||||
_off64_t telldir (DIR *);
|
_off64_t telldir (DIR *);
|
||||||
void seekdir (DIR *, _off64_t);
|
void seekdir (DIR *, _off64_t);
|
||||||
void rewinddir (DIR *);
|
void rewinddir (DIR *);
|
||||||
@ -1164,6 +1168,7 @@ class fhandler_process: public fhandler_proc
|
|||||||
public:
|
public:
|
||||||
fhandler_process ();
|
fhandler_process ();
|
||||||
int exists();
|
int exists();
|
||||||
|
DIR *opendir ();
|
||||||
struct dirent *readdir (DIR *);
|
struct dirent *readdir (DIR *);
|
||||||
int open (int flags, mode_t mode = 0);
|
int open (int flags, mode_t mode = 0);
|
||||||
int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
|
int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));
|
||||||
|
@ -25,6 +25,7 @@ details. */
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
|
|
||||||
#define _COMPILING_NEWLIB
|
#define _COMPILING_NEWLIB
|
||||||
@ -43,10 +44,11 @@ static const int PROCESS_STAT = 11;
|
|||||||
static const int PROCESS_STATM = 12;
|
static const int PROCESS_STATM = 12;
|
||||||
static const int PROCESS_CMDLINE = 13;
|
static const int PROCESS_CMDLINE = 13;
|
||||||
static const int PROCESS_MAPS = 14;
|
static const int PROCESS_MAPS = 14;
|
||||||
|
static const int PROCESS_FD = 15;
|
||||||
/* Keep symlinks always the last entries. */
|
/* Keep symlinks always the last entries. */
|
||||||
static const int PROCESS_ROOT = 15;
|
static const int PROCESS_ROOT = 16;
|
||||||
static const int PROCESS_EXE = 16;
|
static const int PROCESS_EXE = 17;
|
||||||
static const int PROCESS_CWD = 17;
|
static const int PROCESS_CWD = 18;
|
||||||
|
|
||||||
/* The position of "root" defines the beginning of symlik entries. */
|
/* The position of "root" defines the beginning of symlik entries. */
|
||||||
#define is_symlink(nr) ((nr) >= PROCESS_ROOT)
|
#define is_symlink(nr) ((nr) >= PROCESS_ROOT)
|
||||||
@ -68,6 +70,7 @@ static const char * const process_listing[] =
|
|||||||
"statm",
|
"statm",
|
||||||
"cmdline",
|
"cmdline",
|
||||||
"maps",
|
"maps",
|
||||||
|
"fd",
|
||||||
/* Keep symlinks always the last entries. */
|
/* Keep symlinks always the last entries. */
|
||||||
"root",
|
"root",
|
||||||
"exe",
|
"exe",
|
||||||
@ -89,7 +92,7 @@ static bool get_mem_values (DWORD dwProcessId, unsigned long *vmsize,
|
|||||||
unsigned long *vmshare);
|
unsigned long *vmshare);
|
||||||
|
|
||||||
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
/* Returns 0 if path doesn't exist, >0 if path is a directory,
|
||||||
* <0 if path is a file.
|
* -1 if path is a file, -2 if path is a symlink.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
fhandler_process::exists ()
|
fhandler_process::exists ()
|
||||||
@ -106,7 +109,13 @@ fhandler_process::exists ()
|
|||||||
if (pathmatch (path + 1, process_listing[i]))
|
if (pathmatch (path + 1, process_listing[i]))
|
||||||
{
|
{
|
||||||
fileid = i;
|
fileid = i;
|
||||||
return is_symlink (i) ? -2 : -1;
|
return is_symlink (i) ? -2 : (i == PROCESS_FD) ? 1 : -1;
|
||||||
|
}
|
||||||
|
if (pathnmatch (strchr (path, '/') + 1, "fd/", 3))
|
||||||
|
{
|
||||||
|
fileid = PROCESS_FD;
|
||||||
|
if (fill_filebuf ())
|
||||||
|
return -2;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -123,9 +132,6 @@ fhandler_process::fstat (struct __stat64 *buf)
|
|||||||
int file_type = exists ();
|
int file_type = exists ();
|
||||||
(void) fhandler_base::fstat (buf);
|
(void) fhandler_base::fstat (buf);
|
||||||
path += proc_len + 1;
|
path += proc_len + 1;
|
||||||
if (path_prefix_p ("self", path, 4))
|
|
||||||
pid = getpid ();
|
|
||||||
else
|
|
||||||
pid = atoi (path);
|
pid = atoi (path);
|
||||||
pinfo p (pid);
|
pinfo p (pid);
|
||||||
if (!p)
|
if (!p)
|
||||||
@ -142,8 +148,6 @@ fhandler_process::fstat (struct __stat64 *buf)
|
|||||||
set_errno (ENOENT);
|
set_errno (ENOENT);
|
||||||
return -1;
|
return -1;
|
||||||
case 1:
|
case 1:
|
||||||
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
|
||||||
return 0;
|
|
||||||
case 2:
|
case 2:
|
||||||
buf->st_ctime = buf->st_mtime = p->start_time;
|
buf->st_ctime = buf->st_mtime = p->start_time;
|
||||||
buf->st_ctim.tv_nsec = buf->st_mtim.tv_nsec = 0;
|
buf->st_ctim.tv_nsec = buf->st_mtim.tv_nsec = 0;
|
||||||
@ -151,7 +155,10 @@ fhandler_process::fstat (struct __stat64 *buf)
|
|||||||
buf->st_uid = p->uid;
|
buf->st_uid = p->uid;
|
||||||
buf->st_gid = p->gid;
|
buf->st_gid = p->gid;
|
||||||
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
|
||||||
buf->st_nlink = PROCESS_LINK_COUNT;
|
if (file_type == 1)
|
||||||
|
buf->st_nlink = 2;
|
||||||
|
else
|
||||||
|
buf->st_nlink = 3;
|
||||||
return 0;
|
return 0;
|
||||||
case -2:
|
case -2:
|
||||||
buf->st_uid = p->uid;
|
buf->st_uid = p->uid;
|
||||||
@ -167,14 +174,38 @@ fhandler_process::fstat (struct __stat64 *buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DIR *
|
||||||
|
fhandler_process::opendir ()
|
||||||
|
{
|
||||||
|
DIR *dir = fhandler_virtual::opendir ();
|
||||||
|
if (dir && fileid == PROCESS_FD)
|
||||||
|
fill_filebuf ();
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
struct dirent *
|
struct dirent *
|
||||||
fhandler_process::readdir (DIR * dir)
|
fhandler_process::readdir (DIR * dir)
|
||||||
{
|
{
|
||||||
if (dir->__d_position >= PROCESS_LINK_COUNT)
|
if (fileid == PROCESS_FD)
|
||||||
|
{
|
||||||
|
if (dir->__d_position >= 2 + filesize / sizeof (int))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
else if (dir->__d_position >= PROCESS_LINK_COUNT)
|
||||||
|
return NULL;
|
||||||
|
if (fileid == PROCESS_FD && dir->__d_position > 1)
|
||||||
|
{
|
||||||
|
int *p = (int *) filebuf;
|
||||||
|
__small_sprintf (dir->__d_dirent->d_name, "%d", p[dir->__d_position++ - 2]);
|
||||||
|
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
|
||||||
|
dir->__d_dirent->d_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
strcpy (dir->__d_dirent->d_name, process_listing[dir->__d_position++]);
|
strcpy (dir->__d_dirent->d_name, process_listing[dir->__d_position++]);
|
||||||
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
|
syscall_printf ("%p = readdir (%p) (%s)", &dir->__d_dirent, dir,
|
||||||
dir->__d_dirent->d_name);
|
dir->__d_dirent->d_name);
|
||||||
|
}
|
||||||
return dir->__d_dirent;
|
return dir->__d_dirent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,9 +222,6 @@ fhandler_process::open (int flags, mode_t mode)
|
|||||||
|
|
||||||
const char *path;
|
const char *path;
|
||||||
path = get_name () + proc_len + 1;
|
path = get_name () + proc_len + 1;
|
||||||
if (path_prefix_p ("self", path, 4))
|
|
||||||
pid = getpid ();
|
|
||||||
else
|
|
||||||
pid = atoi (path);
|
pid = atoi (path);
|
||||||
while (*path != 0 && !isdirsep (*path))
|
while (*path != 0 && !isdirsep (*path))
|
||||||
path++;
|
path++;
|
||||||
@ -272,15 +300,11 @@ out:
|
|||||||
bool
|
bool
|
||||||
fhandler_process::fill_filebuf ()
|
fhandler_process::fill_filebuf ()
|
||||||
{
|
{
|
||||||
if (!pid)
|
|
||||||
{
|
|
||||||
const char *path;
|
const char *path;
|
||||||
path = get_name () + proc_len + 1;
|
path = get_name () + proc_len + 1;
|
||||||
if (path_prefix_p ("self", path, 4))
|
if (!pid)
|
||||||
pid = getpid ();
|
|
||||||
else
|
|
||||||
pid = atoi (path);
|
pid = atoi (path);
|
||||||
}
|
|
||||||
pinfo p (pid);
|
pinfo p (pid);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
@ -291,6 +315,36 @@ fhandler_process::fill_filebuf ()
|
|||||||
|
|
||||||
switch (fileid)
|
switch (fileid)
|
||||||
{
|
{
|
||||||
|
case PROCESS_FD:
|
||||||
|
{
|
||||||
|
size_t fs;
|
||||||
|
char *fdp = strrchr (path, '/');
|
||||||
|
if (!fdp || *++fdp == 'f') /* The "fd" directory itself. */
|
||||||
|
{
|
||||||
|
if (filebuf)
|
||||||
|
free (filebuf);
|
||||||
|
filebuf = p->fds (fs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (filebuf)
|
||||||
|
free (filebuf);
|
||||||
|
int fd = atoi (fdp);
|
||||||
|
if (fd < 0 || (fd == 0 && !isdigit (*fdp)))
|
||||||
|
{
|
||||||
|
set_errno (ENOENT);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
filebuf = p->fd (fd, fs);
|
||||||
|
if (!filebuf || !*filebuf)
|
||||||
|
{
|
||||||
|
filebuf = strdup ("<disconnected>");
|
||||||
|
fs = strlen (filebuf) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filesize = fs;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case PROCESS_UID:
|
case PROCESS_UID:
|
||||||
case PROCESS_GID:
|
case PROCESS_GID:
|
||||||
case PROCESS_PGID:
|
case PROCESS_PGID:
|
||||||
@ -502,7 +556,7 @@ format_process_maps (_pinfo *p, char *destbuf, size_t maxsize)
|
|||||||
st.st_ino);
|
st.st_ino);
|
||||||
while (written++ < 61)
|
while (written++ < 61)
|
||||||
destbuf[len + written] = ' ';
|
destbuf[len + written] = ' ';
|
||||||
len += written;
|
len += written - 1;
|
||||||
len += __small_sprintf (destbuf + len, "%s\n", posix_modname);
|
len += __small_sprintf (destbuf + len, "%s\n", posix_modname);
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
@ -236,7 +236,7 @@ fhandler_registry::fstat (struct __stat64 *buf)
|
|||||||
buf->st_ctim = buf->st_mtim;
|
buf->st_ctim = buf->st_mtim;
|
||||||
time_as_timestruc_t (&buf->st_atim);
|
time_as_timestruc_t (&buf->st_atim);
|
||||||
if (file_type > 0)
|
if (file_type > 0)
|
||||||
buf->st_nlink = subkey_count;
|
buf->st_nlink = subkey_count + 2;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int pathlen = strlen (path);
|
int pathlen = strlen (path);
|
||||||
|
@ -147,6 +147,15 @@ fhandler_socket::~fhandler_socket ()
|
|||||||
cfree (sun_path);
|
cfree (sun_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *fhandler_socket::get_proc_fd_name (char *buf)
|
||||||
|
{
|
||||||
|
if (get_sun_path ())
|
||||||
|
__small_sprintf (buf, "%s", get_sun_path ());
|
||||||
|
else
|
||||||
|
__small_sprintf (buf, "socket:[%d]", get_socket ());
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fhandler_socket::set_connect_secret ()
|
fhandler_socket::set_connect_secret ()
|
||||||
{
|
{
|
||||||
|
@ -3135,22 +3135,10 @@ symlink_info::check (char *path, const suffix_info *suffixes, unsigned opt)
|
|||||||
int
|
int
|
||||||
symlink_info::set (char *path, int type)
|
symlink_info::set (char *path, int type)
|
||||||
{
|
{
|
||||||
extern suffix_info stat_suffixes[];
|
|
||||||
|
|
||||||
strcpy (contents, path);
|
strcpy (contents, path);
|
||||||
pflags = PATH_SYMLINK;
|
pflags = PATH_SYMLINK;
|
||||||
if (type == -3) /* /proc/self */
|
fileattr = FILE_ATTRIBUTE_NORMAL;
|
||||||
{
|
|
||||||
fileattr = FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
error = 0;
|
error = 0;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* That's save since a virtual symlink doesn't point to itself. */
|
|
||||||
path_conv pc (contents, PC_SYM_NOFOLLOW | PC_FULL, stat_suffixes);
|
|
||||||
fileattr = pc;
|
|
||||||
error = pc.error;
|
|
||||||
}
|
|
||||||
is_symlink = true;
|
is_symlink = true;
|
||||||
ext_tacked_on = case_clash = false;
|
ext_tacked_on = case_clash = false;
|
||||||
ext_here = NULL;
|
ext_here = NULL;
|
||||||
|
@ -380,7 +380,7 @@ extern char **__argv;
|
|||||||
void
|
void
|
||||||
_pinfo::commune_recv ()
|
_pinfo::commune_recv ()
|
||||||
{
|
{
|
||||||
char pathbuf[CYG_MAX_PATH];
|
char path[CYG_MAX_PATH + 1];
|
||||||
DWORD nr;
|
DWORD nr;
|
||||||
DWORD code;
|
DWORD code;
|
||||||
HANDLE hp;
|
HANDLE hp;
|
||||||
@ -460,33 +460,78 @@ _pinfo::commune_recv ()
|
|||||||
}
|
}
|
||||||
case PICOM_CWD:
|
case PICOM_CWD:
|
||||||
{
|
{
|
||||||
unsigned int n = strlen (cygheap->cwd.get (pathbuf, 1, 1, CYG_MAX_PATH)) + 1;
|
|
||||||
CloseHandle (__fromthem); __fromthem = NULL;
|
CloseHandle (__fromthem); __fromthem = NULL;
|
||||||
CloseHandle (hp);
|
CloseHandle (hp);
|
||||||
|
unsigned int n = strlen (cygheap->cwd.get (path, 1, 1,
|
||||||
|
CYG_MAX_PATH)) + 1;
|
||||||
if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL))
|
if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL))
|
||||||
sigproc_printf ("WriteFile sizeof argv failed, %E");
|
sigproc_printf ("WriteFile sizeof cwd failed, %E");
|
||||||
else if (!WriteFile (__tothem, pathbuf, n, &nr, NULL))
|
else if (!WriteFile (__tothem, path, n, &nr, NULL))
|
||||||
sigproc_printf ("WriteFile sizeof argv failed, %E");
|
sigproc_printf ("WriteFile cwd failed, %E");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PICOM_ROOT:
|
case PICOM_ROOT:
|
||||||
{
|
{
|
||||||
unsigned int n;
|
|
||||||
if (cygheap->root.exists ())
|
|
||||||
n = strlen (strcpy (pathbuf, cygheap->root.posix_path ())) + 1;
|
|
||||||
else
|
|
||||||
n = strlen (strcpy (pathbuf, "/")) + 1;
|
|
||||||
CloseHandle (__fromthem); __fromthem = NULL;
|
CloseHandle (__fromthem); __fromthem = NULL;
|
||||||
CloseHandle (hp);
|
CloseHandle (hp);
|
||||||
|
unsigned int n;
|
||||||
|
if (cygheap->root.exists ())
|
||||||
|
n = strlen (strcpy (path, cygheap->root.posix_path ())) + 1;
|
||||||
|
else
|
||||||
|
n = strlen (strcpy (path, "/")) + 1;
|
||||||
if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL))
|
if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL))
|
||||||
sigproc_printf ("WriteFile sizeof argv failed, %E");
|
sigproc_printf ("WriteFile sizeof root failed, %E");
|
||||||
else if (!WriteFile (__tothem, pathbuf, n, &nr, NULL))
|
else if (!WriteFile (__tothem, path, n, &nr, NULL))
|
||||||
sigproc_printf ("WriteFile sizeof argv failed, %E");
|
sigproc_printf ("WriteFile root failed, %E");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PICOM_FDS:
|
||||||
|
{
|
||||||
|
CloseHandle (__fromthem); __fromthem = NULL;
|
||||||
|
CloseHandle (hp);
|
||||||
|
unsigned int n = 0;
|
||||||
|
int fd;
|
||||||
|
cygheap_fdenum cfd;
|
||||||
|
while ((fd = cfd.next ()) >= 0)
|
||||||
|
n += sizeof (int);
|
||||||
|
cfd.rewind ();
|
||||||
|
if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL))
|
||||||
|
sigproc_printf ("WriteFile sizeof fds failed, %E");
|
||||||
|
else
|
||||||
|
while ((fd = cfd.next ()) >= 0)
|
||||||
|
if (!WriteFile (__tothem, &fd, sizeof fd, &nr, NULL))
|
||||||
|
{
|
||||||
|
sigproc_printf ("WriteFile fd %d failed, %E", fd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PICOM_FD:
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
if (!ReadFile (__fromthem, &fd, sizeof fd, &nr, NULL)
|
||||||
|
|| nr != sizeof fd)
|
||||||
|
{
|
||||||
|
sigproc_printf ("ReadFile fd failed, %E");
|
||||||
|
CloseHandle (hp);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
CloseHandle (__fromthem); __fromthem = NULL;
|
||||||
|
CloseHandle (hp);
|
||||||
|
unsigned int n;
|
||||||
|
cygheap_fdget cfd (fd);
|
||||||
|
if (cfd < 0)
|
||||||
|
n = strlen (strcpy (path, "<disconnected>")) + 1;
|
||||||
|
else
|
||||||
|
n = strlen (cfd->get_proc_fd_name (path)) + 1;
|
||||||
|
if (!WriteFile (__tothem, &n, sizeof n, &nr, NULL))
|
||||||
|
sigproc_printf ("WriteFile sizeof fd failed, %E");
|
||||||
|
else if (!WriteFile (__tothem, path, n, &nr, NULL))
|
||||||
|
sigproc_printf ("WriteFile fd failed, %E");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PICOM_FIFO:
|
case PICOM_FIFO:
|
||||||
{
|
{
|
||||||
char path[CYG_MAX_PATH + 1];
|
|
||||||
unsigned len;
|
unsigned len;
|
||||||
if (!ReadFile (__fromthem, &len, sizeof len, &nr, NULL)
|
if (!ReadFile (__fromthem, &len, sizeof len, &nr, NULL)
|
||||||
|| nr != sizeof len)
|
|| nr != sizeof len)
|
||||||
@ -614,9 +659,21 @@ _pinfo::commune_send (DWORD code, ...)
|
|||||||
size_t n;
|
size_t n;
|
||||||
switch (code)
|
switch (code)
|
||||||
{
|
{
|
||||||
|
case PICOM_FD:
|
||||||
|
{
|
||||||
|
int fd = va_arg (args, int);
|
||||||
|
if (!WriteFile (tothem, &fd, sizeof fd, &nr, NULL)
|
||||||
|
|| nr != sizeof fd)
|
||||||
|
{
|
||||||
|
__seterrno ();
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*FALLTHRU*/
|
||||||
case PICOM_CMDLINE:
|
case PICOM_CMDLINE:
|
||||||
case PICOM_CWD:
|
case PICOM_CWD:
|
||||||
case PICOM_ROOT:
|
case PICOM_ROOT:
|
||||||
|
case PICOM_FDS:
|
||||||
if (!ReadFile (fromthem, &n, sizeof n, &nr, NULL) || nr != sizeof n)
|
if (!ReadFile (fromthem, &n, sizeof n, &nr, NULL) || nr != sizeof n)
|
||||||
{
|
{
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
@ -683,6 +740,58 @@ out:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
_pinfo::fd (int fd, size_t &n)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
if (!this || !pid)
|
||||||
|
return NULL;
|
||||||
|
if (pid != myself->pid)
|
||||||
|
{
|
||||||
|
commune_result cr = commune_send (PICOM_FD, fd);
|
||||||
|
s = cr.s;
|
||||||
|
n = cr.n;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cygheap_fdget cfd (fd);
|
||||||
|
if (cfd < 0)
|
||||||
|
s = strdup ("<disconnected>");
|
||||||
|
else
|
||||||
|
s = cfd->get_proc_fd_name ((char *) malloc (CYG_MAX_PATH + 1));
|
||||||
|
n = strlen (s) + 1;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
_pinfo::fds (size_t &n)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
if (!this || !pid)
|
||||||
|
return NULL;
|
||||||
|
if (pid != myself->pid)
|
||||||
|
{
|
||||||
|
commune_result cr = commune_send (PICOM_FDS);
|
||||||
|
s = cr.s;
|
||||||
|
n = cr.n;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n = 0;
|
||||||
|
int fd;
|
||||||
|
cygheap_fdenum cfd;
|
||||||
|
while ((fd = cfd.next ()) >= 0)
|
||||||
|
n += sizeof (int);
|
||||||
|
cfd.rewind ();
|
||||||
|
s = (char *) malloc (n);
|
||||||
|
int *p = (int *) s;
|
||||||
|
while ((fd = cfd.next ()) >= 0 && (char *) p - s < (int) n)
|
||||||
|
*p++ = fd;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
_pinfo::root (size_t& n)
|
_pinfo::root (size_t& n)
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,9 @@ enum picom
|
|||||||
PICOM_CMDLINE = 1,
|
PICOM_CMDLINE = 1,
|
||||||
PICOM_FIFO = 2,
|
PICOM_FIFO = 2,
|
||||||
PICOM_CWD = 3,
|
PICOM_CWD = 3,
|
||||||
PICOM_ROOT = 4
|
PICOM_ROOT = 4,
|
||||||
|
PICOM_FDS = 5,
|
||||||
|
PICOM_FD = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
#define EXITCODE_SET 0x80000000
|
#define EXITCODE_SET 0x80000000
|
||||||
@ -108,6 +110,8 @@ public:
|
|||||||
void commune_recv ();
|
void commune_recv ();
|
||||||
commune_result commune_send (DWORD, ...);
|
commune_result commune_send (DWORD, ...);
|
||||||
bool alive ();
|
bool alive ();
|
||||||
|
char *fd (int fd, size_t &);
|
||||||
|
char *fds (size_t &);
|
||||||
char *root (size_t &);
|
char *root (size_t &);
|
||||||
char *cwd (size_t &);
|
char *cwd (size_t &);
|
||||||
char *cmdline (size_t &);
|
char *cmdline (size_t &);
|
||||||
|
@ -53,6 +53,12 @@ fhandler_pipe::set_close_on_exec (bool val)
|
|||||||
set_no_inheritance (writepipe_exists, val);
|
set_no_inheritance (writepipe_exists, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *fhandler_pipe::get_proc_fd_name (char *buf)
|
||||||
|
{
|
||||||
|
__small_sprintf (buf, "pipe:[%d]", get_handle ());
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
struct pipeargs
|
struct pipeargs
|
||||||
{
|
{
|
||||||
fhandler_base *fh;
|
fhandler_base *fh;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user