#!/usr/bin/perl -w #--------------------------------------------------------------------- # Description: Improvied script to search for non-existent commands # references in Upstart jobs. See: # # https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/912558 # # Usage: Run the command as a non-root user. If it produces any output, # you will be affected by the bug referenced above. # # Author: James Hunt # Date: 7 January 2012 #--------------------------------------------------------------------- use strict; sub escape_shell_chars { my $str = shift; $str =~ s/([;<>\*\|`&\$!#\(\)\[\]\{\}:'"])/\\$1/g; return $str; } sub contains_shell_meta_chars { my $str = shift; my $copy = escape_shell_chars ($str); return $copy eq $str ? 0 : 1; } # use Upstarts default PATH $ENV{PATH} = "/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin"; foreach my $conf (`ls /etc/init/*`) { my $file; my $cmd = undef; my $meta = 0; chomp ($conf); open (FILE, $conf) or die "failed to open file $conf, "; while () { chomp; if ($_ =~ /^(\s*exec\s*|\s*(pre|post)-(start|stop)\s*exec\s*)([^\s]*)/ ) { $cmd = $4; if (contains_shell_meta_chars ($cmd)) { $meta = 1; last; } } } next unless defined $cmd; next if $meta; my @a = split //, $cmd; my $first = (split //, $cmd)[0]; if (($first eq q(/) or $first eq q(.)) and not `ls $cmd 2>/dev/null` ) { print "absolute command $cmd not found\n"; } elsif (not `which $cmd`) { print "relative command $cmd not found\n"; } close (FILE); }