Date: Mon, 10 May 2021 01:14:56 GMT From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: 7a94e71e0586 - stable/13 - gcore: split code to open core file into helper Message-ID: <202105100114.14A1EuDI028778@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=7a94e71e058684f9d8812d1180540c84cbf720c2 commit 7a94e71e058684f9d8812d1180540c84cbf720c2 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2021-04-24 10:31:58 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2021-05-10 01:03:14 +0000 gcore: split code to open core file into helper (cherry picked from commit c192228b7398df72e472128605338555e5aa2db9) --- usr.bin/gcore/gcore.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/usr.bin/gcore/gcore.c b/usr.bin/gcore/gcore.c index 8681b8484d81..cbbfea82085b 100644 --- a/usr.bin/gcore/gcore.c +++ b/usr.bin/gcore/gcore.c @@ -78,12 +78,27 @@ static pid_t pid; SET_DECLARE(dumpset, struct dumpers); +static int +open_corefile(char *corefile) +{ + char fname[MAXPATHLEN]; + + if (corefile == NULL) { + (void)snprintf(fname, sizeof(fname), "core.%d", pid); + corefile = fname; + } + fd = open(corefile, O_RDWR | O_CREAT | O_TRUNC, DEFFILEMODE); + if (fd < 0) + err(1, "%s", corefile); + return (fd); +} + int main(int argc, char *argv[]) { int ch, efd, fd, name[4]; char *binfile, *corefile; - char passpath[MAXPATHLEN], fname[MAXPATHLEN]; + char passpath[MAXPATHLEN]; struct dumpers **d, *dumper; size_t len; @@ -138,13 +153,7 @@ main(int argc, char *argv[]) } if (dumper == NULL) errx(1, "Invalid executable file"); - if (corefile == NULL) { - (void)snprintf(fname, sizeof(fname), "core.%d", pid); - corefile = fname; - } - fd = open(corefile, O_RDWR|O_CREAT|O_TRUNC, DEFFILEMODE); - if (fd < 0) - err(1, "%s", corefile); + fd = open_corefile(corefile); dumper->dump(efd, fd, pid); (void)close(fd);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105100114.14A1EuDI028778>