8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / vscan / vscand / vs_door.c
blob8061318d566cb2a5fa94ac561ae420a8ddf4efea
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
30 * vscand door server
33 #include <door.h>
34 #include <errno.h>
35 #include <syslog.h>
36 #include <unistd.h>
37 #include <varargs.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <synch.h>
42 #include <fcntl.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <sys/param.h>
46 #include <pthread.h>
47 #include "vs_incl.h"
49 #define VS_DOOR_VERSION 1
50 static int vs_door_cookie;
52 /* function prototype */
53 static void vs_door_scan_req(void *, char *, size_t, door_desc_t *, uint_t);
55 /* local data */
56 static int vs_door_fd = -1;
57 static pthread_mutex_t vs_door_mutex = PTHREAD_MUTEX_INITIALIZER;
61 * vs_door_init
63 * Start the vscand door service.
64 * Returns 0 on success. Otherwise, -1.
66 int
67 vs_door_init(void)
69 (void) pthread_mutex_lock(&vs_door_mutex);
71 if ((vs_door_fd = door_create(vs_door_scan_req,
72 &vs_door_cookie, (DOOR_UNREF | DOOR_REFUSE_DESC))) < 0) {
73 syslog(LOG_ERR, "vscand: door create%s", strerror(errno));
74 vs_door_fd = -1;
77 (void) pthread_mutex_unlock(&vs_door_mutex);
78 return (vs_door_fd);
83 * vscan_door_fini
85 * Stop the vscand door service.
87 void
88 vs_door_fini(void)
90 (void) pthread_mutex_lock(&vs_door_mutex);
92 if (vs_door_fd >= 0) {
93 if (door_revoke(vs_door_fd) < 0)
94 syslog(LOG_ERR, "vscand: door revoke %s",
95 strerror(errno));
98 vs_door_fd = -1;
100 (void) pthread_mutex_unlock(&vs_door_mutex);
105 * vs_door_scan_req
107 * Invoke the vscand door service.
109 /* ARGSUSED */
110 static void
111 vs_door_scan_req(void *cookie, char *ptr, size_t size, door_desc_t *dp,
112 uint_t n_desc)
114 vs_scan_req_t *scan_req;
115 uint32_t result = VS_STATUS_ERROR;
117 if (ptr != NULL) {
118 /* LINTED E_BAD_PTR_CAST_ALIGN - to be fixed with encoding */
119 scan_req = (vs_scan_req_t *)ptr;
120 result = vs_svc_queue_scan_req(scan_req);
123 (void) door_return((char *)&result, sizeof (uint32_t), NULL, 0);