From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9408 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] add sched_getcpu Date: Mon, 29 Feb 2016 13:38:16 -0500 Message-ID: <20160229183816.GB9349@brightrain.aerifal.cx> References: <1456765028-23958-1-git-send-email-nathan@nathan7.eu> <1456765216-24883-1-git-send-email-nathan@nathan7.eu> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1456771115 8051 80.91.229.3 (29 Feb 2016 18:38:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 29 Feb 2016 18:38:35 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9421-gllmg-musl=m.gmane.org@lists.openwall.com Mon Feb 29 19:38:34 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1aaSiI-000260-0c for gllmg-musl@m.gmane.org; Mon, 29 Feb 2016 19:38:34 +0100 Original-Received: (qmail 32341 invoked by uid 550); 29 Feb 2016 18:38:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 32323 invoked from network); 29 Feb 2016 18:38:31 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:9408 Archived-At: On Mon, Feb 29, 2016 at 08:23:33PM +0300, Alexander Monakov wrote: > > +int sched_getcpu(void); > > +#endif > > int sched_getaffinity(pid_t, size_t, cpu_set_t *); > > int sched_setaffinity(pid_t, size_t, const cpu_set_t *); > > > > diff --git a/src/sched/sched_getcpu.c b/src/sched/sched_getcpu.c > > new file mode 100644 > > index 0000000..070d6e7 > > --- /dev/null > > +++ b/src/sched/sched_getcpu.c > > @@ -0,0 +1,10 @@ > > +#define _GNU_SOURCE > > +#include > > Do you need this include? > > > +#include > > (this include could also be dropped; I think it's a matter of policy whether > such includes are desirable or not, so please wait for comment from Rich) Policy is to always include the header with the public declaration (and any feature test macros necessary to get it) so that the compiler checks the implementation against the public declaration. > > +#include "syscall.h" > > + > > +int sched_getcpu(void) { > > + int c, s; > > + s = syscall(SYS_getcpu, &c, NULL, NULL); > > + return (s == 0) ? c : s; > > This is wrong, as it doesn't set errno on error, and does not produce -1. This > should be something like 'return s ? __syscall_ret(s) : c;' or maybe > 'return __syscall_ret(s ? s : c);'. Why is an error even possible here? Is it just to account for ancient kernels that lack the syscall? Rich