From cd24077999e1bebf911820096c4dce09576cfcf3 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 27 Mar 2012 18:30:28 +0000 Subject: [PATCH] * fhandler_process.cc (process_tab): Add entry for mountinfo. (format_process_mountstuff): New function, derived from format_process_mounts. Only open another user's user_info shared memory area if the process is owned by another user. Actually access the opened shared user_info to get the right mount table. For other users, don't print remote cygdrive mount points. Print mountinfo or mounts output depending on the bool mountinfo argument. (format_process_mounts): Just call format_process_mountstuff with mountinfo set to false. (format_process_mountinfo): Ditto with mountinfo set to true. * new-features.sgml (ov-new1.7.11): Add mountinfo. --- winsup/cygwin/ChangeLog | 13 +++++++ winsup/cygwin/fhandler_process.cc | 65 ++++++++++++++++++++++++++----- winsup/doc/ChangeLog | 4 ++ winsup/doc/new-features.sgml | 4 ++ 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 0ab179e91..30fde01e3 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2012-03-27 Corinna Vinschen + + * fhandler_process.cc (process_tab): Add entry for mountinfo. + (format_process_mountstuff): New function, derived from + format_process_mounts. Only open another user's user_info shared + memory area if the process is owned by another user. Actually + access the opened shared user_info to get the right mount table. + For other users, don't print remote cygdrive mount points. Print + mountinfo or mounts output depending on the bool mountinfo argument. + (format_process_mounts): Just call format_process_mountstuff with + mountinfo set to false. + (format_process_mountinfo): Ditto with mountinfo set to true. + 2012-03-27 Corinna Vinschen * times.cc (clock_setres): Revert previous change. diff --git a/winsup/cygwin/fhandler_process.cc b/winsup/cygwin/fhandler_process.cc index 12ba292c7..a02df36f6 100644 --- a/winsup/cygwin/fhandler_process.cc +++ b/winsup/cygwin/fhandler_process.cc @@ -27,6 +27,7 @@ details. */ #include "pwdgrp.h" #include "mount.h" #include "tls_pbuf.h" +#include #include #include @@ -51,6 +52,7 @@ static _off64_t format_process_gid (void *, char *&); static _off64_t format_process_ctty (void *, char *&); static _off64_t format_process_fd (void *, char *&); static _off64_t format_process_mounts (void *, char *&); +static _off64_t format_process_mountinfo (void *, char *&); static const virt_tab_t process_tab[] = { @@ -64,6 +66,7 @@ static const virt_tab_t process_tab[] = { _VN ("fd"), FH_PROCESSFD, virt_directory, format_process_fd }, { _VN ("gid"), FH_PROCESS, virt_file, format_process_gid }, { _VN ("maps"), FH_PROCESS, virt_file, format_process_maps }, + { _VN ("mountinfo"), FH_PROCESS, virt_file, format_process_mountinfo }, { _VN ("mounts"), FH_PROCESS, virt_file, format_process_mounts }, { _VN ("pgid"), FH_PROCESS, virt_file, format_process_pgid }, { _VN ("ppid"), FH_PROCESS, virt_file, format_process_ppid }, @@ -1156,7 +1159,7 @@ extern "C" { }; static _off64_t -format_process_mounts (void *data, char *&destbuf) +format_process_mountstuff (void *data, char *&destbuf, bool mountinfo) { _pinfo *p = (_pinfo *) data; user_info *u_shared = NULL; @@ -1164,7 +1167,7 @@ format_process_mounts (void *data, char *&destbuf) _off64_t len = 0; struct mntent *mnt; - if (p->pid != myself->pid) + if (p->uid != myself->uid) { WCHAR sid_string[UNLEN + 1] = L""; /* Large enough for SID */ @@ -1181,26 +1184,58 @@ format_process_mounts (void *data, char *&destbuf) } else u_shared = user_shared; + mount_info *mtab = &u_shared->mountinfo; /* Store old value of _my_tls.locals here. */ int iteration = _my_tls.locals.iteration; unsigned available_drives = _my_tls.locals.available_drives; /* This reinitializes the above values in _my_tls. */ setmntent (NULL, NULL); - while ((mnt = getmntent (NULL))) + /* Restore iteration immediately since it's not used below. We use the + local iteration variable instead*/ + _my_tls.locals.iteration = iteration; + + for (iteration = 0; (mnt = mtab->getmntent (iteration)); ++iteration) { + /* We have no access to the drives mapped into another user session and + _my_tls.locals.available_drives contains the mappings of the current + user. So, when printing the mount table of another user, we check + each cygdrive entry if it's a remote drive. If so, ignore it. */ + if (iteration >= mtab->nmounts && u_hdl) + { + WCHAR drive[3] = { mnt->mnt_fsname[0], L':', L'\0' }; + disk_type dt = get_disk_type (drive); + + if (dt == DT_SHARE_SMB || dt == DT_SHARE_NFS) + continue; + } destbuf = (char *) crealloc_abort (destbuf, len + strlen (mnt->mnt_fsname) + strlen (mnt->mnt_dir) + strlen (mnt->mnt_type) + strlen (mnt->mnt_opts) - + 28); - len += __small_sprintf (destbuf + len, "%s %s %s %s %d %d\n", - mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, - mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno); + + 30); + if (mountinfo) + { + path_conv pc (mnt->mnt_dir, PC_SYM_NOFOLLOW | PC_POSIX); + dev_t dev = pc.exists () ? pc.fs_serial_number () : -1; + + len += __small_sprintf (destbuf + len, + "%d %d %d:%d / %s %s - %s %s %s\n", + iteration, iteration, + major (dev), minor (dev), + mnt->mnt_dir, mnt->mnt_opts, + mnt->mnt_type, mnt->mnt_fsname, + (pc.fs_flags () & FILE_READ_ONLY_VOLUME) + ? "ro" : "rw"); + } + else + len += __small_sprintf (destbuf + len, "%s %s %s %s %d %d\n", + mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, + mnt->mnt_opts, mnt->mnt_freq, mnt->mnt_passno); } - /* Restore old value of _my_tls.locals here. */ - _my_tls.locals.iteration = iteration; + + /* Restore available_drives */ _my_tls.locals.available_drives = available_drives; if (u_hdl) /* Only not-NULL if open_shared has been called. */ @@ -1211,6 +1246,18 @@ format_process_mounts (void *data, char *&destbuf) return len; } +static _off64_t +format_process_mounts (void *data, char *&destbuf) +{ + return format_process_mountstuff (data, destbuf, false); +} + +static _off64_t +format_process_mountinfo (void *data, char *&destbuf) +{ + return format_process_mountstuff (data, destbuf, true); +} + int get_process_state (DWORD dwProcessId) { diff --git a/winsup/doc/ChangeLog b/winsup/doc/ChangeLog index 98c5236aa..e19de178d 100644 --- a/winsup/doc/ChangeLog +++ b/winsup/doc/ChangeLog @@ -1,3 +1,7 @@ +2012-03-27 Corinna Vinschen + + * new-features.sgml (ov-new1.7.11): Add mountinfo. + 2012-03-01 Yaakov Selkowitz * faq-programming.xml (faq.programming.make-execvp): Remove obsolete diff --git a/winsup/doc/new-features.sgml b/winsup/doc/new-features.sgml index d919fb3dc..534b3f9f6 100644 --- a/winsup/doc/new-features.sgml +++ b/winsup/doc/new-features.sgml @@ -18,6 +18,10 @@ creating the cygdrive directory. If Windows claims the drive is unavailable, don't show it in the cygdrive directory listing. + +Add virtual /proc/PID/mountinfo file. + + Raise default stacksize of pthreads from 512K to 1 Meg. It can still be changed using the pthread_attr_setstacksize call.