HNHacker News
TopNewBestAskShowJobs

PeterWhittaker

2,356 karma · joined April 27, 2009

submissionscomments
PeterWhittaker··on Ask HN: What are your favorite one-liner shell commands you use?
git grep -l foo | sort -u
PeterWhittaker··on Ask HN: What are some cool or underrated tech companies based in Canada?
Self-serving mention of https://sphyrnasecurity.com/ - we're a bootstrapped cybersecurity company with two main product lines: cross-domain hardware and GRC/IRM software.
PeterWhittaker··on Writing Code Was Never the Bottleneck
I'd have to more or less agree with a sibling comment, in the sense that writing the code isn't the hardest part (that's the agreement part) but it's not the easiest, either (that's the disagreement part).

I write a lot of code for highly secured black boxes that break a lot of networking rules: undirectional gateways and guards where two things must be guaranteed: one, no matter what, data can flow in one direction and one direction only, and two, no matter what, with the proviso that we cannot control customer operators, the only data flows permitted are those that have been reviewed by two people with independent roles.

The hardest part is understanding the space, how things need to be, what might work, what might go wrong, how a change here might break something there (and this in a system basically running in old-fashioned SELinux "strict" mode).

(There is only so much experimentation and instrumentation possible, because I need to make things work in that closed, tightly controlled appliance.)

The easiest thing is explaining this to others, at various levels: It’s about knowing what to include in the explanation, what to omit, and which analogies are useful, which are harmful. That all comes from repetition and retrospection.

Writing code is somewhere in the middle: once I understand the problem, the code is usually pretty easy, except, of course, when it isn't because oh, yeah, that.

Fortunately, I have a long legged hound. My entire team knows the value of our DWs, dog walks, or, as a colleague recently called it, Diagnostic Wandering.

Two hours a day in the woods, along the rivers, and much becomes clear. Not all, just much.

The really second hardest part is mentally working through the coding alternatives like an adversary, trying to figure which one is best, or, on the whole, given all the layers of defence, good enough.

PeterWhittaker··on Broken by Design: Systemd
Perhaps the fact that it's been 11 years and systemd works pretty well?
PeterWhittaker··on Starship: A minimal, fast, and customizable prompt for any shell
What am I missing? I went to the site, but I can find nothing to suggest why I might want to use this. Are there examples that I've missed, likely owing to having been heads down chasing a pernicious heisenbug all day?

Given that I do like my shiny prompt, which shows me:

  The result of the last command (in green, red, or purple)
  user@host:currentDirectory
  current branch, if in a repo
with the last line showing summary git status, if in a repo, and background jobs, I suspect I might be their market, but I cannot see a why anywhere.

(Green: Last command good, e.g., exit 0) (Red: Last command non-zero exit, with a special indicator if it was interrupted) (Purple: Last command suspended, and few other things)

PeterWhittaker··on Tell HN: Stop using "dropped" to mean "added"
I fall upon the floor, face contorted in uncontrollable guffaws!
PeterWhittaker··on Rewriting Unix Philosophy for the Post-AI Era
Perhaps because it is a dumb example.

  awk '/foo {print $2}' file
does the same thing, without a pipeline.

If one wanted robust rich pipelines, one could use PowerShell (which I used as my UNIX and Linux shell for a while when I was programming in it everyday as part of dayJob).

PeterWhittaker··on tcpulse: A TCP/UDP load generator that provides fine-grained, flow-level control
Any possibility of using it with diodes? I've used iperf for this (two separate instances), but iperf2 doesn't support this. We've also written our own in Rust, tightly coupled to our needs, but if there are better tools out there, well, we'd be silly not to investigate. Thanks!
PeterWhittaker··on Curate your shell history
I opted for a single history across all sessions on any given host: On my main machine, the first of 54,434 entries is timestamped 2020-08-22:12:39, while on the machine on which I do most development at the moment (it varies from product to product and release to release), the first of 34,771 entries is timestamped 2023-05-08:11:34.

For the curious, the salient .bashrc bits are:

  function _setAndReloadHistory {
      builtin history -a
      builtin history -c
      builtin history -r
  }
  
  # preserve shell history
  set -o history
  # preserve multiline commands...
  shopt -s cmdhist
  # preserve multiline command as literally as possible
  shopt -s lithist
  # reedit failed history substitutions
  shopt -s histreedit
  # enforce careful mode... we'll see how this goes
  shopt -s histverify
  
  # timestamp all history entries
  HISTTIMEFORMAT='%Y-%m-%d:%H:%M '
  
  # not the default, we like to be explicit that we are not using defaults
  HISTFILE=~/.bash_eternal_history
  # preserve all history, forever
  HISTSIZE=-1
  # preserve all history, forever, on disk
  HISTFILESIZE=-1
  # record only one instance of a command repeated after itself
  HISTCONTROL=ignoredups
  
  # preserve history across/between shell sessions...
  # ...when the shell exits...
  shopt -s histappend
  # ...and after every command...
  PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; } _setAndReloadHistory"
EDIT: Remembered just after submitting that since I am on MacOS, I ran the command

  touch ~/.bash_sessions_disable
back on August 22nd, 2020, to prevent Terminal from saving per-session information. I've never cleaned out ~/.bash_sessions, suppose I should, but it hasn't been updated since that day.
PeterWhittaker··on Show HN: I wrote a modern Command Line Handbook
One nit: ^D only exits if the cursor is at the beginning of a line. Enter <space>^D and the session remains.

Otherwise, looks good! Use of "env" and proper quoting are strong signals!

PeterWhittaker··on TIL: timeout in Bash scripts
I tend to do something like this. Normally, I wouldn't include the extra jobs calls and extra echo calls, these are just to show what is happening.

  #!/usr/bin/env bash
  
  runUntilDoneOrTimeout () {
      local -i timeout=0
      OPTIND=1
      while getopts "t:" opt; do
          case $opt in
              t) timeout=$OPTARG;;
          esac
      done
      shift $((OPTIND - 1))
      runCommand="$*"
      $runCommand &
      runPID=$!
      echo checking jobs
      jobs # just to prove there are some
      echo job check complete
      while jobs %- >& /dev/null && ((timeout > 0)); do
          echo "waiting for $runCommand for $timeout seconds"
          sleep 1
          ((timeout--))
      done
      if (( timeout == 0 )); then
          echo "$runCommand timed out"
          kill -9 $runPID
          wait $runPID
      else
          echo "$runCommand completed"
      fi
      echo checking jobs
      jobs # just to prove there are none
      echo job check complete
  }
  
  declare -i timeopt=10
  declare -i sleepopt=100
  OPTIND=1
  while getopts "t:s:" opt; do
      case $opt in
          t) timeopt=$OPTARG;;
          s) sleepopt=$OPTARG;;
      esac
  done
  shift $((OPTIND - 1))
  runUntilDoneOrTimeout -t $timeopt sleep $sleepopt
