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