All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Wei Gao <wegao@suse.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] libswap.c: Improve calculate swap dev number
Date: Tue, 5 Mar 2024 15:45:20 +0100	[thread overview]
Message-ID: <20240305144520.GA4052380@pevik> (raw)
In-Reply-To: <20240305141057.8754-1-wegao@suse.com>

> I encounter a dead loop on following code in our test on ppc64 machine:
> while ((c = fgetc(fp)) != EOF)

FYI it fails also on aarch64 and s390x, thus I'll add it to the commit message
before merge. I also try to have look why it's broken.

> Use fgets instead of fgetc can avoid above issue.

LGTM. I probably merge it tonight.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  libs/libltpswap/libswap.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)

> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index c10db91c0..a26ea25e4 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -13,6 +13,7 @@

>  #define TST_NO_DEFAULT_MAIN
>  #define DEFAULT_MAX_SWAPFILE 32
> +#define BUFSIZE 200

>  #include "tst_test.h"
>  #include "libswap.h"
> @@ -279,16 +280,14 @@ int tst_count_swaps(void)
>  {
>  	FILE *fp;
>  	int used = -1;
> -	char c;
> +	char buf[BUFSIZE];

>  	fp = SAFE_FOPEN("/proc/swaps", "r");
>  	if (fp == NULL)
>  		return -1;

> -	while ((c = fgetc(fp)) != EOF) {
> -		if (c == '\n')
> -			used++;
> -	}
> +	while (fgets(buf, BUFSIZE, fp) != NULL)
> +		used++;

>  	SAFE_FCLOSE(fp);
>  	if (used < 0)

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-03-05 14:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01  6:27 [LTP] [PATCH v1] libswap.c: Improve caculate swap dev number Wei Gao via ltp
2024-03-01  6:45 ` Yang Xu (Fujitsu) via ltp
2024-03-03 13:14   ` Petr Vorel
2024-03-04  8:49     ` Li Wang
2024-03-04  9:04       ` Petr Vorel
2024-03-04  9:18       ` Yang Xu (Fujitsu) via ltp
2024-03-04 10:04         ` Li Wang
2024-03-05  4:01           ` Wei Gao via ltp
2024-03-05 10:15             ` Petr Vorel
2024-03-05 14:10 ` [LTP] [PATCH v2] libswap.c: Improve calculate " Wei Gao via ltp
2024-03-05 14:45   ` Petr Vorel [this message]
2024-03-05 21:04   ` Petr Vorel
2024-03-06  1:32     ` Yang Xu (Fujitsu) via ltp
2024-03-06  9:59       ` Petr Vorel

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=20240305144520.GA4052380@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=wegao@suse.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.