PeterWhittaker··on Show HN: 1 min workouts for people who sit all day
It would be cool to be able to pick a start time and a reminder period: starting at 9am, e.g., prompt me to exercise every 45 minutes, with a defer option.
PeterWhittaker··on Show HN: 1 min workouts for people who sit all day
Does X10 for plank and jogging mean 10 seconds, or get into the position, hold, and return to rest 10 times?
PeterWhittaker··on Show HN: 1 min workouts for people who sit all day
Also, it's lose your streak, not loose.
PeterWhittaker··on Goethe's Faustian Life
> I've never heard of queen Victoria having Habsburg ancestry

AFAIK, the only Hapsburg to come near her throne was Phillip II of Spain, husband of Queen Mary (16th C).

Ah! I just checked, and the article now contains the following: Correction: This article has been updated to reflect that Queen Victoria was of Hanoverian, not Hapsburg, descent.

PeterWhittaker··on Goethe's Faustian Life
> Man has a natural inclination to worship something. For most of human history, that has been the divine/supernatural/metaphysical. Nowadays, rationalism and materialism have become the main objects of worship. But rationalism and materialism do not have answers to the existential questions and crises that humans face.

This paintbrush is far too wide. I think many of us have, at least from time to time, felt something between an inclination and need to worship, and many of us feel that all their lives, but I would assert (and die upon this hill) that many lose that [inclination..need].

Personally, I felt it most strongly in my late teens up until my mid twenties when my questioning of everything was at its strongest and my, uh, personality? resolve? acceptance? not sure... was insufficient counter. Like The Stranglers said, I wish(ed) I was a believer, they spend less time being sad.

Eventually, my mechanistic reductionist self made peace with both the many unknowns and the utter ridiculousness of life. The universe is a cold, harsh place, and even our little goldilocks corner of it has an overwhelming imbalance to it, a ruthless "unfairness", at least when viewed through the lens of a humane equity.

Believing in some greater thing does nothing to resolve or address that, though some take solace in believing in some teleology or ultimate reward. Or punishment.

Neither does anything for me and neither is necessary to my life.

> Similar to Christ saying that "man cannot live on bread alone", man cannot live on materialism alone - spiritual nourishment is a very real and necessary thing.

Hard disagree. You might say that my deep breaths and long stares in the woods are spiritual, but I will respectfully disagree. I do not worship those woods, or the lakes or camping with friends or moments of great discovery or satisfaction, whether there or at work, and I find nothing "spiritual" in them.

I accept and rejoice in their being internal affectations, basal responses, and I am quite happy with my reptilian brain. I don't need any sense of anything external or greater or other to celebrate moments of beauty or discovery or to condemn moments of cruelty and injustice.

Please do remember that there are other very different views of the world.

Materialism and our reptile brains are all we've got. I'm content with that. (Unless and until I watch the news, but that is another subject altogether.)

