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

First draft of umask and ulimit cmdlets #183

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
4 participants
@JamesWTruher
Copy link
Member

commented May 24, 2019

No description provided.

```powershell
PS> get-umask
Umask Symbolic AsDecimal

This comment has been minimized.

Copy link
@mklement0

mklement0 May 27, 2019

Contributor

Glad to see this is getting tackled.

I don't think there's much value in including AsDecimal, because even the octal number is typically conceived of as an array of digits rather than a single number.

Set-Umask
SYNTAX
Set-Umask [-Umask] <string> [<CommonParameters>]

This comment has been minimized.

Copy link
@mklement0

mklement0 May 27, 2019

Contributor

I suggest not duplicating the word umask in the parameter name; just like it is Set-Content -Value - not Set-Content -Content - the generic term value should suffice.

I also wonder whether it's worth having a separate parameter for the symbolic argument, given that a single parameter could accept both forms and just distinguish by the string's contents.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

I think if there's an AsDecimal formatter, there should be an argument that takes an int

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

An alternative to the -Symbolic parameter might be a parameter set of three parameters -User, -Group and -Other, which avoids having to encode and parse an argument DSL uncharacteristic in PowerShell


## Umask behavior

A function `Umask` may be written to mimic the behavior of the Unix umask utility.

This comment has been minimized.

Copy link
@mklement0

mklement0 May 27, 2019

Contributor

Note that not writing such functions (umask, ulimit) will implicitly invoke the Get-UMask and Get-Ulimit cmdlets when the user submits umask and ulimit on Linux (where no external-utility implementations exists), due to PowerShell falling back to a Get-prefixed command (default-verb logic) if no command is found with the exact name specified.

Also, in the case of umask, Unix users will likely expect support for the single-letter options supported by the Bash builtin, such as -n for -Resource NumberOfOpenFiles

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

In fact we discussed exactly this. The expectation of bash-compatible options (and the difficulty of implementing those as a PowerShell function) seems to motivate against it

This comment has been minimized.

Copy link
@mklement0

mklement0 May 29, 2019

Contributor

@rjmholt, I agree that it's generally not worth emulating the CLI options of other shell's builtins (or a platform's standard utilities).
The tricky thing here is that we have an unfortunate name collision on Linux, where executing umask will, in fact, invoke Get-UMask (due to the absence of an external umask command, combined with the default-verb logic), which will result in output that differs from Bash's umask - but perhaps that won't be a big problem in practice.

Set-Ulimit [-ResourceInfo] <Platform+ResourceLimitInfo> [<CommonParameters>]
Set-Ulimit -Resource {CpuTime | FileSize | DataSegmentSize | StackSize | CoreFileSize | AddresSpaceSize | MemoryAddressSize |
NumberOfProcesses | NumberOfOpenFiles} [-Current <ulong>] [-Maximum <ulong>] [<CommonParameters>]

This comment has been minimized.

Copy link
@mklement0

mklement0 May 27, 2019

Contributor

I think it's worth explaining how -Current relates to -Maximum.

Presumably, -Current is what https://ss64.com/bash/ulimit.html calls the soft limit, and -Maximum corresponds to the hard limit.

Generally, the help will have to explain this mapping.

Note that Bash's ulimit by default sets both limits.
If we want to deviate from that by only setting the soft (-Current) limit by default, we should make that clear (I think it makes more sense, but it is a departure).

This comment has been minimized.

Copy link
@mklement0

mklement0 May 27, 2019

Contributor

Also,

values are in 1024-byte increments, except for '-t', which is in seconds, '-p', which is in units of 512-byte blocks, and '-n' and '-u', which are unscaled values.

  • consider supporting the symbolic soft, hard and unlimited values that Bash's ulimit supports.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

Soft and Hard might be worthy aliases for Current and Maximum

The `ulimit` cmdlets do not totally replicate the Unix behavior.
Specifically, resources which are not alterable via the `setrlimit` API will not be supported.
The pipe size resource is not retrievable or alterable with the ulimit cmdlets.
The resources available will vary based on the platform, the following table shows what resources shall be returned based on their platform:

This comment has been minimized.

Copy link
@iSazonov

iSazonov May 28, 2019

Contributor

On Windows we have Windows System Resource Manager and we could create ported cmdlet.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

Given the UNIX-specific nature of ulimit, it might be best to have this as the underlying primitive rather than try to balance multiple APIs

RFC: XXXX
Author: Jim Truher
Status: Draft
Area: Strict Mode

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

What does Area: Strict Mode mean?

# Umask and Ulimit

Unix shells have a number of built in commands which are used to configure the shell's behavior.
This RFC proposes two new areas of control for PowerShell, namely, `umask` and `ulimit`

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member
Suggested change
This RFC proposes two new areas of control for PowerShell, namely, `umask` and `ulimit`
This RFC proposes two new areas of control for PowerShell on *nix, namely, the `umask` and `ulimit` APIs.
## UMASK

On Linux and MacOS systems when a file is created, it is created with a specific set of permissions.
This is known as _file mode creation mask_.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member
Suggested change
This is known as _file mode creation mask_.
This is known as the _file mode creation mask_.

On Linux and MacOS systems when a file is created, it is created with a specific set of permissions.
This is known as _file mode creation mask_.
These permissions are set via the system api `umask` and are usually altered by the user with the `umask` command.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member
Suggested change
These permissions are set via the system api `umask` and are usually altered by the user with the `umask` command.
These permissions are set via the system api `umask` and are usually altered by the user in the shell with the `umask` command.
On Linux and MacOS systems when a file is created, it is created with a specific set of permissions.
This is known as _file mode creation mask_.
These permissions are set via the system api `umask` and are usually altered by the user with the `umask` command.
In Unix shells, the `umask` command is built in to the shell, because the new value exists only for as long as the process that started it and any child process.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member
Suggested change
In Unix shells, the `umask` command is built in to the shell, because the new value exists only for as long as the process that started it and any child process.
In Unix shells, the `umask` command is a builtin rather than an executable, because the new value applies only to (and for the duration of) the process calling the API and its subprocesses.
Set-Umask
SYNTAX
Set-Umask [-Umask] <string> [<CommonParameters>]

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

I think if there's an AsDecimal formatter, there should be an argument that takes an int

Set-Umask
SYNTAX
Set-Umask [-Umask] <string> [<CommonParameters>]

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

An alternative to the -Symbolic parameter might be a parameter set of three parameters -User, -Group and -Other, which avoids having to encode and parse an argument DSL uncharacteristic in PowerShell

* A string which represents the umask as an octal number
* Symbolic
* a string which represents the umask as a comma separated group indicating the permissions of the file owner, group, and other.

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

I think we should discuss what the allowed strings are for each parameter and what the behaviours are when bad strings are given.

A few cases arise in my mind because of the very open spectrum of possible string inputs (vs ints for example):

  • '002' vs '2'
  • Giving the argument as a decimal int like 167, coercing that to the string '167' and actually ending up with the decimal permissions 119. The problem is that a literal decimal will succeed because it gets stringified, but if anyone expects an int to work and use a variable to do arithmetic on it, strange things will happen because of the base change.
  • A generic bad string like 'banana'
  • Partial formations of the symbolic string like 'o= or 'x=' or 'u=b'

Essentially I'm thinking that passing strings allows a whole bunch of inputs that aren't valid and we're using them in both cases with a special parser for a sublanguage. I'm not saying we should definitely be using a different type of input instead, but I think we should discuss and define:

  • the language of strings expected by each parameter
  • what the behaviours are when a badly formed string input is given
  • what the alternative implementations of types for parameters might look like

Another thought that just struct me is that it's quite possible for us to define a new type (a struct perhaps) that will coerce from an int or a string equally, or can be constructed more explicitly.

This comment has been minimized.

Copy link
@mklement0

mklement0 May 29, 2019

Contributor

@rjmholt

Given how unhelpful it is to conceive of and formulate the value as a decimal, I don't think we need to worry about decimal input.

Good point about malformed strings; as a data point, Bash's ulimit quietly ignores empty values such as u= and accepts multiple values such as u=rr.

On the flip side, it balks at whitespace and invalid characters, on either side of the =, including the uppercase variants of u, o, and g.

"Balking" means that an error is emitted to stderr, and the exit code is set to 1.

In the world of PowerShell that probably corresponds to a statement-terminating error (you're trying to set a single value, and the input is invalid).

If we implement the separate -User, -Group and -Other parameters (which makes sense to me), you implicitly get a structure of sorts, via splatting, which perhaps is enough:

$umask = @{
  User = 'rw'
  Group = 'r'
  Other = 'r'
}
Set-Umask @umask

Just to spell it out: The separate parameters should have set-a-value-for-that-principal-only logic, not default-the-unspecified-values to-0-logic, the way the symbolic value does it (but not the octal one).

Set-Ulimit [-ResourceInfo] <Platform+ResourceLimitInfo> [<CommonParameters>]
Set-Ulimit -Resource {CpuTime | FileSize | DataSegmentSize | StackSize | CoreFileSize | AddresSpaceSize | MemoryAddressSize |
NumberOfProcesses | NumberOfOpenFiles} [-Current <ulong>] [-Maximum <ulong>] [<CommonParameters>]

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member

Soft and Hard might be worthy aliases for Current and Maximum

None
```

#### Set-Ulimit Examples

This comment has been minimized.

Copy link
@rjmholt

rjmholt May 29, 2019

Member
Suggested change
#### Set-Ulimit Examples
#### Get-Ulimit Examples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.