Friday, July 18, 2014

Windows can have UTC hardware clock

Thanks to reddit's sceptically for this:

There's a registry setting you can use in windows to make it work with UTC on the hardware clock.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
"RealTimeIsUniversal"=dword:00000001

I don't know why they don't press that for you before it leaves the factory...

Dilbert.com

Friday, May 30, 2014

MessageFormat {0} for bash

Here is an sample string formatter written in bash, that works along the lines of the java string format class, see http://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html.


#! /bin/bash
# Sam Liddicott sam@liddicott.com
# e.g. formatecho "Hello {1}, date of {0} is {0,datetime}, using '{0,datetime}'\n" 1401444493 "$USER"

cutstr() {
  printf -v "$1" "%s" "${4%%$3*}"
  printf -v "$2" "%s" "${4#"${!1}"}"
}

formatstr() {
  local target="$1"
  shift
  local format="$1"
  shift

  local result
  local start
  local arg
  local func

  # slice up to ' or { and process
  while test -n "$format"
  do cutstr start format "['{]" "$format"
     result="$result$start"
     case "$format" in
          {*) cutstr start format "}" "$format"
              format="${format:1}"
              cutstr arg start , "${start:1}"
              arg=$(( arg + 1 ))
              if test "${start:0:1}" = ","
              then result="$result"$(${start:1} "${!arg}")
              else result="$result${!arg}"
              fi
            ;;
        "'"*) format="${format:1}"
              cutstr start format "'" "$format"
              # empty string means ' but bash 4.2 errors stop me defaulting 
              # to ' or $'\x29' so I copy the ' from format
              result="$result${start:-${format:0:1}}"
              format="${format:1}"
            ;;
     esac
  done

  printf -v "$target" "$result"
}

formatecho() {
  local _message
  formatstr _message "$@"
  printf "%s" "$_message"
}

datetime() {
  date -d @"$@"
}

formatecho "$@"


Wednesday, May 7, 2014

Passive Aggression

This essay so far only covers passive-aggressive as a defence against the narcissistic psychopath, and not as a method of attack used by the narcissistic psychopath, or as a substitute means of communication.
Passive Aggression
Passive-aggressive: Term for practitioners of non-violent inaction, employed by those who have not yet discovered the futility of ridicule against the practice.
Introduction
Much so-called passive aggression is not so much aggression, as dis-interest.
The accusation of passive aggressive is the last attempt of the psychopath to manipulate and dominate those who have made the ultimate withdrawal from a hostile environment, by refusing to participate.
It's older equivalent from the age of physical violence, which may still be familiar to some, is: "Come back and fight me you snivelling little coward!" or as it was understood by the hearer: “Come back so that I can beat you into submission!”
Those whose eloquence or tired persistence have crumbled before the illogical, unreasonable and unremitting demands of the exploitative bully have concluded that the only way to win is not to play the game; that validation from the psychopath is unsatisfying, that the promise of validation is unbelievable, that while yielding may defer immediate pain into future pain, playing the game only promises pain.
And what's wrong with passive-aggression, if we can call it that? How about calling it non-violent inaction? Does one really prefer passionate aggression, or violence? And does one leave place for those who don’t?

Victim-blaming

The accusation of passive-aggressive is an attempt to blame failure to engage, or to kindle even the smallest spark of trust, on the one whose engagement is to be exploited.
Having spent every cent of political capital, the passive-aggressive-accuser will attempt to bully-up some more, revealing themselves as a psychopathic snake-head demanding the privilege to present, ad-infinitum, scenario after scenario until they can find one that will cause the other to willingly do their bidding.

Preferred Environment

Those who prefer passionate aggression may thrive in an environment of passionate aggression. It may be that they think that they are the most aggressive and persistent and that they can dominate that environment and “do things right” (because, “Hey! If I was wrong, I would have changed my mind”)
Likewise one might expect that those in favour of actual aggression also suppose themselves to be among the biggest and the strongest.
One might suppose that PA accusers are attempting to perpetuate an environment in which (actual violence being outlawed) they can win by force of personality, while simultaneously preventing their victims from carving out a sanctuary of their own.

What does the passive-aggressive see?

