All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [RFC][PATCH 1/2] sched/process.c: Always use pointer to stderr
@ 2021-09-03 21:48 ` Petr Vorel
  2021-09-03 21:48     ` Petr Vorel
                     ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Petr Vorel @ 2021-09-03 21:48 UTC (permalink / raw)
  To: ltp

which was previously used for non-linux OS (not relevant to LTP thus not
used in LTP), for linux stderr directly was used.

This fixes compilation on MUSL which does not like assignment to stderr:

process.c:553:14: error: assignment of read-only variable 'stderr'
  553 |      debugfp = fopen(foo, "a+");
      |              ^

NOTE: needed to initialization in main(), because C standard does not
require stdin, stdout and stderr to be constants (at least not C99),
otherwise it fails to compile:

process.c:144:15: error: initializer element is not constant

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
Hi,

not really sure why anything needs to be assigned to stderr and whether
this is a correct approach. Comments are welcome.

Kind regards,
Petr

 testcases/kernel/sched/process_stress/process.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/sched/process_stress/process.c b/testcases/kernel/sched/process_stress/process.c
index a5ff80987..11837c3cb 100644
--- a/testcases/kernel/sched/process_stress/process.c
+++ b/testcases/kernel/sched/process_stress/process.c
@@ -141,13 +141,8 @@ timer_t timer;			/* timer structure */
 
 Pinfo *shmaddr;			/* Start address  of shared memory */
 
-#ifndef _LINUX
-FILE *errfp = stderr;		/* error file pointer, probably not necessary */
-FILE *debugfp = stderr;		/* debug file pointer, used if AUSDEBUG set */
-#else
-#define errfp stderr
-#define debugfp stderr
-#endif
+FILE *errfp;
+FILE *debugfp;
 
 struct envstruct *edat = envdata;	/* pointer to environment data */
 
@@ -1221,6 +1216,9 @@ void doit(void)
 /* main */
 int main(int argc, char *argv[])
 {
+	errfp = stderr;
+	debugfp = stderr;
+
 	extern Pinfo *shmaddr;	/* start address of shared memory */
 
 	prtln();
-- 
2.33.0


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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [LTP] [PATCH 2/2] ci/alpine: Enable process.c
@ 2021-09-03 21:48     ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2021-09-03 21:48 UTC (permalink / raw)
  To: ltp

Fixed in previous commit.

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
---
 ci/alpine.sh | 1 -
 1 file changed, 1 deletion(-)

diff --git a/ci/alpine.sh b/ci/alpine.sh
index deb9cfdcf..d93a57616 100755
--- a/ci/alpine.sh
+++ b/ci/alpine.sh
@@ -33,7 +33,6 @@ cat /etc/os-release
 echo "WARNING: remove unsupported tests (until they're fixed)"
 cd $(dirname $0)/..
 rm -rfv \
-	testcases/kernel/sched/process_stress/process.c \
 	testcases/kernel/syscalls/confstr/confstr01.c \
 	testcases/kernel/syscalls/fmtmsg/fmtmsg01.c \
 	testcases/kernel/syscalls/getcontext/getcontext01.c \
-- 
2.33.0


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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [RFC][PATCH 1/2] sched/process.c: Always use pointer to stderr
@ 2021-09-03 22:34     ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2021-09-03 22:34 UTC (permalink / raw)
  To: ltp

Hi,

compilation tested:
https://github.com/pevik/ltp/actions/runs/1199503613

Runtime tested only on glibc (I'll test musl as well).

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [RFC][PATCH 1/2] sched/process.c: Always use pointer to stderr
@ 2021-09-04  2:39     ` Li Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Li Wang @ 2021-09-04  2:39 UTC (permalink / raw)
  To: Petr Vorel; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 2567 bytes --]

On Sat, Sep 4, 2021 at 5:48 AM Petr Vorel <petr.vorel@gmail.com> wrote:

> which was previously used for non-linux OS (not relevant to LTP thus not
> used in LTP), for linux stderr directly was used.
>
> This fixes compilation on MUSL which does not like assignment to stderr:
>
> process.c:553:14: error: assignment of read-only variable 'stderr'
>   553 |      debugfp = fopen(foo, "a+");
>       |              ^
>
> NOTE: needed to initialization in main(), because C standard does not
> require stdin, stdout and stderr to be constants (at least not C99),
> otherwise it fails to compile:
>
> process.c:144:15: error: initializer element is not constant
>
> Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
> ---
> Hi,
>
> not really sure why anything needs to be assigned to stderr and whether
> this is a correct approach. Comments are welcome.
>

Hmm, I guess that the original purpose is to redirect stderr to
another destination. But it made a mistake which assigns new
FILE stream to stderr, AFAIK, we should not do like that.
A recomened way is:
    FILE *debugfp = freopen(foo, "w", stderr );

Or, it just wants to make compatible but forget that definition in use then.


Anyway, your fix looks good.
Reviewed-by: Li Wang <liwang@redhat.com>



>
> Kind regards,
> Petr
>
>  testcases/kernel/sched/process_stress/process.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/testcases/kernel/sched/process_stress/process.c
> b/testcases/kernel/sched/process_stress/process.c
> index a5ff80987..11837c3cb 100644
> --- a/testcases/kernel/sched/process_stress/process.c
> +++ b/testcases/kernel/sched/process_stress/process.c
> @@ -141,13 +141,8 @@ timer_t timer;                     /* timer structure
> */
>
>  Pinfo *shmaddr;                        /* Start address  of shared memory
> */
>
> -#ifndef _LINUX
> -FILE *errfp = stderr;          /* error file pointer, probably not
> necessary */
> -FILE *debugfp = stderr;                /* debug file pointer, used if
> AUSDEBUG set */
> -#else
> -#define errfp stderr
> -#define debugfp stderr
> -#endif
> +FILE *errfp;
> +FILE *debugfp;
>
>  struct envstruct *edat = envdata;      /* pointer to environment data */
>
> @@ -1221,6 +1216,9 @@ void doit(void)
>  /* main */
>  int main(int argc, char *argv[])
>  {
> +       errfp = stderr;
> +       debugfp = stderr;
> +
>         extern Pinfo *shmaddr;  /* start address of shared memory */
>
>         prtln();
> --
> 2.33.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 4420 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-04  2:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 21:48 [LTP] [RFC][PATCH 1/2] sched/process.c: Always use pointer to stderr Petr Vorel
2021-09-03 21:48 ` Petr Vorel
2021-09-03 21:48   ` [LTP] [PATCH 2/2] ci/alpine: Enable process.c Petr Vorel
2021-09-03 21:48     ` Petr Vorel
2021-09-03 22:34   ` [LTP] [RFC][PATCH 1/2] sched/process.c: Always use pointer to stderr Petr Vorel
2021-09-03 22:34     ` Petr Vorel
2021-09-04  2:39   ` Li Wang
2021-09-04  2:39     ` Li Wang

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.