summaryrefslogtreecommitdiffstats
path: root/libc/unistd
diff options
context:
space:
mode:
Diffstat (limited to 'libc/unistd')
-rw-r--r--libc/unistd/gethostname.c4
-rw-r--r--libc/unistd/killpg.c45
-rw-r--r--libc/unistd/ptsname_r.c14
-rw-r--r--libc/unistd/seteuid.c3
-rw-r--r--libc/unistd/setresuid.c35
-rw-r--r--libc/unistd/setreuid.c34
-rw-r--r--libc/unistd/setuid.c34
-rw-r--r--libc/unistd/usleep.c11
8 files changed, 167 insertions, 13 deletions
diff --git a/libc/unistd/gethostname.c b/libc/unistd/gethostname.c
index 369d21e..5d3d7d9 100644
--- a/libc/unistd/gethostname.c
+++ b/libc/unistd/gethostname.c
@@ -41,11 +41,11 @@ int gethostname(char* buff, size_t buflen)
int namelen = strlen(name.nodename);
if ((int)buflen < namelen+1) {
- errno = EINVAL;
+ errno = EINVAL;
result = -1;
} else {
memcpy( buff, name.nodename, namelen+1 );
- }
+ }
}
return result;
}
diff --git a/libc/unistd/killpg.c b/libc/unistd/killpg.c
new file mode 100644
index 0000000..75b1ad9
--- /dev/null
+++ b/libc/unistd/killpg.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ */
+
+#include <sys/types.h>
+#include <signal.h>
+#include <errno.h>
+
+/*
+ * Backwards-compatible killpg().
+ */
+int
+killpg(pid_t pgid, int sig)
+{
+ if (pgid == 1) {
+ errno = ESRCH;
+ return (-1);
+ }
+ return (kill(-pgid, sig));
+}
diff --git a/libc/unistd/ptsname_r.c b/libc/unistd/ptsname_r.c
index 1ed067b..2fa4c3d 100644
--- a/libc/unistd/ptsname_r.c
+++ b/libc/unistd/ptsname_r.c
@@ -32,7 +32,7 @@
#include <errno.h>
#include <string.h>
-char* ptsname_r( int fd, char* buf, size_t buflen)
+int ptsname_r( int fd, char* buf, size_t buflen)
{
unsigned int pty_num;
char buff[64];
@@ -40,17 +40,19 @@ char* ptsname_r( int fd, char* buf, size_t buflen)
if (buf == NULL) {
errno = EINVAL;
- return NULL;
+ return -1;
}
- if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 )
- return NULL;
+ if ( ioctl( fd, TIOCGPTN, &pty_num ) != 0 ) {
+ errno = ENOTTY;
+ return -1;
+ }
len = snprintf( buff, sizeof(buff), "/dev/pts/%u", pty_num );
if (len+1 > (int)buflen) {
errno = ERANGE;
- return NULL;
+ return -1;
}
memcpy( buf, buff, len+1 );
- return buf;
+ return 0;
}
diff --git a/libc/unistd/seteuid.c b/libc/unistd/seteuid.c
index 42ee780..dd94932 100644
--- a/libc/unistd/seteuid.c
+++ b/libc/unistd/seteuid.c
@@ -29,5 +29,6 @@
int seteuid(uid_t euid)
{
- return setresuid(-1, euid,-1);
+ cpuacct_add(euid);
+ return __setresuid(-1, euid,-1);
}
diff --git a/libc/unistd/setresuid.c b/libc/unistd/setresuid.c
new file mode 100644
index 0000000..1964881
--- /dev/null
+++ b/libc/unistd/setresuid.c
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+
+int setresuid(uid_t ruid, uid_t euid, uid_t suid)
+{
+ cpuacct_add(euid);
+ return __setresuid(ruid, euid, suid);
+
+}
diff --git a/libc/unistd/setreuid.c b/libc/unistd/setreuid.c
new file mode 100644
index 0000000..04c2826
--- /dev/null
+++ b/libc/unistd/setreuid.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+
+int setreuid(uid_t ruid, uid_t euid)
+{
+ cpuacct_add(euid);
+ return __setreuid(ruid, euid);
+}
diff --git a/libc/unistd/setuid.c b/libc/unistd/setuid.c
new file mode 100644
index 0000000..8ab637d
--- /dev/null
+++ b/libc/unistd/setuid.c
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT OWNER 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.
+ */
+#include <unistd.h>
+
+int setuid(uid_t uid)
+{
+ cpuacct_add(uid);
+ return __setuid(uid);
+}
diff --git a/libc/unistd/usleep.c b/libc/unistd/usleep.c
index 75458b1..19e8ee8 100644
--- a/libc/unistd/usleep.c
+++ b/libc/unistd/usleep.c
@@ -28,7 +28,7 @@
#include <time.h>
#include <errno.h>
-void usleep(unsigned long usec)
+int usleep(unsigned long usec)
{
struct timespec ts;
@@ -43,10 +43,13 @@ void usleep(unsigned long usec)
for (;;)
{
- if ( nanosleep( &ts, &ts ) >= 0 )
- break;
+ if ( nanosleep( &ts, &ts ) == 0 )
+ return 0;
+ // We try again if the nanosleep failure is EINTR.
+ // The other possible failures are EINVAL (which we should pass through),
+ // and ENOSYS, which doesn't happen.
if ( errno != EINTR )
- break;
+ return -1;
}
}