1 /* $NetBSD: am_glue.c,v 1.1 2009/01/16 17:31:22 christos Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 #ifndef lint 31 __RCSID("$NetBSD: am_glue.c,v 1.1 2009/01/16 17:31:22 christos Exp $"); 32 #endif /* not lint */ 33 34 #ifdef HAVE_CONFIG_H 35 # include <config.h> 36 #endif /* HAVE_CONFIG_H */ 37 #include <am_defs.h> 38 #include <amu.h> 39 40 #include "am_glue.h" 41 42 static CLIENT *clnt; 43 44 /* 45 * Appease lint: Properly typecast some numbers defined in 46 * src/extern/bsd/am-utils/dist/include/amq_defs.h. 47 */ 48 #define xAMQ_PROGRAM (rpcprog_t)AMQ_PROGRAM 49 #define xAMQ_VERSION (rpcvers_t)AMQ_VERSION 50 #define xAMQPROC_SYNC_UMNT (rpcproc_t)AMQPROC_SYNC_UMNT 51 52 void 53 am_init(void) 54 { 55 static struct timeval tv = { 5, 0 }; 56 static const char *server = "localhost"; 57 58 /* 59 * Create RPC endpoint 60 */ 61 /* try tcp first */ 62 clnt = clnt_create(server, xAMQ_PROGRAM, xAMQ_VERSION, "tcp"); 63 if (clnt != NULL) 64 return; 65 66 /* try udp next */ 67 clnt = clnt_create(server, xAMQ_PROGRAM, xAMQ_VERSION, "udp"); 68 if (clnt != NULL) /* set udp timeout */ 69 (void)clnt_control(clnt, CLSET_RETRY_TIMEOUT, (void *)&tv); 70 } 71 72 int 73 am_unmount(const char *dirname) 74 { 75 static struct timeval timeout = { ALLOWED_MOUNT_TIME, 0 }; 76 amq_sync_umnt result; 77 78 if (clnt == NULL) 79 return AMQ_UMNT_FAILED; 80 81 if (clnt_call(clnt, xAMQPROC_SYNC_UMNT, xdr_amq_string, &dirname, 82 xdr_amq_sync_umnt, (void *)&result, timeout) != RPC_SUCCESS) 83 return AMQ_UMNT_SERVER; 84 85 return result.au_etype; 86 } 87