The passive-aggressive’s behaviour silently says: “Why should I be interested in your little scheme? I’m not a resource to be exploited to your ends!”, but has somehow found it no longer worthwhile to say this out loud. It is not worthwhile to provide the psychopath with feedback how to constructing a more effective message/weapon.
The passive-aggressive sees no union, no meeting of the minds, except perhaps superficially.
The psychopath will offer scenarios that ostensibly are desirable to both parties based on the superficial union, but the passive aggressive is aware of an additional cost that is too expensive to explain.

How to deal with a passive aggressive

Take some actual real unselfish interest in the welfare and independence of the passive aggressive.
If you find that this doesn’t work then it wasn’t really unselfish, just more latent psychopathy.
Clue: it’s not supposed to work, what were you actually trying to do? Try granting the other person a little self-sovereignty.

Not passive, just hidden?

It isn’t all non-violent inaction though. Here are some classic petty revenges.

The revenge must be perfectly balanced, the punishment must fit the crime.

So is passive-aggressive nature or strategy? How are latent psychopathic in all of us manifest when we are not in a position to get caught by those who matter?

Sunday, April 20, 2014

MAKEDEV and double virtualization

MAKEDEV can run in a couple of seconds - even on a virtual machine.

But if your virtual machine is hosting a qemu guest, then in that guest a fork/exec can take 0.2 of a second, and MAKEDEV generic-i386 can take a couple of hours. (This is because the kqemu kernel module is not available, http://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/qemu-running-on-ubuntu-vmware-guest-cannot-find-dev-kvm-936253/).

The first hacky-hack to cut down on the number of fork/exec is to stop calling sed quite so often, cue this patch (requires MAKEDEV to run under bash).

--- /sbin/MAKEDEV 2009-07-30 08:39:09.000000000 -0700
+++ /sbin/MAKEDEV 2014-02-21 06:31:43.000000000 -0800
@@ -1,4 +1,4 @@
-#! /bin/sh -
+#! /bin/bash -
 # $Id$
 
 #---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#
@@ -116,7 +116,9 @@
 
 devicename () { # translate device names to something safe
  # A-Z is not full alphabet in all locales (e.g. in et_EE)
- echo "$*" | LC_ALL=C sed -e 's/[^A-Za-z0-9_]/_/g' 
+ #echo "$*" | LC_ALL=C sed -e 's/[^A-Za-z0-9_]/_/g' 
+ echo "${*//[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]/_}"
+  
 }
 
 makedev () { # usage: makedev name [bcu] major minor owner group mode
@@ -231,12 +233,14 @@
  exec 3<$procfs/devices
  while read major device extra <&3
  do
-  device=`echo $device | sed 's#/.*##'`
+  #device=`echo $device | sed 's#/.*##'`
+  device="${device%%/*}"
   case "$major" in
    Character|Block|'')
     ;;
    *)
-    safedevname=`devicename $device`
+    safedevname="${device//[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234566
+789]/_}"
     eval "major_$safedevname=$major"
     devices="$devices $device"
     ;;
@@ -247,7 +251,8 @@
 
 Major () {
  device=$2
- devname=`devicename $1`
+ devname="${1//[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234566
+789]/_}"
  if [ "$opt_d" ]
  then
   echo -1 # don't care
@@ -2149,7 +2154,8 @@
    exec 3<$procfs/devices
    while read major device extra <&3
    do
-    device=`echo $device | sed 's#/.*##'`
+    # device=`echo $device | sed 's#/.*##'`
+    device="${device%%/*}"
     case "$major" in
sh-4.1# diff -u /sbin/MAKEDEV /MAKEDEV 
--- /sbin/MAKEDEV 2009-07-30 08:39:09.000000000 -0700
+++ /MAKEDEV 2014-02-21 06:31:43.000000000 -0800
@@ -1,4 +1,4 @@
-#! /bin/sh -
+#! /bin/bash -
 # $Id$
 
 #---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#---#
