Print this page
8485 Remove set but unused variables in usr/src/cmd
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/print/bsd-sysv-commands/disable.c
+++ new/usr/src/cmd/print/bsd-sysv-commands/disable.c
1 1
2 2 /*
3 3 * CDDL HEADER START
4 4 *
5 5 * The contents of this file are subject to the terms of the
6 6 * Common Development and Distribution License (the "License").
7 7 * You may not use this file except in compliance with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22
23 23 /*
24 + * Copyright 2017 Gary Mills
24 25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 26 * Use is subject to license terms.
26 27 *
27 28 */
28 29
29 30 /* $Id: disable.c 146 2006-03-24 00:26:54Z njacobs $ */
30 31
31 32
32 33 #include <stdio.h>
33 34 #include <stdlib.h>
34 35 #include <unistd.h>
35 36 #include <string.h>
36 37 #include <locale.h>
37 38 #include <libintl.h>
38 39 #include <papi.h>
39 40 #include "common.h"
40 41
41 42 static void
42 43 usage(char *program)
43 44 {
44 45 char *name;
45 46
46 47 if ((name = strrchr(program, '/')) == NULL)
47 48 name = program;
48 49 else
49 50 name++;
50 51
51 52 fprintf(stdout,
52 53 gettext("Usage: %s [-c] [-W] [-r reason] destination ...\n"),
53 54 name);
54 55 exit(1);
55 56 }
56 57
57 58 static void
58 59 cancel_active_job(papi_service_t svc, char *dest)
59 60 {
60 61 papi_status_t status;
61 62 papi_job_t *j = NULL;
62 63 char *req_attrs[] = { "job-state", "job-id", NULL };
63 64
64 65 status = papiPrinterListJobs(svc, dest, req_attrs, 0, 0, &j);
65 66 if ((status == PAPI_OK) && (j != NULL)) {
66 67 int i;
67 68
68 69 for (i = 0; j[i] != NULL; j++) {
69 70 papi_attribute_t **a = papiJobGetAttributeList(j[i]);
70 71 int state = 0;
71 72
72 73 if (a == NULL)
73 74 continue;
74 75
75 76 (void) papiAttributeListGetInteger(a, NULL,
76 77 "job-state", &state);
77 78 if (state & 0x082A) { /* If state is RS_ACTIVE */
78 79 int32_t id = papiJobGetId(j[i]);
79 80
80 81 (void) papiJobCancel(svc, dest, id);
81 82 }
82 83 }
83 84 papiJobListFree(j);
84 85 }
↓ open down ↓ |
51 lines elided |
↑ open up ↑ |
85 86 }
86 87
87 88 int
88 89 main(int ac, char *av[])
89 90 {
90 91 papi_status_t status;
91 92 papi_service_t svc = NULL;
92 93 papi_encryption_t encryption = PAPI_ENCRYPT_NEVER;
93 94 int exit_status = 0;
94 95 int cancel = 0;
95 - int pending = 0; /* not implemented */
96 96 char *reason = NULL;
97 97 int c;
98 98
99 99 (void) setlocale(LC_ALL, "");
100 100 (void) textdomain("SUNW_OST_OSCMD");
101 101
102 102 while ((c = getopt(ac, av, "EcWr:")) != EOF)
103 103 switch (c) {
104 104 case 'c': /* cancel active job first */
105 105 cancel = 1;
106 106 break;
107 107 case 'W': /* wait for active request, not implemented */
108 - pending = 1;
109 108 break;
110 109 case 'r': /* reason */
111 110 reason = optarg;
112 111 break;
113 112 case 'E':
114 113 encryption = PAPI_ENCRYPT_NEVER;
115 114 break;
116 115 default:
117 116 usage(av[0]);
118 117 }
119 118
120 119 if (ac <= optind)
121 120 usage(av[0]);
122 121
123 122 while (optind < ac) {
124 123 char *printer = av[optind++];
125 124
126 125 status = papiServiceCreate(&svc, printer, NULL, NULL,
127 126 cli_auth_callback, encryption, NULL);
128 127 if (status != PAPI_OK) {
129 128 fprintf(stderr, gettext(
130 129 "Failed to contact service for %s: %s\n"),
131 130 printer, verbose_papi_message(svc, status));
132 131 exit_status = 1;
133 132 }
134 133
135 134 status = papiPrinterDisable(svc, printer, reason);
136 135 if (status == PAPI_OK) {
137 136 printf(gettext("printer \"%s\" now disabled\n"),
138 137 printer);
139 138 } else if (status == PAPI_NOT_ACCEPTING) {
140 139 fprintf(stderr, gettext(
141 140 "Destination \"%s\" was already disabled.\n"),
142 141 printer);
143 142 exit_status = 1;
144 143 } else {
145 144 /* The operation is not supported in lpd protocol */
146 145 if (status == PAPI_OPERATION_NOT_SUPPORTED) {
147 146 fprintf(stderr,
148 147 verbose_papi_message(svc, status));
149 148 } else {
150 149 fprintf(stderr, gettext("disable: %s: %s\n"),
151 150 printer, verbose_papi_message(svc, status));
152 151 }
153 152 exit_status = 1;
154 153 }
155 154
156 155 if (cancel != 0)
157 156 cancel_active_job(svc, printer);
158 157
159 158 papiServiceDestroy(svc);
160 159 }
161 160
162 161 return (exit_status);
163 162 }
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX