From nobody Tue Mar 15 23:29:48 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C5E0E1A22E88; Tue, 15 Mar 2022 23:29:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4KJ8l051H4z4VjX; Tue, 15 Mar 2022 23:29:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647386988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9CCI9HxKWrz30/G2kd0FBWBnX7nUrNjVCrLzwbxfhLo=; b=xPQE6SRCpyl1aPxxQlo4XXnJVDGD/g152AZBdGQpLgFUbDVqwt8qCGV+BLnLTF3jYkwuDn Z+n/oj2U75PrNdVzNBey8fUwamWoKfEHg/I5JateMDcgkEfk+7N5nHAU85w8+V6bLuK8q6 lEoldbMIEqukwtwr/U0Unf17SGHpENeNM3kXD3gTXgiMDJvGUcB4R7w2qBoocq5TjK/ISk 4Yy/N5w01uEvm4uzzU+fKnDCsCH7y0rnNe7PsbShNWUwMiaG43275h3gKHfLFwa5WtXnNo 7BStOZ5Htjafg9Rcl1sCZxkY2mfvPRhAVnJ4VT1x+xiGsNKWWZJFpM/77nhFJQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 802B92C75; Tue, 15 Mar 2022 23:29:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 22FNTm2F093784; Tue, 15 Mar 2022 23:29:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22FNTmfj093783; Tue, 15 Mar 2022 23:29:48 GMT (envelope-from git) Date: Tue, 15 Mar 2022 23:29:48 GMT Message-Id: <202203152329.22FNTmfj093783@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alfonso S. Siciliano" Subject: git: f27c6a3e872c - main - bsdinstall/distfetch: Replace libdialog with libbsddialog List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asiciliano X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f27c6a3e872c0ee658fa12b40f5b24a85c1f66cc Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1647386988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9CCI9HxKWrz30/G2kd0FBWBnX7nUrNjVCrLzwbxfhLo=; b=KGJlFrGfPW++ffMRQiNXaOKWFnd3ZNrnRSBqwQ556brEVRczb15LDWCcvMFIOWQeViFfOj IdzB5nFVecU3KPEpXl/Ao3qV924Y1JoLvTOeDWeXGNnD4U2LDmCJCFnsnGLp/7g8wm5nz8 0YZ1s5lWMnkMGZJ7whXGhnTlOrfoTw5dDJNVA6Zs2cgDNLEuXljW+obBpjucDe1tDohiOv FQN54Yq3U41I1YsnMTGVjRgjJoZtDPYXXP4KtUjFEylLtQ24/FWahYEKP53ZzXHUk4uYuR X0MM0TjjquRbJA/e2Zc0UIdFtvMTiwMxvePMAqf1lB2oYbDc1pKSHjBz+q05rQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1647386988; a=rsa-sha256; cv=none; b=BBMRQxqo47IkctugLPOanbHBbCoIY9PCihnKGZHcIuQhkP73XifLffGVDbcv4SKTY6RBOU rnyWFCV+Y+ZslcJH5cqKbAhayt9sD0gX3IU+wf2cA34WPMwuTQj6hiZso0R+QBqTjs90Dm MiPcpMhaOTC5lqNRVDFVqW8yYcApA01qJyJApOfmouQ8Zu0vJ8nB95jtxhVbHhx8KcY6k2 heL1QFcntfkm7qaA9RgDm4DlRRrzdwfxqTohKkDdnXMhjvj+pe/4C2Euq48FW4+EEiLAf6 vexG4xXgI/h/2Kbk8R0T7bKuRDcDcQVZPHJEJIDoR8NgTW8uGKSlAlC0x7SrHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asiciliano: URL: https://cgit.FreeBSD.org/src/commit/?id=f27c6a3e872c0ee658fa12b40f5b24a85c1f66cc commit f27c6a3e872c0ee658fa12b40f5b24a85c1f66cc Author: Alfonso S. Siciliano AuthorDate: 2022-03-15 23:27:36 +0000 Commit: Alfonso S. Siciliano CommitDate: 2022-03-15 23:27:36 +0000 bsdinstall/distfetch: Replace libdialog with libbsddialog Replace (LGPL) libdialog with (BSD-2-Clause) libbsddialog, while here diversify error messages to find quickly the exact point of failure. Approved by: bapt (mentor) Differential Revision: https://reviews.freebsd.org/D34464 --- usr.sbin/bsdinstall/distfetch/Makefile | 3 +- usr.sbin/bsdinstall/distfetch/distfetch.c | 117 +++++++++++++++++------------- 2 files changed, 69 insertions(+), 51 deletions(-) diff --git a/usr.sbin/bsdinstall/distfetch/Makefile b/usr.sbin/bsdinstall/distfetch/Makefile index 70ecb381d485..f4ae37edf1a5 100644 --- a/usr.sbin/bsdinstall/distfetch/Makefile +++ b/usr.sbin/bsdinstall/distfetch/Makefile @@ -2,7 +2,8 @@ BINDIR= ${LIBEXECDIR}/bsdinstall PROG= distfetch -LIBADD= fetch dialog m +CFLAGS+= -I${SRCTOP}/contrib/bsddialog/lib +LIBADD= fetch bsddialog MAN= diff --git a/usr.sbin/bsdinstall/distfetch/distfetch.c b/usr.sbin/bsdinstall/distfetch/distfetch.c index 0510965dd4e7..440a708c285f 100644 --- a/usr.sbin/bsdinstall/distfetch/distfetch.c +++ b/usr.sbin/bsdinstall/distfetch/distfetch.c @@ -31,10 +31,12 @@ __FBSDID("$FreeBSD$"); #include + +#include #include #include -#include #include +#include #include #include #include @@ -52,6 +54,7 @@ main(void) int ndists = 0; int nfetched; char error[PATH_MAX + 512]; + struct bsddialog_conf conf; if (getenv("DISTRIBUTIONS") == NULL) errx(EXIT_FAILURE, "DISTRIBUTIONS variable is not set"); @@ -65,12 +68,16 @@ main(void) urls = calloc(ndists, sizeof(const char *)); if (urls == NULL) { free(diststring); - errx(EXIT_FAILURE, "Out of memory!"); + errx(EXIT_FAILURE, "Error: distfetch URLs out of memory!"); } - init_dialog(stdin, stdout); - dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); - dlg_put_backtitle(); + if (bsddialog_init() == BSDDIALOG_ERROR) { + free(diststring); + errx(EXIT_FAILURE, "Error libbsddialog: %s\n", + bsddialog_geterror()); + } + bsddialog_initconf(&conf); + bsddialog_backtitle(&conf, "FreeBSD Installer"); for (i = 0; i < ndists; i++) { urls[i] = malloc(PATH_MAX); @@ -82,14 +89,15 @@ main(void) snprintf(error, sizeof(error), "Could not change to directory %s: %s\n", getenv("BSDINSTALL_DISTDIR"), strerror(errno)); - dialog_msgbox("Error", error, 0, 0, TRUE); - end_dialog(); + conf.title = "Error"; + bsddialog_msgbox(&conf, error, 0, 0); + bsddialog_end(); return (EXIT_FAILURE); } nfetched = fetch_files(ndists, urls); - end_dialog(); + bsddialog_end(); free(diststring); for (i = 0; i < ndists; i++) @@ -104,7 +112,9 @@ fetch_files(int nfiles, char **urls) { FILE *fetch_out; FILE *file_out; - const char **items; + const char **minilabel; + int *miniperc; + int perc; int i; int last_progress; int nsuccess = 0; /* Number of files successfully downloaded */ @@ -115,26 +125,30 @@ fetch_files(int nfiles, char **urls) off_t total_bytes; float file_perc; float mainperc_file; - char status[8]; struct url_stat ustat; char errormsg[PATH_MAX + 512]; uint8_t block[4096]; + struct bsddialog_conf errconf; + struct bsddialog_conf mgconf; - /* Make the transfer list for dialog */ - items = calloc(sizeof(char *), nfiles * 2); - if (items == NULL) - errx(EXIT_FAILURE, "Out of memory!"); + /* Make the transfer list for mixedgauge */ + minilabel = calloc(sizeof(char *), nfiles); + miniperc = calloc(sizeof(int), nfiles); + if (minilabel == NULL || miniperc == NULL) + errx(EXIT_FAILURE, "Error: distfetch minibars out of memory!"); for (i = 0; i < nfiles; i++) { - items[i*2] = strrchr(urls[i], '/'); - if (items[i*2] != NULL) - items[i*2]++; + minilabel[i] = strrchr(urls[i], '/'); + if (minilabel[i] != NULL) + minilabel[i]++; else - items[i*2] = urls[i]; - items[i*2 + 1] = "Pending"; + minilabel[i] = urls[i]; + miniperc[i] = BSDDIALOG_MG_PENDING; } - dialog_msgbox("", "Connecting to server.\nPlease wait...", 0, 0, FALSE); + bsddialog_initconf(&errconf); + bsddialog_infobox(&errconf, "Connecting to server.\nPlease wait...", + 0, 0); /* Try to stat all the files */ total_bytes = 0; @@ -147,6 +161,12 @@ fetch_files(int nfiles, char **urls) } } + errconf.title = "Fetch Error"; + errconf.clear = true; + bsddialog_initconf(&mgconf); + mgconf.title = "Fetching Distribution"; + mgconf.auto_minwidth = 40; + mainperc_file = 100.0 / nfiles; current_bytes = 0; for (i = 0; i < nfiles; i++) { @@ -154,25 +174,23 @@ fetch_files(int nfiles, char **urls) fetch_out = fetchXGetURL(urls[i], &ustat, ""); if (fetch_out == NULL) { snprintf(errormsg, sizeof(errormsg), - "Error while fetching %s: %s\n", urls[i], + "Error (URL) while fetching %s: %s\n", urls[i], fetchLastErrString); - items[i*2 + 1] = "Failed"; - dialog_msgbox("Fetch Error", errormsg, 0, 0, - TRUE); + miniperc[2] = BSDDIALOG_MG_FAILED; + bsddialog_msgbox(&errconf, errormsg, 0, 0); total_bytes = 0; continue; } - items[i*2 + 1] = "In Progress"; + miniperc[i] = BSDDIALOG_MG_INPROGRESS; fsize = 0; - file_out = fopen(items[i*2], "w+"); + file_out = fopen(minilabel[i], "w+"); if (file_out == NULL) { snprintf(errormsg, sizeof(errormsg), - "Error while fetching %s: %s\n", + "Error (fopen) while fetching %s: %s\n", urls[i], strerror(errno)); - items[i*2 + 1] = "Failed"; - dialog_msgbox("Fetch Error", errormsg, 0, 0, - TRUE); + miniperc[i] = BSDDIALOG_MG_FAILED; + bsddialog_msgbox(&errconf, errormsg, 0, 0); fclose(fetch_out); total_bytes = 0; continue; @@ -188,42 +206,41 @@ fetch_files(int nfiles, char **urls) last_progress = progress; if (total_bytes > 0) { - progress = (current_bytes*100)/total_bytes; + progress = (current_bytes * 100) / total_bytes; } else { file_perc = ustat.size > 0 ? - (fsize*100)/ustat.size : 0; + (fsize * 100) / ustat.size : 0; progress = (i * mainperc_file) + ((file_perc * mainperc_file) / 100); } if (ustat.size > 0) { - snprintf(status, sizeof(status), "-%jd", - (fsize*100)/ustat.size); - items[i*2 + 1] = status; + perc = (fsize * 100) / ustat.size; + miniperc[i] = perc; } - if (progress > last_progress) - dialog_mixedgauge("Fetching Distribution", - "Fetching distribution files...", 0, 0, - progress, nfiles, - __DECONST(char **, items)); + if (progress > last_progress) { + bsddialog_mixedgauge(&mgconf, + "\nFetching distribution files...\n", + 0, 0, progress, nfiles, minilabel, + miniperc); + } } if (ustat.size > 0 && fsize < ustat.size) { if (fetchLastErrCode == 0) snprintf(errormsg, sizeof(errormsg), - "Error while fetching %s: %s\n", + "Error (undone) while fetching %s: %s\n", urls[i], strerror(errno)); else snprintf(errormsg, sizeof(errormsg), - "Error while fetching %s: %s\n", + "Error (libfetch) while fetching %s: %s\n", urls[i], fetchLastErrString); - items[i*2 + 1] = "Failed"; - dialog_msgbox("Fetch Error", errormsg, 0, 0, - TRUE); + miniperc[i] = BSDDIALOG_MG_FAILED; + bsddialog_msgbox(&errconf, errormsg, 0, 0); total_bytes = 0; } else { - items[i*2 + 1] = "Done"; + miniperc[i] = BSDDIALOG_MG_DONE; nsuccess++; } @@ -231,10 +248,10 @@ fetch_files(int nfiles, char **urls) fclose(file_out); } - dialog_mixedgauge("Fetching Distribution", - "Fetching distribution completed", 0, 0, progress, nfiles, - __DECONST(char **, items)); + bsddialog_mixedgauge(&mgconf, "\nFetching distribution completed\n", + 0, 0, progress, nfiles, minilabel, miniperc); - free(items); + free(minilabel); + free(miniperc); return (nsuccess); }