1355b466jacobs/*
2355b466jacobs * CDDL HEADER START
3355b466jacobs *
4355b466jacobs * The contents of this file are subject to the terms of the
5355b466jacobs * Common Development and Distribution License (the "License").
6355b466jacobs * You may not use this file except in compliance with the License.
7355b466jacobs *
8355b466jacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b466jacobs * or http://www.opensolaris.org/os/licensing.
10355b466jacobs * See the License for the specific language governing permissions
11355b466jacobs * and limitations under the License.
12355b466jacobs *
13355b466jacobs * When distributing Covered Code, include this CDDL HEADER in each
14355b466jacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b466jacobs * If applicable, add the following below this CDDL HEADER, with the
16355b466jacobs * fields enclosed by brackets "[]" replaced with your own identifying
17355b466jacobs * information: Portions Copyright [yyyy] [name of copyright owner]
18355b466jacobs *
19355b466jacobs * CDDL HEADER END
20355b466jacobs */
21355b466jacobs
22355b466jacobs/*
236b5764csonam gupta - Sun Microsystems - Bangalore India * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24355b466jacobs * Use is subject to license terms.
25355b466jacobs *
26355b466jacobs */
27355b466jacobs
28355b466jacobs/* $Id: lpd-cancel.c 155 2006-04-26 02:34:54Z ktou $ */
29355b466jacobs
30355b466jacobs#define	__EXTENSIONS__	/* for strtok_r() */
31355b466jacobs#include <stdio.h>
32355b466jacobs#include <stdlib.h>
33355b466jacobs#include <unistd.h>
34355b466jacobs#include <string.h>
35355b466jacobs#include <papi_impl.h>
36355b466jacobs
37355b466jacobspapi_status_t
38355b466jacobslpd_cancel_job(service_t *svc, int id)
39355b466jacobs{
40355b466jacobs	papi_status_t status = PAPI_INTERNAL_ERROR;
41355b466jacobs	int fd;
42752ec50jacobs	char *list[2];
43355b466jacobs	char buf[128];	/* this should be overkill */
44355b466jacobs
45355b466jacobs	if (svc == NULL)
46355b466jacobs		return (PAPI_BAD_ARGUMENT);
47355b466jacobs
48355b466jacobs	snprintf(buf, sizeof (buf), "%d", id);
49355b466jacobs	list[0] = buf;
50355b466jacobs	list[1] = NULL;
51355b466jacobs
524bd2082ceastha	if ((fd = lpd_open(svc, 'c', list, 15)) < 0)
53355b466jacobs		return (PAPI_INTERNAL_ERROR);
54355b466jacobs
55355b466jacobs	memset(buf, 0, sizeof (buf));
56355b466jacobs	if (fdgets(buf, sizeof (buf), fd) != NULL) {
57355b466jacobs		if (buf[0] == '\0')
58355b466jacobs			status = PAPI_NOT_FOUND;
596b5764csonam gupta - Sun Microsystems - Bangalore India		else if ((strstr(buf, "permission denied") != NULL) ||
606b5764csonam gupta - Sun Microsystems - Bangalore India		    (strstr(buf, "not-authorized") != NULL))
61355b466jacobs			status = PAPI_NOT_AUTHORIZED;
62355b466jacobs		else if ((strstr(buf, "cancelled") != NULL) ||
636b5764csonam gupta - Sun Microsystems - Bangalore India		    (strstr(buf, "removed") != NULL))
64355b466jacobs			status = PAPI_OK;
65355b466jacobs	} else
66355b466jacobs		status = PAPI_NOT_FOUND;
67355b466jacobs
68355b466jacobs	close(fd);
69355b466jacobs
70355b466jacobs	return (status);
71355b466jacobs}
72355b466jacobs
73355b466jacobspapi_status_t
74355b466jacobslpd_purge_jobs(service_t *svc, job_t ***jobs)
75355b466jacobs{
76355b466jacobs	papi_status_t status = PAPI_INTERNAL_ERROR;
77355b466jacobs	int fd;
78355b466jacobs	char *queue;
79355b466jacobs	char buf[256];
80355b466jacobs
81355b466jacobs	if (svc == NULL)
82