summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/solaris2/kopensolaris-gnu/zone.c
blob: a62c63be0ad558c6c807ebb3cddd344a85a7782f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Copyright (C) 2008 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by David Bartley <dtbartle@csclub.uwaterloo.ca>, 2008.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include <inline-syscall.h>
#include <zone.h>
#include <privP.h>
#include <dlfcn.h>
#include <streams/stropts.h>
#include <sys/ptms.h>

static int (*_zone_get_id) (const char *, zoneid_t *);

DECLARE_INLINE_SYSCALL (zoneid_t, zone_create, zone_def *def);
DECLARE_INLINE_SYSCALL (zoneid_t, zone_lookup, const char *name);



zoneid_t getzoneid (void)
{
  return INLINE_SYSCALL (zone_lookup, 1, NULL);
}


zoneid_t getzoneidbyname (const char *name)
{
  return INLINE_SYSCALL (zone_lookup, 1, name);
}


ssize_t getzonenamebyid (zoneid_t id, char *buf, size_t buflen)
{
  return zone_getattr (id, ZONE_ATTR_NAME, buf, buflen);
}


zoneid_t zone_create (const char *name, const char *root,
      const struct priv_set *privs, const char *rctlbuf, size_t rctlbufsz,
      const char *zfsbuf, size_t zfsbufsz, int *extended_error, int match,
      int doi, const bslabel_t *label, int flags)
{
  zone_def def;
  def.zone_name = name;
  def.zone_root = root;
  def.zone_privs = privs;
  def.zone_privssz = __PRIVSETSIZE;
  def.rctlbuf = rctlbuf;
  def.rctlbufsz = rctlbufsz;
  def.extended_error = extended_error;
  def.zfsbuf = zfsbuf;
  def.zfsbufsz = zfsbufsz;
  def.match = match;
  def.doi = doi;
  def.label = label;
  def.flags = flags;

  return INLINE_SYSCALL (zone_create, 1, &def);
}


int zone_get_id (const char *str, zoneid_t *idp)
{
  /* libzonecfg.so.1 has the real function.  */
  void *lzc = __libc_dlopen ("libzonecfg.so.1");
  if (lzc)
    {
      _zone_get_id = __libc_dlsym (lzc, "zone_get_id");
      if (_zone_get_id)
        return _zone_get_id (str, idp);
    }

  return ENOSYS;
}


int zonept (int fd, zoneid_t zoneid)
{
  /* Send ZONEPT down.  */
  struct strioctl si;
  si.ic_cmd = ZONEPT;
  si.ic_timout = 0;
  si.ic_len = sizeof (zoneid_t);
  si.ic_dp = (char *)&zoneid;

  return (ioctl (fd, I_STR, &si) < 0) ? -1 : 0;
}