[GHC] #8741: `System.Directory.getPermissions` fails on read-only filesystem

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: Type: bug | Status: new Priority: high | Milestone: Component: | Version: 7.6.3 libraries/directory | Operating System: POSIX Keywords: | Type of failure: Incorrect result Architecture: Unknown/Multiple | at runtime Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | -------------------------------------+------------------------------------- Alain O'Dea reports in an [http://permalink.gmane.org/gmane.comp.lang.haskell.libraries/21078 email] that: {{{ Prelude> System.Directory.getPermissions "/usr/bin/ld" *** Exception: /usr/bin/ld: fileAccess: permission denied (Read-only file system) }}}
That seems wrong.
An `access(*, W_OK)` syscall by design should return `EROFS` on a read- only file system by specification.
This breaks Cabal on SmartOS since `/usr` is read-only by design and Cabal calls `getPermissions "/usr/bin/ld"`.
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: new Priority: high | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by AlainODea): * owner: => AlainODea * difficulty: Unknown => Easy (less than 1 hour) * component: libraries/directory => libraries/unix -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: patch Priority: high | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by AlainODea): * status: new => patch -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: patch Priority: high | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by duncan): So the patch looks ok. I think I would also add ETXTBSY as another alternative, i.e. {{{ (err == eACCES || err == eROFS || err == eTXTBSY) }}} Since according to `access(2)` {{{ ETXTBSY Write access was requested to an executable which is being exe‐ cuted. }}} and `open(2)`: {{{ ETXTBSY pathname refers to an executable image which is currently being executed and write access was requested. }}} So the patch on its own is fine, but looking at `System.Directory.getPermissions` leaves me aghast: {{{ read_ok <- Posix.fileAccess name True False False write_ok <- Posix.fileAccess name False True False exec_ok <- Posix.fileAccess name False False True stat <- Posix.getFileStatus name }}} Four! Four? Four calls to stat? (`access()` is just a C lib function that calls `stat()`.) Surely we can do better than that? One call to stat should be enough. Also, `access` doesn't do quite what we want. What we want to know is "if I tried to read/write/exec/traverse this file/dir, would it work?". But access answerss a subtly different question: {{{ The check is done using the calling process's real UID and GID, rather than the effective IDs as is done when actually attempting an operation (e.g., open(2)) on the file. This allows set-user-ID programs to eas‐ ily determine the invoking user's authority. }}} Well, that's all very good and useful, but it's not what we want here. So yes, ideally we'd do one stat call and work it all out from there. {{{ stat <- Posix.getFileStatus name let mode = Posix.fileMode stat read_ok = -- bit twiddling on mode using constants like Posix.ownerReadMode write_ok = -- etc exec_ok = -- etc }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem
-------------------------------------+-------------------------------------
Reporter: hvr | Owner: AlainODea
Type: bug | Status: patch
Priority: high | Milestone:
Component: libraries/unix | Version: 7.6.3
Resolution: | Keywords:
Operating System: POSIX | Architecture: Unknown/Multiple
Type of failure: Incorrect result | Difficulty: Easy (less than 1
at runtime | hour)
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+-------------------------------------
Comment (by Herbert Valerio Riedel

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: merge Priority: high | Milestone: Component: libraries/unix | Version: 7.6.3 Resolution: | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: patch => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: merge Priority: high | Milestone: 7.8.1 Component: libraries/unix | Version: 7.8.1-rc1 Resolution: | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * version: 7.6.3 => 7.8.1-rc1 * milestone: => 7.8.1 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: closed Priority: high | Milestone: 7.8.1 Component: libraries/unix | Version: 7.8.1-rc1 Resolution: fixed | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Changes (by thoughtpolice): * status: merge => closed * resolution: => fixed Comment: Merged in 7.8 for RC2. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: closed Priority: high | Milestone: 7.8.1 Component: libraries/unix | Version: 7.8.1-rc1 Resolution: fixed | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by AlainODea): Quick curiousity: why is this merged to 7.8 instead of a bugfix on 7.6.3? This makes cabal unusable on SmartOS when the packages being installed need to do native builds since it crashes on getPermissions to /usr/bin/ld. Haskell Platform 2013.2.0.0 has GHC 7.6.3. I think this means I can't use Haskell Platform on SmartOS without manually patching the unix library which seems hackish. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: closed Priority: high | Milestone: 7.8.1 Component: libraries/unix | Version: 7.8.1-rc1 Resolution: fixed | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by duncan): Replying to [comment:8 AlainODea]:
Quick curiousity: why is this merged to 7.8 instead of a bugfix on 7.6.3?
I don't think there's any plan for another 7.6.x release (so no HP either), so there's not a lot of value in doing the extra work to backport it. If it's a particular problem for you and you can patch it then go ahead, it's perfectly reasonable to do so. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: closed Priority: high | Milestone: 7.8.1 Component: libraries/unix | Version: 7.8.1-rc1 Resolution: fixed | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by AlainODea): Replying to [comment:9 duncan]:
Replying to [comment:8 AlainODea]:
Quick curiousity: why is this merged to 7.8 instead of a bugfix on 7.6.3?
I don't think there's any plan for another 7.6.x release (so no HP either), so there's not a lot of value in doing the extra work to backport it. If it's a particular problem for you and you can patch it then go ahead, it's perfectly reasonable to do so.
That makes sense. I'll patch manually. A new Haskell Platform is likely on deck with 7.8 nearing release now anyway so I'll focus my effort on making sure that works on SmartOS instead :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8741: `System.Directory.getPermissions` fails on read-only filesystem
-------------------------------------+-------------------------------------
Reporter: hvr | Owner: AlainODea
Type: bug | Status: closed
Priority: high | Milestone: 7.8.1
Component: libraries/unix | Version: 7.8.1-rc1
Resolution: fixed | Keywords:
Operating System: POSIX | Architecture: Unknown/Multiple
Type of failure: Incorrect result | Difficulty: Easy (less than 1
at runtime | hour)
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+-------------------------------------
Comment (by Austin Seipp

#8741: `System.Directory.getPermissions` fails on read-only filesystem -------------------------------------+------------------------------------- Reporter: hvr | Owner: AlainODea Type: bug | Status: closed Priority: high | Milestone: 7.8.1 Component: libraries/unix | Version: 7.8.1-rc1 Resolution: fixed | Keywords: Operating System: POSIX | Architecture: Unknown/Multiple Type of failure: Incorrect result | Difficulty: Easy (less than 1 at runtime | hour) Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------- Comment (by AlainODea): I have a backport of this fix in the pull request queue for the SmartOS PKGSRC package of GHC 7.6.3. That will resolve it for existing SmartOS users until I get 7.8 working. https://github.com/joyent/pkgsrc-wip/pull/10 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8741#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC