mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-23 05:20:06 +00:00
linux: use __fd_to_filename helper function instead of snprintf.
Change made to fchmodat and fexecve. There are tests using xasprintf instead of this helper as well, but this commit doesn't touch them.
This commit is contained in:
parent
19d83270fc
commit
77c1573dbc
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <fd_to_filename.h>
|
||||||
#include <not-cancel.h>
|
#include <not-cancel.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -69,16 +70,8 @@ fchmodat (int fd, const char *file, mode_t mode, int flag)
|
|||||||
|
|
||||||
/* For most file systems, fchmod does not operate on O_PATH
|
/* For most file systems, fchmod does not operate on O_PATH
|
||||||
descriptors, so go through /proc. */
|
descriptors, so go through /proc. */
|
||||||
char buf[32];
|
struct fd_to_filename filename;
|
||||||
if (__snprintf (buf, sizeof (buf), "/proc/self/fd/%d", pathfd) < 0)
|
int ret = __chmod (__fd_to_filename (pathfd, &filename), mode);
|
||||||
{
|
|
||||||
/* This also may report strange error codes to the caller
|
|
||||||
(although snprintf really should not fail). */
|
|
||||||
__close_nocancel (pathfd);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = __chmod (buf, mode);
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <fd_to_filename.h>
|
||||||
#include <sysdep.h>
|
#include <sysdep.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <kernel-features.h>
|
#include <kernel-features.h>
|
||||||
@ -49,12 +50,9 @@ fexecve (int fd, char *const argv[], char *const envp[])
|
|||||||
|
|
||||||
#ifndef __ASSUME_EXECVEAT
|
#ifndef __ASSUME_EXECVEAT
|
||||||
/* We use the /proc filesystem to get the information. If it is not
|
/* We use the /proc filesystem to get the information. If it is not
|
||||||
mounted we fail. */
|
mounted we fail. We do not need the return value. */
|
||||||
char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3];
|
struct fd_to_filename filename;
|
||||||
__snprintf (buf, sizeof (buf), "/proc/self/fd/%d", fd);
|
__execve (__fd_to_filename (fd, &filename), argv, envp);
|
||||||
|
|
||||||
/* We do not need the return value. */
|
|
||||||
__execve (buf, argv, envp);
|
|
||||||
|
|
||||||
int save = errno;
|
int save = errno;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user