savecore.c (b3bfc7199eb51b03496567ea71bff82b75a2209d) savecore.c (4be4929c2b4d34e3b3fe776a16b448b428012e5d)
1/*-
2 * Copyright (c) 1986, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 107 unchanged lines hidden (view full) ---

116void clear_dump __P((void));
117int Create __P((char *, int));
118int dump_exists __P((void));
119char *find_dev __P((dev_t, int));
120int get_crashtime __P((void));
121void kmem_setup __P((void));
122void log __P((int, char *, ...));
123void Lseek __P((int, off_t, int));
1/*-
2 * Copyright (c) 1986, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 107 unchanged lines hidden (view full) ---

116void clear_dump __P((void));
117int Create __P((char *, int));
118int dump_exists __P((void));
119char *find_dev __P((dev_t, int));
120int get_crashtime __P((void));
121void kmem_setup __P((void));
122void log __P((int, char *, ...));
123void Lseek __P((int, off_t, int));
124int Open __P((char *, int rw));
124int Open __P((const char *, int rw));
125int Read __P((int, void *, int));
126char *rawname __P((char *s));
127void save_core __P((void));
128void usage __P((void));
129void Write __P((int, void *, int));
130
131int
132main(argc, argv)

--- 64 unchanged lines hidden (view full) ---

197 exit(0);
198}
199
200void
201kmem_setup()
202{
203 FILE *fp;
204 int kmem, i;
125int Read __P((int, void *, int));
126char *rawname __P((char *s));
127void save_core __P((void));
128void usage __P((void));
129void Write __P((int, void *, int));
130
131int
132main(argc, argv)

--- 64 unchanged lines hidden (view full) ---

197 exit(0);
198}
199
200void
201kmem_setup()
202{
203 FILE *fp;
204 int kmem, i;
205 char *dump_sys;
205 const char *dump_sys;
206
207 /*
208 * Some names we need for the currently running system, others for
209 * the system that was running when the dump was made. The values
210 * obtained from the current system are used to look for things in
211 * /dev/kmem that cannot be found in the dump_sys namelist, but are
212 * presumed to be the same (since the disk partitions are probably
213 * the same!)
214 */
206
207 /*
208 * Some names we need for the currently running system, others for
209 * the system that was running when the dump was made. The values
210 * obtained from the current system are used to look for things in
211 * /dev/kmem that cannot be found in the dump_sys namelist, but are
212 * presumed to be the same (since the disk partitions are probably
213 * the same!)
214 */
215 if ((nlist(_PATH_UNIX, current_nl)) == -1)
216 syslog(LOG_ERR, "%s: nlist: %s", _PATH_UNIX, strerror(errno));
215 if ((nlist(getbootfile(), current_nl)) == -1)
216 syslog(LOG_ERR, "%s: nlist: %s", getbootfile(),
217 strerror(errno));
217 for (i = 0; cursyms[i] != -1; i++)
218 if (current_nl[cursyms[i]].n_value == 0) {
219 syslog(LOG_ERR, "%s: %s not in namelist",
218 for (i = 0; cursyms[i] != -1; i++)
219 if (current_nl[cursyms[i]].n_value == 0) {
220 syslog(LOG_ERR, "%s: %s not in namelist",
220 _PATH_UNIX, current_nl[cursyms[i]].n_name);
221 getbootfile(), current_nl[cursyms[i]].n_name);
221 exit(1);
222 }
223
222 exit(1);
223 }
224
224 dump_sys = kernel ? kernel : _PATH_UNIX;
225 dump_sys = kernel ? kernel : getbootfile();
225 if ((nlist(dump_sys, dump_nl)) == -1)
226 syslog(LOG_ERR, "%s: nlist: %s", dump_sys, strerror(errno));
227 for (i = 0; dumpsyms[i] != -1; i++)
228 if (dump_nl[dumpsyms[i]].n_value == 0) {
229 syslog(LOG_ERR, "%s: %s not in namelist",
230 dump_sys, dump_nl[dumpsyms[i]].n_name);
231 exit(1);
232 }

--- 40 unchanged lines hidden (view full) ---

