summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src/md/unix/unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src/md/unix/unix.c')
-rw-r--r--nsprpub/pr/src/md/unix/unix.c963
1 files changed, 466 insertions, 497 deletions
diff --git a/nsprpub/pr/src/md/unix/unix.c b/nsprpub/pr/src/md/unix/unix.c
index 7c90b5075..a8862a4ce 100644
--- a/nsprpub/pr/src/md/unix/unix.c
+++ b/nsprpub/pr/src/md/unix/unix.c
@@ -41,7 +41,7 @@
#if defined(HAVE_SOCKLEN_T) \
|| (defined(__GLIBC__) && __GLIBC__ >= 2)
#define _PRSockLen_t socklen_t
-#elif defined(IRIX) || defined(HPUX) || defined(OSF1) || defined(SOLARIS) \
+#elif defined(HPUX) || defined(SOLARIS) \
|| defined(AIX4_1) || defined(LINUX) \
|| defined(BSDI) || defined(SCO) \
|| defined(DARWIN) \
@@ -49,7 +49,7 @@
#define _PRSockLen_t int
#elif (defined(AIX) && !defined(AIX4_1)) || defined(FREEBSD) \
|| defined(NETBSD) || defined(OPENBSD) || defined(UNIXWARE) \
- || defined(DGUX) || defined(NTO) || defined(RISCOS)
+ || defined(NTO) || defined(RISCOS)
#define _PRSockLen_t size_t
#else
#error "Cannot determine architecture"
@@ -59,7 +59,7 @@
** Global lock variable used to bracket calls into rusty libraries that
** aren't thread safe (like libc, libX, etc).
*/
-static PRLock *_pr_rename_lock = NULL;
+static PRLock *_pr_unix_rename_lock = NULL;
static PRMonitor *_pr_Xfe_mon = NULL;
static PRInt64 minus_one;
@@ -84,10 +84,6 @@ static sigset_t empty_set;
*/
int _nspr_noclock = 1;
-#ifdef IRIX
-extern PRInt32 _nspr_terminate_on_error;
-#endif
-
/*
* There is an assertion in this code that NSPR's definition of PRIOVec
* is bit compatible with UNIX' definition of a struct iovec. This is
@@ -98,13 +94,15 @@ extern PRInt32 _nspr_terminate_on_error;
int _pr_md_pipefd[2] = { -1, -1 };
static char _pr_md_pipebuf[PIPE_BUF];
static PRInt32 local_io_wait(PRInt32 osfd, PRInt32 wait_flag,
- PRIntervalTime timeout);
+ PRIntervalTime timeout);
_PRInterruptTable _pr_interruptTable[] = {
- {
- "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt, },
- {
- 0 }
+ {
+ "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt,
+ },
+ {
+ 0
+ }
};
void _MD_unix_init_running_cpu(_PRCPU *cpu)
@@ -116,7 +114,7 @@ void _MD_unix_init_running_cpu(_PRCPU *cpu)
PRStatus _MD_open_dir(_MDDir *d, const char *name)
{
-int err;
+ int err;
d->d = opendir(name);
if (!d->d) {
@@ -129,13 +127,13 @@ int err;
PRInt32 _MD_close_dir(_MDDir *d)
{
-int rv = 0, err;
+ int rv = 0, err;
if (d->d) {
rv = closedir(d->d);
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSEDIR_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_CLOSEDIR_ERROR(err);
}
}
return rv;
@@ -143,8 +141,8 @@ int rv = 0, err;
char * _MD_read_dir(_MDDir *d, PRIntn flags)
{
-struct dirent *de;
-int err;
+ struct dirent *de;
+ int err;
for (;;) {
/*
@@ -157,16 +155,19 @@ int err;
err = _MD_ERRNO();
_PR_MD_MAP_READDIR_ERROR(err);
return 0;
- }
+ }
if ((flags & PR_SKIP_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == 0))
+ (de->d_name[0] == '.') && (de->d_name[1] == 0)) {
continue;
+ }
if ((flags & PR_SKIP_DOT_DOT) &&
(de->d_name[0] == '.') && (de->d_name[1] == '.') &&
- (de->d_name[2] == 0))
+ (de->d_name[2] == 0)) {
continue;
- if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.'))
+ }
+ if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.')) {
continue;
+ }
break;
}
return de->d_name;
@@ -174,7 +175,7 @@ int err;
PRInt32 _MD_delete(const char *name)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
#ifdef UNIXWARE
sigset_t set, oset;
#endif
@@ -188,8 +189,8 @@ PRInt32 rv, err;
sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_UNLINK_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_UNLINK_ERROR(err);
}
return(rv);
}
@@ -204,10 +205,12 @@ PRInt32 _MD_rename(const char *from, const char *to)
** of an existing file. Holding a lock across these two function
** and the open function is known to be a bad idea, but ....
*/
- if (NULL != _pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- if (0 == access(to, F_OK))
+ if (NULL != _pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
+ if (0 == access(to, F_OK)) {
PR_SetError(PR_FILE_EXISTS_ERROR, 0);
+ }
else
{
rv = rename(from, to);
@@ -216,15 +219,16 @@ PRInt32 _MD_rename(const char *from, const char *to)
_PR_MD_MAP_RENAME_ERROR(err);
}
}
- if (NULL != _pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
+ if (NULL != _pr_unix_rename_lock) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRInt32 _MD_access(const char *name, PRAccessHow how)
{
-PRInt32 rv, err;
-int amode;
+ PRInt32 rv, err;
+ int amode;
switch (how) {
case PR_ACCESS_WRITE_OK:
@@ -254,46 +258,48 @@ done:
PRInt32 _MD_mkdir(const char *name, PRIntn mode)
{
-int rv, err;
+ int rv, err;
/*
** This lock is used to enforce rename semantics as described
** in PR_Rename. Look there for more fun details.
*/
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
rv = mkdir(name, mode);
if (rv < 0) {
err = _MD_ERRNO();
_PR_MD_MAP_MKDIR_ERROR(err);
}
- if (NULL !=_pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRInt32 _MD_rmdir(const char *name)
{
-int rv, err;
+ int rv, err;
rv = rmdir(name);
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RMDIR_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_RMDIR_ERROR(err);
}
return rv;
}
PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount)
{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-PRInt32 rv, err;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRInt32 rv, err;
#ifndef _PR_USE_POLL
-fd_set rd;
+ fd_set rd;
#else
-struct pollfd pfd;
+ struct pollfd pfd;
#endif /* _PR_USE_POLL */
-PRInt32 osfd = fd->secret->md.osfd;
+ PRInt32 osfd = fd->secret->md.osfd;
#ifndef _PR_USE_POLL
FD_ZERO(&rd);
@@ -310,17 +316,18 @@ PRInt32 osfd = fd->secret->md.osfd;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ,
- PR_INTERVAL_NO_TIMEOUT)) < 0)
- goto done;
+ PR_INTERVAL_NO_TIMEOUT)) < 0) {
+ goto done;
+ }
} else {
#ifndef _PR_USE_POLL
while ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, NULL))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_SELECT() if it is interrupted */
}
#else /* _PR_USE_POLL */
while ((rv = _MD_POLL(&pfd, 1, -1))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_POLL() if it is interrupted */
}
#endif /* _PR_USE_POLL */
@@ -328,9 +335,10 @@ PRInt32 osfd = fd->secret->md.osfd;
break;
}
}
- if (_PR_PENDING_INTERRUPT(me))
+ if (_PR_PENDING_INTERRUPT(me)) {
break;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -350,14 +358,14 @@ done:
PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount)
{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-PRInt32 rv, err;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRInt32 rv, err;
#ifndef _PR_USE_POLL
-fd_set wd;
+ fd_set wd;
#else
-struct pollfd pfd;
+ struct pollfd pfd;
#endif /* _PR_USE_POLL */
-PRInt32 osfd = fd->secret->md.osfd;
+ PRInt32 osfd = fd->secret->md.osfd;
#ifndef _PR_USE_POLL
FD_ZERO(&wd);
@@ -374,17 +382,18 @@ PRInt32 osfd = fd->secret->md.osfd;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE,
- PR_INTERVAL_NO_TIMEOUT)) < 0)
+ PR_INTERVAL_NO_TIMEOUT)) < 0) {
goto done;
+ }
} else {
#ifndef _PR_USE_POLL
while ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, NULL))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_SELECT() if it is interrupted */
}
#else /* _PR_USE_POLL */
while ((rv = _MD_POLL(&pfd, 1, -1))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_POLL() if it is interrupted */
}
#endif /* _PR_USE_POLL */
@@ -392,9 +401,10 @@ PRInt32 osfd = fd->secret->md.osfd;
break;
}
}
- if (_PR_PENDING_INTERRUPT(me))
+ if (_PR_PENDING_INTERRUPT(me)) {
break;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -414,7 +424,7 @@ done:
PRInt32 _MD_fsync(PRFileDesc *fd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = fsync(fd->secret->md.osfd);
if (rv == -1) {
@@ -426,7 +436,7 @@ PRInt32 rv, err;
PRInt32 _MD_close(PRInt32 osfd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = close(osfd);
if (rv == -1) {
@@ -484,7 +494,7 @@ PRInt64 _MD_socketavailable64(PRFileDesc *fd)
#ifndef _PR_USE_POLL
static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv = -1;
struct timeval tv;
@@ -508,10 +518,12 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
FD_ZERO(&rd_wr);
do {
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
_PR_MD_MAP_SELECT_ERROR(syserror);
break;
@@ -543,14 +555,16 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
/*
* we don't consider EINTR a real error
*/
@@ -579,7 +593,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
now += remaining;
} else {
now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
} else {
now = PR_IntervalNow();
@@ -602,7 +616,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
#else /* _PR_USE_POLL */
static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv = -1;
int msecs;
@@ -634,11 +648,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
_PR_MD_MAP_POLL_ERROR(syserror);
break;
}
- /*
- * If POLLERR is set, don't process it; retry the operation
- */
+ /*
+ * If POLLERR is set, don't process it; retry the operation
+ */
if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) {
- rv = -1;
+ rv = -1;
_PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents);
break;
}
@@ -686,11 +700,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
rv = -1;
break;
}
- /*
- * If POLLERR is set, don't process it; retry the operation
- */
+ /*
+ * If POLLERR is set, don't process it; retry the operation
+ */
if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) {
- rv = -1;
+ rv = -1;
_PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents);
break;
}
@@ -739,11 +753,13 @@ static PRInt32 local_io_wait(
PRInt32 rv;
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("waiting to %s on osfd=%d",
- (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write",
- osfd));
+ ("waiting to %s on osfd=%d",
+ (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write",
+ osfd));
- if (timeout == PR_INTERVAL_NO_WAIT) return 0;
+ if (timeout == PR_INTERVAL_NO_WAIT) {
+ return 0;
+ }
pd.osfd = osfd;
pd.in_flags = wait_flag;
@@ -760,17 +776,17 @@ static PRInt32 local_io_wait(
PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
-/*
- * Many OS's (Solaris, Unixware) have a broken recv which won't read
- * from socketpairs. As long as we don't use flags on socketpairs, this
- * is a decent fix. - mikep
- */
+ /*
+ * Many OS's (Solaris, Unixware) have a broken recv which won't read
+ * from socketpairs. As long as we don't use flags on socketpairs, this
+ * is a decent fix. - mikep
+ */
#if defined(UNIXWARE) || defined(SOLARIS)
while ((rv = read(osfd,buf,amount)) == -1) {
#else
@@ -782,13 +798,15 @@ PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -802,29 +820,31 @@ done:
}
PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout)
+ PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
+ PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((*addrlen = PR_NETADDR_SIZE(addr)),
- ((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) {
+ ((rv = recvfrom(osfd, buf, amount, flags,
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) {
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
if (fd->secret->nonblocking) {
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) {
goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -846,13 +866,13 @@ done:
}
PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
#if defined(SOLARIS)
- PRInt32 tmp_amount = amount;
+ PRInt32 tmp_amount = amount;
#endif
/*
@@ -872,48 +892,50 @@ PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
#if defined(SOLARIS)
- /*
- * The write system call has been reported to return the ERANGE
- * error on occasion. Try to write in smaller chunks to workaround
- * this bug.
- */
- if (err == ERANGE) {
- if (tmp_amount > 1) {
- tmp_amount = tmp_amount/2; /* half the bytes */
- continue;
- }
- }
+ /*
+ * The write system call has been reported to return the ERANGE
+ * error on occasion. Try to write in smaller chunks to workaround
+ * this bug.
+ */
+ if (err == ERANGE) {
+ if (tmp_amount > 1) {
+ tmp_amount = tmp_amount/2; /* half the bytes */
+ continue;
+ }
+ }
#endif
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next send() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next send() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (_PR_IS_NATIVE_THREAD(me)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) {
- rv = -1;
- goto done;
- }
+ if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) {
+ rv = -1;
+ goto done;
+ }
} else {
- if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
- rv = -1;
- goto done;
- }
+ if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
+ rv = -1;
+ goto done;
+ }
}
}
if (rv < 0) {
@@ -938,10 +960,10 @@ PRInt32 _MD_sendto(
((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) &addrCopy, addrlen)) == -1) {
+ (struct sockaddr *) &addrCopy, addrlen)) == -1) {
#else
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1) {
+ (struct sockaddr *) addr, addrlen)) == -1) {
#endif
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
@@ -949,13 +971,15 @@ PRInt32 _MD_sendto(
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -997,13 +1021,15 @@ PRInt32 _MD_writev(
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -1015,17 +1041,17 @@ PRInt32 _MD_writev(
* the next writev() call will return EWOULDBLOCK.
*/
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (_PR_IS_NATIVE_THREAD(me)) {
if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
+ rv = -1;
goto done;
- }
+ }
} else {
- if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
- rv = -1;
- goto done;
- }
+ if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
+ rv = -1;
+ goto done;
+ }
}
}
if (rv < 0) {
@@ -1036,27 +1062,29 @@ done:
}
PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen, PRIntervalTime timeout)
+ PRUint32 *addrlen, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((rv = accept(osfd, (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1) {
+ (_PRSockLen_t *)addrlen)) == -1) {
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK) || (err == ECONNABORTED)) {
if (fd->secret->nonblocking) {
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -1084,10 +1112,6 @@ PRInt32 _MD_connect(
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
PRInt32 osfd = fd->secret->md.osfd;
-#ifdef IRIX
-extern PRInt32 _MD_irix_connect(
- PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout);
-#endif
#ifdef _PR_HAVE_SOCKADDR_LEN
PRNetAddr addrCopy;
@@ -1109,15 +1133,11 @@ extern PRInt32 _MD_irix_connect(
*/
retry:
-#ifdef IRIX
- if ((rv = _MD_irix_connect(osfd, addr, addrlen, timeout)) == -1) {
-#else
#ifdef _PR_HAVE_SOCKADDR_LEN
if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1) {
#else
if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1) {
#endif
-#endif
err = _MD_ERRNO();
if (err == EINTR) {
@@ -1132,8 +1152,9 @@ retry:
if (!fd->secret->nonblocking && (err == EINPROGRESS)) {
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
return -1;
+ }
} else {
/*
* socket_io_wait() may return -1 or 1.
@@ -1210,7 +1231,7 @@ PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how)
}
PRInt32 _MD_socketpair(int af, int type, int flags,
- PRInt32 *osfd)
+ PRInt32 *osfd)
{
PRInt32 rv, err;
@@ -1223,12 +1244,12 @@ PRInt32 _MD_socketpair(int af, int type, int flags,
}
PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen)
+ PRUint32 *addrlen)
{
PRInt32 rv, err;
rv = getsockname(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
#ifdef _PR_HAVE_SOCKADDR_LEN
if (rv == 0) {
/* ignore the sa_len field of struct sockaddr */
@@ -1245,12 +1266,12 @@ PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
}
PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen)
+ PRUint32 *addrlen)
{
PRInt32 rv, err;
rv = getpeername(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
#ifdef _PR_HAVE_SOCKADDR_LEN
if (rv == 0) {
/* ignore the sa_len field of struct sockaddr */
@@ -1279,8 +1300,8 @@ PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
return rv==0?PR_SUCCESS:PR_FAILURE;
}
-PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen)
+PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
+ PRInt32 optname, const char* optval, PRInt32 optlen)
{
PRInt32 rv, err;
@@ -1354,7 +1375,7 @@ static void FindBadFDs(void)
if (fcntl(osfd, F_GETFL, 0) == -1) {
/* Found a bad descriptor, remove it from the fd_sets. */
PR_LOG(_pr_io_lm, PR_LOG_MAX,
- ("file descriptor %d is bad", osfd));
+ ("file descriptor %d is bad", osfd));
pds->out_flags = _PR_UNIX_POLL_NVAL;
notify = PR_TRUE;
}
@@ -1369,26 +1390,29 @@ static void FindBadFDs(void)
pq->on_ioq = PR_FALSE;
/*
- * Decrement the count of descriptors for each desciptor/event
- * because this I/O request is being removed from the
- * ioq
- */
+ * Decrement the count of descriptors for each desciptor/event
+ * because this I/O request is being removed from the
+ * ioq
+ */
pds = pq->pds;
for (; pds < epds; pds++) {
PRInt32 osfd = pds->osfd;
PRInt16 in_flags = pds->in_flags;
PR_ASSERT(osfd >= 0 || in_flags == 0);
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
@@ -1399,36 +1423,39 @@ static void FindBadFDs(void)
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ }
}
_PR_THREAD_UNLOCK(pq->thr);
} else {
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
+ }
}
}
#endif /* !defined(_PR_USE_POLL) */
@@ -1466,9 +1493,6 @@ void _MD_PauseCPU(PRIntervalTime ticks)
PRCList *q;
PRUint32 min_timeout;
sigset_t oldset;
-#ifdef IRIX
-extern sigset_t ints_off;
-#endif
PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
@@ -1487,24 +1511,15 @@ extern sigset_t ints_off;
*/
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
npollfds++;
-#ifdef IRIX
- /*
- * On Irix, a second pipe is used to cause the primordial cpu to
- * wakeup and exit, when the process is exiting because of a call
- * to exit/PR_ProcessExit.
- */
- if (me->cpu->id == 0) {
- npollfds++;
- }
-#endif
- }
+ }
/*
* if the cpu's pollfd array is not big enough, release it and allocate a new one
*/
if (npollfds > _PR_IOQ_POLLFDS_SIZE(me->cpu)) {
- if (_PR_IOQ_POLLFDS(me->cpu) != NULL)
+ if (_PR_IOQ_POLLFDS(me->cpu) != NULL) {
PR_DELETE(_PR_IOQ_POLLFDS(me->cpu));
+ }
pollfds_size = PR_MAX(_PR_IOQ_MIN_POLLFDS_SIZE(me->cpu), npollfds);
pollfds = (struct pollfd *) PR_MALLOC(pollfds_size * sizeof(struct pollfd));
_PR_IOQ_POLLFDS(me->cpu) = pollfds;
@@ -1522,16 +1537,6 @@ extern sigset_t ints_off;
pollfdPtr->fd = _pr_md_pipefd[0];
pollfdPtr->events = POLLIN;
pollfdPtr++;
-#ifdef IRIX
- /*
- * On Irix, the second element is the exit pipe
- */
- if (me->cpu->id == 0) {
- pollfdPtr->fd = _pr_irix_primoridal_cpu_fd[0];
- pollfdPtr->events = POLLIN;
- pollfdPtr++;
- }
-#endif
}
min_timeout = PR_INTERVAL_NO_TIMEOUT;
@@ -1545,9 +1550,9 @@ extern sigset_t ints_off;
}
for (; pds < epds; pds++, pollfdPtr++) {
/*
- * Assert that the pollfdPtr pointer does not go
- * beyond the end of the pollfds array
- */
+ * Assert that the pollfdPtr pointer does not go
+ * beyond the end of the pollfds array
+ */
PR_ASSERT(pollfdPtr < pollfds + npollfds);
pollfdPtr->fd = pds->osfd;
/* direct copy of poll flags */
@@ -1589,17 +1594,19 @@ extern sigset_t ints_off;
}
#ifdef _PR_USE_POLL
- if (min_timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (min_timeout == PR_INTERVAL_NO_TIMEOUT) {
timeout = -1;
- else
+ }
+ else {
timeout = PR_IntervalToMilliseconds(min_timeout);
+ }
#else
if (min_timeout == PR_INTERVAL_NO_TIMEOUT) {
tvp = NULL;
} else {
timeout.tv_sec = PR_IntervalToSeconds(min_timeout);
timeout.tv_usec = PR_IntervalToMicroseconds(min_timeout)
- % PR_USEC_PER_SEC;
+ % PR_USEC_PER_SEC;
tvp = &timeout;
}
#endif /* _PR_USE_POLL */
@@ -1615,22 +1622,10 @@ extern sigset_t ints_off;
* are enabled. Otherwise, when the select/poll calls are interrupted, the
* timer value starts ticking from zero again when the system call is restarted.
*/
-#ifdef IRIX
- /*
- * SIGCHLD signal is used on Irix to detect he termination of an
- * sproc by SIGSEGV, SIGBUS or SIGABRT signals when
- * _nspr_terminate_on_error is set.
- */
- if ((!_nspr_noclock) || (_nspr_terminate_on_error))
-#else
- if (!_nspr_noclock)
-#endif /* IRIX */
-#ifdef IRIX
- sigprocmask(SIG_BLOCK, &ints_off, &oldset);
-#else
- PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ if (!_nspr_noclock) {
+ PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ }
sigprocmask(SIG_BLOCK, &timer_set, &oldset);
-#endif /* IRIX */
#endif /* !_PR_NO_CLOCK_TIMER */
#ifndef _PR_USE_POLL
@@ -1641,19 +1636,14 @@ extern sigset_t ints_off;
#endif /* !_PR_USE_POLL */
#ifndef _PR_NO_CLOCK_TIMER
-#ifdef IRIX
- if ((!_nspr_noclock) || (_nspr_terminate_on_error))
-#else
- if (!_nspr_noclock)
-#endif /* IRIX */
- sigprocmask(SIG_SETMASK, &oldset, 0);
+ if (!_nspr_noclock) {
+ sigprocmask(SIG_SETMASK, &oldset, 0);
+ }
#endif /* !_PR_NO_CLOCK_TIMER */
_MD_CHECK_FOR_EXIT();
-#ifdef IRIX
- _PR_MD_primordial_cpu();
-#endif
+ _PR_MD_primordial_cpu();
_PR_MD_IOQ_LOCK();
/*
@@ -1664,45 +1654,21 @@ extern sigset_t ints_off;
pollfdPtr = pollfds;
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
/*
- * Assert that the pipe is the first element in the
- * pollfds array.
- */
+ * Assert that the pipe is the first element in the
+ * pollfds array.
+ */
PR_ASSERT(pollfds[0].fd == _pr_md_pipefd[0]);
if ((pollfds[0].revents & POLLIN) && (nfd == 1)) {
/*
- * woken up by another thread; read all the data
- * in the pipe to empty the pipe
- */
+ * woken up by another thread; read all the data
+ * in the pipe to empty the pipe
+ */
while ((rv = read(_pr_md_pipefd[0], _pr_md_pipebuf,
- PIPE_BUF)) == PIPE_BUF){
+ PIPE_BUF)) == PIPE_BUF) {
}
PR_ASSERT((rv > 0) || ((rv == -1) && (errno == EAGAIN)));
}
pollfdPtr++;
-#ifdef IRIX
- /*
- * On Irix, check to see if the primordial cpu needs to exit
- * to cause the process to terminate
- */
- if (me->cpu->id == 0) {
- PR_ASSERT(pollfds[1].fd == _pr_irix_primoridal_cpu_fd[0]);
- if (pollfdPtr->revents & POLLIN) {
- if (_pr_irix_process_exit) {
- /*
- * process exit due to a call to PR_ProcessExit
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(_pr_irix_process_exit_code);
- } else {
- while ((rv = read(_pr_irix_primoridal_cpu_fd[0],
- _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) {
- }
- PR_ASSERT(rv > 0);
- }
- }
- pollfdPtr++;
- }
-#endif
}
for (q = _PR_IOQ(me->cpu).next; q != &_PR_IOQ(me->cpu); q = q->next) {
PRPollQueue *pq = _PR_POLLQUEUE_PTR(q);
@@ -1744,26 +1710,27 @@ extern sigset_t ints_off;
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- if (_pr_md_idle_cpus > 1)
- _PR_MD_WAKEUP_WAITER(thred);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ if (_pr_md_idle_cpus > 1) {
+ _PR_MD_WAKEUP_WAITER(thred);
+ }
+ }
}
_PR_THREAD_UNLOCK(thred);
_PR_IOQ_OSFD_CNT(me->cpu) -= pq->npds;
@@ -1827,16 +1794,19 @@ extern sigset_t ints_off;
PRInt16 in_flags = pds->in_flags;
PR_ASSERT(osfd >= 0 || in_flags == 0);
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
@@ -1845,7 +1815,7 @@ extern sigset_t ints_off;
* after being added to the run queue, do not dereference
* pq
*/
- thred = pq->thr;
+ thred = pq->thr;
_PR_THREAD_LOCK(thred);
if (pq->thr->flags & (_PR_ON_PAUSEQ|_PR_ON_SLEEPQ)) {
_PRCPU *cpu = thred->cpu;
@@ -1853,79 +1823,62 @@ extern sigset_t ints_off;
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- pq->thr->cpu = cpu;
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- if (_pr_md_idle_cpus > 1)
- _PR_MD_WAKEUP_WAITER(thred);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ pq->thr->cpu = cpu;
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ if (_pr_md_idle_cpus > 1) {
+ _PR_MD_WAKEUP_WAITER(thred);
+ }
+ }
}
_PR_THREAD_UNLOCK(thred);
} else {
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
if ((FD_ISSET(_pr_md_pipefd[0], rp)) && (nfd == 1)) {
/*
- * woken up by another thread; read all the data
- * in the pipe to empty the pipe
- */
+ * woken up by another thread; read all the data
+ * in the pipe to empty the pipe
+ */
while ((rv =
- read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
- == PIPE_BUF){
+ read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
+ == PIPE_BUF) {
}
PR_ASSERT((rv > 0) ||
- ((rv == -1) && (errno == EAGAIN)));
+ ((rv == -1) && (errno == EAGAIN)));
}
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
-#ifdef IRIX
- if ((me->cpu->id == 0) &&
- (FD_ISSET(_pr_irix_primoridal_cpu_fd[0], rp))) {
- if (_pr_irix_process_exit) {
- /*
- * process exit due to a call to PR_ProcessExit
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(_pr_irix_process_exit_code);
- } else {
- while ((rv = read(_pr_irix_primoridal_cpu_fd[0],
- _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) {
- }
- PR_ASSERT(rv > 0);
- }
- }
- if (me->cpu->id == 0) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_irix_primoridal_cpu_fd[0])
- _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0];
- }
-#endif
+ }
}
} else if (nfd < 0) {
if (errno == EBADF) {
FindBadFDs();
} else {
PR_LOG(_pr_io_lm, PR_LOG_MAX, ("select() failed with errno %d",
- errno));
+ errno));
}
} else {
PR_ASSERT(nfd == 0);
@@ -1947,14 +1900,17 @@ extern sigset_t ints_off;
pq_max_osfd = pds->osfd;
}
}
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
+ }
}
}
#endif /* _PR_USE_POLL */
@@ -1973,11 +1929,11 @@ void _MD_Wakeup_CPUs()
* pipe full, read all data in pipe to empty it
*/
while ((rv =
- read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
- == PIPE_BUF) {
+ read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
+ == PIPE_BUF) {
}
PR_ASSERT((rv > 0) ||
- ((rv == -1) && (errno == EAGAIN)));
+ ((rv == -1) && (errno == EAGAIN)));
rv = write(_pr_md_pipefd[1], &data, 1);
}
}
@@ -2041,10 +1997,10 @@ static void ClockInterruptHandler()
}
#else /* _PR_NO_PREEMPT */
/*
- ** Re-enable unix interrupts (so that we can use
- ** setjmp/longjmp for context switching without having to
- ** worry about the signal state)
- */
+ ** Re-enable unix interrupts (so that we can use
+ ** setjmp/longjmp for context switching without having to
+ ** worry about the signal state)
+ */
sigprocmask(SIG_SETMASK, &empty_set, 0);
PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock caused context switch"));
@@ -2056,8 +2012,9 @@ static void ClockInterruptHandler()
_PR_ADD_RUNQ(me, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
_PR_THREAD_UNLOCK(me);
- } else
+ } else {
me->state = _PR_RUNNABLE;
+ }
_MD_SWITCH_CONTEXT(me);
PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock back from context switch"));
#endif /* _PR_NO_PREEMPT */
@@ -2096,10 +2053,12 @@ void _MD_StartInterrupts()
char *eval;
if ((eval = getenv("NSPR_NOCLOCK")) != NULL) {
- if (atoi(eval) == 0)
+ if (atoi(eval) == 0) {
_nspr_noclock = 0;
- else
+ }
+ else {
_nspr_noclock = 1;
+ }
}
#ifndef _PR_NO_CLOCK_TIMER
@@ -2135,10 +2094,10 @@ void _MD_EnableClockInterrupts()
#endif /* HPUX9 */
PR_ASSERT(_pr_numCPU == 1);
- itval.it_interval.tv_sec = 0;
- itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC;
- itval.it_value = itval.it_interval;
- setitimer(ITIMER_REAL, &itval, 0);
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC;
+ itval.it_value = itval.it_interval;
+ setitimer(ITIMER_REAL, &itval, 0);
}
void _MD_DisableClockInterrupts()
@@ -2147,10 +2106,10 @@ void _MD_DisableClockInterrupts()
extern PRUintn _pr_numCPU;
PR_ASSERT(_pr_numCPU == 1);
- itval.it_interval.tv_sec = 0;
- itval.it_interval.tv_usec = 0;
- itval.it_value = itval.it_interval;
- setitimer(ITIMER_REAL, &itval, 0);
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = 0;
+ itval.it_value = itval.it_interval;
+ setitimer(ITIMER_REAL, &itval, 0);
}
void _MD_BlockClockInterrupts()
@@ -2181,7 +2140,7 @@ void _MD_MakeNonblock(PRFileDesc *fd)
*/
fcntl(osfd, F_SETFL, flags | O_NONBLOCK);
- }
+}
PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
{
@@ -2196,12 +2155,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
osflags = O_RDONLY;
}
- if (flags & PR_EXCL)
+ if (flags & PR_EXCL) {
osflags |= O_EXCL;
- if (flags & PR_APPEND)
+ }
+ if (flags & PR_APPEND) {
osflags |= O_APPEND;
- if (flags & PR_TRUNCATE)
+ }
+ if (flags & PR_TRUNCATE) {
osflags |= O_TRUNC;
+ }
if (flags & PR_SYNC) {
#if defined(O_SYNC)
osflags |= O_SYNC;
@@ -2219,8 +2181,9 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
if (flags & PR_CREATE_FILE)
{
osflags |= O_CREAT;
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
}
#if defined(ANDROID)
@@ -2234,14 +2197,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
_PR_MD_MAP_OPEN_ERROR(err);
}
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock))
- PR_Unlock(_pr_rename_lock);
+ if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock)) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRIntervalTime intr_timeout_ticks;
-#if defined(SOLARIS) || defined(IRIX)
+#if defined(SOLARIS)
static void sigsegvhandler() {
fprintf(stderr,"Received SIGSEGV\n");
fflush(stderr);
@@ -2259,7 +2223,7 @@ static void sigbushandler() {
fflush(stderr);
pause();
}
-#endif /* SOLARIS, IRIX */
+#endif /* SOLARIS */
#endif /* !defined(_PR_PTHREADS) */
@@ -2271,7 +2235,7 @@ void _MD_query_fd_inheritable(PRFileDesc *fd)
flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
PR_ASSERT(-1 != flags);
fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_FALSE : _PR_TRI_TRUE;
+ _PR_TRI_FALSE : _PR_TRI_TRUE;
}
PROffset32 _MD_lseek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
@@ -2537,12 +2501,15 @@ static int _MD_convert_stat_to_fileinfo(
const struct stat *sb,
PRFileInfo *info)
{
- if (S_IFREG & sb->st_mode)
+ if (S_IFREG & sb->st_mode) {
info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb->st_mode)
+ }
+ else if (S_IFDIR & sb->st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
#if defined(_PR_HAVE_LARGE_OFF_T)
if (0x7fffffffL < sb->st_size)
@@ -2561,12 +2528,15 @@ static int _MD_convert_stat64_to_fileinfo64(
const _MDStat64 *sb,
PRFileInfo64 *info)
{
- if (S_IFREG & sb->st_mode)
+ if (S_IFREG & sb->st_mode) {
info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb->st_mode)
+ }
+ else if (S_IFDIR & sb->st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
LL_I2L(info->size, sb->st_size);
@@ -2580,10 +2550,12 @@ PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info)
struct stat sb;
rv = stat(fn, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_STAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat_to_fileinfo(&sb, info);
+ }
return rv;
}
@@ -2591,10 +2563,12 @@ PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info)
{
_MDStat64 sb;
PRInt32 rv = _md_iovector._stat64(fn, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_STAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat64_to_fileinfo64(&sb, info);
+ }
return rv;
}
@@ -2602,10 +2576,12 @@ PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info)
{
struct stat sb;
PRInt32 rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat_to_fileinfo(&sb, info);
+ }
return rv;
}
@@ -2613,10 +2589,12 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)
{
_MDStat64 sb;
PRInt32 rv = _md_iovector._fstat64(fd->secret->md.osfd, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat64_to_fileinfo64(&sb, info);
+ }
return rv;
}
@@ -2626,11 +2604,7 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)
* initialized by _PR_MD_FINAL_INIT. This means the log file cannot be a
* large file on some platforms.
*/
-#ifdef SYMBIAN
-struct _MD_IOVector _md_iovector; /* Will crash if NSPR_LOG_FILE is set. */
-#else
struct _MD_IOVector _md_iovector = { open };
-#endif
/*
** These implementations are to emulate large file routines on systems that
@@ -2700,7 +2674,9 @@ static PROffset64 _MD_Unix_lseek64(PRIntn osfd, PROffset64 offset, PRIntn whence
LL_L2I(off, offset);
LL_I2L(rv, lseek(osfd, off, whence));
}
- else errno = EFBIG; /* we can't go there */
+ else {
+ errno = EFBIG; /* we can't go there */
+ }
return rv;
} /* _MD_Unix_lseek64 */
@@ -2735,28 +2711,6 @@ mmap64(void *addr, size_t len, int prot, int flags, int fd, loff_t offset)
}
#endif
-#if defined(OSF1) && defined(__GNUC__)
-
-/*
- * On OSF1 V5.0A, <sys/stat.h> defines stat and fstat as
- * macros when compiled under gcc, so it is rather tricky to
- * take the addresses of the real functions the macros expend
- * to. A simple solution is to define forwarder functions
- * and take the addresses of the forwarder functions instead.
- */
-
-static int stat_forwarder(const char *path, struct stat *buffer)
-{
- return stat(path, buffer);
-}
-
-static int fstat_forwarder(int filedes, struct stat *buffer)
-{
- return fstat(filedes, buffer);
-}
-
-#endif
-
static void _PR_InitIOV(void)
{
#if defined(SOLARIS2_5)
@@ -2789,7 +2743,7 @@ static void _PR_InitIOV(void)
_md_iovector._stat64 = stat;
_md_iovector._lseek64 = _MD_Unix_lseek64;
#elif defined(_PR_HAVE_OFF64_T)
-#if defined(IRIX5_3) || (defined(ANDROID) && __ANDROID_API__ < 21)
+#if (defined(ANDROID) && __ANDROID_API__ < 21)
/*
* Android < 21 doesn't have open64. We pass the O_LARGEFILE flag to open
* in _MD_open.
@@ -2811,13 +2765,8 @@ static void _PR_InitIOV(void)
#elif defined(_PR_HAVE_LARGE_OFF_T)
_md_iovector._open64 = open;
_md_iovector._mmap64 = mmap;
-#if defined(OSF1) && defined(__GNUC__)
- _md_iovector._fstat64 = fstat_forwarder;
- _md_iovector._stat64 = stat_forwarder;
-#else
_md_iovector._fstat64 = fstat;
_md_iovector._stat64 = stat;
-#endif
_md_iovector._lseek64 = lseek;
#else
#error "I don't know yet"
@@ -2837,9 +2786,9 @@ void _PR_UnixInit(void)
sigaddset(&timer_set, SIGALRM);
sigemptyset(&empty_set);
intr_timeout_ticks =
- PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS);
+ PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS);
-#if defined(SOLARIS) || defined(IRIX)
+#if defined(SOLARIS)
if (getenv("NSPR_SIGSEGV_HANDLE")) {
sigact.sa_handler = sigsegvhandler;
@@ -2871,8 +2820,8 @@ void _PR_UnixInit(void)
rv = sigaction(SIGPIPE, &sigact, 0);
PR_ASSERT(0 == rv);
- _pr_rename_lock = PR_NewLock();
- PR_ASSERT(NULL != _pr_rename_lock);
+ _pr_unix_rename_lock = PR_NewLock();
+ PR_ASSERT(NULL != _pr_unix_rename_lock);
_pr_Xfe_mon = PR_NewMonitor();
PR_ASSERT(NULL != _pr_Xfe_mon);
@@ -2881,9 +2830,9 @@ void _PR_UnixInit(void)
void _PR_UnixCleanup(void)
{
- if (_pr_rename_lock) {
- PR_DestroyLock(_pr_rename_lock);
- _pr_rename_lock = NULL;
+ if (_pr_unix_rename_lock) {
+ PR_DestroyLock(_pr_unix_rename_lock);
+ _pr_unix_rename_lock = NULL;
}
if (_pr_Xfe_mon) {
PR_DestroyMonitor(_pr_Xfe_mon);
@@ -2917,7 +2866,7 @@ void _MD_InitSegs(void)
return;
}
#endif
- _pr_zero_fd = open("/dev/zero",O_RDWR , 0);
+ _pr_zero_fd = open("/dev/zero",O_RDWR, 0);
/* Prevent the fd from being inherited by child processes */
fcntl(_pr_zero_fd, F_SETFD, FD_CLOEXEC);
_pr_md_lock = PR_NewLock();
@@ -2956,8 +2905,8 @@ from_heap:
prot |= PROT_EXEC;
#endif
rv = mmap((vaddr != 0) ? vaddr : lastaddr, size, prot,
- _MD_MMAP_FLAGS,
- _pr_zero_fd, 0);
+ _MD_MMAP_FLAGS,
+ _pr_zero_fd, 0);
if (rv == (void*)-1) {
goto from_heap;
}
@@ -2973,10 +2922,12 @@ exit:
void _MD_FreeSegment(PRSegment *seg)
{
- if (seg->flags & _PR_SEG_VM)
+ if (seg->flags & _PR_SEG_VM) {
(void) munmap(seg->vaddr, seg->size);
- else
+ }
+ else {
PR_DELETE(seg->vaddr);
+ }
}
#endif /* _PR_PTHREADS */
@@ -3123,7 +3074,7 @@ PRInt32 _PR_WaitForMultipleFDs(
}
_PR_IOQ_OSFD_CNT(me->cpu) += pdcnt;
-
+
_PR_SLEEPQ_LOCK(me->cpu);
_PR_ADD_SLEEPQ(me, timeout);
me->state = _PR_IO_WAIT;
@@ -3139,7 +3090,7 @@ PRInt32 _PR_WaitForMultipleFDs(
me->io_suspended = PR_FALSE;
/*
- * This thread should run on the same cpu on which it was blocked; when
+ * This thread should run on the same cpu on which it was blocked; when
* the IO request times out the fd sets and fd counts for the
* cpu are updated below.
*/
@@ -3163,16 +3114,19 @@ PRInt32 _PR_WaitForMultipleFDs(
PRInt16 in_flags = unixpd->in_flags;
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
#endif /* _PR_USE_POLL */
@@ -3220,12 +3174,12 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
{
int pri = thr->priority;
_PRCPU *cpu = thr->cpu;
-
+
/*
* GLOBAL threads wakeup periodically to check for interrupt
*/
if (_PR_IS_NATIVE_THREAD(thr)) {
- _PR_THREAD_UNLOCK(thr);
+ _PR_THREAD_UNLOCK(thr);
return;
}
@@ -3267,7 +3221,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
if (strcmp(superblock.f_basetype, "ttcpip") == 0) {
/* Using the Tiny Stack! */
rv = getpeername(osfd, (struct sockaddr *) &addr,
- (_PRSockLen_t *) &addrlen);
+ (_PRSockLen_t *) &addrlen);
if (rv == -1) {
int errno_copy = errno; /* make a copy so I don't
* accidentally reset */
@@ -3306,7 +3260,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
_PRSockLen_t optlen = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &optlen) == -1) {
+ (char *) &err, &optlen) == -1) {
return errno;
} else {
return err;
@@ -3325,16 +3279,16 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
rv = getmsg(osfd, NULL, NULL, &flags);
PR_ASSERT(-1 == rv || 0 == rv);
if (-1 == rv && errno != EAGAIN && errno != EWOULDBLOCK) {
- return errno;
+ return errno;
}
return 0; /* no error */
#else
- int err;
- _PRSockLen_t optlen = sizeof(err);
- if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) {
- return errno;
- }
- return err;
+ int err;
+ _PRSockLen_t optlen = sizeof(err);
+ if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) {
+ return errno;
+ }
+ return err;
#endif
}
@@ -3390,8 +3344,9 @@ _MD_LockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLKW, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3407,8 +3362,9 @@ _MD_TLockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLK, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3424,8 +3380,9 @@ _MD_UnlockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLK, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3439,8 +3396,9 @@ _MD_LockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_EX);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3450,8 +3408,9 @@ _MD_TLockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_EX|LOCK_NB);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3461,8 +3420,9 @@ _MD_UnlockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_UN);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3473,8 +3433,9 @@ _MD_LockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_LOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3484,8 +3445,9 @@ _MD_TLockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_TLOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3495,8 +3457,9 @@ _MD_UnlockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_ULOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3516,20 +3479,23 @@ PRStatus _MD_gethostname(char *name, PRUint32 namelen)
PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen)
{
- struct utsname info;
+ struct utsname info;
- PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
+ PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
- if (uname(&info) == -1) {
- _PR_MD_MAP_DEFAULT_ERROR(errno);
- return PR_FAILURE;
- }
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, info.sysname);
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, info.release);
- else
- return PR_FAILURE;
+ if (uname(&info) == -1) {
+ _PR_MD_MAP_DEFAULT_ERROR(errno);
+ return PR_FAILURE;
+ }
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, info.sysname);
+ }
+ else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, info.release);
+ }
+ else {
+ return PR_FAILURE;
+ }
return PR_SUCCESS;
}
@@ -3569,12 +3535,15 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
}
if (fmap->prot == PR_PROT_READONLY) {
fmap->md.prot = PROT_READ;
-#ifdef OSF1V4_MAP_PRIVATE_BUG
+#if defined(DARWIN) || defined(ANDROID)
/*
- * Use MAP_SHARED to work around a bug in OSF1 V4.0D
- * (QAR 70220 in the OSF_QAR database) that results in
- * corrupted data in the memory-mapped region. This
- * bug is fixed in V5.0.
+ * This is needed on OS X because its implementation of
+ * POSIX shared memory returns an error for MAP_PRIVATE, even
+ * when the mapping is read-only.
+ *
+ * And this is needed on Android, because mapping ashmem with
+ * MAP_PRIVATE creates a mapping of zeroed memory instead of
+ * the shm contents.
*/
fmap->md.flags = MAP_SHARED;
#else
@@ -3601,8 +3570,8 @@ void * _MD_MemMap(
LL_L2I(off, offset);
if ((addr = mmap(0, len, fmap->md.prot, fmap->md.flags,
- fmap->fd->secret->md.osfd, off)) == (void *) -1) {
- _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());
+ fmap->fd->secret->md.osfd, off)) == (void *) -1) {
+ _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());
addr = NULL;
}
return addr;
@@ -3623,7 +3592,7 @@ PRStatus _MD_CloseFileMap(PRFileMap *fmap)
PRStatus rc = PR_Close( fmap->fd );
if ( PR_FAILURE == rc ) {
PR_LOG( _pr_io_lm, PR_LOG_DEBUG,
- ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));
+ ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));
return PR_FAILURE;
}
}