2,356 karma · joined April 27, 2009
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.
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)
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).
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.Otherwise, looks good! Use of "env" and proper quoting are strong signals!
#!/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 $sleepoptAFAIK, 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.
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.)
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.
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.)
Nuke it from orbit, or something like that.
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).
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.
(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....)
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.
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.