Skip to content

Commit

Permalink
Include SIGKILL. Add GitHub Actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdappollonio committed Dec 14, 2024
1 parent 09cdbd1 commit a1aa0e8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 5 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release Rust Application

on:
release:
types: [created]

permissions:
contents: write

jobs:
release:
name: Release for ${{ matrix.target }}
strategy:
matrix:
include:
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive: linux-arm64
- target: aarch64-apple-darwin
os: macos-latest
archive: darwin-arm64
- target: x86_64-apple-darwin
os: macos-latest
archive: darwin-x86_64
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: linux-x86_64
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: windows-x86_64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- shell: bash
run: |
# Update the version in Cargo.toml
TAG_NAME="${{ github.event.release.tag_name }}"
TAG_NAME="${TAG_NAME#v}"
if [[ "${{ runner.os }}" == "macOS" ]]; then
sed -i"" -e "s/^version = .*/version = \"$TAG_NAME\"/" Cargo.toml
else
sed -i -e "s/^version = .*/version = \"$TAG_NAME\"/" Cargo.toml
fi
- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: gc-rust
archive: $bin-$tag-${{ matrix.archive }}
target: ${{ matrix.target }}
tar: unix
zip: windows
token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Test Rust Application

on:
push:

jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Run tests
run: cargo test
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# `dotenv`

**dotenv** is a small command-line utility that allows you to inject environment variables from a `.env` file into a command's environment before running it. It also supports a "strict" mode that only includes variables from the `.env` file plus a few common whitelist of essential environment variables, like `PATH`, `HOME` or even `SHLVL`.
**`dotenv`** is a small command-line utility that allows you to **inject environment variables from a `.env` file into a command's environment before running it.** It also supports a "strict" mode that only includes variables from the `.env` file without leaking potentially private environment variables, plus a few common whitelist of essential environment variables, like `PATH`, `HOME` or even `SHLVL`.

- [`dotenv`](#dotenv)
- [Features](#features)
Expand All @@ -20,25 +20,40 @@
If an `.env` file is present in the current directory, `dotenv` loads it automatically.

- **Named environments:**
Use `--environment <name>` to load variables from `~/.dotenv/<name>.env`.
Use `--environment <name>` to load variables from `$HOME/.dotenv/<name>.env`.

- **Strict mode:**
Use `--strict` to start the command with only the variables from the `.env` file and a minimal whitelist (like `PATH`, `HOME`, etc.).
The `.env` file itself can enforce strict mode by setting `DOTENV_STRICT=true`.

The `.env` file itself can enforce strict mode by setting `DOTENV_STRICT=true` without needing to specify `--strict`.

- **Transparent command execution:**
After loading the environment variables, `dotenv` executes the specified command, passing all arguments along.

- **Compatibility with commands requiring their own flags:**
Use a double dash (`--`) to signal that subsequent arguments belong to the executed command, not to `dotenv`.

- **Death signal propagation:**
If the parent is killed by a `SIGTERM` or `SIGKILL` signal, the child process is also killed using `PR_SET_PDEATHSIG` *(only available in Linux)*.

## Installation

### Precompiled Binaries

Precompiled binaries for Linux, macOS, and Windows are available on the [Releases page](https://github.com/patrickdappollonio/dotenv/releases).

Download the binary for your platform, then move it to a directory in your `PATH`.
Download the binary for your platform, then move it to a directory in your `$PATH`, or use `install`:

```bash
$ ls
dotenv

# add executable permissions
$ chmod +x dotenv

# install it to /usr/local/bin
$ sudo install -m 755 dotenv /usr/local/bin/dotenv
```

### Rust and Cargo

Expand Down Expand Up @@ -85,7 +100,7 @@ If you prefer custom environment variables, you can overwrite `dotenv`'s default
Any file here named `<name>.env` can be loaded by specifying `--environment <name>` or `-e <name>`:

```bash
$ cat ~/.dotenv/example.env
$ cat $HOME/.dotenv/example.env
FOO=bar

$ dotenv --environment example -- printenv FOO
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ fn main() -> Result<()> {
return Err(Error::last_os_error());
}

// Set the parent-death signal to SIGKILL
if libc::prctl(libc::PR_SET_PDEATHSIG, libc::SIGKILL, 0, 0, 0) != 0 {
return Err(Error::last_os_error());
}

// Double-check parent PID
let ppid = libc::getppid();
if ppid == 1 {
Expand Down

0 comments on commit a1aa0e8

Please sign in to comment.