@@ -116,7 +116,9 @@
 
 devicename () { # translate device names to something safe
  # A-Z is not full alphabet in all locales (e.g. in et_EE)
- echo "$*" | LC_ALL=C sed -e 's/[^A-Za-z0-9_]/_/g' 
+ #echo "$*" | LC_ALL=C sed -e 's/[^A-Za-z0-9_]/_/g' 
+ echo "${*//[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789]/_}"
+  
 }
 
 makedev () { # usage: makedev name [bcu] major minor owner group mode
@@ -231,12 +233,14 @@
  exec 3<$procfs/devices
  while read major device extra <&3
  do
-  device=`echo $device | sed 's#/.*##'`
+  #device=`echo $device | sed 's#/.*##'`
+  device="${device%%/*}"
   case "$major" in
    Character|Block|'')
     ;;
    *)
-    safedevname=`devicename $device`
+    safedevname="${device//[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234566
+789]/_}"
     eval "major_$safedevname=$major"
     devices="$devices $device"
     ;;
@@ -247,7 +251,8 @@
 
 Major () {
  device=$2
- devname=`devicename $1`
+ devname="${1//[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234566
+789]/_}"
  if [ "$opt_d" ]
  then
   echo -1 # don't care
@@ -2149,7 +2154,8 @@
    exec 3<$procfs/devices
    while read major device extra <&3
    do
-    device=`echo $device | sed 's#/.*##'`
+    # device=`echo $device | sed 's#/.*##'`
+    device="${device%%/*}"
     case "$major" in
      Character|Block|'')
       ;;


The next hack is to stop the 5 or 6 fork/exec when MAKEDEV deletes a device node, creates a (temporary device node), chmods it, chowns it, and renames it.

How do we do that? We run MAKEDEV -n so that it does none of these and then feed the output to a perl script which will do them.

Sadly perl has no native mknod call and there are no libraries in this environment, and so I use perl's blessed syscall function with a hard-wired syscall 133 for mknod (as it is, on my kernel):

time /MAKEDEV -n generic-i386 | perl -ne '
print; 
umask(0);
($c, $f, $node, $major, $minor, $own, $perm) = split; 
if ($node eq "->") { 
  symlink($major, $f) || die "sym: $!";
} else {
  # system("mknod",$f,$node,$major,$minor) && die "mknod($f,$node,$major,$minor): $? $!"; 
  # chmod(oct($perm), $f) || die "chmod: $!"; 
  $n=0;
  $n=0010000 if ($node eq "f");
  $n=0020000 if ($node eq "c");
  $n=0060000 if ($node eq "b");
  $n=0140000 if ($node eq "s");
  if (syscall(133, $f, oct($perm) | $n, (($minor & 0xff) | (($major & 0xfff) << 8)
          | (( ($minor & ~0xff)) << 12)
          | (( ($major & ~0xfff)) << 32))) == -1) { die "syscall: $!"; }
  ($user,$group)=split(/:/,$own);
  $user=getpwnam($user);
  $group=getgrnam($group);
  chown($user,$group,$f) || die "chown: $own $!"; 
}
'

