From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28267 invoked by alias); 21 Feb 2017 15:39:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40604 Received: (qmail 27113 invoked from network); 21 Feb 2017 15:39:59 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-mqugw.biglobe.ne.jp by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(133.208.100.3):SA:0(-0.7/5.0):. Processed in 4.289274 secs); 21 Feb 2017 15:39:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: takimoto-j@kba.biglobe.ne.jp X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at spf01.biglobe.ne.jp designates 133.208.100.3 as permitted sender) X-Biglobe-Sender: Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: fix watch implementation (and Re: UTF-8 locales on BSDs do not support collation correctly) From: "Jun T." In-Reply-To: <20170112220502.GA11170@trex.cs.ovgu.de> Date: Tue, 21 Feb 2017 23:55:34 +0900 Content-Transfer-Encoding: 7bit Message-Id: <9001F45C-404E-4642-91D8-3465019B5736@kba.biglobe.ne.jp> References: <20170112064644.GB10414@trex.cs.ovgu.de> <20170112102138.34f3e759@pwslap01u.europe.root.pri> <20170112220502.GA11170@trex.cs.ovgu.de> To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.1878.6) X-Biglobe-Spnum: 62803 After the commit d3cf881 (worker/40333), watch.c fails to compile on OpenBSD (worker/40416), simply because OpenBSD does not have getutent() (nor getutxent()). We need to use the old way (open/fread/close) to read the utmp/utmpx file on systems like OpenBSD. diff --git a/Src/watch.c b/Src/watch.c index 6103ef1..f033805 100644 --- a/Src/watch.c +++ b/Src/watch.c @@ -91,6 +91,9 @@ # define setutent setutxent # define getutent getutxent # define endutent endutxent +# ifndef HAVE_GETUTENT +# define HAVE_GETUTENT +# endif # endif /* @@ -482,21 +485,32 @@ ucmp(WATCH_STRUCT_UTMP *u, WATCH_STRUCT_UTMP *v) static int readwtab(WATCH_STRUCT_UTMP **head, int initial_sz) { - WATCH_STRUCT_UTMP *uptr, *tmp; + WATCH_STRUCT_UTMP *uptr; int wtabmax = initial_sz < 2 ? 32 : initial_sz; int sz = 0; +# ifdef HAVE_GETUTENT + WATCH_STRUCT_UTMP *tmp; +# else + FILE *in; +# endif uptr = *head = (WATCH_STRUCT_UTMP *) zalloc(wtabmax * sizeof(WATCH_STRUCT_UTMP)); +# ifdef HAVE_GETUTENT setutent(); while ((tmp = getutent()) != NULL) { + memcpy(uptr, tmp, sizeof (WATCH_STRUCT_UTMP)); +# else + if (!(in = fopen(WATCH_UTMP_FILE, "r"))) + return 0; + while (fread(uptr, sizeof(WATCH_STRUCT_UTMP), 1, in)) { +# endif # ifdef USER_PROCESS - if (tmp->ut_type == USER_PROCESS) + if (uptr->ut_type == USER_PROCESS) # else /* !USER_PROCESS */ - if (tmp->ut_name[0]) + if (uptr->ut_name[0]) # endif /* !USER_PROCESS */ { - memcpy(uptr, tmp, sizeof (WATCH_STRUCT_UTMP)); uptr++; if (++sz == wtabmax) { uptr = (WATCH_STRUCT_UTMP *) @@ -512,7 +526,11 @@ readwtab(WATCH_STRUCT_UTMP **head, int initial_sz) } } } +# ifdef HAVE_GETUTENT endutent(); +# else + fclose(in); +# endif if (sz) qsort((void *) *head, sz, sizeof(WATCH_STRUCT_UTMP), diff --git a/configure.ac b/configure.ac index c6ece67..0551a69 100644 --- a/configure.ac +++ b/configure.ac @@ -1325,7 +1325,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \ cygwin_conv_path \ nanosleep \ srand_deterministic \ - setutxent getutxent endutxent) + setutxent getutxent endutxent getutent) AC_FUNC_STRCOLL AH_TEMPLATE([REALPATH_ACCEPTS_NULL],