1*10120SGhee.Teo@Sun.COM#!/usr/perl5/bin/perl
2*10120SGhee.Teo@Sun.COM#
3*10120SGhee.Teo@Sun.COM# CDDL HEADER START
4*10120SGhee.Teo@Sun.COM#
5*10120SGhee.Teo@Sun.COM# The contents of this file are subject to the terms of the
6*10120SGhee.Teo@Sun.COM# Common Development and Distribution License (the "License").
7*10120SGhee.Teo@Sun.COM# You may not use this file except in compliance with the License.
8*10120SGhee.Teo@Sun.COM#
9*10120SGhee.Teo@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*10120SGhee.Teo@Sun.COM# or http://www.opensolaris.org/os/licensing.
11*10120SGhee.Teo@Sun.COM# See the License for the specific language governing permissions
12*10120SGhee.Teo@Sun.COM# and limitations under the License.
13*10120SGhee.Teo@Sun.COM#
14*10120SGhee.Teo@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
15*10120SGhee.Teo@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*10120SGhee.Teo@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
17*10120SGhee.Teo@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
18*10120SGhee.Teo@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
19*10120SGhee.Teo@Sun.COM#
20*10120SGhee.Teo@Sun.COM# CDDL HEADER END
21*10120SGhee.Teo@Sun.COM#
22*10120SGhee.Teo@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*10120SGhee.Teo@Sun.COM# Use is subject to license terms.
24*10120SGhee.Teo@Sun.COM#
25*10120SGhee.Teo@Sun.COM#
26*10120SGhee.Teo@Sun.COM
27*10120SGhee.Teo@Sun.COMmy $SVC_CUPS_SCHEDULER = 'cups/scheduler';
28*10120SGhee.Teo@Sun.COMmy $SVCPROP = '/usr/bin/svcprop';
29*10120SGhee.Teo@Sun.COM
30*10120SGhee.Teo@Sun.COMsub svcprop {
31*10120SGhee.Teo@Sun.COM        local ($fmri, $property) = @_;
32*10120SGhee.Teo@Sun.COM        my $FH;
33*10120SGhee.Teo@Sun.COM
34*10120SGhee.Teo@Sun.COM        open($FH, "$SVCPROP -C -p $property $fmri 2>/dev/null |");
35*10120SGhee.Teo@Sun.COM        $result = <$FH>;
36*10120SGhee.Teo@Sun.COM        close($FH);
37*10120SGhee.Teo@Sun.COM
38*10120SGhee.Teo@Sun.COM        return ($result);
39*10120SGhee.Teo@Sun.COM}
40*10120SGhee.Teo@Sun.COM
41*10120SGhee.Teo@Sun.COMsub print_service {
42*10120SGhee.Teo@Sun.COM        my $service;
43*10120SGhee.Teo@Sun.COM
44*10120SGhee.Teo@Sun.COM        $service = svcprop("$SVC_CUPS_SCHEDULER:default", "general/active");
45*10120SGhee.Teo@Sun.COM        ($service =~ /true/) && ($service = 'cups') || ($service = 'lp');
46*10120SGhee.Teo@Sun.COM
47*10120SGhee.Teo@Sun.COM        return ($service);
48*10120SGhee.Teo@Sun.COM}
49*10120SGhee.Teo@Sun.COM
50*10120SGhee.Teo@Sun.COMsub kill_running_applets {
51*10120SGhee.Teo@Sun.COM        # cups applet daemon
52*10120SGhee.Teo@Sun.COM        system("pkill -f '/system-config-printer/applet.py'");
53*10120SGhee.Teo@Sun.COM        # lp applet daemon
54*10120SGhee.Teo@Sun.COM        system("pkill ospm-applet");
55*10120SGhee.Teo@Sun.COM}
56*10120SGhee.Teo@Sun.COM
57*10120SGhee.Teo@Sun.COMmy $pid;
58*10120SGhee.Teo@Sun.COM
59*10120SGhee.Teo@Sun.COMsub handle_signal {
60*10120SGhee.Teo@Sun.COM        kill_running_applets ();
61*10120SGhee.Teo@Sun.COM}
62*10120SGhee.Teo@Sun.COM$SIG{USR1} = \&handle_signal;
63*10120SGhee.Teo@Sun.COM
64*10120SGhee.Teo@Sun.COM
65*10120SGhee.Teo@Sun.COM$SIG{CHLD} = 'IGNORE';
66*10120SGhee.Teo@Sun.COMmy $service;
67*10120SGhee.Teo@Sun.COM$service =  print_service();
68*10120SGhee.Teo@Sun.COM$pid = fork();
69*10120SGhee.Teo@Sun.COMif ($pid) {
70*10120SGhee.Teo@Sun.COM        waitpid($pid, 0);
71*10120SGhee.Teo@Sun.COM        exec('/usr/bin/desktop-print-management-applet');
72*10120SGhee.Teo@Sun.COM}
73*10120SGhee.Teo@Sun.COMelse {
74*10120SGhee.Teo@Sun.COM        if ($service eq 'lp') {
75*10120SGhee.Teo@Sun.COM                exec('/usr/lib/lp/bin/desktop-print-management-applet');
76*10120SGhee.Teo@Sun.COM        }
77*10120SGhee.Teo@Sun.COM        else {
78*10120SGhee.Teo@Sun.COM                exec('/usr/lib/cups/bin/desktop-print-management-applet');
79*10120SGhee.Teo@Sun.COM        }
80*10120SGhee.Teo@Sun.COM}
81*10120SGhee.Teo@Sun.COM
82