Skip to contentSkip to conversation

sched/process.c: Always use pointer to stderr

RFC PATCH New Petr Vorel 2 participants 4 messages Sep 3, 2021 – Sep 4, 2021

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

RFC PATCH 1/2 sched/process.c: Always use pointer to stderr

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

---
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(-)
testcases/kernel/sched/process_stress/process.c +5 -7
index a5ff80987..11837c3cb 100644
@@ -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();
Signature · 1 line
2.33.0
author
#1 lore raw

PATCH 2/2 ci/alpine: Enable process.c

Fixed in previous commit.

---
 ci/alpine.sh | 1 -
 1 file changed, 1 deletion(-)
ci/alpine.sh +0 -1
index deb9cfdcf..d93a57616 100755
@@ -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 \
Signature · 1 line
2.33.0
#3 lore raw

RFC PATCH 1/2 sched/process.c: Always use pointer to stderr

In reply to Petr Vorel
Quoted 13 lines · Petr Vorel

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:

Quoted 9 lines

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

---
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.

Quoted 50 lines

Kind regards,
Petr

 testcases/kernel/sched/process_stress/process.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
testcases/kernel/sched/process_stress/process.c +0 -2
index a5ff80987..11837c3cb 100644
@@ -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 */

testcases/kernel/sched/process_stress/process.c +5 -5
-#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

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20210904/87504d7e/attachment-0001.htm>