status.c revision 125011
152419Sjulian
252419Sjulian/*
352419Sjulian * status.c
452419Sjulian *
552419Sjulian * Copyright (c) 1996-1999 Whistle Communications, Inc.
652419Sjulian * All rights reserved.
752419Sjulian *
852419Sjulian * Subject to the following obligations and disclaimer of warranty, use and
952419Sjulian * redistribution of this software, in source or object code forms, with or
1052419Sjulian * without modifications are expressly permitted by Whistle Communications;
1152419Sjulian * provided, however, that:
1252419Sjulian * 1. Any and all reproductions of the source or object code must include the
1352419Sjulian *    copyright notice above and the following disclaimer of warranties; and
1452419Sjulian * 2. No rights are granted, in any manner or form, to use Whistle
1552419Sjulian *    Communications, Inc. trademarks, including the mark "WHISTLE
1652419Sjulian *    COMMUNICATIONS" on advertising, endorsements, or otherwise except as
1752419Sjulian *    such appears in the above copyright notice or in the software.
1852419Sjulian *
1952419Sjulian * THIS SOFTWARE IS BEING PROVIDED BY WHISTLE COMMUNICATIONS "AS IS", AND
2052419Sjulian * TO THE MAXIMUM EXTENT PERMITTED BY LAW, WHISTLE COMMUNICATIONS MAKES NO
2152419Sjulian * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS SOFTWARE,
2252419Sjulian * INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED WARRANTIES OF
2352419Sjulian * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
2452419Sjulian * WHISTLE COMMUNICATIONS DOES NOT WARRANT, GUARANTEE, OR MAKE ANY
2552419Sjulian * REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS OF THE USE OF THIS
2652419Sjulian * SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY, RELIABILITY OR OTHERWISE.
2752419Sjulian * IN NO EVENT SHALL WHISTLE COMMUNICATIONS BE LIABLE FOR ANY DAMAGES
2852419Sjulian * RESULTING FROM OR ARISING OUT OF ANY USE OF THIS SOFTWARE, INCLUDING
2952419Sjulian * WITHOUT LIMITATION, ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
3052419Sjulian * PUNITIVE, OR CONSEQUENTIAL DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR
3152419Sjulian * SERVICES, LOSS OF USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY
3252419Sjulian * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3352419Sjulian * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3452419Sjulian * THIS SOFTWARE, EVEN IF WHISTLE COMMUNICATIONS IS ADVISED OF THE POSSIBILITY
3552419Sjulian * OF SUCH DAMAGE.
3652419Sjulian *
3752419Sjulian * $FreeBSD: head/usr.sbin/ngctl/status.c 125011 2004-01-26 10:27:18Z ru $
3852419Sjulian */
3952419Sjulian
4052419Sjulian#include "ngctl.h"
4152419Sjulian
4252419Sjulian#define NOSTATUS	"<no status>"
4352419Sjulian
4452419Sjulianstatic int StatusCmd(int ac, char **av);
4552419Sjulian
4652419Sjulianconst struct ngcmd status_cmd = {
4752419Sjulian	StatusCmd,
4852419Sjulian	"status <path>",
4952419Sjulian	"Get human readable status information from the node at <path>",
50125011Sru	NULL,
51125011Sru	{}
5252419Sjulian};
5352419Sjulian
5452419Sjulianstatic int
5552419SjulianStatusCmd(int ac, char **av)
5652419Sjulian{
5752419Sjulian	u_char sbuf[sizeof(struct ng_mesg) + NG_TEXTRESPONSE];
5852419Sjulian	struct ng_mesg *const resp = (struct ng_mesg *) sbuf;
5952419Sjulian	char *const status = (char *) resp->data;
6052419Sjulian	char *path;
6152419Sjulian	int nostat = 0;
6252419Sjulian
6352419Sjulian	/* Get arguments */
6452419Sjulian	switch (ac) {
6552419Sjulian	case 2:
6652419Sjulian		path = av[1];
6752419Sjulian		break;
6852419Sjulian	default:
6952419Sjulian		return(CMDRTN_USAGE);
7052419Sjulian	}
7152419Sjulian
7252419Sjulian	/* Get node status summary */
7352419Sjulian	if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
7452419Sjulian	    NGM_TEXT_STATUS, NULL, 0) < 0) {
7552419Sjulian		switch (errno) {
7652419Sjulian		case EINVAL:
7752419Sjulian			nostat = 1;
7852419Sjulian			break;
7952419Sjulian		default:
8052419Sjulian			warn("send msg");
8152419Sjulian			return(CMDRTN_ERROR);
8252419Sjulian		}
8352419Sjulian	} else {
8452419Sjulian		if (NgRecvMsg(csock, resp, sizeof(sbuf), NULL) < 0
8552419Sjulian		    || (resp->header.flags & NGF_RESP) == 0)
8652419Sjulian			nostat = 1;
8752419Sjulian	}
8852419Sjulian
8952419Sjulian	/* Show it */
9052419Sjulian	if (nostat)
9152419Sjulian		printf("No status available for \"%s\"\n", path);
9252419Sjulian	else
9352419Sjulian		printf("Status for \"%s\":\n%s\n", path, status);
9452419Sjulian	return(CMDRTN_OK);
9552419Sjulian}
9652419Sjulian
97