From: "Ján Tomko" <jtomko@redhat.com>
To: Michal Privoznik <mprivozn@redhat.com>
Cc: qemu-devel@nongnu.org, michael.roth@amd.com, kkostiuk@redhat.com
Subject: Re: [PATCH 2/4] qga: Invert logic on return value in main()
Date: Wed, 6 Nov 2024 17:06:55 +0100 [thread overview]
Message-ID: <ZyuUH9SJzvJo72kC@fedora> (raw)
In-Reply-To: <5182ceb139a43aacaab2c8b833bf52b13279dcf0.1730713917.git.mprivozn@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 2657 bytes --]
On a Monday in 2024, Michal Privoznik wrote:
>Current logic on return value ('ret' variable) in main() is error
>prone. The variable is initialized to EXIT_SUCCESS and then set
>to EXIT_FAILURE on error paths. This makes it very easy to forget
>to set the variable to indicate error when adding new error path,
>as is demonstrated by handling of initialize_agent() failure.
>It's simply lacking setting of the variable.
>
>There's just one case where success should be indicated: when
>dumping the config ('-D' cmd line argument).
>
>To resolve this, initialize the variable to failure value and set
>it explicitly to success value in that one specific case.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> qga/main.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
>diff --git a/qga/main.c b/qga/main.c
>index 4a695235f0..c003aacbe0 100644
>--- a/qga/main.c
>+++ b/qga/main.c
>@@ -1579,7 +1579,7 @@ static void stop_agent(GAState *s, bool requested)
>
> int main(int argc, char **argv)
> {
>- int ret = EXIT_SUCCESS;
>+ int ret = EXIT_FAILURE;
> GAState *s;
> GAConfig *config = g_new0(GAConfig, 1);
> int socket_activation;
>@@ -1607,7 +1607,6 @@ int main(int argc, char **argv)
> socket_activation = check_socket_activation();
> if (socket_activation > 1) {
> g_critical("qemu-ga only supports listening on one socket");
>- ret = EXIT_FAILURE;
> goto end;
> }
> if (socket_activation) {
>@@ -1631,7 +1630,6 @@ int main(int argc, char **argv)
>
> if (!config->method) {
> g_critical("unsupported listen fd type");
>- ret = EXIT_FAILURE;
> goto end;
> }
> } else if (config->channel_path == NULL) {
>@@ -1643,13 +1641,13 @@ int main(int argc, char **argv)
> config->channel_path = g_strdup(QGA_SERIAL_PATH_DEFAULT);
> } else {
> g_critical("must specify a path for this channel");
>- ret = EXIT_FAILURE;
> goto end;
> }
> }
>
> if (config->dumpconf) {
> config_dump(config);
>+ ret = EXIT_SUCCESS;
> goto end;
> }
>
Below this there's another place that misses an EXIT_SUCCESS, on _WIN32
when config->daemonize is set:
#ifdef _WIN32
if (config->daemonize) {
SERVICE_TABLE_ENTRY service_table[] = {
{ (char *)QGA_SERVICE_NAME, service_main }, { NULL, NULL } };
StartServiceCtrlDispatcher(service_table);
} else {
ret = run_agent(s);
}
#else
ret = run_agent(s);
#endif
But after patch 4/4 ret is set to EXIT_SUCCESS in all the cases.
Jano
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2024-11-06 16:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-04 9:54 [PATCH 0/4] qga: Open channel before going daemon Michal Privoznik
2024-11-04 9:54 ` [PATCH 1/4] qga: Don't access global variable in run_agent_once() Michal Privoznik
2024-12-04 9:29 ` Konstantin Kostiuk
2024-11-04 9:54 ` [PATCH 2/4] qga: Invert logic on return value in main() Michal Privoznik
2024-11-06 16:06 ` Ján Tomko [this message]
2024-12-04 9:34 ` Konstantin Kostiuk
2024-11-04 9:54 ` [PATCH 3/4] qga: Don't daemonize before channel is initialized Michal Privoznik
2024-12-04 9:44 ` Konstantin Kostiuk
2024-12-05 15:31 ` Michal Prívozník
2024-11-04 9:54 ` [PATCH 4/4] qga: Make run_agent() and run_agent_once() return no value Michal Privoznik
2024-11-06 16:07 ` [PATCH 0/4] qga: Open channel before going daemon Ján Tomko
2024-12-02 8:15 ` Michal Prívozník
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZyuUH9SJzvJo72kC@fedora \
--to=jtomko@redhat.com \
--cc=kkostiuk@redhat.com \
--cc=michael.roth@amd.com \
--cc=mprivozn@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).