Project

General

Profile

Bug #3346

svc-hostid uses perl stupidly

Added by Garrett D'Amore over 8 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Category:
cmd - userland programs
Start date:
2012-11-06
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

The svc-hostid script uses a crazy perl script to perform its calculation of ROT-47. (The /etc/hostid file is ROT-47 for legacy licensing reasons. With open source, there is no longer any point in trying to obfuscate this file except for historical legacy. We can't change to clear text without busting existing hostid files.)

Here's the perl script (taken from /lib/svc/method/svc-hostid):

r=`echo "0x${host}" | /usr/bin/perl e \
'while(<STDIN>){chop;tr/!
/P-!-O/;print $_,"\n";}exit 0;'`

Here's the equivalent using just plain "tr":

r=`echo "0x${host}" | /usr/bin/tr 'P-~!-O' '!-OP-~'`

This eliminates yet one more perl dependency, and as a little bonus, saves about a millisecond during boot. (If bringing up many zones this can add up. A script to compare 100 iterations of each of these finds that the tr based version runs in about 60-75% of the time of the perl version.)

Of course, most zones will never encounter this, if they have a persistent root filesystem. Because the script only runs if it doesn't find an existing /etc/hostid file.

Also available in: Atom PDF