xref: /titanic_41/usr/src/cmd/print/selector/desktop-print-management-applet (revision 4d55575c4716bff317c5c79721ff1559769462d6)
16124874eSGhee Teo#!/usr/perl5/bin/perl
26124874eSGhee Teo#
36124874eSGhee Teo# CDDL HEADER START
46124874eSGhee Teo#
56124874eSGhee Teo# The contents of this file are subject to the terms of the
66124874eSGhee Teo# Common Development and Distribution License (the "License").
76124874eSGhee Teo# You may not use this file except in compliance with the License.
86124874eSGhee Teo#
96124874eSGhee Teo# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
106124874eSGhee Teo# or http://www.opensolaris.org/os/licensing.
116124874eSGhee Teo# See the License for the specific language governing permissions
126124874eSGhee Teo# and limitations under the License.
136124874eSGhee Teo#
146124874eSGhee Teo# When distributing Covered Code, include this CDDL HEADER in each
156124874eSGhee Teo# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
166124874eSGhee Teo# If applicable, add the following below this CDDL HEADER, with the
176124874eSGhee Teo# fields enclosed by brackets "[]" replaced with your own identifying
186124874eSGhee Teo# information: Portions Copyright [yyyy] [name of copyright owner]
196124874eSGhee Teo#
206124874eSGhee Teo# CDDL HEADER END
216124874eSGhee Teo#
226124874eSGhee Teo# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
236124874eSGhee Teo# Use is subject to license terms.
246124874eSGhee Teo#
256124874eSGhee Teo#
26*4d55575cSGhee Teouse Errno qw(EINTR :POSIX);
276124874eSGhee Teo
286124874eSGhee Teomy $SVC_CUPS_SCHEDULER = 'cups/scheduler';
296124874eSGhee Teomy $SVCPROP = '/usr/bin/svcprop';
30*4d55575cSGhee Teomy $reexec = 0;
316124874eSGhee Teo
326124874eSGhee Teosub svcprop {
336124874eSGhee Teo        local ($fmri, $property) = @_;
346124874eSGhee Teo        my $FH;
356124874eSGhee Teo
366124874eSGhee Teo        open($FH, "$SVCPROP -C -p $property $fmri 2>/dev/null |");
376124874eSGhee Teo        $result = <$FH>;
386124874eSGhee Teo        close($FH);
396124874eSGhee Teo
406124874eSGhee Teo        return ($result);
416124874eSGhee Teo}
426124874eSGhee Teo
436124874eSGhee Teosub print_service {
446124874eSGhee Teo        my $service;
456124874eSGhee Teo
466124874eSGhee Teo        $service = svcprop("$SVC_CUPS_SCHEDULER:default", "general/active");
476124874eSGhee Teo        ($service =~ /true/) && ($service = 'cups') || ($service = 'lp');
486124874eSGhee Teo
496124874eSGhee Teo        return ($service);
506124874eSGhee Teo}
516124874eSGhee Teo
526124874eSGhee Teosub kill_running_applets {
53*4d55575cSGhee Teo	$reexec = 1;
546124874eSGhee Teo        # cups applet daemon
556124874eSGhee Teo        system("pkill -f '/system-config-printer/applet.py'");
566124874eSGhee Teo        # lp applet daemon
576124874eSGhee Teo        system("pkill ospm-applet");
586124874eSGhee Teo}
596124874eSGhee Teo
606124874eSGhee Teosub handle_signal {
616124874eSGhee Teo        kill_running_applets ();
626124874eSGhee Teo}
63*4d55575cSGhee Teo
646124874eSGhee Teo$SIG{USR1} = \&handle_signal;
656124874eSGhee Teo
66*4d55575cSGhee Teomy $pid = fork();
67*4d55575cSGhee Teoif (! defined($pid)) {
68*4d55575cSGhee Teo	die "Error: fork() failed\n";
696124874eSGhee Teo}
70*4d55575cSGhee Teoelsif ($pid == 0) {
71*4d55575cSGhee Teo	my $service =  print_service();
726124874eSGhee Teo        if ($service eq 'lp') {
736124874eSGhee Teo                exec('/usr/lib/lp/bin/desktop-print-management-applet');
746124874eSGhee Teo        }
756124874eSGhee Teo        else {
766124874eSGhee Teo                exec('/usr/lib/cups/bin/desktop-print-management-applet');
776124874eSGhee Teo        }
78*4d55575cSGhee Teo
79*4d55575cSGhee Teo}
80*4d55575cSGhee Teoelse {
81*4d55575cSGhee Teo	my $retid;
82*4d55575cSGhee Teo	while ((($retid = waitpid($pid, 0)) < 0) && $!{EINTR}) {
836124874eSGhee Teo	}
846124874eSGhee Teo
85*4d55575cSGhee Teo	if ($retid == $pid && $reexec) {
86*4d55575cSGhee Teo        	exec('/usr/bin/desktop-print-management-applet');
87*4d55575cSGhee Teo	}
88*4d55575cSGhee Teo}
89*4d55575cSGhee Teo
90*4d55575cSGhee Teoexit(0);
91