savecore.c (82725ba9bf1fd59746a4006a06f24d4d61d142f2) savecore.c (6026dcd7ca888f3433f4df34ede69a77c1eb7701)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2002 Poul-Henning Kamp
5 * Copyright (c) 2002 Networks Associates Technology, Inc.
6 * All rights reserved.
7 *
8 * This software was developed for the FreeBSD Project by Poul-Henning Kamp

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

104
105static void
106printheader(xo_handle_t *xo, const struct kerneldumpheader *h,
107 const char *device, int bounds, const int status)
108{
109 uint64_t dumplen;
110 time_t t;
111 const char *stat_str;
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2002 Poul-Henning Kamp
5 * Copyright (c) 2002 Networks Associates Technology, Inc.
6 * All rights reserved.
7 *
8 * This software was developed for the FreeBSD Project by Poul-Henning Kamp

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

104
105static void
106printheader(xo_handle_t *xo, const struct kerneldumpheader *h,
107 const char *device, int bounds, const int status)
108{
109 uint64_t dumplen;
110 time_t t;
111 const char *stat_str;
112 const char *comp_str;
112
113 xo_flush_h(xo);
114 xo_emit_h(xo, "{Lwc:Dump header from device}{:dump_device/%s}\n",
115 device);
116 xo_emit_h(xo, "{P: }{Lwc:Architecture}{:architecture/%s}\n",
117 h->architecture);
118 xo_emit_h(xo,
119 "{P: }{Lwc:Architecture Version}{:architecture_version/%u}\n",
120 dtoh32(h->architectureversion));
121 dumplen = dtoh64(h->dumplength);
122 xo_emit_h(xo, "{P: }{Lwc:Dump Length}{:dump_length_bytes/%lld}\n",
123 (long long)dumplen);
124 xo_emit_h(xo, "{P: }{Lwc:Blocksize}{:blocksize/%d}\n",
125 dtoh32(h->blocksize));
113
114 xo_flush_h(xo);
115 xo_emit_h(xo, "{Lwc:Dump header from device}{:dump_device/%s}\n",
116 device);
117 xo_emit_h(xo, "{P: }{Lwc:Architecture}{:architecture/%s}\n",
118 h->architecture);
119 xo_emit_h(xo,
120 "{P: }{Lwc:Architecture Version}{:architecture_version/%u}\n",
121 dtoh32(h->architectureversion));
122 dumplen = dtoh64(h->dumplength);
123 xo_emit_h(xo, "{P: }{Lwc:Dump Length}{:dump_length_bytes/%lld}\n",
124 (long long)dumplen);
125 xo_emit_h(xo, "{P: }{Lwc:Blocksize}{:blocksize/%d}\n",
126 dtoh32(h->blocksize));
126 xo_emit_h(xo, "{P: }{Lwc:Compression}{:compression/%s}\n",
127 h->compression == KERNELDUMP_COMP_GZIP ?
128 "gzip" : "none");
129
127 switch (h->compression) {
128 case KERNELDUMP_COMP_NONE:
129 comp_str = "none";
130 break;
131 case KERNELDUMP_COMP_GZIP:
132 comp_str = "gzip";
133 break;
134 case KERNELDUMP_COMP_ZSTD:
135 comp_str = "zstd";
136 break;
137 default:
138 comp_str = "???";
139 break;
140 }
141 xo_emit_h(xo, "{P: }{Lwc:Compression}{:compression/%s}\n", comp_str);
130 t = dtoh64(h->dumptime);
131 xo_emit_h(xo, "{P: }{Lwc:Dumptime}{:dumptime/%s}", ctime(&t));
132 xo_emit_h(xo, "{P: }{Lwc:Hostname}{:hostname/%s}\n", h->hostname);
133 xo_emit_h(xo, "{P: }{Lwc:Magic}{:magic/%s}\n", h->magic);
134 xo_emit_h(xo, "{P: }{Lwc:Version String}{:version_string/%s}",
135 h->versionstring);
136 xo_emit_h(xo, "{P: }{Lwc:Panic String}{:panic_string/%s}\n",
137 h->panicstring);

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

244 dumpsize = 0;
245
246 (void)snprintf(path, sizeof(path), "info.%d", bounds);
247 dumpsize += file_size(path);
248 (void)snprintf(path, sizeof(path), "vmcore.%d", bounds);
249 dumpsize += file_size(path);
250 (void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds);
251 dumpsize += file_size(path);
142 t = dtoh64(h->dumptime);
143 xo_emit_h(xo, "{P: }{Lwc:Dumptime}{:dumptime/%s}", ctime(&t));
144 xo_emit_h(xo, "{P: }{Lwc:Hostname}{:hostname/%s}\n", h->hostname);
145 xo_emit_h(xo, "{P: }{Lwc:Magic}{:magic/%s}\n", h->magic);
146 xo_emit_h(xo, "{P: }{Lwc:Version String}{:version_string/%s}",
147 h->versionstring);
148 xo_emit_h(xo, "{P: }{Lwc:Panic String}{:panic_string/%s}\n",
149 h->panicstring);

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

256 dumpsize = 0;
257
258 (void)snprintf(path, sizeof(path), "info.%d", bounds);
259 dumpsize += file_size(path);
260 (void)snprintf(path, sizeof(path), "vmcore.%d", bounds);
261 dumpsize += file_size(path);
262 (void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds);
263 dumpsize += file_size(path);
264 (void)snprintf(path, sizeof(path), "vmcore.%d.zst", bounds);
265 dumpsize += file_size(path);
252 (void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds);
253 dumpsize += file_size(path);
254 (void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds);
255 dumpsize += file_size(path);
256
257 return (dumpsize);
258}
259
260static void
261saved_dump_remove(int bounds)
262{
263 static char path[PATH_MAX];
264
265 (void)snprintf(path, sizeof(path), "info.%d", bounds);
266 (void)unlink(path);
267 (void)snprintf(path, sizeof(path), "vmcore.%d", bounds);
268 (void)unlink(path);
269 (void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds);
270 (void)unlink(path);
266 (void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds);
267 dumpsize += file_size(path);
268 (void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds);
269 dumpsize += file_size(path);
270
271 return (dumpsize);
272}
273
274static void
275saved_dump_remove(int bounds)
276{
277 static char path[PATH_MAX];
278
279 (void)snprintf(path, sizeof(path), "info.%d", bounds);
280 (void)unlink(path);
281 (void)snprintf(path, sizeof(path), "vmcore.%d", bounds);
282 (void)unlink(path);
283 (void)snprintf(path, sizeof(path), "vmcore.%d.gz", bounds);
284 (void)unlink(path);
285 (void)snprintf(path, sizeof(path), "vmcore.%d.zst", bounds);
286 (void)unlink(path);
271 (void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds);
272 (void)unlink(path);
273 (void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds);
274 (void)unlink(path);
275}
276
277static void
278symlinks_remove(void)
279{
280
281 (void)unlink("info.last");
282 (void)unlink("key.last");
283 (void)unlink("vmcore.last");
284 (void)unlink("vmcore.last.gz");
287 (void)snprintf(path, sizeof(path), "textdump.tar.%d", bounds);
288 (void)unlink(path);
289 (void)snprintf(path, sizeof(path), "textdump.tar.%d.gz", bounds);
290 (void)unlink(path);
291}
292
293static void
294symlinks_remove(void)
295{
296
297 (void)unlink("info.last");
298 (void)unlink("key.last");
299 (void)unlink("vmcore.last");
300 (void)unlink("vmcore.last.gz");
301 (void)unlink("vmcore.last.zstd");
285 (void)unlink("vmcore_encrypted.last");
286 (void)unlink("vmcore_encrypted.last.gz");
287 (void)unlink("textdump.tar.last");
288 (void)unlink("textdump.tar.last.gz");
289}
290
291/*
292 * Check that sufficient space is available on the disk that holds the

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

610 status = STATUS_BAD;
611 if (force == 0)
612 goto closefd;
613 }
614 switch (kdhl.compression) {
615 case KERNELDUMP_COMP_NONE:
616 break;
617 case KERNELDUMP_COMP_GZIP:
302 (void)unlink("vmcore_encrypted.last");
303 (void)unlink("vmcore_encrypted.last.gz");
304 (void)unlink("textdump.tar.last");
305 (void)unlink("textdump.tar.last.gz");
306}
307
308/*
309 * Check that sufficient space is available on the disk that holds the

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

627 status = STATUS_BAD;
628 if (force == 0)
629 goto closefd;
630 }
631 switch (kdhl.compression) {
632 case KERNELDUMP_COMP_NONE:
633 break;
634 case KERNELDUMP_COMP_GZIP:
635 case KERNELDUMP_COMP_ZSTD:
618 if (compress && verbose)
619 printf("dump is already compressed\n");
620 compress = false;
621 iscompressed = true;
622 break;
623 default:
624 syslog(LOG_ERR, "unknown compression type %d on %s",
625 kdhl.compression, device);

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

738 oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file. */
739 isencrypted = (dumpkeysize > 0);
740 if (compress) {
741 snprintf(corename, sizeof(corename), "%s.%d.gz",
742 istextdump ? "textdump.tar" :
743 (isencrypted ? "vmcore_encrypted" : "vmcore"), bounds);
744 fp = zopen(corename, "w");
745 } else if (iscompressed && !isencrypted) {
636 if (compress && verbose)
637 printf("dump is already compressed\n");
638 compress = false;
639 iscompressed = true;
640 break;
641 default:
642 syslog(LOG_ERR, "unknown compression type %d on %s",
643 kdhl.compression, device);

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

756 oumask = umask(S_IRWXG|S_IRWXO); /* Restrict access to the core file. */
757 isencrypted = (dumpkeysize > 0);
758 if (compress) {
759 snprintf(corename, sizeof(corename), "%s.%d.gz",
760 istextdump ? "textdump.tar" :
761 (isencrypted ? "vmcore_encrypted" : "vmcore"), bounds);
762 fp = zopen(corename, "w");
763 } else if (iscompressed && !isencrypted) {
746 snprintf(corename, sizeof(corename), "vmcore.%d.gz", bounds);
764 snprintf(corename, sizeof(corename), "vmcore.%d.%s", bounds,
765 (kdhl.compression == KERNELDUMP_COMP_GZIP) ? "gz" : "zst");
747 fp = fopen(corename, "w");
748 } else {
749 snprintf(corename, sizeof(corename), "%s.%d",
750 istextdump ? "textdump.tar" :
751 (isencrypted ? "vmcore_encrypted" : "vmcore"), bounds);
752 fp = fopen(corename, "w");
753 }
754 if (fp == NULL) {

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

840 if (isencrypted) {
841 if (symlink(keyname, "key.last") == -1) {
842 syslog(LOG_WARNING,
843 "unable to create symlink %s/%s: %m", savedir,
844 "key.last");
845 }
846 }
847 if (compress || iscompressed) {
766 fp = fopen(corename, "w");
767 } else {
768 snprintf(corename, sizeof(corename), "%s.%d",
769 istextdump ? "textdump.tar" :
770 (isencrypted ? "vmcore_encrypted" : "vmcore"), bounds);
771 fp = fopen(corename, "w");
772 }
773 if (fp == NULL) {

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

859 if (isencrypted) {
860 if (symlink(keyname, "key.last") == -1) {
861 syslog(LOG_WARNING,
862 "unable to create symlink %s/%s: %m", savedir,
863 "key.last");
864 }
865 }
866 if (compress || iscompressed) {
848 snprintf(linkname, sizeof(linkname), "%s.last.gz",
867 snprintf(linkname, sizeof(linkname), "%s.last.%s",
849 istextdump ? "textdump.tar" :
868 istextdump ? "textdump.tar" :
850 (isencrypted ? "vmcore_encrypted" : "vmcore"));
869 (isencrypted ? "vmcore_encrypted" : "vmcore"),
870 (kdhl.compression == KERNELDUMP_COMP_ZSTD) ? "zst" : "gz");
851 } else {
852 snprintf(linkname, sizeof(linkname), "%s.last",
853 istextdump ? "textdump.tar" :
854 (isencrypted ? "vmcore_encrypted" : "vmcore"));
855 }
856 if (symlink(corename, linkname) == -1) {
857 syslog(LOG_WARNING, "unable to create symlink %s/%s: %m",
858 savedir, linkname);

--- 153 unchanged lines hidden ---
871 } else {
872 snprintf(linkname, sizeof(linkname), "%s.last",
873 istextdump ? "textdump.tar" :
874 (isencrypted ? "vmcore_encrypted" : "vmcore"));
875 }
876 if (symlink(corename, linkname) == -1) {
877 syslog(LOG_WARNING, "unable to create symlink %s/%s: %m",
878 savedir, linkname);

--- 153 unchanged lines hidden ---