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