Define SEM_VALUE_MAX in only one place.

Adding a whole extra header file just for this is not the optimal
solution... but stuffing it in with anything else exposes things that
otherwise wouldn't be.

Nothing in userland should use <sys/semaphore.h> directly, and if some
foolish third-party software should decide to do so anyway in spite of
the instructions to the contrary I will ruthlessly break it later when
the big kernel includes cleanup finally happens.

Reported by Kamil Rytarowski, and, as it turns out, also by Klaus
Heinz in 2008.
This commit is contained in:
dholland 2016-04-24 19:48:29 +00:00
parent f7945701d6
commit 521eaa499b
5 changed files with 54 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.2031 2016/04/23 23:28:13 christos Exp $
# $NetBSD: mi,v 1.2032 2016/04/24 19:48:30 dholland Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@ -2918,6 +2918,7 @@
./usr/include/sys/select.h comp-c-include
./usr/include/sys/selinfo.h comp-c-include
./usr/include/sys/sem.h comp-c-include
./usr/include/sys/semaphore.h comp-c-include
./usr/include/sys/sha1.h comp-c-include
./usr/include/sys/sha2.h comp-c-include
./usr/include/sys/shm.h comp-c-include

View File

@ -1,4 +1,4 @@
/* $NetBSD: semaphore.h,v 1.4 2012/03/08 21:59:28 joerg Exp $ */
/* $NetBSD: semaphore.h,v 1.5 2016/04/24 19:48:29 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -38,8 +38,8 @@ struct _sem_st;
typedef struct _sem_st *sem_t;
#define SEM_FAILED ((sem_t *)0)
#define SEM_VALUE_MAX (~0U)
#include <sys/semaphore.h> /* some kernel-only bits */
#include <sys/time.h>
__BEGIN_DECLS

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_sem.c,v 1.44 2015/11/09 01:55:03 pgoyette Exp $ */
/* $NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.44 2015/11/09 01:55:03 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.45 2016/04/24 19:48:29 dholland Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.44 2015/11/09 01:55:03 pgoyette Exp $
#include <sys/kauth.h>
#include <sys/module.h>
#include <sys/mount.h>
#include <sys/semaphore.h>
#include <sys/syscall.h>
#include <sys/syscallargs.h>
#include <sys/syscallvar.h>
@ -85,7 +86,6 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_sem.c,v 1.44 2015/11/09 01:55:03 pgoyette Exp $
MODULE(MODULE_CLASS_MISC, ksem, NULL);
#define SEM_MAX_NAMELEN 14
#define SEM_VALUE_MAX (~0U)
#define KS_UNLINKED 0x01

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.158 2016/04/02 20:38:40 christos Exp $
# $NetBSD: Makefile,v 1.159 2016/04/24 19:48:29 dholland Exp $
.include <bsd.own.mk>
@ -34,8 +34,8 @@ INCS= acct.h agpio.h aio.h ansi.h aout_mids.h ataio.h atomic.h audioio.h \
queue.h quota.h quotactl.h \
ras.h rbtree.h reboot.h radioio.h resource.h resourcevar.h rmd160.h \
rnd.h rndio.h rwlock.h \
scanio.h sched.h scsiio.h sdt.h select.h selinfo.h sem.h sha1.h \
sha2.h shm.h siginfo.h signal.h signalvar.h sigtypes.h \
scanio.h sched.h scsiio.h sdt.h select.h selinfo.h sem.h semaphore.h \
sha1.h sha2.h shm.h siginfo.h signal.h signalvar.h sigtypes.h \
sleepq.h socket.h \
socketvar.h sockio.h spawn.h specificdata.h stat.h \
statvfs.h syscall.h syscallargs.h sysctl.h stdarg.h stdbool.h \

44
sys/sys/semaphore.h Normal file
View File

@ -0,0 +1,44 @@
/* $NetBSD: semaphore.h,v 1.1 2016/04/24 19:48:29 dholland Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This file is NOT a public interface. From userland you should
* include <semaphore.h>.
*/
#ifndef _SYS_SEMAPHORE_H_
#define _SYS_SEMAPHORE_H_
/* POSIX 1003.1b semaphores */
#define SEM_VALUE_MAX (~0U)
#endif /* !_SYS_SEMAPHORE_H_ */