clear_locks.c revision 285830
1169691Skan/*- 2132720Skan * Copyright (c) 2008 Isilon Inc http://www.isilon.com/ 397403Sobrien * Authors: Doug Rabson <dfr@rabson.org> 4169691Skan * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org> 5169691Skan * 697403Sobrien * Redistribution and use in source and binary forms, with or without 797403Sobrien * modification, are permitted provided that the following conditions 897403Sobrien * are met: 997403Sobrien * 1. Redistributions of source code must retain the above copyright 1097403Sobrien * notice, this list of conditions and the following disclaimer. 1197403Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1297403Sobrien * notice, this list of conditions and the following disclaimer in the 1397403Sobrien * documentation and/or other materials provided with the distribution. 1497403Sobrien * 15132720Skan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1697403Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17169691Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1897403Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1997403Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2097403Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2197403Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2297403Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2397403Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2497403Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25132720Skan * SUCH DAMAGE. 2697403Sobrien */ 27132720Skan 28132720Skan#include <sys/cdefs.h> 29132720Skan__FBSDID("$FreeBSD: releng/10.2/usr.sbin/clear_locks/clear_locks.c 177633 2008-03-26 15:23:12Z dfr $"); 30132720Skan 31132720Skan#include <stdio.h> 3297403Sobrien#include <stdlib.h> 3397403Sobrien#include <unistd.h> 3497403Sobrien 3597403Sobrien#include <rpc/rpc.h> 3697403Sobrien#include <rpcsvc/nlm_prot.h> 3797403Sobrien 3897403Sobrienint 3997403Sobrienmain(int argc, char **argv) 4097403Sobrien{ 41169691Skan enum clnt_stat stat; 42169691Skan char *hostname; 43169691Skan nlm4_notify notify; 44169691Skan 45169691Skan if (argc != 2) { 46169691Skan fprintf(stderr, "Usage: clear_locks <hostname>\n"); 47169691Skan exit(1); 48169691Skan } 49169691Skan hostname = argv[1]; 50169691Skan 51169691Skan if (geteuid() != 0) { 52169691Skan fprintf(stderr, "clear_locks: must be root\n"); 53169691Skan exit(1); 54169691Skan } 55169691Skan 56169691Skan notify.name = hostname; 57169691Skan notify.state = 0; 58169691Skan stat = rpc_call("localhost", NLM_PROG, NLM_VERS4, NLM4_FREE_ALL, 59169691Skan (xdrproc_t) xdr_nlm4_notify, (void *) ¬ify, 60169691Skan (xdrproc_t) xdr_void, NULL, NULL); 61169691Skan 62169691Skan if (stat != RPC_SUCCESS) { 63169691Skan clnt_perrno(stat); 64169691Skan exit(1); 65169691Skan } 66169691Skan fprintf(stderr, "clear_locks: cleared locks for hostname %s\n", 67169691Skan hostname); 68169691Skan 69169691Skan return (0); 70169691Skan} 71169691Skan