@@ -328,7 +328,7 @@ __open_catalog (const char *cat_name, const char *nlspath, const char *env_var,
/* Release the lock again. */
close_unlock_return:
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
free (buf);
return result;
@@ -386,7 +386,7 @@ write_gmon (void)
/* write basic-block execution counts: */
write_bb_counts (fd);
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
@@ -71,7 +71,7 @@ __gconv_load_cache (void)
|| (size_t) st.st_size < sizeof (struct gconvcache_header))
{
close_and_exit:
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return -1;
}
@@ -108,7 +108,7 @@ __gconv_load_cache (void)
}
/* We don't need the file descriptor anymore. */
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
/* Check the consistency. */
header = (struct gconvcache_header *) gconv_cache;
@@ -446,7 +446,7 @@
because some ISO C functions will require linking with this object
file and the name space must not be polluted. */
# define open(name, flags) __open_nocancel (name, flags)
-# define close(fd) close_not_cancel_no_status (fd)
+# define close(fd) __close_nocancel_no_status (fd)
# define read(fd, buf, n) __read_nocancel (fd, buf, n)
# define mmap(addr, len, prot, flags, fd, offset) \
__mmap (addr, len, prot, flags, fd, offset)
@@ -341,7 +341,7 @@ open_dir_stream (int *dfdp, struct ftw_data *data, struct dir_data *dirp)
O_RDONLY | O_DIRECTORY | O_NDELAY);
dirp->stream = NULL;
if (fd != -1 && (dirp->stream = __fdopendir (fd)) == NULL)
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
else
{
@@ -791,7 +791,7 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors,
{
int save_err = errno;
__fchdir (cwdfd);
- close_not_cancel_no_status (cwdfd);
+ __close_nocancel_no_status (cwdfd);
__set_errno (save_err);
}
else if (cwd != NULL)
@@ -242,7 +242,7 @@ _IO_file_open (_IO_FILE *fp, const char *filename, int posix_mode, int prot,
_IO_off64_t new_pos = _IO_SYSSEEK (fp, 0, _IO_seek_end);
if (new_pos == _IO_pos_BAD && errno != ESPIPE)
{
- close_not_cancel (fdesc);
+ __close_nocancel (fdesc);
return NULL;
}
}
@@ -1231,7 +1231,7 @@ _IO_file_close_mmap (_IO_FILE *fp)
fp->_IO_buf_base = fp->_IO_buf_end = NULL;
/* Cancelling close should be avoided if possible since it leaves an
unrecoverable state behind. */
- return close_not_cancel (fp->_fileno);
+ return __close_nocancel (fp->_fileno);
}
int
@@ -1239,7 +1239,7 @@ _IO_file_close (_IO_FILE *fp)
{
/* Cancelling close should be avoided if possible since it leaves an
unrecoverable state behind. */
- return close_not_cancel (fp->_fileno);
+ return __close_nocancel (fp->_fileno);
}
libc_hidden_def (_IO_file_close)
@@ -76,7 +76,7 @@ extern int _IO_dup2 (int fd, int fd2) __THROW;
#ifndef _IO_close
#ifdef _LIBC
-#define _IO_close close_not_cancel
+#define _IO_close __close_nocancel
#else
#define _IO_close close
#endif
@@ -213,7 +213,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
/* stat failed, very strange. */
close_and_out:
if (fd >= 0)
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return NULL;
}
@@ -253,7 +253,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
{
/* We've mapped the whole file already, so we can be
sure we won't need this file descriptor later. */
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
fd = -1;
}
@@ -452,7 +452,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
/* We don't need the file descriptor any longer. */
if (fd >= 0)
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
fd = -1;
/* We succeeded in mapping all the necessary regions of the archive.
@@ -181,7 +181,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) < 0)
{
puntfd:
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return;
}
if (__glibc_unlikely (S_ISDIR (st.st_mode)))
@@ -191,7 +191,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
char *newp;
size_t filenamelen;
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
filenamelen = strlen (file->filename);
newp = (char *) alloca (filenamelen
@@ -257,7 +257,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
#endif /* _POSIX_MAPPED_FILES */
/* We have mapped the data, so we no longer need the descriptor. */
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (__glibc_unlikely (filedata == NULL))
/* We failed to map or read the data. */
@@ -382,10 +382,10 @@ pututline_file (const struct utmp *data)
if (__lseek64 (new_fd, __lseek64 (file_fd, 0, SEEK_CUR), SEEK_SET) == -1
|| __dup2 (new_fd, file_fd) < 0)
{
- close_not_cancel_no_status (new_fd);
+ __close_nocancel_no_status (new_fd);
return NULL;
}
- close_not_cancel_no_status (new_fd);
+ __close_nocancel_no_status (new_fd);
file_writable = true;
}
@@ -471,7 +471,7 @@ endutent_file (void)
{
assert (file_fd >= 0);
- close_not_cancel_no_status (file_fd);
+ __close_nocancel_no_status (file_fd);
file_fd = -1;
}
@@ -518,7 +518,7 @@ unlock_return:
UNLOCK_FILE (fd);
/* Close WTMP file. */
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return result;
}
@@ -80,12 +80,12 @@ daemon (int nochdir, int noclose)
} else {
/* We must set an errno value since no
function call actually failed. */
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
__set_errno (ENODEV);
return -1;
}
} else {
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return -1;
}
}
@@ -189,7 +189,7 @@ __nscd_getai (const char *key, struct nscd_ai_result **result, int *h_errnop)
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -305,7 +305,7 @@ nscd_getgr_r (const char *key, size_t keylen, request_type type,
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -436,7 +436,7 @@ nscd_gethst_r (const char *key, size_t keylen, request_type type,
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -218,7 +218,7 @@ nscd_getpw_r (const char *key, size_t keylen, request_type type,
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -356,7 +356,7 @@ nscd_getserv_r (const char *crit, size_t critlen, const char *proto,
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -236,7 +236,7 @@ open_socket (request_type type, const char *key, size_t keylen)
}
out:
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
return -1;
}
@@ -555,7 +555,7 @@ __nscd_open_socket (const char *key, size_t keylen, request_type type,
return sock;
}
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
}
__set_errno (saved_errno);
@@ -157,7 +157,7 @@ __nscd_getgrouplist (const char *user, gid_t group, long int *size,
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -139,7 +139,7 @@ __nscd_setnetgrent (const char *group, struct __netgrent *datap)
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -263,7 +263,7 @@ __nscd_innetgr (const char *netgroup, const char *host, const char *user,
out_close:
if (sock != -1)
- close_not_cancel_no_status (sock);
+ __close_nocancel_no_status (sock);
out:
if (__nscd_drop_map_ref (mapped, &gc_cycle) != 0)
{
@@ -52,7 +52,7 @@ internal_setent (const char *file, struct nss_db_map *mapping)
status = NSS_STATUS_TRYAGAIN;
}
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
return status;
@@ -94,7 +94,7 @@ __res_iclose (res_state statp, bool free_addr)
{
if (statp->_vcsock >= 0)
{
- close_not_cancel_no_status (statp->_vcsock);
+ __close_nocancel_no_status (statp->_vcsock);
statp->_vcsock = -1;
statp->_flags &= ~(RES_F_VC | RES_F_CONN);
}
@@ -103,7 +103,7 @@ __res_iclose (res_state statp, bool free_addr)
{
if (statp->_u._ext.nssocks[ns] != -1)
{
- close_not_cancel_no_status (statp->_u._ext.nssocks[ns]);
+ __close_nocancel_no_status (statp->_u._ext.nssocks[ns]);
statp->_u._ext.nssocks[ns] = -1;
}
if (free_addr)
@@ -81,7 +81,7 @@ pmap_getmaps (struct sockaddr_in *address)
}
/* We only need to close the socket here if we opened it. */
if (closeit)
- close_not_cancel (socket);
+ __close_nocancel (socket);
address->sin_port = 0;
return head;
}
@@ -26,9 +26,9 @@
__openat (__VA_ARGS__)
#define __openat64_nocancel(...) \
__openat64 (__VA_ARGS__)
-#define close_not_cancel(fd) \
+#define __close_nocancel(fd) \
__close (fd)
-#define close_not_cancel_no_status(fd) \
+#define __close_nocancel_no_status(fd) \
(void) __close (fd)
#define __read_nocancel(fd, buf, n) \
__read (fd, buf, n)
@@ -49,6 +49,6 @@ __closedir (DIR *dirp)
free ((void *) dirp);
- return close_not_cancel (fd);
+ return __close_nocancel (fd);
}
weak_alias (__closedir, closedir)
@@ -2401,7 +2401,7 @@ getaddrinfo (const char *name, const char *service,
{
if (fd != -1)
close_retry:
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
af = q->ai_family;
fd = __socket (af, SOCK_DGRAM | SOCK_CLOEXEC, IPPROTO_IP);
}
@@ -2504,7 +2504,7 @@ getaddrinfo (const char *name, const char *service,
}
if (fd != -1)
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
/* We got all the source addresses we can get, now sort using
the information. */
@@ -176,7 +176,7 @@ extern char *alloca ();
# include <kernel-features.h>
#else
# define __openat64_nocancel(dfd, name, mode) openat64 (dfd, name, mode)
-# define close_not_cancel_no_status(fd) close (fd)
+# define __close_nocancel_no_status(fd) close (fd)
#endif
#ifndef PATH_MAX
@@ -521,7 +521,7 @@ __getcwd (char *buf, size_t size)
if (dirstream != NULL)
__closedir (dirstream);
if (fd_needs_closing)
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
#ifndef NO_ALLOCATION
if (buf == NULL)
free (path);
@@ -65,7 +65,7 @@ tryopen_o_directory (void)
if (x >= 0)
{
- close_not_cancel_no_status (x);
+ __close_nocancel_no_status (x);
o_directory_works = -1;
}
else if (errno != ENOTDIR)
@@ -129,7 +129,7 @@ opendir_tail (int fd)
{
__set_errno (ENOTDIR);
lose:
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return NULL;
}
@@ -227,7 +227,7 @@ __alloc_dir (int fd, bool close_fd, int flags, const struct stat64 *statp)
if (close_fd)
{
int save_errno = errno;
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
__set_errno (save_errno);
}
return NULL;
@@ -157,7 +157,7 @@ __spawni_child (void *arguments)
switch (action->tag)
{
case spawn_do_close:
- if (close_not_cancel (action->action.close_action.fd) != 0)
+ if (__close_nocancel (action->action.close_action.fd) != 0)
{
if (have_fdlimit == 0)
{
@@ -183,7 +183,7 @@ __spawni_child (void *arguments)
with the process already at maximum number of file descriptor
opened and also for multiple actions on single-open special
paths (like /dev/watchdog). */
- close_not_cancel (action->action.open_action.fd);
+ __close_nocancel (action->action.open_action.fd);
int new_fd = __open_nocancel (action->action.open_action.path,
action->action.open_action.oflag
@@ -200,7 +200,7 @@ __spawni_child (void *arguments)
!= action->action.open_action.fd)
goto fail;
- if ((ret = close_not_cancel (new_fd) != 0))
+ if ((ret = __close_nocancel (new_fd) != 0))
goto fail;
}
}
@@ -167,7 +167,7 @@ __check_native (uint32_t a1_index, int *a1_native,
while (! done);
out:
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return;
@@ -328,7 +328,7 @@ __check_pf (bool *seen_ipv4, bool *seen_ipv6,
&addr_len) == 0)
data = make_request (fd, nladdr.nl_pid);
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
if (data != NULL)
@@ -18,6 +18,7 @@
#include <unistd.h>
#include <sysdep-cancel.h>
+#include <not-cancel.h>
/* Close the file descriptor FD. */
int
@@ -28,3 +29,10 @@ __close (int fd)
libc_hidden_def (__close)
strong_alias (__close, __libc_close)
weak_alias (__close, close)
+
+int
+__close_nocancel (int fd)
+{
+ return INLINE_SYSCALL_CALL (close, fd);
+}
+libc_hidden_def (__close_nocancel)
@@ -50,7 +50,7 @@ fips_enabled_p (void)
char buf[32];
ssize_t n;
n = TEMP_FAILURE_RETRY (__read_nocancel (fd, buf, sizeof (buf) - 1));
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (n > 0)
{
@@ -53,7 +53,7 @@ sethostid (long int id)
written = __write_nocancel (fd, &id32, sizeof (id32));
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return written != sizeof (id32) ? -1 : 0;
}
@@ -82,7 +82,7 @@ gethostid (void)
{
ssize_t n = __read_nocancel (fd, &id, sizeof (id));
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (n == sizeof (id))
return id;
@@ -43,7 +43,7 @@ getloadavg (double loadavg[], int nelem)
int i;
nread = __read_nocancel (fd, buf, sizeof buf - 1);
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (nread <= 0)
return -1;
buf[nread - 1] = '\0';
@@ -43,7 +43,7 @@ __getlogin_r_loginuid (char *name, size_t namesize)
char uidbuf[12];
ssize_t n = TEMP_FAILURE_RETRY (__read_nocancel (fd, uidbuf,
sizeof (uidbuf)));
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
uid_t uid;
char *endp;
@@ -180,7 +180,7 @@ __get_nprocs (void)
}
while (l < re);
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (result > 0)
goto out;
@@ -207,7 +207,7 @@ __get_nprocs (void)
else if (isdigit (l[3]))
++result;
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
else
{
@@ -215,7 +215,7 @@ __get_nprocs (void)
if (fd != -1)
{
GET_NPROCS_PARSER (fd, buffer, cp, re, buffer_end, result);
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
}
@@ -26,7 +26,7 @@ close_all_fds (void)
char *endp;
long int fd = strtol (d->d_name, &endp, 10);
if (*endp == '\0' && fd != PTY_FILENO && fd != dirfd (dir))
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
__closedir (dir);
@@ -47,7 +47,7 @@ is_smp_system (void)
/* This also didn't work. We give up and say it's a UP machine. */
u.buf[0] = '\0';
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
cp = u.buf;
}
@@ -41,7 +41,7 @@ has_cpuclock (void)
|| buf[0] != '0' || buf[1] != '\n')
newval = -1;
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
itc_usable = newval;
@@ -47,12 +47,12 @@ __if_nametoindex (const char *ifname)
if (__ioctl (fd, SIOCGIFINDEX, &ifr) < 0)
{
int saved_errno = errno;
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (saved_errno == EINVAL)
__set_errno (ENOSYS);
return 0;
}
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return ifr.ifr_ifindex;
#endif
}
@@ -224,7 +224,7 @@ __if_indextoname (unsigned int ifindex, char *ifname)
ifr.ifr_ifindex = ifindex;
status = __ioctl (fd, SIOCGIFNAME, &ifr);
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (status < 0)
{
@@ -59,7 +59,7 @@ backtrace_and_maps (int do_abort, bool written, int fd)
while ((n2 = __read_nocancel (fd2, buf, sizeof (buf))) > 0)
if (__write_nocancel (fd, buf, n2) != n2)
break;
- close_not_cancel_no_status (fd2);
+ __close_nocancel_no_status (fd2);
}
}
}
@@ -49,7 +49,7 @@ check_may_shrink_heap (void)
char val;
ssize_t n = __read_nocancel (fd, &val, 1);
may_shrink_heap = n > 0 && val == '2';
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
}
}
@@ -209,7 +209,7 @@ init_mq_netlink (void)
if (err != 0)
{
- close_not_cancel_no_status (netlink_socket);
+ __close_nocancel_no_status (netlink_socket);
netlink_socket = -1;
}
}
@@ -51,13 +51,17 @@ __typeof (__write) __write_nocancel;
libc_hidden_proto (__write_nocancel)
/* Uncancelable close. */
-#define __close_nocancel(fd) \
- INLINE_SYSCALL (close, 1, fd)
-#define close_not_cancel(fd) \
- __close_nocancel (fd)
-#define close_not_cancel_no_status(fd) \
- (void) ({ INTERNAL_SYSCALL_DECL (err); \
- INTERNAL_SYSCALL (close, err, 1, (fd)); })
+__typeof (__close) __close_nocancel;
+libc_hidden_proto (__close_nocancel)
+
+/* Non cancellable close syscall that does not also set errno in case of
+ failure. */
+static inline int
+__close_nocancel_no_status (int fd)
+{
+ INTERNAL_SYSCALL_DECL (err);
+ return INTERNAL_SYSCALL (close, err, 1, (fd));
+}
/* Uncancelable writev. */
#define writev_not_cancel_no_status(fd, iov, n) \
@@ -63,7 +63,7 @@ pthread_getname_np (pthread_t th, char *buf, size_t len)
buf[n] = '\0';
}
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return res;
}
@@ -57,7 +57,7 @@ pthread_setname_np (pthread_t th, const char *name)
else if (n != name_len)
res = EIO;
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
return res;
}
@@ -205,7 +205,7 @@ __spawni_child (void *arguments)
switch (action->tag)
{
case spawn_do_close:
- if (close_not_cancel (action->action.close_action.fd) != 0)
+ if (__close_nocancel (action->action.close_action.fd) != 0)
{
if (!have_fdlimit)
{
@@ -228,7 +228,7 @@ __spawni_child (void *arguments)
with the process already at maximum number of file descriptor
opened and also for multiple actions on single-open special
paths (like /dev/watchdog). */
- close_not_cancel (action->action.open_action.fd);
+ __close_nocancel (action->action.open_action.fd);
int ret = __open_nocancel (action->action.open_action.path,
action->action.
@@ -247,7 +247,7 @@ __spawni_child (void *arguments)
!= action->action.open_action.fd)
goto fail;
- if (close_not_cancel (new_fd) != 0)
+ if (__close_nocancel (new_fd) != 0)
goto fail;
}
}
@@ -122,7 +122,7 @@ __sysconf (int name)
char buf[32];
ssize_t n;
n = TEMP_FAILURE_RETRY (__read_nocancel (fd, buf, sizeof (buf) - 1));
- close_not_cancel_no_status (fd);
+ __close_nocancel_no_status (fd);
if (n > 0)
{