273 syslog(LOG_ERR, "%s: fdopen: %m", ddname);
274 exit(1);
275 }
276 fseek(fp, (off_t)(dumplo + ok(dump_nl[X_VERSION].n_value)), L_SET);
277 fgets(core_vers, sizeof(core_vers), fp);
278 if (strcmp(vers, core_vers) && kernel == 0)
279 syslog(LOG_WARNING,
280 "warning: %s version mismatch:\n\t%s\nand\t%s\n",
226 if ((nlist(dump_sys, dump_nl)) == -1)
227 syslog(LOG_ERR, "%s: nlist: %s", dump_sys, strerror(errno));
228 for (i = 0; dumpsyms[i] != -1; i++)
229 if (dump_nl[dumpsyms[i]].n_value == 0) {
230 syslog(LOG_ERR, "%s: %s not in namelist",
231 dump_sys, dump_nl[dumpsyms[i]].n_name);
232 exit(1);
233 }

--- 40 unchanged lines hidden (view full) ---

274 syslog(LOG_ERR, "%s: fdopen: %m", ddname);
275 exit(1);
276 }
277 fseek(fp, (off_t)(dumplo + ok(dump_nl[X_VERSION].n_value)), L_SET);
278 fgets(core_vers, sizeof(core_vers), fp);
279 if (strcmp(vers, core_vers) && kernel == 0)
280 syslog(LOG_WARNING,
281 "warning: %s version mismatch:\n\t%s\nand\t%s\n",
281 _PATH_UNIX, vers, core_vers);
282 getbootfile(), vers, core_vers);
282 (void)fseek(fp,
283 (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET);
284 (void)fread(&panicstr, sizeof(panicstr), 1, fp);
285 if (panicstr) {
286 (void)fseek(fp, dumplo + ok(panicstr), L_SET);
287 cp = panic_mesg;
288 do
289 *cp = getc(fp);

--- 118 unchanged lines hidden (view full) ---

408 (void)printf("\n");
409 (void)close(ifd);
410 if (compress)
411 (void)fclose(fp);
412 else
413 (void)close(ofd);
414
415 /* Copy the kernel. */
283 (void)fseek(fp,
284 (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET);
285 (void)fread(&panicstr, sizeof(panicstr), 1, fp);
286 if (panicstr) {
287 (void)fseek(fp, dumplo + ok(panicstr), L_SET);
288 cp = panic_mesg;
289 do
290 *cp = getc(fp);

--- 118 unchanged lines hidden (view full) ---

409 (void)printf("\n");
410 (void)close(ifd);
411 if (compress)
412 (void)fclose(fp);
413 else
414 (void)close(ofd);
415
416 /* Copy the kernel. */
416 ifd = Open(kernel ? kernel : _PATH_UNIX, O_RDONLY);
417 ifd = Open(kernel ? kernel : getbootfile(), O_RDONLY);
417 (void)snprintf(path, sizeof(path), "%s/kernel.%d%s",
418 dirname, bounds, compress ? ".Z" : "");
419 if (compress) {
420 if ((fp = zopen(path, "w", 0)) == NULL) {
421 syslog(LOG_ERR, "%s: %s", path, strerror(errno));
422 exit(1);
423 }
424 } else

--- 10 unchanged lines hidden (view full) ---

435 path, strerror(nw == 0 ? EIO : errno));
436 syslog(LOG_WARNING,
437 "WARNING: kernel may be incomplete");
438 exit(1);
439 }
440 }
441 if (nr < 0) {
442 syslog(LOG_ERR, "%s: %s",
418 (void)snprintf(path, sizeof(path), "%s/kernel.%d%s",
419 dirname, bounds, compress ? ".Z" : "");
420 if (compress) {
421 if ((fp = zopen(path, "w", 0)) == NULL) {
422 syslog(LOG_ERR, "%s: %s", path, strerror(errno));
423 exit(1);
424 }
425 } else

--- 10 unchanged lines hidden (view full) ---

436 path, strerror(nw == 0 ? EIO : errno));
437 syslog(LOG_WARNING,
438 "WARNING: kernel may be incomplete");
439 exit(1);
440 }
441 }
442 if (nr < 0) {
443 syslog(LOG_ERR, "%s: %s",
443 kernel ? kernel : _PATH_UNIX, strerror(errno));
444 kernel ? kernel : getbootfile(), strerror(errno));
444 syslog(LOG_WARNING,
445 "WARNING: kernel may be incomplete");
446 exit(1);
447 }
448 if (compress)
449 (void)fclose(fp);
450 else
451 (void)close(ofd);

--- 75 unchanged lines hidden (view full) ---

527 }
528 return (1);
529}
530
531int
532check_space()
533{
534 register FILE *fp;
445 syslog(LOG_WARNING,
446 "WARNING: kernel may be incomplete");
447 exit(1);
448 }
449 if (compress)
450 (void)fclose(fp);
451 else
452 (void)close(ofd);

--- 75 unchanged lines hidden (view full) ---

528 }
529 return (1);
530}
531
532int
533check_space()
534{
535 register FILE *fp;
535 char *tkernel;
536 const char *tkernel;
536 off_t minfree, spacefree, kernelsize, needed;
537 struct stat st;
538 struct statfs fsbuf;
539 char buf[100], path[MAXPATHLEN];
540
537 off_t minfree, spacefree, kernelsize, needed;
538 struct stat st;
539 struct statfs fsbuf;
540 char buf[100], path[MAXPATHLEN];
541
541 tkernel = kernel ? kernel : _PATH_UNIX;
542 tkernel = kernel ? kernel : getbootfile();
542 if (stat(tkernel, &st) < 0) {
543 syslog(LOG_ERR, "%s: %m", tkernel);
544 exit(1);
545 }
546 kernelsize = st.st_blocks * S_BLKSIZE;
547 if (statfs(dirname, &fsbuf) < 0) {
548 syslog(LOG_ERR, "%s: %m", dirname);
549 exit(1);

--- 20 unchanged lines hidden (view full) ---

570 if (spacefree - needed < minfree)
571 syslog(LOG_WARNING,
572 "dump performed, but free space threshold crossed");
573 return (1);
574}
575
576int
577Open(name, rw)
543 if (stat(tkernel, &st) < 0) {
544 syslog(LOG_ERR, "%s: %m", tkernel);
545 exit(1);
546 }
547 kernelsize = st.st_blocks * S_BLKSIZE;
548 if (statfs(dirname, &fsbuf) < 0) {
549 syslog(LOG_ERR, "%s: %m", dirname);
550 exit(1);

--- 20 unchanged lines hidden (view full) ---

571 if (spacefree - needed < minfree)
572 syslog(LOG_WARNING,
573 "dump performed, but free space threshold crossed");
574 return (1);
575}
576
577int
578Open(name, rw)
578 char *name;
579 const char *name;
579 int rw;
580{
581 int fd;
582
583 if ((fd = open(name, rw, 0)) < 0) {
584 syslog(LOG_ERR, "%s: %m", name);
585 exit(1);
586 }

--- 66 unchanged lines hidden ---
580 int rw;
581{
582 int fd;
583
584 if ((fd = open(name, rw, 0)) < 0) {
585 syslog(LOG_ERR, "%s: %m", name);
586 exit(1);
587 }

--- 66 unchanged lines hidden ---