Skip to content

First draft of umask and ulimit cmdlets - #183

Closed
James Truher (JamesWTruher) wants to merge 1 commit into
PowerShell:masterfrom
JamesWTruher:Umask-Ulimit
Closed

James Truher (JamesWTruher) wants to merge 1 commit into
PowerShell:masterfrom
JamesWTruher:Umask-Ulimit

Conversation

@JamesWTruher

Copy link
Copy Markdown
Contributor

No description provided.

```powershell
PS> get-umask

Umask Symbolic AsDecimal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rob Holt (@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>]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@rjmholt Rob Holt (rjmholt) May 29, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rob Holt (@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>]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Soft and Hard might be worthy aliases for Current and Maximum

None
```

#### Set-Ulimit Examples

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#### Set-Ulimit Examples
#### Get-Ulimit Examples

@JamesWTruher

Copy link
Copy Markdown
Contributor Author

I'm closing this RFC because I'm going to release the via the PowerShell gallery. After it has some usage data we can make a determination as to whether it should be in the product.

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

Successfully merging this pull request may close these issues.

4 participants