Print this page
    
NEX-9586 remove nodename from the default savecore directory path
Reviewed by: Dan Fields <dan.fields@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/dumpadm/dconf.c
          +++ new/usr/src/cmd/dumpadm/dconf.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  
    | 
      ↓ open down ↓ | 
    12 lines elided | 
    
      ↑ open up ↑ | 
  
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
       23 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
  24   24   */
  25   25  
  26   26  #include <sys/types.h>
  27   27  #include <sys/stat.h>
  28   28  #include <sys/swap.h>
  29   29  #include <sys/dumpadm.h>
  30      -#include <sys/utsname.h>
  31   30  
  32   31  #include <unistd.h>
  33   32  #include <string.h>
  34   33  #include <stdlib.h>
  35   34  #include <stdio.h>
  36   35  #include <fcntl.h>
  37   36  #include <errno.h>
  38   37  #include <libdiskmgt.h>
  39   38  #include <libzfs.h>
  40   39  #include <uuid/uuid.h>
  41   40  
  42   41  #include "dconf.h"
  43   42  #include "minfree.h"
  44   43  #include "utils.h"
  45   44  #include "swap.h"
  46   45  
  47   46  typedef struct dc_token {
  48   47          const char *tok_name;
  49   48          int (*tok_parse)(dumpconf_t *, char *);
  50   49          int (*tok_print)(const dumpconf_t *, FILE *);
  51   50  } dc_token_t;
  52   51  
  53   52  
  54   53  static int print_device(const dumpconf_t *, FILE *);
  55   54  static int print_savdir(const dumpconf_t *, FILE *);
  56   55  static int print_content(const dumpconf_t *, FILE *);
  57   56  static int print_enable(const dumpconf_t *, FILE *);
  58   57  static int print_csave(const dumpconf_t *, FILE *);
  59   58  
  60   59  static const dc_token_t tokens[] = {
  61   60          { "DUMPADM_DEVICE", dconf_str2device, print_device },
  62   61          { "DUMPADM_SAVDIR", dconf_str2savdir, print_savdir },
  63   62          { "DUMPADM_CONTENT", dconf_str2content, print_content },
  64   63          { "DUMPADM_ENABLE", dconf_str2enable, print_enable },
  65   64          { "DUMPADM_CSAVE", dconf_str2csave, print_csave },
  66   65          { NULL, NULL, NULL }
  67   66  };
  68   67  
  69   68  static const char DC_STR_ON[] = "on";           /* On string */
  70   69  static const char DC_STR_OFF[] = "off";         /* Off string */
  71   70  static const char DC_STR_YES[] = "yes";         /* Enable on string */
  72   71  static const char DC_STR_NO[] = "no";           /* Enable off string */
  73   72  static const char DC_STR_SWAP[] = "swap";       /* Default dump device */
  74   73  static const char DC_STR_NONE[] = "none";
  75   74  
  76   75  /* The pages included in the dump */
  77   76  static const char DC_STR_KERNEL[] = "kernel";   /* Kernel only */
  78   77  static const char DC_STR_CURPROC[] = "curproc"; /* Kernel + current process */
  79   78  static const char DC_STR_ALL[] = "all";         /* All pages */
  80   79  
  
    | 
      ↓ open down ↓ | 
    40 lines elided | 
    
      ↑ open up ↑ | 
  
  81   80  /*
  82   81   * Permissions and ownership for the configuration file:
  83   82   */
  84   83  #define DC_OWNER        0                               /* Uid 0 (root) */
  85   84  #define DC_GROUP        1                               /* Gid 1 (other) */
  86   85  #define DC_PERM (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) /* Mode 0644 */
  87   86  
  88   87  static void
  89   88  dconf_init(dumpconf_t *dcp, int dcmode)
  90   89  {
  91      -        struct utsname ut;
  92      -
  93   90          /*
  94   91           * Default device for dumps is 'swap' (appropriate swap device),
  95      -         * and default savecore directory is /var/crash/`uname -n`,
       92 +         * and default savecore directory is /var/crash,
  96   93           * which is compatible with pre-dumpadm behavior.
  97   94           */
  98   95          (void) strcpy(dcp->dc_device, DC_STR_SWAP);
  99   96          (void) strcpy(dcp->dc_savdir, "/var/crash");
 100   97  
 101      -        if (uname(&ut) != -1) {
 102      -                (void) strcat(dcp->dc_savdir, "/");
 103      -                (void) strcat(dcp->dc_savdir, ut.nodename);
 104      -        }
 105      -
 106   98          /*
 107   99           * Default is contents kernel, savecore enabled on reboot,
 108  100           * savecore saves compressed core files.
 109  101           */
 110  102          dcp->dc_cflags = DUMP_KERNEL;
 111  103          dcp->dc_enable = DC_ON;
 112  104          dcp->dc_csave = DC_COMPRESSED;
 113  105  
 114  106          dcp->dc_mode = dcmode;
 115  107          dcp->dc_conf_fp = NULL;
 116  108          dcp->dc_conf_fd = -1;
 117  109          dcp->dc_dump_fd = -1;
 118  110          dcp->dc_readonly = B_FALSE;
 119  111  }
 120  112  
 121  113  int
 122  114  dconf_open(dumpconf_t *dcp, const char *dpath, const char *fpath, int dcmode)
 123  115  {
 124  116          char buf[BUFSIZ];
 125  117          int line;
 126  118          const char *fpmode = "r+";
 127  119  
 128  120          dconf_init(dcp, dcmode);
 129  121  
 130  122          if ((dcp->dc_dump_fd = open(dpath, O_RDWR)) == -1) {
 131  123                  warn(gettext("failed to open %s"), dpath);
 132  124                  return (-1);
 133  125          }
 134  126  
 135  127          if ((dcp->dc_conf_fd = open(fpath, O_RDWR | O_CREAT, DC_PERM)) == -1) {
 136  128                  /*
 137  129                   * Attempt to open the file read-only.
 138  130                   */
 139  131                  if ((dcp->dc_conf_fd = open(fpath, O_RDONLY)) == -1) {
 140  132                          warn(gettext("failed to open %s"), fpath);
 141  133                          return (-1);
 142  134                  }
 143  135  
 144  136                  dcp->dc_readonly = B_TRUE;
 145  137                  fpmode = "r";
 146  138          }
 147  139  
 148  140          if ((dcp->dc_conf_fp = fdopen(dcp->dc_conf_fd, fpmode)) == NULL) {
 149  141                  warn(gettext("failed to open stream for %s"), fpath);
 150  142                  return (-1);
 151  143          }
 152  144  
 153  145          /*
 154  146           * If we're in override mode, the current kernel settings override the
 155  147           * default settings and anything invalid in the configuration file.
 156  148           */
 157  149          if (dcmode == DC_OVERRIDE)
 158  150                  (void) dconf_getdev(dcp);
 159  151  
 160  152          for (line = 1; fgets(buf, BUFSIZ, dcp->dc_conf_fp) != NULL; line++) {
 161  153  
 162  154                  char name[BUFSIZ], value[BUFSIZ];
 163  155                  const dc_token_t *tokp;
 164  156                  int len;
 165  157  
 166  158                  if (buf[0] == '#' || buf[0] == '\n')
 167  159                          continue;
 168  160  
 169  161                  /*
 170  162                   * Look for "name=value", with optional whitespace on either
 171  163                   * side, terminated by a newline, and consuming the whole line.
 172  164                   */
 173  165                  /* LINTED - unbounded string specifier */
 174  166                  if (sscanf(buf, " %[^=]=%s \n%n", name, value, &len) == 2 &&
 175  167                      name[0] != '\0' && value[0] != '\0' && len == strlen(buf)) {
 176  168                          /*
 177  169                           * Locate a matching token in the tokens[] table,
 178  170                           * and invoke its parsing function.
 179  171                           */
 180  172                          for (tokp = tokens; tokp->tok_name != NULL; tokp++) {
 181  173                                  if (strcmp(name, tokp->tok_name) == 0) {
 182  174                                          if (tokp->tok_parse(dcp, value) == -1) {
 183  175                                                  warn(gettext("\"%s\", line %d: "
 184  176                                                      "warning: invalid %s\n"),
 185  177                                                      fpath, line, name);
 186  178                                          }
 187  179                                          break;
 188  180                                  }
 189  181                          }
 190  182  
 191  183                          /*
 192  184                           * If we hit the end of the tokens[] table,
 193  185                           * no matching token was found.
 194  186                           */
 195  187                          if (tokp->tok_name == NULL) {
 196  188                                  warn(gettext("\"%s\", line %d: warning: "
 197  189                                      "invalid token: %s\n"), fpath, line, name);
 198  190                          }
 199  191  
 200  192                  } else {
 201  193                          warn(gettext("\"%s\", line %d: syntax error\n"),
 202  194                              fpath, line);
 203  195                  }
 204  196          }
 205  197  
 206  198          /*
 207  199           * If we're not in override mode, the current kernel settings
 208  200           * override the settings read from the configuration file.
 209  201           */
 210  202          if (dcmode == DC_CURRENT)
 211  203                  return (dconf_getdev(dcp));
 212  204  
 213  205          return (0);
 214  206  }
 215  207  
 216  208  int
 217  209  dconf_getdev(dumpconf_t *dcp)
 218  210  {
 219  211          int status = 0;
 220  212  
 221  213          if ((dcp->dc_cflags = ioctl(dcp->dc_dump_fd, DIOCGETCONF, 0)) == -1) {
 222  214                  warn(gettext("failed to get kernel dump settings"));
 223  215                  status = -1;
 224  216          }
 225  217  
 226  218          if (ioctl(dcp->dc_dump_fd, DIOCGETDEV, dcp->dc_device) == -1) {
 227  219                  if (errno != ENODEV) {
 228  220                          warn(gettext("failed to get dump device"));
 229  221                          status = -1;
 230  222                  } else
 231  223                          dcp->dc_device[0] = '\0';
 232  224          }
 233  225  
 234  226          return (status);
 235  227  }
 236  228  
 237  229  int
 238  230  dconf_close(dumpconf_t *dcp)
 239  231  {
 240  232          if (fclose(dcp->dc_conf_fp) == 0) {
 241  233                  (void) close(dcp->dc_dump_fd);
 242  234                  return (0);
 243  235          }
 244  236          return (-1);
 245  237  }
 246  238  
 247  239  int
 248  240  dconf_write(dumpconf_t *dcp)
 249  241  {
 250  242          const dc_token_t *tokp;
 251  243  
 252  244          if (fseeko(dcp->dc_conf_fp, (off_t)0, SEEK_SET) == -1) {
 253  245                  warn(gettext("failed to seek config file"));
 254  246                  return (-1);
 255  247          }
 256  248  
 257  249          if (ftruncate(dcp->dc_conf_fd, (off_t)0) == -1) {
 258  250                  warn(gettext("failed to truncate config file"));
 259  251                  return (-1);
 260  252          }
 261  253  
 262  254          (void) fputs("#\n# dumpadm.conf\n#\n"
 263  255              "# Configuration parameters for system crash dump.\n"
 264  256              "# Do NOT edit this file by hand -- use dumpadm(1m) instead.\n"
 265  257              "#\n", dcp->dc_conf_fp);
 266  258  
 267  259          for (tokp = tokens; tokp->tok_name != NULL; tokp++) {
 268  260                  if (fprintf(dcp->dc_conf_fp, "%s=", tokp->tok_name) == -1 ||
 269  261                      tokp->tok_print(dcp, dcp->dc_conf_fp) == -1) {
 270  262                          warn(gettext("failed to write token"));
 271  263                          return (-1);
 272  264                  }
 273  265          }
 274  266  
 275  267          if (fflush(dcp->dc_conf_fp) != 0)
 276  268                  warn(gettext("warning: failed to flush config file"));
 277  269  
 278  270          if (fsync(dcp->dc_conf_fd) == -1)
 279  271                  warn(gettext("warning: failed to sync config file to disk"));
 280  272  
 281  273          if (fchmod(dcp->dc_conf_fd, DC_PERM) == -1)
 282  274                  warn(gettext("warning: failed to reset mode on config file"));
 283  275  
 284  276          if (fchown(dcp->dc_conf_fd, DC_OWNER, DC_GROUP) == -1)
 285  277                  warn(gettext("warning: failed to reset owner on config file"));
 286  278  
 287  279          return (0);
 288  280  }
 289  281  
 290  282  static int
 291  283  open_stat64(const char *path, struct stat64 *stp)
 292  284  {
 293  285          int fd = open64(path, O_RDONLY);
 294  286  
 295  287          if (fd >= 0) {
 296  288                  int status = fstat64(fd, stp);
 297  289                  (void) close(fd);
 298  290                  return (status);
 299  291          }
 300  292  
 301  293          return (-1);
 302  294  }
 303  295  
 304  296  static int
 305  297  dconf_swap_compare(const swapent_t *s1, const swapent_t *s2)
 306  298  {
 307  299          struct stat64 st1, st2;
 308  300  
 309  301          int prefer_s1 = -1;     /* Return value to move s1 left (s1 < s2) */
 310  302          int prefer_s2 = 1;      /* Return value to move s2 left (s1 > s2) */
 311  303  
 312  304          /*
 313  305           * First try: open and fstat each swap entry.  If either system
 314  306           * call fails, arbitrarily prefer the other entry.
 315  307           */
 316  308          if (open_stat64(s1->ste_path, &st1) == -1)
 317  309                  return (prefer_s2);
 318  310  
 319  311          if (open_stat64(s2->ste_path, &st2) == -1)
 320  312                  return (prefer_s1);
 321  313  
 322  314          /*
 323  315           * Second try: if both entries are block devices, or if
 324  316           * neither is a block device, prefer the larger.
 325  317           */
 326  318          if (S_ISBLK(st1.st_mode) == S_ISBLK(st2.st_mode)) {
 327  319                  if (st2.st_size > st1.st_size)
 328  320                          return (prefer_s2);
 329  321                  return (prefer_s1);
 330  322          }
 331  323  
 332  324          /*
 333  325           * Third try: prefer the entry that is a block device.
 334  326           */
 335  327          if (S_ISBLK(st2.st_mode))
 336  328                  return (prefer_s2);
 337  329          return (prefer_s1);
 338  330  }
 339  331  
 340  332  static int
 341  333  dconf_dev_ioctl(dumpconf_t *dcp, int cmd)
 342  334  {
 343  335          if (ioctl(dcp->dc_dump_fd, cmd, dcp->dc_device) == 0)
 344  336                  return (0);
 345  337  
 346  338          switch (errno) {
 347  339          case ENOTSUP:
 348  340                  warn(gettext("dumps not supported on %s\n"), dcp->dc_device);
 349  341                  break;
 350  342          case EBUSY:
 351  343                  warn(gettext("device %s is already in use\n"), dcp->dc_device);
 352  344                  break;
 353  345          case EBADR:
 354  346                  /* ZFS pool is too fragmented to support a dump device */
 355  347                  warn(gettext("device %s is too fragmented to be used as "
 356  348                      "a dump device\n"), dcp->dc_device);
 357  349                  break;
 358  350          default:
 359  351                  /*
 360  352                   * NOTE: The stmsboot(1M) command's boot-up script parses this
 361  353                   * error to get the dump device name. If you change the format
 362  354                   * of this message, make sure that stmsboot(1M) is in sync.
 363  355                   */
 364  356                  warn(gettext("cannot use %s as dump device"), dcp->dc_device);
 365  357          }
 366  358          return (-1);
 367  359  }
 368  360  
 369  361  int
 370  362  dconf_update(dumpconf_t *dcp, int checkinuse)
 371  363  {
 372  364          int             oconf;
 373  365          int             error;
 374  366          char            *msg;
 375  367  
 376  368          error = 0;
 377  369  
 378  370          if (checkinuse && (dm_inuse(dcp->dc_device, &msg, DM_WHO_DUMP,
 379  371              &error) || error)) {
 380  372                  if (error != 0) {
 381  373                          warn(gettext("failed to determine if %s is"
 382  374                              " in use"), dcp->dc_device);
 383  375                  } else {
 384  376                          warn(msg);
 385  377                          free(msg);
 386  378                          return (-1);
 387  379                  }
 388  380          }
 389  381  
 390  382          /*
 391  383           * Save the existing dump configuration in case something goes wrong.
 392  384           */
 393  385          if ((oconf = ioctl(dcp->dc_dump_fd, DIOCGETCONF, 0)) == -1) {
 394  386                  warn(gettext("failed to get kernel dump configuration"));
 395  387                  return (-1);
 396  388          }
 397  389  
 398  390          oconf &= DUMP_CONTENT;
 399  391          dcp->dc_cflags &= DUMP_CONTENT;
 400  392  
 401  393          if (ioctl(dcp->dc_dump_fd, DIOCSETCONF, dcp->dc_cflags) == -1) {
 402  394                  warn(gettext("failed to update kernel dump configuration"));
 403  395                  return (-1);
 404  396          }
 405  397  
 406  398          if (strcmp(dcp->dc_device, DC_STR_SWAP) == 0) {
 407  399                  swaptbl_t *swt;
 408  400                  int i;
 409  401  
 410  402                  if ((swt = swap_list()) == NULL)
 411  403                          goto err;
 412  404  
 413  405                  if (swt->swt_n == 0) {
 414  406                          warn(gettext("no swap devices are available\n"));
 415  407                          free(swt);
 416  408                          goto err;
 417  409                  }
 418  410  
 419  411                  qsort(&swt->swt_ent[0], swt->swt_n, sizeof (swapent_t),
 420  412                      (int (*)(const void *, const void *))dconf_swap_compare);
 421  413  
 422  414                  /*
 423  415                   * Iterate through the prioritized list of swap entries,
 424  416                   * trying to configure one as the dump device.
 425  417                   */
 426  418                  for (i = 0; i < swt->swt_n; i++) {
 427  419                          if (ioctl(dcp->dc_dump_fd, DIOCSETDEV,
 428  420                              swt->swt_ent[i].ste_path) == 0) {
 429  421                                  (void) strcpy(dcp->dc_device,
 430  422                                      swt->swt_ent[i].ste_path);
 431  423                                  break;
 432  424                          }
 433  425                  }
 434  426  
 435  427                  if (i == swt->swt_n) {
 436  428                          warn(gettext("no swap devices could be configured "
 437  429                              "as the dump device\n"));
 438  430                          free(swt);
 439  431                          goto err;
 440  432                  }
 441  433                  free(swt);
 442  434  
 443  435          } else if (strcmp(dcp->dc_device, DC_STR_NONE) == 0) {
 444  436                  if (ioctl(dcp->dc_dump_fd, DIOCRMDEV, NULL) == -1) {
 445  437                          warn(gettext("failed to remove dump device"));
 446  438                          return (-1);
 447  439                  }
 448  440          } else if (dcp->dc_device[0] != '\0') {
 449  441                  /*
 450  442                   * If we're not in forcible update mode, then fail the change
 451  443                   * if the selected device cannot be used as the dump device,
 452  444                   * or if it is not big enough to hold the dump.
 453  445                   */
 454  446                  if (dcp->dc_mode == DC_CURRENT) {
 455  447                          struct stat64 st;
 456  448                          uint64_t d;
 457  449  
 458  450                          if (dconf_dev_ioctl(dcp, DIOCTRYDEV) == -1)
 459  451                                  goto err;
 460  452  
 461  453                          if (open_stat64(dcp->dc_device, &st) == -1) {
 462  454                                  warn(gettext("failed to access %s"),
 463  455                                      dcp->dc_device);
 464  456                                  goto err;
 465  457                          }
 466  458  
 467  459                          if ((error = zvol_check_dump_config(
 468  460                              dcp->dc_device)) > 0)
 469  461                                  goto err;
 470  462                          if (ioctl(dcp->dc_dump_fd, DIOCGETDUMPSIZE, &d) == -1) {
 471  463                                  warn(gettext("failed to get kernel dump size"));
 472  464                                  goto err;
 473  465                          }
 474  466  
 475  467                          if (st.st_size < d) {
 476  468                                  warn(gettext("dump device %s is too small to "
 477  469                                      "hold a system dump\ndump size %llu "
 478  470                                      "bytes, device size %lld bytes\n"),
 479  471                                      dcp->dc_device, d, st.st_size);
 480  472                                  goto err;
 481  473                          }
 482  474                  }
 483  475  
 484  476                  if (dconf_dev_ioctl(dcp, DIOCSETDEV) == -1)
 485  477                          goto err;
 486  478          }
 487  479  
 488  480          /*
 489  481           * Now that we've updated the dump device, we need to issue another
 490  482           * ioctl to re-read the config flags to determine whether we
 491  483           * obtained DUMP_EXCL access on our dump device.
 492  484           */
 493  485          if ((dcp->dc_cflags = ioctl(dcp->dc_dump_fd, DIOCGETCONF, 0)) == -1) {
 494  486                  warn(gettext("failed to re-read kernel dump configuration"));
 495  487                  return (-1);
 496  488          }
 497  489  
 498  490          return (0);
 499  491  
 500  492  err:
 501  493          (void) ioctl(dcp->dc_dump_fd, DIOCSETCONF, oconf);
 502  494          return (-1);
 503  495  }
 504  496  
 505  497  int
 506  498  dconf_write_uuid(dumpconf_t *dcp)
 507  499  {
 508  500          char uuidstr[36 + 1];
 509  501          uuid_t uu;
 510  502          int err;
 511  503  
 512  504          uuid_generate(uu);
 513  505          uuid_unparse(uu, uuidstr);
 514  506  
 515  507          err = ioctl(dcp->dc_dump_fd, DIOCSETUUID, uuidstr);
 516  508  
 517  509          if (err)
 518  510                  warn(gettext("kernel image uuid write failed"));
 519  511  
 520  512          return (err == 0);
 521  513  }
 522  514  
 523  515  int
 524  516  dconf_get_dumpsize(dumpconf_t *dcp)
 525  517  {
 526  518          char buf[32];
 527  519          uint64_t d;
 528  520  
 529  521          if (ioctl(dcp->dc_dump_fd, DIOCGETDUMPSIZE, &d) == -1) {
 530  522                  warn(gettext("failed to get kernel dump size"));
 531  523                  return (-1);
 532  524          }
 533  525  
 534  526          zfs_nicenum(d, buf, sizeof (buf));
 535  527  
 536  528          (void) printf(gettext("Estimated dump size: %s\n"), buf);
 537  529          return (0);
 538  530  }
 539  531  
 540  532  void
 541  533  dconf_print(dumpconf_t *dcp, FILE *fp)
 542  534  {
 543  535          u_longlong_t min;
 544  536          char *content;
 545  537  
 546  538          if (dcp->dc_cflags & DUMP_ALL)
 547  539                  content = gettext("all");
 548  540          else if (dcp->dc_cflags & DUMP_CURPROC)
 549  541                  content = gettext("kernel and current process");
 550  542          else
 551  543                  content = gettext("kernel");
 552  544  
 553  545          (void) fprintf(fp, gettext("      Dump content: %s pages\n"), content);
 554  546  
 555  547          if (dcp->dc_device[0] != '\0') {
 556  548                  (void) fprintf(fp, gettext("       Dump device: %s (%s)\n"),
 557  549                      dcp->dc_device, (dcp->dc_cflags & DUMP_EXCL) ?
 558  550                      gettext("dedicated") : gettext("swap"));
 559  551          } else {
 560  552                  (void) fprintf(fp, gettext("       Dump device: none "
 561  553                      "(dumps disabled)\n"));
 562  554          }
 563  555  
 564  556          (void) fprintf(fp, gettext("Savecore directory: %s"), dcp->dc_savdir);
 565  557  
 566  558          if (minfree_read(dcp->dc_savdir, &min) == 0) {
 567  559                  if (min < 1024 || (min % 1024) != 0)
 568  560                          (void) fprintf(fp, gettext(" (minfree = %lluKB)"), min);
 569  561                  else
 570  562                          (void) fprintf(fp, gettext(" (minfree = %lluMB)"),
 571  563                              min / 1024);
 572  564          }
 573  565  
 574  566          (void) fprintf(fp, gettext("\n"));
 575  567  
 576  568          (void) fprintf(fp, gettext("  Savecore enabled: %s\n"),
 577  569              (dcp->dc_enable == DC_OFF) ? gettext("no") : gettext("yes"));
 578  570          (void) fprintf(fp, gettext("   Save compressed: %s\n"),
 579  571              (dcp->dc_csave == DC_UNCOMPRESSED) ? gettext("off") :
 580  572              gettext("on"));
 581  573  }
 582  574  
 583  575  int
 584  576  dconf_str2device(dumpconf_t *dcp, char *buf)
 585  577  {
 586  578          if (strcasecmp(buf, DC_STR_SWAP) == 0) {
 587  579                  (void) strcpy(dcp->dc_device, DC_STR_SWAP);
 588  580                  return (0);
 589  581          }
 590  582  
 591  583          if (strcasecmp(buf, DC_STR_NONE) == 0) {
 592  584                  (void) strcpy(dcp->dc_device, DC_STR_NONE);
 593  585                  return (0);
 594  586          }
 595  587  
 596  588          if (valid_abspath(buf)) {
 597  589                  (void) strcpy(dcp->dc_device, buf);
 598  590                  return (0);
 599  591          }
 600  592  
 601  593          return (-1);
 602  594  }
 603  595  
 604  596  int
 605  597  dconf_str2savdir(dumpconf_t *dcp, char *buf)
 606  598  {
 607  599          if (valid_abspath(buf)) {
 608  600                  (void) strcpy(dcp->dc_savdir, buf);
 609  601                  return (0);
 610  602          }
 611  603  
 612  604          return (-1);
 613  605  }
 614  606  
 615  607  int
 616  608  dconf_str2content(dumpconf_t *dcp, char *buf)
 617  609  {
 618  610          if (strcasecmp(buf, DC_STR_KERNEL) == 0) {
 619  611                  dcp->dc_cflags = (dcp->dc_cflags & ~DUMP_CONTENT) | DUMP_KERNEL;
 620  612                  return (0);
 621  613          }
 622  614  
 623  615          if (strcasecmp(buf, DC_STR_CURPROC) == 0) {
 624  616                  dcp->dc_cflags = (dcp->dc_cflags & ~DUMP_CONTENT) |
 625  617                      DUMP_CURPROC;
 626  618                  return (0);
 627  619          }
 628  620  
 629  621          if (strcasecmp(buf, DC_STR_ALL) == 0) {
 630  622                  dcp->dc_cflags = (dcp->dc_cflags & ~DUMP_CONTENT) | DUMP_ALL;
 631  623                  return (0);
 632  624          }
 633  625  
 634  626          warn(gettext("invalid dump content type -- %s\n"), buf);
 635  627          return (-1);
 636  628  }
 637  629  
 638  630  int
 639  631  dconf_str2enable(dumpconf_t *dcp, char *buf)
 640  632  {
 641  633          if (strcasecmp(buf, DC_STR_YES) == 0) {
 642  634                  dcp->dc_enable = DC_ON;
 643  635                  return (0);
 644  636          }
 645  637  
 646  638          if (strcasecmp(buf, DC_STR_NO) == 0) {
 647  639                  dcp->dc_enable = DC_OFF;
 648  640                  return (0);
 649  641          }
 650  642  
 651  643          warn(gettext("invalid enable value -- %s\n"), buf);
 652  644          return (-1);
 653  645  }
 654  646  
 655  647  int
 656  648  dconf_str2csave(dumpconf_t *dcp, char *buf)
 657  649  {
 658  650          if (strcasecmp(buf, DC_STR_ON) == 0) {
 659  651                  dcp->dc_csave = DC_COMPRESSED;
 660  652                  return (0);
 661  653          }
 662  654  
 663  655          if (strcasecmp(buf, DC_STR_OFF) == 0) {
 664  656                  dcp->dc_csave = DC_UNCOMPRESSED;
 665  657                  return (0);
 666  658          }
 667  659  
 668  660          warn(gettext("invalid save compressed value -- %s\n"), buf);
 669  661          return (-1);
 670  662  }
 671  663  
 672  664  static int
 673  665  print_content(const dumpconf_t *dcp, FILE *fp)
 674  666  {
 675  667          const char *content;
 676  668  
 677  669          if (dcp->dc_cflags & DUMP_ALL)
 678  670                  content = DC_STR_ALL;
 679  671          else if (dcp->dc_cflags & DUMP_CURPROC)
 680  672                  content = DC_STR_CURPROC;
 681  673          else
 682  674                  content = DC_STR_KERNEL;
 683  675  
 684  676          return (fprintf(fp, "%s\n", content));
 685  677  }
 686  678  
 687  679  static int
 688  680  print_device(const dumpconf_t *dcp, FILE *fp)
 689  681  {
 690  682          return (fprintf(fp, "%s\n", (dcp->dc_device[0] != '\0') ?
 691  683              dcp->dc_device : DC_STR_SWAP));
 692  684  }
 693  685  
 694  686  static int
 695  687  print_enable(const dumpconf_t *dcp, FILE *fp)
 696  688  {
 697  689          return (fprintf(fp, "%s\n", (dcp->dc_enable == DC_OFF) ?
 698  690              DC_STR_NO : DC_STR_YES));
 699  691  }
 700  692  
 701  693  static int
 702  694  print_csave(const dumpconf_t *dcp, FILE *fp)
 703  695  {
 704  696          return (fprintf(fp, "%s\n", (dcp->dc_csave == DC_COMPRESSED) ?
 705  697              DC_STR_ON : DC_STR_OFF));
 706  698  }
 707  699  
 708  700  static int
 709  701  print_savdir(const dumpconf_t *dcp, FILE *fp)
 710  702  {
 711  703          return (fprintf(fp, "%s\n", dcp->dc_savdir));
 712  704  }
  
    | 
      ↓ open down ↓ | 
    597 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX