Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in example due to incompatibility with macOS sandboxing #7

Open
barracuda156 opened this issue Feb 18, 2023 · 6 comments
Open

Comments

@barracuda156
Copy link

* checking examples ... ERROR
Running examples in ‘sfsmisc-Ex.R’ failed
The error most likely occurred in:

> ### Name: Sys.ps
> ### Title: Return Process Status (Unix 'ps') Information
> ### Aliases: Sys.ps Sys.sizes
> ### Keywords: utilities
> 
> ### ** Examples
> 
> (.pid <- Sys.getpid()) ## process ID of current process
[1] 89213
> Sys.sizes(.pid)
Warning in Sys.ps.cmd() :
  Unknown OS [Operating System]; 'ps' may not be compatible
Warning in Sys.ps.cmd() :
  Unknown OS [Operating System]; 'ps' may not be compatible
Warning in Sys.ps(process, c("rss", "vsz")) :
  Dropping invalid field names rss
sh: /bin/ps: Operation not permitted
Warning in system(cmd, intern = !usefile) :
  running command 'ps -p 89213 -o vsz ' had status 126
Error in Sys.ps(process, c("rss", "vsz")) : 
  call returned less than two lines:
Calls: Sys.sizes -> Sys.ps
Execution halted
@barracuda156 barracuda156 changed the title Error in example: possibly due to incompatibility with macOS sandboxing Error in example due to incompatibility with macOS sandboxing Feb 18, 2023
@barracuda156
Copy link
Author

This happens because macOS sandboxing forbids execution of /bin/ps.

@mmaechler
Copy link
Owner

I don't have direct access to a Mac and the Macbuilder does I think work, i.e., is not "sandboxing".
Do you know on how to find out in R if it is running "sandboxed" in this way?

What does

file.access(mode = 1, Sys.which("ps"))

give you on such a sandboxed mac ?

@barracuda156
Copy link
Author

@mmaechler

> file.access(mode = 1, Sys.which("ps"))
/bin/ps 
      0

We have a solution in Macports for such cases, and it works for sfsmisc, but it is Macports-specific (added into portfile, solves the problem):

pre-test {
    # Example uses /bin/ps, which is forbidden by sandboxing.
    append portsandbox_profile " (allow process-exec (literal \"/bin/ps\") (with no-profile))"
}

@mmaechler
Copy link
Owner

> file.access(mode = 1, Sys.which("ps"))
/bin/ps 
      0

Hmm, the above says that /bin/ps does have execute permission...
So it seems to me that macOS is "lying" because you tell me the later /bin/ps is not allowed to execute.

Can you think of another way I can check on macOS, using R's system() or system2() if necessary,
if Sys.which("ps") will be working?

Of course, in the worst case, I probably should use something like try(system(....)) and see if it gives an error or not.
?

@mmaechler
Copy link
Owner

mmaechler commented Feb 20, 2023

@barracuda156 : Can you tell me how this (replacing the current function in pkg sfsmisc) works:

Sys.ps.cmd <- function() {
  sys <- (si <- Sys.info())[["sysname"]]
  if(sys == "Linux") {
    s.rel <- si[["release"]] ## 2013-7: Kurt sees s.rel <- "3.9-1-amd64"
    rel <- c(as.integer(strsplit(s.rel,"[[:punct:]]")[[1]][1:2]) %*% c(1000,1))
    if(is.na(rel)) rel <- 3000
    if(rel >= 2006) "/bin/ps w" ## Linux kernel >= 2.6 (this is true for Ubuntu!)
    else if(rel >= 2002) "/bin/ps --width 1000" ## Linux >= 2.2
    else struct("/bin/ps w", type="BSD")
  }
  else if(sys == "SunOS") "/usr/bin/ps"
  else if(sys == "Darwin") { # macOS
    cmd <- struct("/bin/ps w", type="Darwin/macOS")
    ## test if it *works* (to some extent) {"sandboxed" did not allow /bin/ps to run}
    tmp <- tryCatch(u.sys(cmd, " | grep 'grep'"), error=identity)
    if(!inherits(tmp, "error"))
        cmd
    else
        stop(cmd," is not working: ", conditionMessage(tmp))
  }
  else {
    warning("Unknown OS [Operating System]; 'ps' may not be compatible")
    "ps"
  }
}

@mmaechler
Copy link
Owner

I will close this as "fixed" soon, as I did not get any reply from @barracuda156 about the above fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants