Port getprogname module to SCO OpenServer
I ported the getprogname module to SCO OpenServer 6 (should also work on OSR5 and UnixWare). It prevents several OSS packages from building. I just made it read from /proc//cmdline to get the command name. The patch is below. Comments are welcome. Thanks! -Benji diff --git a/lib/getprogname.c b/lib/getprogname.c index 744466ea9..9ee4c226d 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -51,6 +51,11 @@ # include #endif +#ifdef __SCO_VERSION__ +# include +# include +#endif + #include "basename-lgpl.h" #ifndef HAVE_GETPROGNAME /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */ @@ -245,6 +250,39 @@ getprogname (void) } } return NULL; +# elif defined __SCO_VERSION__ /* SCO OpenServer/UnixWare */ + char buf[50]; + char *ret; + int fd; + int pathlen; + sprintf (buf, "/proc/%d/cmdline", (int)getpid()); + fd = open (buf, O_RDONLY); + if (0 <= fd) + { + size_t n = read (fd, buf, 49); + if (n > 0) + { + buf[49] = '\0'; /* Guarantee null-termination */ + pathlen = strlen (buf); + ret = malloc (pathlen + 1); + if (ret) + { + int i; + int pathsep = 0; + for (i = 0; i < pathlen; i++) + { + if (buf[i] == '/') + { + pathsep = i; + } + } + strcpy (ret, buf + pathsep + 1); + return ret; + } + } + close (fd); + } + return "?"; # else # error "getprogname module not ported to this OS" # endif
Re: hard-locale.c: SETLOCALE_NULL_MAX
Hi Bruno, thank you for your reply. I could finally track down the error. It was in my build configuration. Somehow, the wrong "-I ..." flags were set up during the compilation of the Gnulib modules. It's working now. So, everything is alright with Gnulib and I can retract my bug report. Please excuse me for bothering you. Initially, when I found the bug on Gentoo's bug tracker, I didn't think of such a simple cause. As for your questions, it was probably only (6) that caused the problem. Marc Am Mi., 30. Sept. 2020 um 18:38 Uhr schrieb Bruno Haible : > > Hi Marc, > > > The compiler throws the following error at me: > > > > lib/hard-locale.c: In function 'hard_locale': > > lib/hard-locale.c:29:15: error: 'SETLOCALE_NULL_MAX' undeclared (first > > use in this function); did you mean 'SETLOCALE_NULL_ALL_MTSAFE'? > >29 | char locale[SETLOCALE_NULL_MAX]; > > | ^~ > > Does the error occur always, or only with "make -j"? > > Are the following statements true in your build? > (1) I use the module 'hard-locale'. > (2) I use the module 'setlocale-null'. > (3) config.status defines GNULIB_SETLOCALE_NULL to 1. > (4) The file lib/setlocale_null.h exists. > (5) The file lib/locale.h includes setlocale_null.h. > (6) The -I options passed to GCC make sure that setlocale_null.h gets found. > > Bruno >
Re: Port getprogname module to SCO OpenServer
Hi Benji, > I just made it read from /proc//cmdline to get the command name. > The patch is below. Comments are welcome. Thanks! Thanks for the patch. I have a couple of improvement suggestions, though: > + char buf[50]; > + char *ret; > + int fd; > + int pathlen; Can you try to minimize the scope of local variables? Listing all the local variables upfront is BSD style and leads to code that is hard to understand. > +{ > + size_t n = read (fd, buf, 49); > + if (n > 0) > +{ > + buf[49] = '\0'; /* Guarantee null-termination */ > + pathlen = strlen (buf); If n < 49, this call to strlen may read uninitialized memory, no? Better put a NUL in buf[n], not buf[49], then. > + ret = malloc (pathlen + 1); > + if (ret) > +{ > + int i; > + int pathsep = 0; > + for (i = 0; i < pathlen; i++) > +{ > + if (buf[i] == '/') > +{ > + pathsep = i; > +} > +} > + strcpy (ret, buf + pathsep + 1); Can't this code be simplified by calling strrchr (buf, '/') ? > + return ret; Is the size pathlen + 1 really needed for ret? It looks like you need only strlen (buf + pathsep + 1) + 1 bytes. > + } > +} > + close (fd); > +} > + return "?"; > # else Bruno
Re: Port getprogname module to SCO OpenServer
Hi Benji, On Wed, 30 Sep 2020, Benji Wiebe wrote: > I ported the getprogname module to SCO OpenServer 6 (should also work on OSR5 > and UnixWare). It prevents several OSS packages from building. No proc filesystem on Openserver 5 so it will not work there. Would need a different "#ifdef" for 5 anyway. > I just made it read from /proc//cmdline to get the command name. The > patch is below. Comments are welcome. Thanks! Note reading /proc//cmdline will limit you to a 79 char pathname. And your program limits to 49. > > +# elif defined __SCO_VERSION__ /* SCO OpenServer/UnixWare */ While __SCO_VERSION__ covers Openserver 6 and UnixWare 7, what is normally used for 6 and 7 is __USLC__ for the native compiler and __sysv5__ for gcc Ie. # elif defined __USLC__ || defined __sysv5__ -- Tim RiceMultitalents t...@multitalents.net
Re: Port getprogname module to SCO OpenServer
Oh and I forgot to mention, the cast from strrchr is needed to silence a warning from SCO's CC: UX:acomp: WARNING: "gpn_test.c", line 16: improper pointer/integer combination: op "="
another stdio patch for UnixWare
I have attached an additional patch for the stdio parts 2020-09-30 Tim Rice * lib/stdio-impl.h: Add support for UnixWare * lib/freadahead.c: Use __fpending on UnixWare * lib/fflush.c: Update comments for UnixWare * lib/fpending.c: Likewise. * lib/freadable.c: Likewise. * lib/freadptr.c: Likewise. * lib/freadseek.c: Likewise. * lib/fseterr.c: Likewise. * lib/fwritable.c: Likewise. * lib/fwriting.c: Likewise. THe hunk in lib/freadahead.c could potentially be used for other system that define HAVE__FPENDING (Solaris and others?) but I have not tested them so limited to UniWare (and OpenServer 6). With either of the nap() patches in https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00126.html and the stdio_ext patch in https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00127.html and the stdio_ext_m4 patch in https://lists.gnu.org/archive/html/bug-gnulib/2020-09/msg00132.html and the attached patch, I am down to 2 failures in the stdio tests. I used this from one of Bruno's posts ./gnulib-tool --create-testdir --dir=/var/tmp --with-tests \ --single-configure --avoid=havelib-tests fseterr freadable fwritable \ fbufmode freading fwriting freadptr freadseek freadahead fpurge fseeko ftello fpending fflush gltests/test-suite.log looks like this. - = dummy 0: gltests/test-suite.log = # TOTAL: 118 # PASS: 116 # SKIP: 0 # XFAIL: 0 # FAIL: 2 # XPASS: 0 # ERROR: 0 .. contents:: :depth: 2 FAIL: test-fflush2.sh = test-fflush2.c:93: assertion 'c == '!'' failed Abort - core dumped FAIL test-fflush2.sh (exit status: 134) FAIL: test-sigaction test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed [snip 12150 lines] test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed test-sigaction.c:69: assertion '(sa.sa_flags & SA_SIGINFO) == 0' failed FAIL test-sigaction (exit status: 139) - Looks like test-fflush2 failure may be an ungetc issue. I'll see if I can get a Xinuos engineer to fix ungetc/ungetwc While I was working on this I spotted a mistake in the extended stdio bits on UnixWare. __fbufsiz should have been __fbufsize. I will work on getting a Xinuos engineer to fix this. And then there is the test-sigaction.c failure. Ah, more debugging to do. I am looking forward to seeing the patches make it onto the tree. Thanks for your consideration. -- Tim RiceMultitalents t...@multitalents.net2020-09-30 Tim Rice * lib/stdio-impl.h: Add support for UnixWare * lib/freadahead.c: Use __fpending on Unixware * lib/fflush.c: Update comments for UnixWare * lib/fpending.c: Likewise. * lib/freadable.c: Likewise. * lib/freadptr.c: Likewise. * lib/freadseek.c: Likewise. * lib/fseterr.c: Likewise. * lib/fwritable.c: Likewise. * lib/fwriting.c: Likewise. diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index 067b95ebd..f745a170b 100644 --- a/lib/stdio-impl.h +++ b/lib/stdio-impl.h @@ -175,7 +175,8 @@ # define fp_ fp # endif -# if defined _SCO_DS/* OpenServer */ +/* OpenServer, UnixWare (best not to use __base on these platforms) */ +# if defined _SCO_DS || defined __USLC__ || defined __sysv5__ # define _cnt __cnt # define _ptr __ptr # define _base __base diff --git a/lib/freadahead.c b/lib/freadahead.c index be14a3dab..aaa2b9b57 100644 --- a/lib/freadahead.c +++ b/lib/freadahead.c @@ -62,10 +62,14 @@ freadahead (FILE *fp) if ((fp_->_flags & _IOWRITING) != 0) return 0; return fp_->_count; -#elif defined _IOERR/* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel, OpenVMS */ +#elif defined _IOERR/* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, MSVC, NonStop Kernel, OpenVMS, UnixWare */ if ((fp_->_flag & _IOWRT) != 0) return 0; +# if defined __USLC__ || defined __sysv5__ + return __fpending(fp_); +# else return fp_->_cnt; +# endif #elif defined __UCLIBC__/* uClibc */ # ifdef __STDIO_BUFFERS if (fp->__modeflags & __FLAG_WRITING) diff --git a/lib/fflush.c b/lib/fflush.c index b3a40e86a..4e437a623 100644 --- a/lib/fflush.c +++ b/lib/fflush.c @@ -64,7 +64,7 @@ clear_ungetc_buffer (FILE *fp) fp->_ungetc_count = 0; fp->_rcount = - fp->_rcount; } -# elif defined _