Mailinglist Archive: yast-devel (39 mails)

< Previous Next >
[yast-devel] Review Request (yast2-core)
Hi,

I noticed that YaST prints garbage when the logfile cannot be
opened. The problem is that strerror_r may leave buf untouched so
you have to print the returned pointer (when using the GNU
version of strerror_r).

ciao Arvin

--
Arvin Schnell, <aschnell@xxxxxxx>
Senior Software Engineer, Research & Development
SUSE LINUX Products GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer, HRB
16746 (AG Nürnberg)
Maxfeldstraße 5
90409 Nürnberg
Germany
Index: liby2util-r/src/y2log.cc
===================================================================
--- liby2util-r/src/y2log.cc (revision 68092)
+++ liby2util-r/src/y2log.cc (working copy)
@@ -119,10 +119,10 @@
FILE * newstderr = fdopen( dupstderr, "a" );

if ( newstderr == NULL ) {
- char buf[100];
+ char buf1[100];
//bnc#493152#c22
- strerror_r(errno, buf, sizeof(buf)-1);
- fprintf( Y2LOG_STDERR, "y2log: Can't fdopen new stderr: %s.\n", buf);
+ const char* buf2 = strerror_r(errno, buf1, sizeof(buf1)-1);
+ fprintf(Y2LOG_STDERR, "y2log: Can't fdopen new stderr: %s.\n", buf2);
}
else {
fcntl (fileno (newstderr), F_SETFD, fcntl (fileno (newstderr),
F_GETFD) | FD_CLOEXEC);
@@ -130,9 +130,9 @@
}
}
else {
- char buf[100];
- strerror_r(errno, buf, sizeof(buf)-1);
- fprintf( Y2LOG_STDERR, "y2log: Can't dup stderr: %s.\n", buf );
+ char buf1[100];
+ const char* buf2 = strerror_r(errno, buf1, sizeof(buf1)-1);
+ fprintf(Y2LOG_STDERR, "y2log: Can't dup stderr: %s.\n", buf2);
}
return 1;
}
@@ -150,10 +150,10 @@
logfile = fopen (logname, "a");
}
if (!logfile && !log_simple) {
- char buf[100];
- strerror_r(errno, buf, sizeof(buf)-1);
- fprintf (Y2LOG_STDERR, "y2log: Error opening logfile '%s': %s.\n",
- logname, buf);
+ char buf1[100];
+ const char* buf2 = strerror_r(errno, buf1, sizeof(buf1)-1);
+ fprintf(Y2LOG_STDERR, "y2log: Error opening logfile '%s': %s.\n",
+ logname, buf2);
return NULL;
}
}
< Previous Next >
Follow Ups