2338N/A/*
2338N/A * CDDL HEADER START
2338N/A *
2338N/A * The contents of this file are subject to the terms of the
2338N/A * Common Development and Distribution License (the "License").
2338N/A * You may not use this file except in compliance with the License.
2338N/A *
2338N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2338N/A * or http://www.opensolaris.org/os/licensing.
2338N/A * See the License for the specific language governing permissions
2338N/A * and limitations under the License.
2338N/A *
2338N/A * When distributing Covered Code, include this CDDL HEADER in each
2338N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2338N/A * If applicable, add the following below this CDDL HEADER, with the
2338N/A * fields enclosed by brackets "[]" replaced with your own identifying
2338N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2338N/A *
2338N/A * CDDL HEADER END
2338N/A */
2338N/A/*
2665N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
2338N/A */
2338N/A
2338N/A/*
2338N/A * Notify zoneproxyd when a zone is added or removed. If zoneproxyd is not
2338N/A * running, this does nothing.
2338N/A */
2338N/A
2338N/A#include <sys/types.h>
2338N/A#include <door.h>
2338N/A#include <errno.h>
2338N/A#include <fcntl.h>
2338N/A#include <locale.h>
2338N/A#include <stdio.h>
2338N/A#include <stdlib.h>
2338N/A#include <unistd.h>
2338N/A#include <zone.h>
2338N/A#include <zoneproxy_impl.h>
2338N/A
2338N/Astatic void
2338N/Ausage(void)
2338N/A{
2338N/A (void) fprintf(stderr, "Usage: zoneproxy-adm [-R] zonename\n");
2338N/A (void) fprintf(stderr,
2338N/A "\tNote: zoneproxy-adm should not be run directly.\n");
2338N/A exit(2);
2338N/A}
2338N/A
2338N/Astatic void
2338N/Anotify_zoneproxyd(zoneid_t zoneid, boolean_t remove)
2338N/A{
2338N/A int cmd[2];
2338N/A int fd;
2338N/A door_arg_t params;
2338N/A
2338N/A fd = open(ZP_DOOR_PATH, O_RDONLY);
2338N/A if (fd < 0)
2338N/A return;
2338N/A
2338N/A if (remove) {
2338N/A cmd[0] = ZP_CMD_ZONE_REMOVED;
2338N/A } else {
2338N/A cmd[0] = ZP_CMD_ZONE_ADDED;
2338N/A }
2338N/A cmd[1] = zoneid;
2338N/A params.data_ptr = (char *)cmd;
2338N/A params.data_size = sizeof (cmd);
2338N/A params.desc_ptr = NULL;
2338N/A params.desc_num = 0;
2338N/A params.rbuf = NULL;
2338N/A params.rsize = NULL;
2338N/A (void) door_call(fd, &params);
2338N/A (void) close(fd);
2338N/A}
2338N/A
2338N/Aint
2338N/Amain(int argc, char *argv[])
2338N/A{
2338N/A int opt;
2338N/A boolean_t remove = B_FALSE;
2338N/A zoneid_t zoneid;
2338N/A
2338N/A while ((opt = getopt(argc, argv, "R")) != EOF) {
2338N/A switch (opt) {
2338N/A case 'R':
2338N/A remove = B_TRUE;
2338N/A break;
2338N/A default:
2338N/A usage();
2338N/A }
2338N/A }
2338N/A
2338N/A if (argc - optind != 1) {
2338N/A usage();
2338N/A }
2338N/A
2338N/A zoneid = getzoneidbyname(argv[optind]);
2338N/A
2338N/A if (zoneid == -1) {
2338N/A (void) fprintf(stderr, "unable to get zone id for zone: %s",
2338N/A argv[optind]);
2338N/A exit(1);
2338N/A }
2338N/A
2338N/A notify_zoneproxyd(zoneid, remove);
2338N/A
2338N/A return 0;
2338N/A}