3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/stat.h>
  28 #include <sys/swap.h>
  29 #include <sys/dumpadm.h>
  30 #include <sys/utsname.h>
  31 
  32 #include <unistd.h>
  33 #include <string.h>
  34 #include <stdlib.h>
  35 #include <stdio.h>
  36 #include <fcntl.h>
  37 #include <errno.h>
  38 #include <libdiskmgt.h>
  39 #include <libzfs.h>
  40 #include <uuid/uuid.h>
  41 
  42 #include "dconf.h"
  43 #include "minfree.h"
  44 #include "utils.h"
  45 #include "swap.h"
  46 
  47 typedef struct dc_token {
  48         const char *tok_name;
  49         int (*tok_parse)(dumpconf_t *, char *);
  50         int (*tok_print)(const dumpconf_t *, FILE *);
 
  71 static const char DC_STR_YES[] = "yes";         /* Enable on string */
  72 static const char DC_STR_NO[] = "no";           /* Enable off string */
  73 static const char DC_STR_SWAP[] = "swap";       /* Default dump device */
  74 static const char DC_STR_NONE[] = "none";
  75 
  76 /* The pages included in the dump */
  77 static const char DC_STR_KERNEL[] = "kernel";   /* Kernel only */
  78 static const char DC_STR_CURPROC[] = "curproc"; /* Kernel + current process */
  79 static const char DC_STR_ALL[] = "all";         /* All pages */
  80 
  81 /*
  82  * Permissions and ownership for the configuration file:
  83  */
  84 #define DC_OWNER        0                               /* Uid 0 (root) */
  85 #define DC_GROUP        1                               /* Gid 1 (other) */
  86 #define DC_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) /* Mode 0644 */
  87 
  88 static void
  89 dconf_init(dumpconf_t *dcp, int dcmode)
  90 {
  91         struct utsname ut;
  92 
  93         /*
  94          * Default device for dumps is 'swap' (appropriate swap device),
  95          * and default savecore directory is /var/crash/`uname -n`,
  96          * which is compatible with pre-dumpadm behavior.
  97          */
  98         (void) strcpy(dcp->dc_device, DC_STR_SWAP);
  99         (void) strcpy(dcp->dc_savdir, "/var/crash");
 100 
 101         if (uname(&ut) != -1) {
 102                 (void) strcat(dcp->dc_savdir, "/");
 103                 (void) strcat(dcp->dc_savdir, ut.nodename);
 104         }
 105 
 106         /*
 107          * Default is contents kernel, savecore enabled on reboot,
 108          * savecore saves compressed core files.
 109          */
 110         dcp->dc_cflags = DUMP_KERNEL;
 111         dcp->dc_enable = DC_ON;
 112         dcp->dc_csave = DC_COMPRESSED;
 113 
 114         dcp->dc_mode = dcmode;
 115         dcp->dc_conf_fp = NULL;
 116         dcp->dc_conf_fd = -1;
 117         dcp->dc_dump_fd = -1;
 118         dcp->dc_readonly = B_FALSE;
 119 }
 120 
 121 int
 122 dconf_open(dumpconf_t *dcp, const char *dpath, const char *fpath, int dcmode)
 123 {
 124         char buf[BUFSIZ];
 125         int line;
 
 | 
 
 
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/stat.h>
  28 #include <sys/swap.h>
  29 #include <sys/dumpadm.h>
  30 
  31 #include <unistd.h>
  32 #include <string.h>
  33 #include <stdlib.h>
  34 #include <stdio.h>
  35 #include <fcntl.h>
  36 #include <errno.h>
  37 #include <libdiskmgt.h>
  38 #include <libzfs.h>
  39 #include <uuid/uuid.h>
  40 
  41 #include "dconf.h"
  42 #include "minfree.h"
  43 #include "utils.h"
  44 #include "swap.h"
  45 
  46 typedef struct dc_token {
  47         const char *tok_name;
  48         int (*tok_parse)(dumpconf_t *, char *);
  49         int (*tok_print)(const dumpconf_t *, FILE *);
 
  70 static const char DC_STR_YES[] = "yes";         /* Enable on string */
  71 static const char DC_STR_NO[] = "no";           /* Enable off string */
  72 static const char DC_STR_SWAP[] = "swap";       /* Default dump device */
  73 static const char DC_STR_NONE[] = "none";
  74 
  75 /* The pages included in the dump */
  76 static const char DC_STR_KERNEL[] = "kernel";   /* Kernel only */
  77 static const char DC_STR_CURPROC[] = "curproc"; /* Kernel + current process */
  78 static const char DC_STR_ALL[] = "all";         /* All pages */
  79 
  80 /*
  81  * Permissions and ownership for the configuration file:
  82  */
  83 #define DC_OWNER        0                               /* Uid 0 (root) */
  84 #define DC_GROUP        1                               /* Gid 1 (other) */
  85 #define DC_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) /* Mode 0644 */
  86 
  87 static void
  88 dconf_init(dumpconf_t *dcp, int dcmode)
  89 {
  90         /*
  91          * Default device for dumps is 'swap' (appropriate swap device),
  92          * and default savecore directory is /var/crash,
  93          * which is compatible with pre-dumpadm behavior.
  94          */
  95         (void) strcpy(dcp->dc_device, DC_STR_SWAP);
  96         (void) strcpy(dcp->dc_savdir, "/var/crash");
  97 
  98         /*
  99          * Default is contents kernel, savecore enabled on reboot,
 100          * savecore saves compressed core files.
 101          */
 102         dcp->dc_cflags = DUMP_KERNEL;
 103         dcp->dc_enable = DC_ON;
 104         dcp->dc_csave = DC_COMPRESSED;
 105 
 106         dcp->dc_mode = dcmode;
 107         dcp->dc_conf_fp = NULL;
 108         dcp->dc_conf_fd = -1;
 109         dcp->dc_dump_fd = -1;
 110         dcp->dc_readonly = B_FALSE;
 111 }
 112 
 113 int
 114 dconf_open(dumpconf_t *dcp, const char *dpath, const char *fpath, int dcmode)
 115 {
 116         char buf[BUFSIZ];
 117         int line;
 
 |