[git commit nptl] not-cancel: use *_not_cancel variants directly
Austin Foxley
austinf at cetoncorp.com
Mon Sep 21 16:16:52 UTC 2009
commit: http://git.uclibc.org/uClibc/commit/?id=e2784760e51ec0de62bbee61d27a85147460ece0
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/nptl
add a no threads version of not-cancel.h to fallback on
Signed-off-by: Austin Foxley <austinf at cetoncorp.com>
---
Rules.mak | 1 +
libc/inet/hostid.c | 18 --------------
libc/inet/if_index.c | 34 ---------------------------
libc/misc/dirent/closedir.c | 6 -----
libc/misc/dirent/opendir.c | 14 -----------
libc/misc/utmp/utent.c | 27 ----------------------
libc/misc/utmp/wtent.c | 14 -----------
libc/stdio/tmpfile.c | 7 -----
libc/sysdeps/linux/common/not-cancel.h | 19 +++++++++++++++
libc/unistd/daemon.c | 39 +++++++++++++------------------
librt/Makefile.in | 2 +-
11 files changed, 37 insertions(+), 144 deletions(-)
create mode 100644 libc/sysdeps/linux/common/not-cancel.h
diff --git a/Rules.mak b/Rules.mak
index 9eeef3f..fe40c3e 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -654,6 +654,7 @@ else
PTNAME :=
PTINC :=
endif
+CFLAGS += -I$(top_srcdir)libc/sysdeps/linux/common
CFLAGS += -I$(KERNEL_HEADERS)
#CFLAGS += -iwithprefix include-fixed -iwithprefix include
diff --git a/libc/inet/hostid.c b/libc/inet/hostid.c
index caacef8..86be796 100644
--- a/libc/inet/hostid.c
+++ b/libc/inet/hostid.c
@@ -14,9 +14,7 @@
#include <netdb.h>
#include <fcntl.h>
#include <unistd.h>
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <not-cancel.h>
-#endif
#define HOSTID "/etc/hostid"
@@ -28,17 +26,10 @@ int sethostid(long int new_id)
int ret;
if (geteuid() || getuid()) return __set_errno(EPERM);
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
if ((fd=open_not_cancel(HOSTID,O_CREAT|O_WRONLY,0644))<0) return -1;
ret = write_not_cancel(fd,(void *)&new_id,sizeof(new_id)) ==
sizeof(new_id) ? 0 : -1;
close_not_cancel_no_status (fd);
-#else
- if ((fd=open(HOSTID,O_CREAT|O_WRONLY,0644))<0) return -1;
- ret = write(fd,(void *)&new_id,sizeof(new_id)) == sizeof(new_id)
- ? 0 : -1;
- close (fd);
-#endif
return ret;
}
#endif
@@ -52,7 +43,6 @@ long int gethostid(void)
* It is not an error if we cannot read this file. It is not even an
* error if we cannot read all the bytes, we just carry on trying...
*/
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
if ((fd =open_not_cancel_2 (HOSTID, O_RDONLY)) >= 0 &&
read_not_cancel (fd, (void *) &id, sizeof (id)))
{
@@ -60,14 +50,6 @@ long int gethostid(void)
return id;
}
if (fd >= 0) close_not_cancel_no_status (fd);
-#else
- if ((fd=open(HOSTID,O_RDONLY))>=0 && read(fd,(void *)&id,sizeof(id)))
- {
- close (fd);
- return id;
- }
- if (fd >= 0) close (fd);
-#endif
/* Try some methods of returning a unique 32 bit id. Clearly IP
* numbers, if on the internet, will have a unique address. If they
diff --git a/libc/inet/if_index.c b/libc/inet/if_index.c
index b76d011..c249ad9 100644
--- a/libc/inet/if_index.c
+++ b/libc/inet/if_index.c
@@ -32,9 +32,7 @@
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <libc-internal.h>
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <not-cancel.h>
-#endif
#include "netlinkaccess.h"
@@ -58,21 +56,13 @@ if_nametoindex(const char* ifname)
{
/* close never fails here, fd is just a unconnected socket
*int saved_errno = errno; */
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(fd);
-#else
- close(fd);
-#endif
/*if (saved_errno == EINVAL)
* __set_errno(ENOSYS); */
return 0;
}
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(fd);
-#else
- close(fd);
-#endif
return ifr.ifr_ifindex;
#endif
}
@@ -123,11 +113,7 @@ if_nameindex (void)
if (ioctl (fd, SIOCGIFCONF, &ifc) < 0)
{
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status (fd);
-#else
- close (fd);
-#endif
return NULL;
}
}
@@ -138,11 +124,7 @@ if_nameindex (void)
idx = malloc ((nifs + 1) * sizeof (struct if_nameindex));
if (idx == NULL)
{
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status (fd);
-#else
- close(fd);
-#endif
__set_errno(ENOBUFS);
return NULL;
}
@@ -160,11 +142,7 @@ if_nameindex (void)
for (j = 0; j < i; ++j)
free (idx[j].if_name);
free(idx);
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status (fd);
-#else
- close(fd);
-#endif
if (saved_errno == EINVAL)
saved_errno = ENOSYS;
else if (saved_errno == ENOMEM)
@@ -178,11 +156,7 @@ if_nameindex (void)
idx[i].if_index = 0;
idx[i].if_name = NULL;
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status (fd);
-#else
- close(fd);
-#endif
return idx;
#endif
}
@@ -325,22 +299,14 @@ if_indextoname (unsigned int ifindex, char *ifname)
if (ioctl (fd, SIOCGIFNAME, &ifr) < 0)
{
int serrno = errno;
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status (fd);
-#else
- close (fd);
-#endif
if (serrno == ENODEV)
/* POSIX requires ENXIO. */
serrno = ENXIO;
__set_errno (serrno);
return NULL;
}
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status (fd);
-#else
- close (fd);
-#endif
return strncpy (ifname, ifr.ifr_name, IFNAMSIZ);
# else
diff --git a/libc/misc/dirent/closedir.c b/libc/misc/dirent/closedir.c
index a7d980f..dfb53f8 100644
--- a/libc/misc/dirent/closedir.c
+++ b/libc/misc/dirent/closedir.c
@@ -9,9 +9,7 @@
#include <stdlib.h>
#include <unistd.h>
#include "dirstream.h"
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <not-cancel.h>
-#endif
int closedir(DIR * dir)
@@ -34,10 +32,6 @@ int closedir(DIR * dir)
__UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
free(dir->dd_buf);
free(dir);
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
return close_not_cancel(fd);
-#else
- return close(fd);
-#endif
}
libc_hidden_def(closedir)
diff --git a/libc/misc/dirent/opendir.c b/libc/misc/dirent/opendir.c
index a2cfd51..c2e008a 100644
--- a/libc/misc/dirent/opendir.c
+++ b/libc/misc/dirent/opendir.c
@@ -12,9 +12,7 @@
#include <unistd.h>
#include <sys/dir.h>
#include <sys/stat.h>
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <not-cancel.h>
-#endif
#include <dirent.h>
#include "dirstream.h"
@@ -89,11 +87,7 @@ DIR *opendir(const char *name)
# define O_CLOEXEC 0
#endif
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
fd = open_not_cancel_2(name, O_RDONLY|O_NDELAY|O_DIRECTORY|O_CLOEXEC);
-#else
- fd = open(name, O_RDONLY|O_NDELAY|O_DIRECTORY|O_CLOEXEC);
-#endif
if (fd < 0)
return NULL;
/* Note: we should check to make sure that between the stat() and open()
@@ -105,11 +99,7 @@ DIR *opendir(const char *name)
/* this close() never fails
*int saved_errno;
*saved_errno = errno; */
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(fd);
-#else
- close(fd);
-#endif
/*__set_errno(saved_errno);*/
return NULL;
}
@@ -123,11 +113,7 @@ DIR *opendir(const char *name)
ptr = fd_to_DIR(fd, statbuf.st_blksize);
if (!ptr) {
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(fd);
-#else
- close(fd);
-#endif
__set_errno(ENOMEM);
}
return ptr;
diff --git a/libc/misc/utmp/utent.c b/libc/misc/utmp/utent.c
index 0176bbf..edada17 100644
--- a/libc/misc/utmp/utent.c
+++ b/libc/misc/utmp/utent.c
@@ -19,10 +19,7 @@
#include <errno.h>
#include <string.h>
#include <utmp.h>
-
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <not-cancel.h>
-#endif
#include <bits/uClibc_mutex.h>
__UCLIBC_MUTEX_STATIC(utmplock, PTHREAD_MUTEX_INITIALIZER);
@@ -42,17 +39,9 @@ static void __setutent(void)
# define O_CLOEXEC 0
#endif
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC);
-#else
- static_fd = open(static_ut_name, O_RDWR | O_CLOEXEC);
-#endif
if (static_fd < 0) {
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
static_fd = open_not_cancel_2(static_ut_name, O_RDONLY | O_CLOEXEC);
-#else
- static_fd = open(static_ut_name, O_RDONLY | O_CLOEXEC);
-#endif
if (static_fd < 0) {
return; /* static_fd remains < 0 */
}
@@ -60,11 +49,7 @@ static void __setutent(void)
if (O_CLOEXEC == 0) {
/* Make sure the file will be closed on exec() */
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
fcntl_not_cancel(static_fd, F_SETFD, FD_CLOEXEC);
-#else
- fcntl(static_fd, F_SETFD, FD_CLOEXEC);
-#endif
/* thus far, {G,S}ETFD only has this single flag,
* and setting it never fails.
*int ret = fcntl(static_fd, F_GETFD, 0);
@@ -101,11 +86,7 @@ static struct utmp *__getutent(void)
}
}
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
if (read_not_cancel(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) {
-#else
- if (read(static_fd, &static_utmp, sizeof(static_utmp)) == sizeof(static_utmp)) {
-#endif
ret = &static_utmp;
}
@@ -116,11 +97,7 @@ void endutent(void)
{
__UCLIBC_MUTEX_LOCK(utmplock);
if (static_fd >= 0)
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(static_fd);
-#else
- close(static_fd);
-#endif
static_fd = -1;
__UCLIBC_MUTEX_UNLOCK(utmplock);
}
@@ -221,11 +198,7 @@ int utmpname(const char *new_ut_name)
}
if (static_fd >= 0) {
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel_no_status(static_fd);
-#else
- close(static_fd);
-#endif
static_fd = -1;
}
__UCLIBC_MUTEX_UNLOCK(utmplock);
diff --git a/libc/misc/utmp/wtent.c b/libc/misc/utmp/wtent.c
index 9b27637..5ab743d 100644
--- a/libc/misc/utmp/wtent.c
+++ b/libc/misc/utmp/wtent.c
@@ -13,10 +13,7 @@
#include <utmp.h>
#include <fcntl.h>
#include <sys/file.h>
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-#include <errno.h>
#include <not-cancel.h>
-#endif
#if 0
/* This is enabled in uClibc/libutil/logwtmp.c */
@@ -40,7 +37,6 @@ void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
{
int fd;
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
fd = open_not_cancel(wtmp_file, O_APPEND | O_WRONLY, 0);
if (fd >= 0) {
if (lockf(fd, F_LOCK, 0) == 0) {
@@ -49,14 +45,4 @@ void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
close_not_cancel_no_status(fd);
}
}
-#else
- fd = open(wtmp_file, O_APPEND | O_WRONLY);
- if (fd >= 0) {
- if (lockf(fd, F_LOCK, 0) == 0) {
- write(fd, lutmp, sizeof(*lutmp));
- lockf(fd, F_ULOCK, 0);
- close(fd);
- }
- }
-#endif
}
diff --git a/libc/stdio/tmpfile.c b/libc/stdio/tmpfile.c
index f11595a..57f2527 100644
--- a/libc/stdio/tmpfile.c
+++ b/libc/stdio/tmpfile.c
@@ -20,10 +20,7 @@
#include <stdio.h>
#include <unistd.h>
#include "../misc/internals/tempname.h"
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
-#include <errno.h>
#include <not-cancel.h>
-#endif
/* This returns a new stream opened on a temporary file (generated
@@ -47,11 +44,7 @@ FILE * tmpfile (void)
(void) remove (buf);
if ((f = fdopen (fd, "w+b")) == NULL)
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
close_not_cancel (fd);
-#else
- close (fd);
-#endif
return f;
}
diff --git a/libc/sysdeps/linux/common/not-cancel.h b/libc/sysdeps/linux/common/not-cancel.h
new file mode 100644
index 0000000..ebdc607
--- /dev/null
+++ b/libc/sysdeps/linux/common/not-cancel.h
@@ -0,0 +1,19 @@
+/* By default we have none. Map the name to the normal functions. */
+#define open_not_cancel(name, flags, mode) \
+ open (name, flags, mode)
+#define open_not_cancel_2(name, flags) \
+ open (name, flags)
+#define close_not_cancel(fd) \
+ close (fd)
+#define close_not_cancel_no_status(fd) \
+ (void) close (fd)
+#define read_not_cancel(fd, buf, n) \
+ read (fd, buf, n)
+#define write_not_cancel(fd, buf, n) \
+ write (fd, buf, n)
+#define writev_not_cancel_no_status(fd, iov, n) \
+ (void) writev (fd, iov, n)
+#define fcntl_not_cancel(fd, cmd, val) \
+ fcntl (fd, cmd, val)
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ waitpid (pid, stat_loc, options)
diff --git a/libc/unistd/daemon.c b/libc/unistd/daemon.c
index c270603..c3b5631 100644
--- a/libc/unistd/daemon.c
+++ b/libc/unistd/daemon.c
@@ -46,10 +46,19 @@
#include <paths.h>
#include <signal.h>
#include <unistd.h>
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
+#include <not-cancel.h>
#include <errno.h>
+
+#ifdef __UCLIBC_HAS_THREADS_NATIVE__
#include <sys/stat.h>
-#include <not-cancel.h>
+#endif
+
+#ifdef __UCLIBC_HAS_LFS__
+#define STAT stat64
+#define FSTAT fstat64
+#else
+#define STAT stat
+#define FSTAT fstat
#endif
#if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
@@ -112,35 +121,20 @@ int daemon(int nochdir, int noclose)
if (!nochdir)
chdir("/");
-#ifndef __UCLIBC_HAS_THREADS_NATIVE__
- if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR)) != -1)
- {
-#else
if (!noclose)
{
-#ifdef __UCLIBC_HAS_LFS__
- struct stat64 st;
-#else
- struct stat st;
-#endif
+ struct STAT st;
if ((fd = open_not_cancel(_PATH_DEVNULL, O_RDWR, 0)) != -1
-#ifdef __UCLIBC_HAS_LFS__
- && (__builtin_expect (fstat64 (fd, &st), 0) == 0))
-#else
- && (__builtin_expect (fstat (fd, &st), 0) == 0))
-#endif
+ && (__builtin_expect (FSTAT (fd, &st), 0) == 0))
{
if (__builtin_expect (S_ISCHR (st.st_mode), 1) != 0) {
-#endif
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if (fd > 2)
close(fd);
-#ifdef __UCLIBC_HAS_THREADS_NATIVE__
- }
- else {
+ } else {
/* We must set an errno value since no
function call actually failed. */
close_not_cancel_no_status (fd);
@@ -148,10 +142,9 @@ int daemon(int nochdir, int noclose)
return -1;
}
} else {
- close_not_cancel_no_status (fd);
- return -1;
+ close_not_cancel_no_status (fd);
+ return -1;
}
-#endif
}
return 0;
}
diff --git a/librt/Makefile.in b/librt/Makefile.in
index 1596d3a..ea1d03e 100644
--- a/librt/Makefile.in
+++ b/librt/Makefile.in
@@ -30,7 +30,7 @@ librt_CSRC := $(filter-out mq_notify.c timer_create.c timer_delete.c \
$(notdir $(wildcard $(librt_DIR)/*.c)))
librt_SSRC := $(wildcard $(librt_DIR)/*.S)
librt_OBJ := $(patsubst %.c,$(librt_OUT)/%.o,$(librt_CSRC))
-librt_OBJ += $(patsubst %.S,$(librt_OUT)/%.o,$(librt_SSRC))
+librt_OBJ += $(patsubst $(librt_DIR)/%.S,$(librt_OUT)/%.o,$(librt_SSRC))
else
librt_SRC := $(filter-out clock_nanosleep.c clock_getcpuclockid.c clock_gettime.c, \
$(notdir $(wildcard $(librt_DIR)/*.c)))
--
1.6.3.3
More information about the uClibc-cvs
mailing list