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