* [PATCH ucspi-vsock] Factor out set_verbosity()
@ 2021-03-18 0:35 Alyssa Ross
2021-03-18 6:55 ` Cole Helbling
0 siblings, 1 reply; 3+ messages in thread
From: Alyssa Ross @ 2021-03-18 0:35 UTC (permalink / raw)
To: devel
This will save some cognitive load when reading main functions.
---
log.c | 20 +++++++++++++++++++-
log.h | 5 +++++
vsockclient.c | 6 +-----
vsockserver.c | 6 +-----
4 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/log.c b/log.c
index 385d39f..cdfacd6 100644
--- a/log.c
+++ b/log.c
@@ -1,15 +1,33 @@
// SPDX-License-Identifier: GPL-2.0-or-later
-// SPDX-FileCopyrightText: 2020 Alyssa Ross <hi@alyssa.is>
+// SPDX-FileCopyrightText: 2020-2021 Alyssa Ross <hi@alyssa.is>
#define _GNU_SOURCE
#include "log.h"
#include <err.h>
+#include <stdbool.h>
#include <stdlib.h>
enum verbosity verbosity = errors;
+bool set_verbosity(int opt)
+{
+ switch (opt) {
+ case 'q':
+ verbosity = nothing;
+ return true;
+ case 'Q':
+ verbosity = errors;
+ return true;
+ case 'v':
+ verbosity = all;
+ return true;
+ }
+
+ return false;
+}
+
void veloge(const char *fmt, va_list args)
{
if (verbosity)
diff --git a/log.h b/log.h
index ea9e9cf..7b40e48 100644
--- a/log.h
+++ b/log.h
@@ -11,6 +11,11 @@ enum verbosity {
extern enum verbosity verbosity;
+// If opt is a character that matches a standard UCSPI command line
+// verbosity option, sets the verbosity appropriately and returns
+// true. Otherwise, returns false.
+_Bool set_verbosity(int opt);
+
// Log an error message, followed by strerrno(errno), then exit with
// status eval.
_Noreturn void diee(int eval, const char *fmt, ...);
diff --git a/vsockclient.c b/vsockclient.c
index 91e1320..d25ab13 100644
--- a/vsockclient.c
+++ b/vsockclient.c
@@ -35,13 +35,9 @@ int main(int argc, char *argv[])
while ((opt = getopt(argc, argv, "+qQv")) != -1) {
switch (opt) {
case 'q':
- verbosity = nothing;
- break;
case 'Q':
- verbosity = errors;
- break;
case 'v':
- verbosity = all;
+ set_verbosity(opt);
break;
default:
ex_usage();
diff --git a/vsockserver.c b/vsockserver.c
index 03d9838..4c251b0 100644
--- a/vsockserver.c
+++ b/vsockserver.c
@@ -43,13 +43,9 @@ int main(int argc, char *argv[])
notify = true;
break;
case 'q':
- verbosity = nothing;
- break;
case 'Q':
- verbosity = errors;
- break;
case 'v':
- verbosity = all;
+ set_verbosity(opt);
break;
default:
ex_usage();
--
2.30.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH ucspi-vsock] Factor out set_verbosity()
2021-03-18 0:35 [PATCH ucspi-vsock] Factor out set_verbosity() Alyssa Ross
@ 2021-03-18 6:55 ` Cole Helbling
2021-03-18 13:12 ` Alyssa Ross
0 siblings, 1 reply; 3+ messages in thread
From: Cole Helbling @ 2021-03-18 6:55 UTC (permalink / raw)
To: Alyssa Ross, devel
On Wed Mar 17, 2021 at 5:35 PM PDT, Alyssa Ross wrote:
> This will save some cognitive load when reading main functions.
> ---
> log.c | 20 +++++++++++++++++++-
> log.h | 5 +++++
> vsockclient.c | 6 +-----
> vsockserver.c | 6 +-----
> 4 files changed, 26 insertions(+), 11 deletions(-)
Yay, refactoring!
Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH ucspi-vsock] Factor out set_verbosity()
2021-03-18 6:55 ` Cole Helbling
@ 2021-03-18 13:12 ` Alyssa Ross
0 siblings, 0 replies; 3+ messages in thread
From: Alyssa Ross @ 2021-03-18 13:12 UTC (permalink / raw)
To: Cole Helbling; +Cc: devel
[-- Attachment #1: Type: text/plain, Size: 344 bytes --]
>> This will save some cognitive load when reading main functions.
>> ---
>> log.c | 20 +++++++++++++++++++-
>> log.h | 5 +++++
>> vsockclient.c | 6 +-----
>> vsockserver.c | 6 +-----
>> 4 files changed, 26 insertions(+), 11 deletions(-)
>
> Yay, refactoring!
>
> Reviewed-by: Cole Helbling <cole.e.helbling@outlook.com>
Committed as c2990a9.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-18 13:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18 0:35 [PATCH ucspi-vsock] Factor out set_verbosity() Alyssa Ross
2021-03-18 6:55 ` Cole Helbling
2021-03-18 13:12 ` Alyssa Ross
Code repositories for project(s) associated with this public inbox
https://spectrum-os.org/git/crosvm
https://spectrum-os.org/git/doc
https://spectrum-os.org/git/mktuntap
https://spectrum-os.org/git/nixpkgs
https://spectrum-os.org/git/spectrum
https://spectrum-os.org/git/ucspi-vsock
https://spectrum-os.org/git/www
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).