summaryrefslogtreecommitdiff
path: root/usr/src/lib/libc/port/gen
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libc/port/gen')
-rw-r--r--usr/src/lib/libc/port/gen/atexit.c25
-rw-r--r--usr/src/lib/libc/port/gen/err.c29
-rw-r--r--usr/src/lib/libc/port/gen/fdopendir.c6
-rw-r--r--usr/src/lib/libc/port/gen/getutx.c6
-rw-r--r--usr/src/lib/libc/port/gen/msync.c11
-rw-r--r--usr/src/lib/libc/port/gen/ndbm.c33
-rw-r--r--usr/src/lib/libc/port/gen/nss_common.c32
-rw-r--r--usr/src/lib/libc/port/gen/remove.c (renamed from usr/src/lib/libc/port/gen/rename.c)15
-rw-r--r--usr/src/lib/libc/port/gen/tcdrain.c11
-rw-r--r--usr/src/lib/libc/port/gen/truncate.c31
-rw-r--r--usr/src/lib/libc/port/gen/wait3.c53
-rw-r--r--usr/src/lib/libc/port/gen/wait4.c161
-rw-r--r--usr/src/lib/libc/port/gen/waitpid.c159
-rw-r--r--usr/src/lib/libc/port/gen/xpg4.c10
-rw-r--r--usr/src/lib/libc/port/gen/xpg6.c10
15 files changed, 251 insertions, 341 deletions
diff --git a/usr/src/lib/libc/port/gen/atexit.c b/usr/src/lib/libc/port/gen/atexit.c
index 69de21f524..d687f8d48c 100644
--- a/usr/src/lib/libc/port/gen/atexit.c
+++ b/usr/src/lib/libc/port/gen/atexit.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -67,10 +67,9 @@ extern caddr_t _getfp(void);
* that the registered functions actually return (no longjmp()s).
*
* Because exitfns_lock is declared to be a recursive mutex, we
- * cannot use it with lmutex_lock()/lmutex_unlock() and we must use
- * rmutex_lock()/rmutex_unlock() (which are defined to be simply
- * mutex_lock()/mutex_unlock()). This means that atexit() and
- * exit() are not async-signal-safe. We make them fork1-safe
+ * cannot use it with lmutex_lock()/lmutex_unlock() and we must
+ * use mutex_lock()/mutex_unlock(). This means that atexit()
+ * and exit() are not async-signal-safe. We make them fork1-safe
* via the atexit_locks()/atexit_unlocks() functions, called from
* libc_prepare_atfork()/libc_child_atfork()/libc_parent_atfork()
*/
@@ -82,13 +81,13 @@ extern caddr_t _getfp(void);
void
atexit_locks()
{
- (void) rmutex_lock(&__uberdata.atexit_root.exitfns_lock);
+ (void) _private_mutex_lock(&__uberdata.atexit_root.exitfns_lock);
}
void
atexit_unlocks()
{
- (void) rmutex_unlock(&__uberdata.atexit_root.exitfns_lock);
+ (void) _private_mutex_unlock(&__uberdata.atexit_root.exitfns_lock);
}
/*
@@ -109,13 +108,13 @@ _atexit(void (*func)(void))
arp = &__uberdata.atexit_root;
else {
arp = &self->ul_uberdata->atexit_root;
- (void) rmutex_lock(&arp->exitfns_lock);
+ (void) _private_mutex_lock(&arp->exitfns_lock);
}
p->hdlr = func;
p->next = arp->head;
arp->head = p;
if (self != NULL)
- (void) rmutex_unlock(&arp->exitfns_lock);
+ (void) _private_mutex_unlock(&arp->exitfns_lock);
return (0);
}
@@ -125,7 +124,7 @@ _exithandle(void)
atexit_root_t *arp = &curthread->ul_uberdata->atexit_root;
_exthdlr_t *p;
- (void) rmutex_lock(&arp->exitfns_lock);
+ (void) _private_mutex_lock(&arp->exitfns_lock);
arp->exit_frame_monitor = _getfp() + STACK_BIAS;
p = arp->head;
while (p != NULL) {
@@ -134,7 +133,7 @@ _exithandle(void)
lfree(p, sizeof (_exthdlr_t));
p = arp->head;
}
- (void) rmutex_unlock(&arp->exitfns_lock);
+ (void) _private_mutex_unlock(&arp->exitfns_lock);
}
/*
@@ -288,7 +287,7 @@ _preexec_exit_handlers(Lc_addr_range_t range[], uint_t count)
_exthdlr_t *o; /* previous node */
_exthdlr_t *p; /* this node */
- (void) rmutex_lock(&arp->exitfns_lock);
+ (void) _private_mutex_lock(&arp->exitfns_lock);
o = NULL;
p = arp->head;
while (p != NULL) {
@@ -307,7 +306,7 @@ _preexec_exit_handlers(Lc_addr_range_t range[], uint_t count)
p = p->next;
}
}
- (void) rmutex_unlock(&arp->exitfns_lock);
+ (void) _private_mutex_unlock(&arp->exitfns_lock);
_preexec_tsd_unload(range, count);
_preexec_atfork_unload(range, count);
diff --git a/usr/src/lib/libc/port/gen/err.c b/usr/src/lib/libc/port/gen/err.c
index 7af600f48f..3819d4881f 100644
--- a/usr/src/lib/libc/port/gen/err.c
+++ b/usr/src/lib/libc/port/gen/err.c
@@ -18,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -35,6 +36,8 @@
#pragma weak vwarnx = _vwarnx
#include "synonyms.h"
+#include "file64.h"
+#include "mtlib.h"
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
@@ -42,6 +45,7 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
+#include "stdiom.h"
/* Function exit/warning functions and global variables. */
@@ -51,12 +55,14 @@ static const char *progname;
* warncore() is the workhorse of these functions. Everything else has
* a warncore() component in it.
*/
-static void
+static rmutex_t *
warncore(FILE *fp, const char *fmt, va_list args)
{
const char *execname;
+ rmutex_t *lk;
+
+ FLOCKFILE(lk, fp);
- flockfile(fp);
if (progname == NULL) {
execname = getexecname();
if ((execname != NULL) &&
@@ -72,22 +78,26 @@ warncore(FILE *fp, const char *fmt, va_list args)
if (fmt != NULL) {
(void) vfprintf(fp, fmt, args);
}
+
+ return (lk);
}
/* Finish a warning with a newline and a flush of stderr. */
static void
-warnfinish(FILE *fp)
+warnfinish(FILE *fp, rmutex_t *lk)
{
(void) fputc('\n', fp);
(void) fflush(fp);
- funlockfile(fp);
+ FUNLOCKFILE(lk);
}
void
_vwarnxfp(FILE *fp, const char *fmt, va_list args)
{
- warncore(fp, fmt, args);
- warnfinish(fp);
+ rmutex_t *lk;
+
+ lk = warncore(fp, fmt, args);
+ warnfinish(fp, lk);
}
void
@@ -100,14 +110,15 @@ void
_vwarnfp(FILE *fp, const char *fmt, va_list args)
{
int tmperr = errno; /* Capture errno now. */
+ rmutex_t *lk;
- warncore(fp, fmt, args);
+ lk = warncore(fp, fmt, args);
if (fmt != NULL) {
(void) fputc(':', fp);
(void) fputc(' ', fp);
}
(void) fputs(strerror(tmperr), fp);
- warnfinish(fp);
+ warnfinish(fp, lk);
}
void
diff --git a/usr/src/lib/libc/port/gen/fdopendir.c b/usr/src/lib/libc/port/gen/fdopendir.c
index 237d6a59ff..344c3af2be 100644
--- a/usr/src/lib/libc/port/gen/fdopendir.c
+++ b/usr/src/lib/libc/port/gen/fdopendir.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -47,8 +47,6 @@
#include <errno.h>
#include "libc.h"
-extern int __fcntl(int fd, int cmd, intptr_t arg);
-
DIR *
fdopendir(int fd)
{
@@ -64,7 +62,7 @@ fdopendir(int fd)
* POSIX mandated behavior
* close on exec if using file descriptor
*/
- if (__fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
goto fail;
if (fstat64(fd, &sbuf) < 0)
goto fail;
diff --git a/usr/src/lib/libc/port/gen/getutx.c b/usr/src/lib/libc/port/gen/getutx.c
index 3d8e69cf4e..fe0da52342 100644
--- a/usr/src/lib/libc/port/gen/getutx.c
+++ b/usr/src/lib/libc/port/gen/getutx.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -82,6 +82,7 @@
#include <ctype.h>
#include <stdlib.h>
#include <sys/wait.h>
+#include <pthread.h>
#include <limits.h>
#include <signal.h>
#include <spawn.h>
@@ -508,6 +509,7 @@ invoke_utmp_update(const struct utmpx *entryx)
posix_spawnattr_t attr;
int status;
+ int cancel_state;
pid_t child;
pid_t w;
int i;
@@ -587,9 +589,11 @@ invoke_utmp_update(const struct utmpx *entryx)
goto out;
}
+ (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
do {
w = waitpid(child, &status, 0);
} while (w == -1 && errno == EINTR);
+ (void) pthread_setcancelstate(cancel_state, NULL);
/*
* We can get ECHILD if the process is ignoring SIGCLD.
diff --git a/usr/src/lib/libc/port/gen/msync.c b/usr/src/lib/libc/port/gen/msync.c
index 73c023f7ad..cf1e29031c 100644
--- a/usr/src/lib/libc/port/gen/msync.c
+++ b/usr/src/lib/libc/port/gen/msync.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,13 +29,12 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-
#include "synonyms.h"
#include <sys/types.h>
#include <sys/mman.h>
int
-_msync(caddr_t addr, size_t len, int flags)
+__msync(caddr_t addr, size_t len, int flags)
{
return (memcntl(addr, len, MC_SYNC, (caddr_t)(uintptr_t)flags, 0, 0));
}
diff --git a/usr/src/lib/libc/port/gen/ndbm.c b/usr/src/lib/libc/port/gen/ndbm.c
index 13ca8ce2ae..70a8e5e275 100644
--- a/usr/src/lib/libc/port/gen/ndbm.c
+++ b/usr/src/lib/libc/port/gen/ndbm.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -50,6 +50,7 @@
#include <ndbm.h>
#include <unistd.h>
#include <string.h>
+#include <pthread.h>
/* add support for batched writing for NIS */
@@ -452,10 +453,22 @@ loop:
datum
dbm_firstkey(DBM *db)
{
+ /*
+ * For some reason, the Posix specification (SUSv3)
+ * says that dbm_firstkey() is not a cancellation point.
+ * It really should be, but in order to pass the SUSv3
+ * test suite we make it not a cancellation point.
+ * XXX: fix me when the SUSv3 specification gets fixed.
+ */
+ int cancel_state;
+ datum rval;
db->dbm_blkptr = 0L;
db->dbm_keyptr = 0;
- return (dbm_firsthash(db, 0L));
+ (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
+ rval = dbm_firsthash(db, 0L);
+ (void) pthread_setcancelstate(cancel_state, NULL);
+ return (rval);
}
datum
@@ -496,7 +509,7 @@ dbm_slow_nextkey(DBM *db)
where = (((off64_t)db->dbm_blkptr) * PBLKSIZ);
if ((lseek64(db->dbm_pagf, where, L_SET) != where) ||
(read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) !=
- PBLKSIZ))
+ PBLKSIZ))
(void) memset(db->dbm_pagbuf, 0, PBLKSIZ);
#ifdef DEBUG
else if (chkblk(db->dbm_pagbuf) < 0)
@@ -557,7 +570,7 @@ dbm_do_nextkey(DBM *db, datum inkey)
/* is this a manual firstkey request? */
if (db->dbm_blkptr == 0L &&
- db->dbm_keyptr == 0)
+ db->dbm_keyptr == 0)
return (dbm_firsthash(db, 0L));
/* no -- get lastkey this is like dbm_access by blkptr */
@@ -569,7 +582,7 @@ dbm_do_nextkey(DBM *db, datum inkey)
where = (((off64_t)db->dbm_blkptr) * PBLKSIZ);
if ((lseek64(db->dbm_pagf, where, L_SET) != where) ||
(read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) !=
- PBLKSIZ))
+ PBLKSIZ))
(void) memset(db->dbm_pagbuf, 0, PBLKSIZ);
#ifdef DEBUG
else if (chkblk(db->dbm_pagbuf) < 0)
@@ -727,7 +740,7 @@ dbm_access(DBM *db, unsigned long hash)
where = (((off64_t)b) * DBLKSIZ);
if ((lseek64(db->dbm_dirf, where, L_SET) != where) ||
(read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) !=
- DBLKSIZ))
+ DBLKSIZ))
(void) memset(db->dbm_dirbuf, 0, DBLKSIZ);
}
if ((db->dbm_dirbuf[i] & (1<<n)) == 0) break;
@@ -747,7 +760,7 @@ dbm_access(DBM *db, unsigned long hash)
where = (((off64_t)db->dbm_pagbno) * PBLKSIZ);
if ((lseek64(db->dbm_pagf, where, L_SET) != where) ||
(write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) !=
- PBLKSIZ)) {
+ PBLKSIZ)) {
db->dbm_flags |= _DBM_IOERR;
}
dbm_clrdirty(db);
diff --git a/usr/src/lib/libc/port/gen/nss_common.c b/usr/src/lib/libc/port/gen/nss_common.c
index d21f635d42..f7a77e278b 100644
--- a/usr/src/lib/libc/port/gen/nss_common.c
+++ b/usr/src/lib/libc/port/gen/nss_common.c
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -52,6 +52,8 @@
#include <stdio.h>
#include <string.h>
#include <thread.h>
+#include <synch.h>
+#include <pthread.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
@@ -145,24 +147,24 @@ void _nss_db_state_destr(struct nss_db_state *);
/* ==== null definitions if !MTSAFE? Ditto lock field in nss_db_root_t */
-#define NSS_ROOTLOCK(r, sp) ((void) _private_mutex_lock(&(r)->lock), \
+#define NSS_ROOTLOCK(r, sp) (cancel_safe_mutex_lock(&(r)->lock), \
*(sp) = (r)->s)
-#define NSS_UNLOCK(r) ((void) _private_mutex_unlock(&(r)->lock))
+#define NSS_UNLOCK(r) (cancel_safe_mutex_unlock(&(r)->lock))
#define NSS_CHECKROOT(rp, s) ((s) != (*(rp))->s && \
- ((void) _private_mutex_unlock(&(*(rp))->lock), \
- (void) _private_mutex_lock(&(s)->orphan_root.lock), \
+ (cancel_safe_mutex_unlock(&(*(rp))->lock), \
+ cancel_safe_mutex_lock(&(s)->orphan_root.lock), \
*(rp) = &(s)->orphan_root))
-#define NSS_RELOCK(rp, s) ((void) _private_mutex_lock(&(*(rp))->lock), \
+#define NSS_RELOCK(rp, s) (cancel_safe_mutex_lock(&(*(rp))->lock), \
NSS_CHECKROOT(rp, s))
#define NSS_STATE_REF_u(s) (++(s)->refcount)
#define NSS_UNREF_UNLOCK(r, s) (--(s)->refcount != 0 \
? ((void)NSS_UNLOCK(r)) \
- : (NSS_UNLOCK(r), (void)_nss_db_state_destr(s)))
+ : ((void)NSS_UNLOCK(r), (void)_nss_db_state_destr(s)))
#define NSS_LOCK_CHECK(r, f, sp) (NSS_ROOTLOCK((r), (sp)), \
*(sp) == 0 && \
@@ -752,6 +754,7 @@ nss_get_backend_u(nss_db_root_t **rootpp, struct nss_db_state *s, int n_src)
{
struct nss_src_state *src = &s->src[n_src];
nss_backend_t *be;
+ int cancel_state;
for (;;) {
if (src->n_dormant > 0) {
@@ -810,7 +813,10 @@ nss_get_backend_u(nss_db_root_t **rootpp, struct nss_db_state *s, int n_src)
}
src->n_waiting++;
+ (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,
+ &cancel_state);
(void) cond_wait(&src->wanna_be, &(*rootpp)->lock);
+ (void) pthread_setcancelstate(cancel_state, NULL);
NSS_CHECKROOT(rootpp, s);
src->n_waiting--;
@@ -1290,9 +1296,9 @@ nss_setent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp)
if (contextpp == 0) {
return;
}
- (void) _private_mutex_lock(&contextpp->lock);
+ cancel_safe_mutex_lock(&contextpp->lock);
nss_setent_u(rootp, initf, contextpp);
- (void) _private_mutex_unlock(&contextpp->lock);
+ cancel_safe_mutex_unlock(&contextpp->lock);
}
nss_status_t
@@ -1304,9 +1310,9 @@ nss_getent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp,
if (contextpp == 0) {
return (NSS_UNAVAIL);
}
- (void) _private_mutex_lock(&contextpp->lock);
+ cancel_safe_mutex_lock(&contextpp->lock);
status = nss_getent_u(rootp, initf, contextpp, args);
- (void) _private_mutex_unlock(&contextpp->lock);
+ cancel_safe_mutex_unlock(&contextpp->lock);
return (status);
}
@@ -1316,9 +1322,9 @@ nss_endent(nss_db_root_t *rootp, nss_db_initf_t initf, nss_getent_t *contextpp)
if (contextpp == 0) {
return;
}
- (void) _private_mutex_lock(&contextpp->lock);
+ cancel_safe_mutex_lock(&contextpp->lock);
nss_endent_u(rootp, initf, contextpp);
- (void) _private_mutex_unlock(&contextpp->lock);
+ cancel_safe_mutex_unlock(&contextpp->lock);
}
/*
diff --git a/usr/src/lib/libc/port/gen/rename.c b/usr/src/lib/libc/port/gen/remove.c
index f2a5854521..bf76e3824b 100644
--- a/usr/src/lib/libc/port/gen/rename.c
+++ b/usr/src/lib/libc/port/gen/remove.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,7 +29,6 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-
#include "synonyms.h"
#include <sys/types.h>
#include <sys/stat.h>
@@ -52,9 +51,3 @@ remove(const char *filename)
return (unlink(filename));
return (rmdir(filename));
}
-
-int
-rename(const char *old, const char *new)
-{
- return (_rename(old, new));
-}
diff --git a/usr/src/lib/libc/port/gen/tcdrain.c b/usr/src/lib/libc/port/gen/tcdrain.c
index 7e1b3f7bb6..78190fe231 100644
--- a/usr/src/lib/libc/port/gen/tcdrain.c
+++ b/usr/src/lib/libc/port/gen/tcdrain.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,7 +29,6 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
-
#include "synonyms.h"
#include <sys/termios.h>
#include <unistd.h>
@@ -39,7 +38,7 @@
* wait until all output on the filedes is drained
*/
int
-_tcdrain(int fildes)
+__tcdrain(int fildes)
{
return (ioctl(fildes, TCSBRK, 1));
}
diff --git a/usr/src/lib/libc/port/gen/truncate.c b/usr/src/lib/libc/port/gen/truncate.c
index 9fae764f31..eff577845f 100644
--- a/usr/src/lib/libc/port/gen/truncate.c
+++ b/usr/src/lib/libc/port/gen/truncate.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -54,6 +54,7 @@
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
+#include <pthread.h>
#include <sys/types.h>
int
@@ -76,17 +77,19 @@ int
_truncate(const char *path, off_t len)
{
+ int rval = 0;
+ int cancel_state;
int fd;
- if ((fd = open(path, O_WRONLY)) == -1) {
- return (-1);
- }
-
- if (ftruncate(fd, len) == -1) {
+ /*
+ * truncate() is not a cancellation point,
+ * even though it calls open() and close().
+ */
+ (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancel_state);
+ if ((fd = open(path, O_WRONLY)) == -1 || ftruncate(fd, len) == -1)
+ rval = -1;
+ if (fd >= 0)
(void) close(fd);
- return (-1);
- }
-
- (void) close(fd);
- return (0);
+ (void) pthread_setcancelstate(cancel_state, NULL);
+ return (rval);
}
diff --git a/usr/src/lib/libc/port/gen/wait3.c b/usr/src/lib/libc/port/gen/wait3.c
deleted file mode 100644
index 00b25b15bc..0000000000
--- a/usr/src/lib/libc/port/gen/wait3.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
-/* All Rights Reserved */
-
-/*
- * Portions of this source code were derived from Berkeley 4.3 BSD
- * under license from the Regents of the University of California.
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include "synonyms.h"
-
-/*
- * Compatibility lib for BSD's wait3() - falls through to wait4().
- */
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <wait.h>
-#include <sys/resource.h>
-#include <unistd.h>
-
-pid_t
-_wait3(int *status, int options, struct rusage *rp)
-{
- return (wait4(0, status, options, rp));
-}
diff --git a/usr/src/lib/libc/port/gen/wait4.c b/usr/src/lib/libc/port/gen/wait4.c
deleted file mode 100644
index 15ffdc92e4..0000000000
--- a/usr/src/lib/libc/port/gen/wait4.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
- * All Rights Reserved
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include "synonyms.h"
-
-/*
- * Compatibility lib for SunOS's wait4().
- */
-
-#include <sys/types.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <wait.h>
-#include <sys/siginfo.h>
-#include <sys/procset.h>
-#include <sys/param.h>
-#include <sys/resource.h>
-#include <string.h>
-#include <errno.h>
-
-/*
- * Since sysV does not support rusage as in BSD, an approximate approach
- * is:
- * ...
- * call times
- * call waitid
- * if ( a child is found )
- * call times again
- * rusage ~= diff in the 2 times call
- * ...
- */
-
-static int wstat(int, int);
-
-pid_t
-wait4(pid_t pid, int *status, int options, struct rusage *rp)
-{
- struct tms before_tms;
- struct tms after_tms;
- siginfo_t info;
- int error;
- int noptions;
- idtype_t idtype;
-
- if (rp)
- (void) memset(rp, 0, sizeof (struct rusage));
- (void) memset(&info, 0, sizeof (siginfo_t));
-
- if (times(&before_tms) == (clock_t)-1)
- return (-1); /* errno is set by times() */
-
- /*
- * SunOS's wait4() previously supported only WNOHANG &
- * WUNTRACED. XPG4v2 mandates that wait3() (which calls
- * wait4()) also support WCONTINUED.
- */
- if (options & ~(WNOHANG|WUNTRACED|WCONTINUED)) {
- errno = EINVAL;
- return (-1);
- }
- noptions = options | WEXITED | WTRAPPED;
-
- /*
- * Emulate undocumented 4.x semantics for 1186845
- */
- if (pid < 0) {
- pid = -pid;
- idtype = P_PGID;
- } else if (pid == 0)
- idtype = P_ALL;
- else
- idtype = P_PID;
-
- error = waitid(idtype, pid, &info, noptions);
- if (error == 0) {
- clock_t diffu; /* difference in usertime (ticks) */
- clock_t diffs; /* difference in systemtime (ticks) */
- clock_t hz;
-
- if ((options & WNOHANG) && (info.si_pid == 0))
- return (0); /* no child found */
-
- if (rp) {
-
- if (times(&after_tms) == (clock_t)-1)
- return (-1); /* errno set by times() */
- /*
- * The system/user time is an approximation only !!!
- */
- diffu = after_tms.tms_cutime - before_tms.tms_cutime;
- diffs = after_tms.tms_cstime - before_tms.tms_cstime;
- hz = CLK_TCK;
- rp->ru_utime.tv_sec = diffu / hz;
- rp->ru_utime.tv_usec = (diffu % hz) * (1000000 / hz);
- rp->ru_stime.tv_sec = diffs / hz;
- rp->ru_stime.tv_usec = (diffs % hz) * (1000000 / hz);
- }
- if (status)
- *status = wstat(info.si_code, info.si_status);
- return (info.si_pid);
- } else {
- return (-1); /* error number is set by waitid() */
- }
-}
-
-/*
- * Convert the status code to old style wait status
- */
-static int
-wstat(int code, int status)
-{
- int stat = (status & 0377);
-
- switch (code) {
- case CLD_EXITED:
- stat <<= 8;
- break;
- case CLD_DUMPED:
- stat |= WCOREFLG;
- break;
- case CLD_KILLED:
- break;
- case CLD_TRAPPED:
- case CLD_STOPPED:
- stat <<= 8;
- stat |= WSTOPFLG;
- break;
- case CLD_CONTINUED:
- stat = WCONTFLG;
- break;
- }
- return (stat);
-}
diff --git a/usr/src/lib/libc/port/gen/waitpid.c b/usr/src/lib/libc/port/gen/waitpid.c
index 993e046097..3a7d66330e 100644
--- a/usr/src/lib/libc/port/gen/waitpid.c
+++ b/usr/src/lib/libc/port/gen/waitpid.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -29,14 +29,55 @@
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
+/*
+ * All of these functions are cancellation points.
+ */
+#pragma weak waitpid = _waitpid
+#pragma weak wait = _wait
+#pragma weak wait4 = _wait4
+#pragma weak wait3 = _wait3
#include "synonyms.h"
-#include <sys/types.h>
#include <unistd.h>
+#include <string.h>
+#include <errno.h>
#include <wait.h>
+#include <sys/types.h>
+#include <sys/siginfo.h>
+#include <sys/times.h>
+#include <sys/resource.h>
+
+/*
+ * Convert the siginfo_t code and status fields to an old style wait status.
+ */
+static int
+wstat(int code, int status)
+{
+ int stat = (status & 0377);
+
+ switch (code) {
+ case CLD_EXITED:
+ stat <<= 8;
+ break;
+ case CLD_DUMPED:
+ stat |= WCOREFLG;
+ break;
+ case CLD_KILLED:
+ break;
+ case CLD_TRAPPED:
+ case CLD_STOPPED:
+ stat <<= 8;
+ stat |= WSTOPFLG;
+ break;
+ case CLD_CONTINUED:
+ stat = WCONTFLG;
+ break;
+ }
+ return (stat);
+}
pid_t
-_waitpid(pid_t pid, int *stat_loc, int options)
+waitpid(pid_t pid, int *stat_loc, int options)
{
idtype_t idtype;
id_t id;
@@ -62,37 +103,91 @@ _waitpid(pid_t pid, int *stat_loc, int options)
if ((error = waitid(idtype, id, &info, options)) < 0)
return (error);
- if (stat_loc) {
-
- int stat = (info.si_status & 0377);
-
- switch (info.si_code) {
- case CLD_EXITED:
- stat <<= 8;
- break;
- case CLD_DUMPED:
- stat |= WCOREFLG;
- break;
- case CLD_KILLED:
- break;
- case CLD_TRAPPED:
- case CLD_STOPPED:
- stat <<= 8;
- stat |= WSTOPFLG;
- break;
- case CLD_CONTINUED:
- stat = WCONTFLG;
- break;
- }
-
- *stat_loc = stat;
- }
+ if (stat_loc)
+ *stat_loc = wstat(info.si_code, info.si_status);
return (info.si_pid);
}
pid_t
-_wait(int *stat_loc)
+wait(int *stat_loc)
{
return (waitpid(-1, stat_loc, 0));
}
+
+pid_t
+wait4(pid_t pid, int *stat_loc, int options, struct rusage *rp)
+{
+ struct tms before_tms;
+ struct tms after_tms;
+ siginfo_t info;
+ int error;
+ int noptions;
+ idtype_t idtype;
+
+ if (rp)
+ (void) memset(rp, 0, sizeof (struct rusage));
+ (void) memset(&info, 0, sizeof (siginfo_t));
+
+ if (times(&before_tms) == (clock_t)-1)
+ return (-1); /* errno is set by times() */
+
+ /*
+ * SunOS's wait4() previously supported only WNOHANG &
+ * WUNTRACED. XPG4v2 mandates that wait3() (which calls
+ * wait4()) also support WCONTINUED.
+ */
+ if (options & ~(WNOHANG|WUNTRACED|WCONTINUED)) {
+ errno = EINVAL;
+ return (-1);
+ }
+ noptions = options | WEXITED | WTRAPPED;
+
+ /*
+ * Emulate undocumented 4.x semantics for 1186845
+ */
+ if (pid < 0) {
+ pid = -pid;
+ idtype = P_PGID;
+ } else if (pid == 0) {
+ idtype = P_ALL;
+ } else {
+ idtype = P_PID;
+ }
+
+ error = waitid(idtype, pid, &info, noptions);
+ if (error == 0) {
+ clock_t diffu; /* difference in usertime (ticks) */
+ clock_t diffs; /* difference in systemtime (ticks) */
+ clock_t hz;
+
+ if ((options & WNOHANG) && info.si_pid == 0)
+ return (0); /* no child found */
+
+ if (rp) {
+ if (times(&after_tms) == (clock_t)-1)
+ return (-1); /* errno set by times() */
+ /*
+ * The system/user time is an approximation only !!!
+ */
+ diffu = after_tms.tms_cutime - before_tms.tms_cutime;
+ diffs = after_tms.tms_cstime - before_tms.tms_cstime;
+ hz = CLK_TCK;
+ rp->ru_utime.tv_sec = diffu / hz;
+ rp->ru_utime.tv_usec = (diffu % hz) * (1000000 / hz);
+ rp->ru_stime.tv_sec = diffs / hz;
+ rp->ru_stime.tv_usec = (diffs % hz) * (1000000 / hz);
+ }
+ if (stat_loc)
+ *stat_loc = wstat(info.si_code, info.si_status);
+ return (info.si_pid);
+ } else {
+ return (-1); /* error number is set by waitid() */
+ }
+}
+
+pid_t
+wait3(int *stat_loc, int options, struct rusage *rp)
+{
+ return (wait4(0, stat_loc, options, rp));
+}
diff --git a/usr/src/lib/libc/port/gen/xpg4.c b/usr/src/lib/libc/port/gen/xpg4.c
index f7140f12f3..2df91f6d38 100644
--- a/usr/src/lib/libc/port/gen/xpg4.c
+++ b/usr/src/lib/libc/port/gen/xpg4.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -34,3 +34,5 @@
*/
int __xpg4 = 0;
+
+int libc__xpg4; /* copy of __xpg4, private to libc */
diff --git a/usr/src/lib/libc/port/gen/xpg6.c b/usr/src/lib/libc/port/gen/xpg6.c
index 333d87ed9e..d00ca8e1ce 100644
--- a/usr/src/lib/libc/port/gen/xpg6.c
+++ b/usr/src/lib/libc/port/gen/xpg6.c
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -19,8 +18,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -50,3 +50,5 @@
#include "xpg6.h"
unsigned int __xpg6 = _C99SUSv3_mode_OFF;
+
+unsigned int libc__xpg6; /* copy of __xpg6, private to libc */