Project

General

Profile

Bug #3346

svc-hostid uses perl stupidly

Added by Garrett D'Amore about 7 years ago. Updated over 5 years ago.

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

100%

Estimated time:
Difficulty:
Medium
Tags:

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.

History

#1

Updated by Garrett D'Amore over 5 years ago

This code doesn't execute many times for zones -- it only executes in the global zone.

Nonetheless, nuking perl from system startup can only be a good thing. (Too bad we haven't fixed intrd yet.)

 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
+# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+#

 . /lib/svc/share/smf_include.sh

@@ -36,8 +38,7 @@ if smf_is_globalzone; then
         else
                host=`/usr/bin/hostid`  
                 echo "# DO NOT EDIT" > /etc/hostid
-               r=`echo "0x${host}" | /usr/bin/perl -e \\
-                   'while(<STDIN>){chop;tr/!-~/P-~!-O/;print $_,"\\n";}exit 0;'`
+               r=`echo "0x${host}" | /usr/bin/tr 'P-~!-O' '!-OP-~'`
                printf "\\"%s\\"\\n"  $r >> /etc/hostid
         fi
 fi
#2

Updated by Garrett D'Amore over 5 years ago

Actually, on my VM, with a very hot cache, the difference is about 2 msec.

#3

Updated by Electric Monk over 5 years ago

  • Status changed from New to Closed
  • % Done changed from 80 to 100

git commit 7ab4e62e3b5c454f248a38bec0d489e8f5543324

commit  7ab4e62e3b5c454f248a38bec0d489e8f5543324
Author: Garrett D'Amore <garrett@damore.org>
Date:   2014-07-21T16:22:30.000Z

    3346 svc-hostid uses perl stupidly
    Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
    Reviewed by: Adam Števko <adam.stevko@gmail.com>
    Reviewed by: Dan McDonald <danmcd@omniti.com>
    Approved by: Dan McDonald <danmcd@omniti.com>

Also available in: Atom PDF