Print this page
OS-3280 need a way to specify the root of a native system in the lx brand
OS-3279 lx brand should allow delegated datasets
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>


   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #pragma ident   "%Z%%M% %I%     %E% SMI"
  28 
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <unistd.h>
  32 #include <fcntl.h>
  33 #include <ctype.h>
  34 #include <string.h>
  35 #include <signal.h>
  36 #include <errno.h>
  37 #include <sys/types.h>
  38 #include <sys/wait.h>
  39 #include <libproc.h>


  40 
  41 #define NOREAP_TIME 60          /* wait 60 seconds before allow a reap */
  42 
  43 static volatile int interrupt;
  44 static int Fflag;
  45 static char *command;
  46 
  47 static void
  48 intr(int sig)
  49 {
  50         interrupt = sig;
  51 }
  52 
  53 static int
  54 open_usage(pid_t pid, int *perr)
  55 {
  56         char path[64];
  57         struct stat64 st;
  58         int fd;
  59 
  60         (void) snprintf(path, sizeof (path), "/proc/%d/usage", (int)pid);
  61 
  62         /*
  63          * Attempt to open the usage file, and return the fd if we can
  64          * confirm this is a regular file provided by /proc.
  65          */
  66         if ((fd = open64(path, O_RDONLY)) >= 0) {
  67                 if (fstat64(fd, &st) != 0 || !S_ISREG(st.st_mode) ||
  68                     strcmp(st.st_fstype, "proc") != 0) {
  69                         (void) close(fd);
  70                         fd = -1;
  71                 }
  72         } else if (errno == EACCES || errno == EPERM)
  73                 *perr = G_PERM;
  74 
  75         return (fd);
  76 }
  77 
  78 static int
  79 proc_usage(pid_t pid, prusage_t *pup, int *perr)
  80 {




   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 


  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <unistd.h>
  30 #include <fcntl.h>
  31 #include <ctype.h>
  32 #include <string.h>
  33 #include <signal.h>
  34 #include <errno.h>
  35 #include <sys/types.h>
  36 #include <sys/wait.h>
  37 #include <libproc.h>
  38 #include <limits.h>
  39 #include "ptools_common.h"
  40 
  41 #define NOREAP_TIME 60          /* wait 60 seconds before allow a reap */
  42 
  43 static volatile int interrupt;
  44 static int Fflag;
  45 static char *command;
  46 
  47 static void
  48 intr(int sig)
  49 {
  50         interrupt = sig;
  51 }
  52 
  53 static int
  54 open_usage(pid_t pid, int *perr)
  55 {
  56         char path[PATH_MAX];
  57         struct stat64 st;
  58         int fd;
  59 
  60         (void) proc_snprintf(path, sizeof (path), "/proc/%d/usage", (int)pid);
  61 
  62         /*
  63          * Attempt to open the usage file, and return the fd if we can
  64          * confirm this is a regular file provided by /proc.
  65          */
  66         if ((fd = open64(path, O_RDONLY)) >= 0) {
  67                 if (fstat64(fd, &st) != 0 || !S_ISREG(st.st_mode) ||
  68                     strcmp(st.st_fstype, "proc") != 0) {
  69                         (void) close(fd);
  70                         fd = -1;
  71                 }
  72         } else if (errno == EACCES || errno == EPERM)
  73                 *perr = G_PERM;
  74 
  75         return (fd);
  76 }
  77 
  78 static int
  79 proc_usage(pid_t pid, prusage_t *pup, int *perr)
  80 {