diff options
-rw-r--r-- | public/arch-systemd.md | 44 | ||||
-rw-r--r-- | public/bash-arrays.md | 2 | ||||
-rw-r--r-- | public/emacs-shells.md | 4 | ||||
-rw-r--r-- | public/fd_printf.md | 3 | ||||
-rw-r--r-- | public/fs-licensing-explanation.md | 2 | ||||
-rw-r--r-- | public/java-segfault-redux.md | 2 | ||||
-rw-r--r-- | public/java-segfault.md | 4 | ||||
-rw-r--r-- | public/pacman-overview.md | 4 | ||||
-rw-r--r-- | public/rails-improvements.md | 2 | ||||
-rw-r--r-- | public/what-im-working-on-fall-2014.md | 2 | ||||
-rw-r--r-- | public/x11-systemd.md | 210 |
11 files changed, 138 insertions, 141 deletions
diff --git a/public/arch-systemd.md b/public/arch-systemd.md index 3ada087..7f6de00 100644 --- a/public/arch-systemd.md +++ b/public/arch-systemd.md @@ -34,27 +34,27 @@ there is compatibility for the variables that used to be there, but that is going away. [^1]: - *I* don't think it's bloated, but that is the criticism. - Basically, I discount any argument that uses "bloated" without - backing it up. I was trying to say that it takes a lot of heat - for being bloated, and that there is be some truth to that (the - systemd-fsck and syslog comments), but that these claims are - largely unsubstantiated, and more along the lines of "I would have - done it differently". Maybe your ideas are better, but you - haven't written the code. - - I personally don't have an opinion either way about SysV-init vs - systemd. I recently migrated my boxes to systemd, but that was - because the SysV init scripts for NFSv4 in Arch are problematic. I - suppose this is another **advantage** I missed: *people generally - consider systemd "units" to be more robust and easier to write - than SysV "scripts".* - - I'm actually not a fan of either. If I had more time on my hands, - I'd be running a `make`-based init system based on a research - project IBM did a while ago. So I consider myself fairly - objective; my horse isn't in this race. + *I* don't think it's bloated, but that is the criticism. + Basically, I discount any argument that uses "bloated" without + backing it up. I was trying to say that it takes a lot of heat + for being bloated, and that there is be some truth to that (the + systemd-fsck and syslog comments), but that these claims are + largely unsubstantiated, and more along the lines of "I would have + done it differently". Maybe your ideas are better, but you + haven't written the code. + + I personally don't have an opinion either way about SysV-init vs + systemd. I recently migrated my boxes to systemd, but that was + because the SysV init scripts for NFSv4 in Arch are problematic. I + suppose this is another **advantage** I missed: *people generally + consider systemd "units" to be more robust and easier to write + than SysV "scripts".* + + I'm actually not a fan of either. If I had more time on my hands, + I'd be running a `make`-based init system based on a research + project IBM did a while ago. So I consider myself fairly + objective; my horse isn't in this race. [^2]: - You can still have `USEDMRAID`, `USELVM`, `interface`, `address`, - `netmask`, and `gateway`. But those are minor. + You can still have `USEDMRAID`, `USELVM`, `interface`, `address`, + `netmask`, and `gateway`. But those are minor. diff --git a/public/bash-arrays.md b/public/bash-arrays.md index bf27dcb..4f47718 100644 --- a/public/bash-arrays.md +++ b/public/bash-arrays.md @@ -311,7 +311,7 @@ Did you notice what was inconsistent? The variables `$*`, `$@`, and <td><code>"${#}"</code></td> <td>→</td> <td>length-1</td> - </tr> + </tr> </tbody> </table> diff --git a/public/emacs-shells.md b/public/emacs-shells.md index 638ddbb..3e52804 100644 --- a/public/emacs-shells.md +++ b/public/emacs-shells.md @@ -33,7 +33,7 @@ me). There are two modes of operation: * `(term-escape-char) C-j` switches to line mode. * line mode: Editing is done like in a normal Emacs buffer, `<enter>` sends the current line to the shell. This is useful for working with - a program's output. + a program's output. * `C-c C-k` switches to char mode. This mode is activated with @@ -64,7 +64,7 @@ highlighting on the currently being typed command. Ncurses programs will of course not work. This mode is activated with: M-x shell - + eshell-mode ----------- diff --git a/public/fd_printf.md b/public/fd_printf.md index 85ebde4..51e16aa 100644 --- a/public/fd_printf.md +++ b/public/fd_printf.md @@ -38,9 +38,8 @@ to others: return len; } - It is a version of `printf` that prints to a file descriptor—where `fprintf` prints to a `FILE*` data structure. The appeal of this is that `FILE*` I/O is buffered—which means mixing -it with raw file descriptor I/O is going to produce weird results. +it with raw file descriptor I/O is going to produce weird results. diff --git a/public/fs-licensing-explanation.md b/public/fs-licensing-explanation.md index a8ef5ac..9bed879 100644 --- a/public/fs-licensing-explanation.md +++ b/public/fs-licensing-explanation.md @@ -13,7 +13,7 @@ This is based on a post on [reddit][1], published on 2013-02-21. > Foundation Inc". How can software be both licensed under GNU and > copyrighted to a single group? It was my understanding that once > code became free it didn't belong to any particular group or -> individual. +> individual. > > [LiveCode is GPLv3, but also sells non-free licenses] Can you really > have the same code under two conflicting licenses? Once licensed diff --git a/public/java-segfault-redux.md b/public/java-segfault-redux.md index cc4254d..be403ba 100644 --- a/public/java-segfault-redux.md +++ b/public/java-segfault-redux.md @@ -189,7 +189,7 @@ to this: getWidth(); // bogus call to keep `this` around return ret; } - + Yeah. After spending weeks wading through though thousands of lines of Java, C, and C++, a bogus call to a method I didn't care about was the fix. diff --git a/public/java-segfault.md b/public/java-segfault.md index 295ef48..7a2d4c3 100644 --- a/public/java-segfault.md +++ b/public/java-segfault.md @@ -91,7 +91,7 @@ like: // `this` may now be garbage collected return child.somethingElse(var); // segfault comes here } - + Where the destructor method of `this` calls a method that will `free()` native memory that is also accessed by `child`; if `this` is garbage collected before `child.somethingElse()` runs, the backing @@ -111,7 +111,7 @@ around until after we were also done with `child`: this.getSize(); // bogus call to keep `this` around return ret; } - + Yeah. After spending weeks wading through though thousands of lines of Java, C, and C++, a bogus call to a method I didn't care about was the fix. diff --git a/public/pacman-overview.md b/public/pacman-overview.md index 6cee805..4dc2696 100644 --- a/public/pacman-overview.md +++ b/public/pacman-overview.md @@ -36,11 +36,9 @@ To give a brief explanation of cover the "high-level" operations, and which databases they deal with: * "Q" Queries "the database" of locally installed packages. - - * "S" deals with "package databases", and Syncing "the database" with + * "S" deals with "package databases", and Syncing "the database" with them; meaning it installs/updates packages that are in package databases, but not installed on the local system. - * "R" Removes packages "the database"; removing them from the local system. diff --git a/public/rails-improvements.md b/public/rails-improvements.md index c87c093..02a862c 100644 --- a/public/rails-improvements.md +++ b/public/rails-improvements.md @@ -20,7 +20,7 @@ the changes to take effect. Adding the following lines to your [`config/application.rb`][application.rb] will allow it to automatically load and reload files from the `lib/` directory. You -can of course change this to whichever directory/ies you like. +can of course change this to whichever directory/ies you like. module YourApp class Application < Rails::Application diff --git a/public/what-im-working-on-fall-2014.md b/public/what-im-working-on-fall-2014.md index a18b4b1..5f7debf 100644 --- a/public/what-im-working-on-fall-2014.md +++ b/public/what-im-working-on-fall-2014.md @@ -119,7 +119,7 @@ I've got several other projects that I'm putting on hold for a while. compiler bugs that no longer exist (which I guess means that *no one* has tried to build it from source after it was originally published). I've been working on-and-off on this for more than a - year. My favorite part of it was writing a + year. My favorite part of it was writing a [sed script](/dump/jflex2jlex.sed.txt) that translates a JFlex grammar specification into a JLex grammar, which is used to bootstrap JFlex; its both gross and delightful at the diff --git a/public/x11-systemd.md b/public/x11-systemd.md index 6c37895..a24a49b 100644 --- a/public/x11-systemd.md +++ b/public/x11-systemd.md @@ -23,11 +23,11 @@ This means that all of my graphical units take `DISPLAY` as an `@` argument. To get this to all work out, this goes in each `.service` file, unless otherwise noted: - [Unit] - After=X11@%i.target - Requisite=X11@%i.target - [Service] - Environment=DISPLAY=%I + [Unit] + After=X11@%i.target + Requisite=X11@%i.target + [Service] + Environment=DISPLAY=%I We'll get to `X11@.target` later, what it says is "I should only be running if X11 is running". @@ -47,12 +47,12 @@ Xorg requires a TTY to run on; if we log in to a TTY with `logind`, it will give us the `XDG_VTNR` variable to tell us which one we have, so I pass this to `X` in [my `.xserverrc`][X11/serverrc]: - #!/hint/sh - if [ -z "$XDG_VTNR" ]; then - exec /usr/bin/X -nolisten tcp "$@" - else - exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR - fi + #!/hint/sh + if [ -z "$XDG_VTNR" ]; then + exec /usr/bin/X -nolisten tcp "$@" + else + exec /usr/bin/X -nolisten tcp "$@" vt$XDG_VTNR + fi This was the default for [a while][arch-addvt] in Arch, to support `logind`, but was [later removed][arch-delvt] in part because `startx` @@ -65,21 +65,21 @@ So I copy/pasted it into my user `xserverrc`. That's the boring part, though. Where the magic starts happening is in [my `.xinitrc`][X11/clientrc]: - #!/hint/sh - - if [ -z "$XDG_RUNTIME_DIR" ]; then - printf "XDG_RUNTIME_DIR isn't set\n" >&2 - exit 6 - fi - - _DISPLAY="$(systemd-escape -- "$DISPLAY")" - trap "rm -f $(printf '%q' "${XDG_RUNTIME_DIR}/x11-wm@${_DISPLAY}")" EXIT - mkfifo "${XDG_RUNTIME_DIR}/x11-wm@${_DISPLAY}" - - cat < "${XDG_RUNTIME_DIR}/x11-wm@${_DISPLAY}" & - systemctl --user start "X11@${_DISPLAY}.target" & - wait - systemctl --user stop "X11@${_DISPLAY}.target" + #!/hint/sh + + if [ -z "$XDG_RUNTIME_DIR" ]; then + printf "XDG_RUNTIME_DIR isn't set\n" >&2 + exit 6 + fi + + _DISPLAY="$(systemd-escape -- "$DISPLAY")" + trap "rm -f $(printf '%q' "${XDG_RUNTIME_DIR}/x11-wm@${_DISPLAY}")" EXIT + mkfifo "${XDG_RUNTIME_DIR}/x11-wm@${_DISPLAY}" + + cat < "${XDG_RUNTIME_DIR}/x11-wm@${_DISPLAY}" & + systemctl --user start "X11@${_DISPLAY}.target" & + wait + systemctl --user stop "X11@${_DISPLAY}.target" There are two contracts/interfaces here: the `X11@DISPLAY.target` systemd target, and the `${XDG_RUNTIME_DIR}/x11-wm@DISPLAY` named @@ -95,7 +95,7 @@ window manager exits, the pipe will get closed, sending EOF to the The window manager (WMII) is made to have the pipe opened by executing it this way in [its `.service` file][wmii@.service]: - ExecStart=/usr/bin/env bash -c 'exec 8>${XDG_RUNTIME_DIR}/x11-wm@%I; exec wmii' + ExecStart=/usr/bin/env bash -c 'exec 8>${XDG_RUNTIME_DIR}/x11-wm@%I; exec wmii' which just opens the file on file descriptor 8, then launches the window manager normally. The only further logic required by the @@ -103,24 +103,24 @@ window manager with regard to the pipe is that in the window manager [configuration][wmii/config.sh], I should close that file descriptor after forking any process that isn't "part of" the window manager: - runcmd() ( - ... - exec 8>&- # xinit/systemd handshake - ... - ) + runcmd() ( + ... + exec 8>&- # xinit/systemd handshake + ... + ) So, back to the `X11@DISPLAY.target`; I configure what it "does" with symlinks in the `.requires` and `.wants` directories: <ul class=tree><li>[.config/systemd/user/][systemd/user] -* [X11@.target][] -* [X11@.target.requires][]/ + * [X11@.target][] + * [X11@.target.requires][]/ + wmii@.service -> ../[wmii@.service][] -* [X11@.target.wants][]/ + * [X11@.target.wants][]/ + xmodmap@.service -> ../[xmodmap@.service][] + xresources-dpi@.service -> ../[xresources-dpi@.service][] - - doodle + - doodle + xresources@.service -> ../[xresources@.service][] </li></ul> @@ -154,9 +154,9 @@ isn't. Anyway, Mozilla's change drove me to to create a display resolution. Disclaimer: I have no idea if it works if the X server has multiple displays (with possibly varying resolution). - #!/usr/bin/env bash - dpi=$(LC_ALL=C xdpyinfo|sed -rn 's/^\s*resolution:\s*(.*) dots per inch$/\1/p') - xrdb -merge <<<"Xft.dpi: ${dpi}" + #!/usr/bin/env bash + dpi=$(LC_ALL=C xdpyinfo|sed -rn 's/^\s*resolution:\s*(.*) dots per inch$/\1/p') + xrdb -merge <<<"Xft.dpi: ${dpi}" Since we want XRDB to be set up before any other programs launch, we give both of the `xresources` units `Before=X11@%i.target` (instead of @@ -174,7 +174,7 @@ I've stuck them in a directory `wmii@.service.wants`: <ul class=tree><li>[.config/systemd/user/][systemd/user] -* [wmii@.service.wants][]/ + * [wmii@.service.wants][]/ + dunst@.service -> ../[dunst@.service][] # a notification daemon + lxpanel@.service -> ../[lxpanel@.service][] # a system panel + rbar@97_acpi.service -> ../[rbar@.service][] # wmii stuff @@ -189,7 +189,7 @@ and call it a day (and I did for a while). But, I like to have [my WMII configuration][wmii/config.sh] stick this in the WMII [`/rules`][wmii/rules]: - /panel/ tags=/.*/ floating=always + /panel/ tags=/.*/ floating=always Unfortunately, for this to work, `lxpanel` must be started _after_ that gets inserted into WMII's rules. That wasn't a problem @@ -199,26 +199,26 @@ way of notifying systemd that WMII's fully started, and it's safe to start `lxpanel`. So, I stuck this in [my WMII `.service` file][wmii@.service]: - # This assumes that you write READY=1 to $NOTIFY_SOCKET in wmiirc - Type=notify - NotifyAccess=all + # This assumes that you write READY=1 to $NOTIFY_SOCKET in wmiirc + Type=notify + NotifyAccess=all and this in [my WMII configuration][wmii/wmiirc]: - systemd-notify --ready || true + systemd-notify --ready || true Now, this setup means that `NOTIFY_SOCKET` is set for all the children of `wmii`; I'd rather not have it leak into the applications that I start from the window manager, so I also stuck `unset NOTIFY_SOCKET` after forking a process that isn't part of the window manager: - runcmd() ( - ... - unset NOTIFY_SOCKET # systemd - ... - exec 8>&- # xinit/systemd handshake - ... - ) + runcmd() ( + ... + unset NOTIFY_SOCKET # systemd + ... + exec 8>&- # xinit/systemd handshake + ... + ) Unfortunately, because of a couple of [bugs][sd-slash] and [race conditions][sd-esrch] in systemd, `systemd-notify` isn't @@ -238,7 +238,7 @@ getting EOF from the `UNIX-SENDTO` end will ever be faster than the systemd manager from handling the datagram that got sent. Which is to say, "we work around the race condition by being slow and shitty." - socat STDIO UNIX-SENDTO:"$NOTIFY_SOCKET" <<<READY=1 || true + socat STDIO UNIX-SENDTO:"$NOTIFY_SOCKET" <<<READY=1 || true But, I don't like that. I'd rather write my WMII configuration to the world as I wish it existed, and have workarounds encapsulated @@ -247,46 +247,46 @@ elsewhere; So, I wrote a `systemd-notify` compatible [function][wmii/workarounds.sh] that ultimately calls `socat`: - ## - # Just like systemd-notify(1), but slower, which is a shitty - # workaround for a race condition in systemd. - ## - systemd-notify() { - local args - args="$(getopt -n systemd-notify -o h -l help,version,ready,pid::,status:,booted -- "$@")" - ret=$?; [[ $ret == 0 ]] || return $ret - eval set -- "$args" - - local arg_ready=false - local arg_pid=0 - local arg_status= - while [[ $# -gt 0 ]]; do - case "$1" in - -h|--help) command systemd-notify --help; return $?;; - --version) command systemd-notify --version; return $?;; - --ready) arg_ready=true; shift 1;; - --pid) arg_pid=${2:-$$}; shift 2;; - --status) arg_status=$2; shift 2;; - --booted) command systemd-notify --booted; return $?;; - --) shift 1; break;; - esac - done - - local our_env=() - if $arg_ready; then - our_env+=("READY=1") - fi - if [[ -n "$arg_status" ]]; then - our_env+=("STATUS=$arg_status") - fi - if [[ "$arg_pid" -gt 0 ]]; then - our_env+=("MAINPID=$arg_pid") - fi - our_env+=("$@") - local n - printf -v n '%s\n' "${our_env[@]}" - socat STDIO UNIX-SENDTO:"$NOTIFY_SOCKET" <<<"$n" - } + ## + # Just like systemd-notify(1), but slower, which is a shitty + # workaround for a race condition in systemd. + ## + systemd-notify() { + local args + args="$(getopt -n systemd-notify -o h -l help,version,ready,pid::,status:,booted -- "$@")" + ret=$?; [[ $ret == 0 ]] || return $ret + eval set -- "$args" + + local arg_ready=false + local arg_pid=0 + local arg_status= + while [[ $# -gt 0 ]]; do + case "$1" in + -h|--help) command systemd-notify --help; return $?;; + --version) command systemd-notify --version; return $?;; + --ready) arg_ready=true; shift 1;; + --pid) arg_pid=${2:-$$}; shift 2;; + --status) arg_status=$2; shift 2;; + --booted) command systemd-notify --booted; return $?;; + --) shift 1; break;; + esac + done + + local our_env=() + if $arg_ready; then + our_env+=("READY=1") + fi + if [[ -n "$arg_status" ]]; then + our_env+=("STATUS=$arg_status") + fi + if [[ "$arg_pid" -gt 0 ]]; then + our_env+=("MAINPID=$arg_pid") + fi + our_env+=("$@") + local n + printf -v n '%s\n' "${our_env[@]}" + socat STDIO UNIX-SENDTO:"$NOTIFY_SOCKET" <<<"$n" + } So, one day when the systemd bugs have been fixed (and presumably the Linux kernel supports passing the cgroup of a process as part of its @@ -302,12 +302,12 @@ why should I couple them? Instead, I create [`wm-running@.target`][wm-running@.target] that can be used as a synchronization point: - # wmii@.service - Before=wm-running@%i.target + # wmii@.service + Before=wm-running@%i.target - # lxpanel@.service - After=X11@%i.target wm-running@%i.target - Requires=wm-running@%i.target + # lxpanel@.service + After=X11@%i.target wm-running@%i.target + Requires=wm-running@%i.target Finally, I have my desktop started and running. Now, I'd like for programs that aren't part of the window manager to not dump their @@ -316,13 +316,13 @@ record of which graphical programs crashed, and like to have a prettier cgroup/process graph. So, I use `systemd-run` to run external programs from the window manager: - runcmd() ( - ... - unset NOTIFY_SOCKET # systemd - ... - exec 8>&- # xinit/systemd handshake - exec systemd-run --user --scope -- sh -c "$*" - ) + runcmd() ( + ... + unset NOTIFY_SOCKET # systemd + ... + exec 8>&- # xinit/systemd handshake + exec systemd-run --user --scope -- sh -c "$*" + ) I run them as a scope instead of a service so that they inherit environment variables, and don't have to mess with getting `DISPLAY` |