#!/usr/perl5/bin/perl -w
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)s8_system.pl	1.1	08/05/06 SMI"
#

require 5.005;
use locale;

sub output_warn {
	print STDERR "NOTICE: /etc/system directive '$line';\n" .
	    "    is not applicable in the virtual environment.\n";
	print "\n* The directive below is not applicable in the " .
	    "virtualized environment.\n";
}

@system_vars = (
	"rlim_fd_max",
	"rlim_fd_cur",

	"msgsys:msginfo_msgmax",
	"msgsys:msginfo_msgmnb",
	"msgsys:msginfo_msgmni",
	"msgsys:msginfo_msgtql",

	"semsys:seminfo_semmni",
	"semsys:seminfo_semmns",
	"semsys:seminfo_semmnu",
	"semsys:seminfo_semmsl",
	"semsys:seminfo_semopm",
	"semsys:seminfo_semume",
	"semsys:seminfo_semvmx",
	"semsys:seminfo_semaem",

	"shmsys:shminfo_shmmax",
	"shmsys:shminfo_shmmin",
	"shmsys:shminfo_shmmni",
	"shmsys:shminfo_shmseg"
);

while (<STDIN>) {
	# just echo out comments and lines with no content.
	if ((m/^\s*\*/) || (m/^\s*$/)) {
		print $_;
		next;
	}

	$line = $_;
	chomp $line;

	unless ((m/^\s*exclude/) ||
	    (m/^\s*include/) ||
	    (m/^\s*forceload/) ||
	    (m/^\s*rootdev/) ||
	    (m/^\s*rootfs/) ||
	    (m/^\s*moddir/) ||
	    (m/^\s*set/)) {
		print STDERR "WARNING: Unrecognized /etc/system directive " .
		    "'$line'.\n";
		print "$line\n";
		next;
	}

	#
	# See if this is a 'set' action.
	#
	if (m/^\s*set\s*([a-zA-Z0-9:_]+)\s*([=|&])\s*(\S+)/) {
		$var = $1;

		#
		# See if the variable is one we handle.
		#
		if (!grep(/^$var$/, @system_vars)) {
			output_warn();
		}

	} else {
		output_warn();
	}

	print "$line\n";
}
