xref: /titanic_44/usr/src/cmd/svc/profile/listsvcs.pl (revision 6a42cb7b9d730ae02bbdb8898dc074179f96e178)
1*6a42cb7bSjohnz#!/usr/bin/perl
2*6a42cb7bSjohnz#
3*6a42cb7bSjohnz# CDDL HEADER START
4*6a42cb7bSjohnz#
5*6a42cb7bSjohnz# The contents of this file are subject to the terms of the
6*6a42cb7bSjohnz# Common Development and Distribution License (the "License").
7*6a42cb7bSjohnz# You may not use this file except in compliance with the License.
8*6a42cb7bSjohnz#
9*6a42cb7bSjohnz# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*6a42cb7bSjohnz# or http://www.opensolaris.org/os/licensing.
11*6a42cb7bSjohnz# See the License for the specific language governing permissions
12*6a42cb7bSjohnz# and limitations under the License.
13*6a42cb7bSjohnz#
14*6a42cb7bSjohnz# When distributing Covered Code, include this CDDL HEADER in each
15*6a42cb7bSjohnz# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*6a42cb7bSjohnz# If applicable, add the following below this CDDL HEADER, with the
17*6a42cb7bSjohnz# fields enclosed by brackets "[]" replaced with your own identifying
18*6a42cb7bSjohnz# information: Portions Copyright [yyyy] [name of copyright owner]
19*6a42cb7bSjohnz#
20*6a42cb7bSjohnz# CDDL HEADER END
21*6a42cb7bSjohnz
22*6a42cb7bSjohnz#
23*6a42cb7bSjohnz# ident	"%Z%%M%	%I%	%E% SMI"
24*6a42cb7bSjohnz#
25*6a42cb7bSjohnz# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
26*6a42cb7bSjohnz# Use is subject to license terms.
27*6a42cb7bSjohnz#
28*6a42cb7bSjohnz
29*6a42cb7bSjohnz#
30*6a42cb7bSjohnz# listsvcs [-e] profile ...
31*6a42cb7bSjohnz#
32*6a42cb7bSjohnz# List all service instances in an SMF profile.
33*6a42cb7bSjohnz# Options:
34*6a42cb7bSjohnz#	-e	List enabled instances only
35*6a42cb7bSjohnz#
36*6a42cb7bSjohnz
37*6a42cb7bSjohnzuse XML::Parser;
38*6a42cb7bSjohnzuse Getopt::Std;
39*6a42cb7bSjohnzuse strict;
40*6a42cb7bSjohnz
41*6a42cb7bSjohnzmy %opts;
42*6a42cb7bSjohnzmy $servicename;	# name attribute of the enclosing service element
43*6a42cb7bSjohnzmy @svcs = ();		# services list under construction
44*6a42cb7bSjohnz
45*6a42cb7bSjohnzif (!getopts("e", \%opts)) {
46*6a42cb7bSjohnz	die "Usage: $0 [-e] profile ...\n";
47*6a42cb7bSjohnz}
48*6a42cb7bSjohnzmy $list_all = !$opts{e};
49*6a42cb7bSjohnz
50*6a42cb7bSjohnzmy $parser = new XML::Parser;
51*6a42cb7bSjohnz$parser->setHandlers(Start => \&start_handler, End => \&end_handler);
52*6a42cb7bSjohnz
53*6a42cb7bSjohnzfor my $file (@ARGV) {
54*6a42cb7bSjohnz	$parser->parsefile($file);
55*6a42cb7bSjohnz}
56*6a42cb7bSjohnzprint join("\n", sort(@svcs)), "\n";
57*6a42cb7bSjohnz
58*6a42cb7bSjohnzsub start_handler
59*6a42cb7bSjohnz{
60*6a42cb7bSjohnz	my ($p, $el, %attrs) = @_;
61*6a42cb7bSjohnz	my $name;
62*6a42cb7bSjohnz
63*6a42cb7bSjohnz	return unless ($attrs{"name"});
64*6a42cb7bSjohnz	$name = $attrs{"name"};
65*6a42cb7bSjohnz
66*6a42cb7bSjohnz	if ($el eq "service") {
67*6a42cb7bSjohnz		$servicename = $name;
68*6a42cb7bSjohnz	} elsif ($el eq "instance" && defined $servicename) {
69*6a42cb7bSjohnz		push(@svcs, "$servicename:$name")
70*6a42cb7bSjohnz			if ($list_all || $attrs{"enabled"} eq "true");
71*6a42cb7bSjohnz	}
72*6a42cb7bSjohnz}
73*6a42cb7bSjohnz
74*6a42cb7bSjohnzsub end_handler
75*6a42cb7bSjohnz{
76*6a42cb7bSjohnz	my ($p, $el) = @_;
77*6a42cb7bSjohnz
78*6a42cb7bSjohnz	if ($el eq "service") {
79*6a42cb7bSjohnz		$servicename = undef;
80*6a42cb7bSjohnz	}
81*6a42cb7bSjohnz}
82