Leaving in the system("mknod,...) took around 24 minutes, but moving straight to syscall(mknod,...) takes1 minute 8 seconds.

I did toy with having bash use printf or something to pack a binary tar archive (or even getting perl to pack a tar archive) to pipe to tar -x, but... this will have to do for now.

I suspect this depends on a bug in MAKEDEV which seems to still create sub-directories needed even in -n mode.

It would have been better to pipe the output to a c program which would parse it, I will do that, another day...

Wednesday, March 19, 2014

NFS/LDAP only at home

NOTE: This doesn't work reliable for only some users. It seems like nsswitch.conf needs faking earlier than that. A better answer might be to iptables-rst the ldap requests or something so that ldap fails quickly.

I have this pre-init script in /etc/init/autofs.conf

start on runlevel [2345] and net-device-up IFACE=wlan0
...
pre-start script
    modprobe -q autofs4 || true
    if iwconfig | grep 00:18:84:26:7E:1B 
    then sed -e 's/ #ldap/ ldap/' /etc/nsswitch.conf > /var/tmp/nsswitch.conf && mount /var/tmp/nsswitch.conf /etc/nsswitch.conf -o bind
    else ! true
    fi
end script

and these lines in my /etc/nsswitch.conf

passwd:         compat #ldap
group:          compat #ldap
shadow:         compat #ldap

When I'm on my home wireless network (detected by the access-point mac address, autofs will run to mount home directories, and ldap will be enabled and used to validate user accounts.

Otherwise it is a standalone laptop and will revert to built in accounts and home directories.

Tuesday, February 25, 2014

A Christmastime Computer Ghost Story, or, a loop in time

The poor coder was running out of time for his deadline, and right before the Christmas holidays

The new system was not working. PAM had been updated to a newer version which choked on the old style pam.d files which used the old @ style include directives.

This meant that CRON was failing with permission denied because it's config file could not be processed.

Examination of the source version control system showed that old versions of the system used the same new version of pam and yet did not have that problem at all.

The pam.d config files were not supplied as part of the pam source, and so had come from somewhere else - and came from the base file system on which the system was based.

An older version of the system was fired up, and sure enough, it had a different set of pam.d files to cope with the newer pam release that was also in use on the older system.

It seemed simpler to just transfer the pam.d files from the old system to the new system - and indeed that fixed the problem.

These were then added as a fixup to the pam project, so that the new pam.d files would be installed whenever the new pam project was used. Otherwise, the original files would still be used.

The build system was tested and it did indeed deposit the new pam.d files in the correct place.

A new build was fired up and just before delivery for QA was found to fail in exactly the same way as before.

Things get spooky...

Analysis showed that the old pam files were installed after all; and this was because the old pam files had been packed in the install image, and this was because the fixup to the pam project contained the old pam files.

What?

Didn't the coder fix that to have new pam files the day before? Version control showed that he did, but version control showed that the fixup archive contained the old files, known not to work; and only those files were committed.

The previous system was fired up again, and to his surprise it was using the old pam files too and yet was NOT failing - because it was using the old pam libraries, and not the new pam libraries!

The command history showed that it's pam files had been packaged up using tar ... | base64, for cut-n-paste from window to window, so there was sadly not left behind any temporary files of evidence of what was actually packaged. But it was clearly the machine from which the files were taken.

The new system on which the replacement pam files had been tested had been re-installed to test the new build, and so it had the newly installed old broken pam files and not the new ones that had been proved to work.

There had been a fix and it had worked but all that was left was the same old pam.d files that did not work. And nowhere to get a fix from.

The coder then remembered that the previous installation is always preserved on a backup partition, and so quickly mounted this on the new system and found the new, different, pam.d files - which worked.

The coder packaged these up to a fixup to the pam project, just like 2 days before.

And kept a back up just to be sure.

The coder was glad to have his fix in time for the deadline, and have his Christmas holidays, but if the newer fixed files had not come from the working older system (which did not use new pam after all), where had they come from... and where did they go to... But he did not let these questions prevent him from starting a new build for QA, and going off to enjoy his long anticipated holidays.

Monday, January 27, 2014

A Plea for Social Equality

True democratic wealth is time: everybody has 24 hours of it a day.

The significant social inequality of the day is that some peoples time is not exchangeable for much value, while other peoples time is very much in demand and exchangeable at a high rate.

I simplify somewhat, for a person can sometimes exert control over their exchange rate by means of how much effort they put in; but even at maximum effort there is still a large disparity between the exchangeable values of the time of different people, or in different locations.

In the corrupt imperial west there is a notion that 8 hours of effort per day should be exchangeable for necessities of life (and some discretionary comforts) but the opportunity to make this exchange is not granted equally to all people (and nor is the standard of life).

In the name of social conscience and humanity, this inequality is often reasonably addressed by moving a surfeit of value from those who found favourable exchange, to those who who found a poor rate of exchange.

Yet paradoxically, the extreme inequality of those who found no exchange is addressed by an attempt to provide the value of life necessities with no exchange required.

This does not introduce equality but instead introduces further inequality for in transferring the surfeit of value to those who find no exchange, it leaves them with a surfeit of time. It reduces them to the status of beggar and provides no way to contribute.

It would be more equitable to provide opportunity of exchange to those who found no exchange, making all equal contributors to society from the universal and collective wealth of time, and condemning none to the status of beggar.

TLDR: Or in other words, why in the UK when taxes are going up, and public works are going down, why, are we paying people to do nothing?

It is no socialist triumph to lose the working class and gain another idle class (however unwilling).

Let the time of each be valued equally - sufficient for life, and let all contribute.

And here's hoping for a shorter working day for all, enough time for dancing and singing.