PeterWhittaker··on Variadic Switch
I find the article very interesting and informative but, honestly, of all of the approaches, I find the basic switch to be the most readable and likely the most maintainable, at least for this case.
PeterWhittaker··on Why our waistlines expand in middle age: aging stem cells shift into overdrive
Bwa ha ha ha ha, no.
PeterWhittaker··on io_uring based rootkit can bypass syscall-focused Linux security tools
True, but even those calls require appropriate permissions, and will fail if the program lacks said perms. (Just to emphasize the point that the original article doesn't provide a means of privilege escalation, nor exploit a vulnerability.)
PeterWhittaker··on io_uring based rootkit can bypass syscall-focused Linux security tools
This isn't a "bypass" (and it certainly isn't "terrifying", as reported on /. and elsewhere).

1. The program can only do what it is permitted to do: io_uring just reduces the number of system calls required - but since it works on file descriptors, you must have already acquired the fd in the correct mode.

2. Some monitoring systems hook into system calls and report when they are used: io_uring and opcodes mean the program can perform actions without being noticed by these programs...

3. ...which can report on the use of the system calls that set up io_uring access...

4. ...and could report on the resuting I/O by other means.

I won’t go so far as to say this is a nothing burger, but it feels close.

PeterWhittaker··on Advanced Shell Scripting with Bash (2006) [pdf]
I will definitely check out the sudo-bash deck, thanks!
PeterWhittaker··on Advanced Shell Scripting with Bash (2006) [pdf]
Great presentation. I've been writing bash for waaaay too long, and, while I nodded and said yup, yup, a few times, I also learned some new tricks, so thank you!

The social graces having been observed, if you were to update this presentation to reflect modern bash, and especially reference variables, what would be your top 3 additions?

(I am a big fan of reference variables. They make it possible to, among other things, do some funky things that would otherwise require liberal use of eval, which I eschew. Figuring out how to ensure that the target of a reference variable was in fact an associative array while running under `set -u` was a trick of which I am proud. Note: what I did works and isn't totally ugly, there may be a better way, YMMV, IANAL, etc.)

Second Q, if you will permit: Given the memory leaks in associative array management that have been corrected over the last several years, what are your thoughts on a) whether or not bash should have ever gone that route, and, potentially more controversially, b) the current state of bash maintenance?

(I'm not going to ask about embedding multiple levels of ${...#...} or ${...#...}, because even if it worked, readability would tend to 0 very, very quickly. I'd rather be repetitive and readable and maintainable. Well. Most of the time.)

PeterWhittaker··on Advanced Shell Scripting with Bash (2006) [pdf]
That. Is. Evil.

Nuke it from orbit, or something like that.

PeterWhittaker··on Intuiting TLS
No, though HMACs can play a role. It was a protocol developed specifically for establishment of secure, encrypted, authenticated, and integrity-protected sessions.

I've been racking my brain trying to remember (rarely accessed memories from ~27 years ago). The basic challenge is that unless authenticity, key exchange, and integrity are managed simultaneously during session establishment, there are attacks possible against whatever was omitted. There was a protocol developed at that time that did all of the above as part of session establishment, but I don't remember it really taking off (IIRC, it was patent-encumbered, and that was an obstacle to adoption).

PeterWhittaker··on Intuiting TLS
Interest article, but overlooks SPEKE, which solves problem #1.

There is another protocol for authenticated and integrity protected key exchange, one that solved both the problem of authenticity and integrity attacks, but I cannot recall it.

Hoping someone else remembers it.

PeterWhittaker··on Val Kilmer, star of Top Gun and The Doors, dies aged 65
The Suzuki Method of violin training, perhaps: https://en.m.wikipedia.org/wiki/Suzuki_method
PeterWhittaker··on Introduction to System Programming in Linux (Early Access)
There are applications where ncurses is still a great approach for a controlled, structured UI, e.g., certain security appliances with complex configurations where web UIs, e.g., are not, by default, permissible.

(I spend a lot of time in ncurses on our appliances. We are looking at a web interface, but it will have to be homegrown and SELinux aware. It's a ways out yet....)

PeterWhittaker··on Rust Any part 3: we have upcasts
If Bar inherited from Foo, Bar would have Foo's methods. So if you implemented Bar for Gum, Gum would get Bar and Foo.

But Bar requiring Foo means that if you want to use Gum in a place that expects Bar, Gum must have both Bar's methods and Foo's methods.

In some cases, you might be able to derive some of those.

PeterWhittaker··on Ogres Are Cool
...as does parfait.
PeterWhittaker··on Stupid Smart Pointers in C
1) 2018

2) I recently discovered the implementation of free_on_exit won't work if called directly from main if gcc aligns the stack. In this case, main adds padding between the saved eip and the saved ebp, (example). I think this can be fixed some tweaking, and will update this article when it is fixed.

I do not believe the article was updated, suggesting that the "tweaking" was far more complex than the author expected...

...which doesn't surprise me, because the overall tone is one of a clever but far-less-experienced-than-they-think programmer having what they think is a flash of insight and realizing thereby they can solve simply a problem that has plagued the industry and community for decades.

← PreviousPage 4 of 34Next →