#include <exec/exec.h>
#include <clib/exec_protos.h>

#include "lavd.h"

static const char	PortName[] = "lavd";
struct MsgPort	*lavdPort = NULL;
struct MsgPort	*RepPort = NULL;	/* Reply port. */
lavdMsg	Req;

main()
{

	if ((RepPort = CreateMsgPort()) == NULL) {
		PutStr("Couldn't create a message port.\n");
		goto exitmain;
	}
	Req.lm_Message.mn_ReplyPort = RepPort;
	Req.lm_Message.mn_Length = sizeof(lavdMsg);
	Req.Class = LAV_STOP;

	/* Forbid so the port doesn't go away... */
	Forbid();
	if ((lavdPort = FindPort(PortName)) == NULL) {
		Permit();
		PutStr("Demon not running.\n");
		goto exitmain;
	}
	PutMsg (lavdPort, &Req);
	Permit();

	WaitPort(RepPort);	/* Wait for the reply. */

      exitmain:
	if (RepPort != NULL) {
		DeleteMsgPort(RepPort);
	}
	exit(0);
}
