Print this page
2445 savecore fails with dump archive but return EXIT_OK


   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) 1983, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */



  24 
  25 #include <stdio.h>
  26 #include <stdlib.h>
  27 #include <stdarg.h>
  28 #include <unistd.h>
  29 #include <fcntl.h>
  30 #include <errno.h>
  31 #include <string.h>
  32 #include <deflt.h>
  33 #include <time.h>
  34 #include <syslog.h>
  35 #include <stropts.h>
  36 #include <pthread.h>
  37 #include <limits.h>
  38 #include <atomic.h>
  39 #include <libnvpair.h>
  40 #include <libintl.h>
  41 #include <sys/mem.h>
  42 #include <sys/statvfs.h>
  43 #include <sys/dumphdr.h>


 201                                 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
 202                                 syslog(LOG_WARNING, buf);
 203                                 break;
 204 
 205                         default:
 206                                 break;
 207                         }
 208                 }
 209                 va_end(args);
 210         }
 211 
 212         switch (flags & _SC_ALLEXIT) {
 213         case 0:
 214                 return;
 215 
 216         case SC_EXIT_OK:
 217                 code = 0;
 218                 break;
 219 
 220         case SC_EXIT_PEND:







 221                 code = 2;
 222                 break;
 223 
 224         case SC_EXIT_FM:
 225                 code = 3;
 226                 break;
 227 
 228         case SC_EXIT_ERR:
 229         default:
 230                 /*
 231                  * Raise an ireport saying why we are exiting.  Do not
 232                  * raise if run as savecore -m.  If something in the
 233                  * raise_event codepath calls logprint avoid recursion.
 234                  */
 235                 if (!mflag && logprint_raised++ == 0)
 236                         raise_event(SC_EVENT_SAVECORE_FAILURE, buf);
 237                 code = 1;
 238                 break;
 239         }
 240 
 241         exit(code);
 242 }
 243 
 244 /*
 245  * System call / libc wrappers that exit on error.
 246  */
 247 static int
 248 Open(const char *name, int oflags, mode_t mode)
 249 {
 250         int fd;
 251 
 252         if ((fd = open64(name, oflags, mode)) == -1)
 253                 logprint(SC_SL_ERR | SC_EXIT_ERR, "open(\"%s\"): %s",
 254                     name, strerror(errno));


 339                 (void) fscanf(fp, "%ld", &file_value);
 340                 (void) fclose(fp);
 341         }
 342         return (file_value < 0 ? default_value : file_value);
 343 }
 344 
 345 static void
 346 read_dumphdr(void)
 347 {
 348         if (filemode)
 349                 dumpfd = Open(dumpfile, O_RDONLY, 0644);
 350         else
 351                 dumpfd = Open(dumpfile, O_RDWR | O_DSYNC, 0644);
 352         endoff = llseek(dumpfd, -DUMP_OFFSET, SEEK_END) & -DUMP_OFFSET;
 353         Pread(dumpfd, &dumphdr, sizeof (dumphdr), endoff);
 354         Pread(dumpfd, &datahdr, sizeof (datahdr), endoff + sizeof (dumphdr));
 355 
 356         pagesize = dumphdr.dump_pagesize;
 357 
 358         if (dumphdr.dump_magic != DUMP_MAGIC)
 359                 logprint(SC_SL_NONE | SC_EXIT_OK, "bad magic number %x",
 360                     dumphdr.dump_magic);
 361 
 362         if ((dumphdr.dump_flags & DF_VALID) == 0 && !disregard_valid_flag)
 363                 logprint(SC_SL_NONE | SC_IF_VERBOSE | SC_EXIT_OK,
 364                     "dump already processed");
 365 
 366         if (dumphdr.dump_version != DUMP_VERSION)
 367                 logprint(SC_SL_NONE | SC_IF_VERBOSE | SC_EXIT_OK,
 368                     "dump version (%d) != %s version (%d)",
 369                     dumphdr.dump_version, progname, DUMP_VERSION);
 370 
 371         if (dumphdr.dump_wordsize != DUMP_WORDSIZE)
 372                 logprint(SC_SL_NONE | SC_EXIT_OK,
 373                     "dump is from %u-bit kernel - cannot save on %u-bit kernel",
 374                     dumphdr.dump_wordsize, DUMP_WORDSIZE);
 375 
 376         if (datahdr.dump_datahdr_magic == DUMP_DATAHDR_MAGIC) {
 377                 if (datahdr.dump_datahdr_version != DUMP_DATAHDR_VERSION)
 378                         logprint(SC_SL_NONE | SC_IF_VERBOSE | SC_EXIT_OK,
 379                             "dump data version (%d) != %s data version (%d)",
 380                             datahdr.dump_datahdr_version, progname,
 381                             DUMP_DATAHDR_VERSION);
 382         } else {
 383                 (void) memset(&datahdr, 0, sizeof (datahdr));
 384                 datahdr.dump_maxcsize = pagesize;
 385         }
 386 
 387         /*
 388          * Read the initial header, clear the valid bits, and compare headers.
 389          * The main header may have been overwritten by swapping if we're
 390          * using a swap partition as the dump device, in which case we bail.
 391          */
 392         Pread(dumpfd, &corehdr, sizeof (dumphdr_t), dumphdr.dump_start);
 393 
 394         corehdr.dump_flags &= ~DF_VALID;
 395         dumphdr.dump_flags &= ~DF_VALID;
 396 
 397         if (memcmp(&corehdr, &dumphdr, sizeof (dumphdr_t)) != 0) {
 398                 /*




   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) 1983, 2010, Oracle and/or its affiliates. All rights reserved.
  23  */
  24 /*
  25  * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  26  */
  27 
  28 #include <stdio.h>
  29 #include <stdlib.h>
  30 #include <stdarg.h>
  31 #include <unistd.h>
  32 #include <fcntl.h>
  33 #include <errno.h>
  34 #include <string.h>
  35 #include <deflt.h>
  36 #include <time.h>
  37 #include <syslog.h>
  38 #include <stropts.h>
  39 #include <pthread.h>
  40 #include <limits.h>
  41 #include <atomic.h>
  42 #include <libnvpair.h>
  43 #include <libintl.h>
  44 #include <sys/mem.h>
  45 #include <sys/statvfs.h>
  46 #include <sys/dumphdr.h>


 204                                 /*LINTED: E_SEC_PRINTF_VAR_FMT*/
 205                                 syslog(LOG_WARNING, buf);
 206                                 break;
 207 
 208                         default:
 209                                 break;
 210                         }
 211                 }
 212                 va_end(args);
 213         }
 214 
 215         switch (flags & _SC_ALLEXIT) {
 216         case 0:
 217                 return;
 218 
 219         case SC_EXIT_OK:
 220                 code = 0;
 221                 break;
 222 
 223         case SC_EXIT_PEND:
 224                 /*
 225                  * Raise an ireport saying why we are exiting.  Do not
 226                  * raise if run as savecore -m.  If something in the
 227                  * raise_event codepath calls logprint avoid recursion.
 228                  */
 229                 if (!mflag && logprint_raised++ == 0)
 230                         raise_event(SC_EVENT_SAVECORE_FAILURE, buf);
 231                 code = 2;
 232                 break;
 233 
 234         case SC_EXIT_FM:
 235                 code = 3;
 236                 break;
 237 
 238         case SC_EXIT_ERR:
 239         default:





 240                 if (!mflag && logprint_raised++ == 0)
 241                         raise_event(SC_EVENT_SAVECORE_FAILURE, buf);
 242                 code = 1;
 243                 break;
 244         }
 245 
 246         exit(code);
 247 }
 248 
 249 /*
 250  * System call / libc wrappers that exit on error.
 251  */
 252 static int
 253 Open(const char *name, int oflags, mode_t mode)
 254 {
 255         int fd;
 256 
 257         if ((fd = open64(name, oflags, mode)) == -1)
 258                 logprint(SC_SL_ERR | SC_EXIT_ERR, "open(\"%s\"): %s",
 259                     name, strerror(errno));


 344                 (void) fscanf(fp, "%ld", &file_value);
 345                 (void) fclose(fp);
 346         }
 347         return (file_value < 0 ? default_value : file_value);
 348 }
 349 
 350 static void
 351 read_dumphdr(void)
 352 {
 353         if (filemode)
 354                 dumpfd = Open(dumpfile, O_RDONLY, 0644);
 355         else
 356                 dumpfd = Open(dumpfile, O_RDWR | O_DSYNC, 0644);
 357         endoff = llseek(dumpfd, -DUMP_OFFSET, SEEK_END) & -DUMP_OFFSET;
 358         Pread(dumpfd, &dumphdr, sizeof (dumphdr), endoff);
 359         Pread(dumpfd, &datahdr, sizeof (datahdr), endoff + sizeof (dumphdr));
 360 
 361         pagesize = dumphdr.dump_pagesize;
 362 
 363         if (dumphdr.dump_magic != DUMP_MAGIC)
 364                 logprint(SC_SL_NONE | SC_EXIT_PEND, "bad magic number %x",
 365                     dumphdr.dump_magic);
 366 
 367         if ((dumphdr.dump_flags & DF_VALID) == 0 && !disregard_valid_flag)
 368                 logprint(SC_SL_NONE | SC_IF_VERBOSE | SC_EXIT_OK,
 369                     "dump already processed");
 370 
 371         if (dumphdr.dump_version != DUMP_VERSION)
 372                 logprint(SC_SL_NONE | SC_IF_VERBOSE | SC_EXIT_PEND,
 373                     "dump version (%d) != %s version (%d)",
 374                     dumphdr.dump_version, progname, DUMP_VERSION);
 375 
 376         if (dumphdr.dump_wordsize != DUMP_WORDSIZE)
 377                 logprint(SC_SL_NONE | SC_EXIT_PEND,
 378                     "dump is from %u-bit kernel - cannot save on %u-bit kernel",
 379                     dumphdr.dump_wordsize, DUMP_WORDSIZE);
 380 
 381         if (datahdr.dump_datahdr_magic == DUMP_DATAHDR_MAGIC) {
 382                 if (datahdr.dump_datahdr_version != DUMP_DATAHDR_VERSION)
 383                         logprint(SC_SL_NONE | SC_IF_VERBOSE | SC_EXIT_PEND,
 384                             "dump data version (%d) != %s data version (%d)",
 385                             datahdr.dump_datahdr_version, progname,
 386                             DUMP_DATAHDR_VERSION);
 387         } else {
 388                 (void) memset(&datahdr, 0, sizeof (datahdr));
 389                 datahdr.dump_maxcsize = pagesize;
 390         }
 391 
 392         /*
 393          * Read the initial header, clear the valid bits, and compare headers.
 394          * The main header may have been overwritten by swapping if we're
 395          * using a swap partition as the dump device, in which case we bail.
 396          */
 397         Pread(dumpfd, &corehdr, sizeof (dumphdr_t), dumphdr.dump_start);
 398 
 399         corehdr.dump_flags &= ~DF_VALID;
 400         dumphdr.dump_flags &= ~DF_VALID;
 401 
 402         if (memcmp(&corehdr, &dumphdr, sizeof (dumphdr_t)) != 0) {
 403                 /*