Two small ld.so and ldconfig cleanups
Diff below contains two small cleanups for ld.so and ldconfig:
1. Introduce a _dl_dirdesc struct for ld.so to use for its
_dl_{open,read,close}dir functions instead of reusing libc's
_dirdesc. (I have a followup diff for libc to change DIR into
an opaque type and change dirfd(3) from a macro into a function.)
2. Switch ldconfig to use futimens() instead of futimes().
ok?
Index: dir.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/libexec/ld.so/dir.c,v
retrieving revision 1.15
diff -u -p -r1.15 dir.c
--- dir.c 14 Jul 2011 02:16:00 -0000 1.15
+++ dir.c 22 Jul 2011 18:52:29 -0000
@@ -43,16 +43,22 @@
#include "util.h"
#include "dir.h"
-long _dl_telldir(const DIR *dirp);
-void _dl_seekdir(DIR *dirp, long loc);
+struct _dl_dirdesc {
+ int dd_fd; /* file descriptor associated with directory */
+ long dd_loc; /* offset in current buffer */
+ long dd_size; /* amount of data returned by getdirentries */
+ char *dd_buf; /* data buffer */
+ int dd_len; /* size of data buffer */
+ off_t dd_seek; /* magic cookie returned by getdirentries */
+};
/*
* Open a directory.
*/
-DIR *
+_dl_DIR *
_dl_opendir(const char *name)
{
- DIR *dirp;
+ _dl_DIR *dirp;
int fd;
struct stat sb;
@@ -63,7 +69,7 @@ _dl_opendir(const char *name)
return (NULL);
}
if (_dl_fcntl(fd, F_SETFD, FD_CLOEXEC) < 0 ||
- (dirp = (DIR *)_dl_malloc(sizeof(DIR))) == NULL) {
+ (dirp = _dl_malloc(sizeof(*dirp))) == NULL) {
_dl_close(fd);
return (NULL);
}
@@ -87,7 +93,7 @@ _dl_opendir(const char *name)
* close a directory.
*/
int
-_dl_closedir(DIR *dirp)
+_dl_closedir(_dl_DIR *dirp)
{
int fd;
int ret;
@@ -106,7 +112,7 @@ _dl_closedir(DIR *dirp)
* get next entry in a directory.
*/
struct dirent *
-_dl_readdir(DIR *dirp)
+_dl_readdir(_dl_DIR *dirp)
{
struct dirent *dp;
Index: dir.h
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/libexec/ld.so/dir.h,v
retrieving revision 1.2
diff -u -p -r1.2 dir.h
--- dir.h 2 Jun 2003 19:38:24 -0000 1.2
+++ dir.h 22 Jul 2011 18:37:08 -0000
@@ -29,6 +29,8 @@
* SUCH DAMAGE.
*/
-DIR *_dl_opendir(const char *name);
-int _dl_closedir(DIR *dirp);
-struct dirent *_dl_readdir(DIR *dirp);
+typedef struct _dl_dirdesc _dl_DIR;
+
+_dl_DIR *_dl_opendir(const char *name);
+int _dl_closedir(_dl_DIR *dirp);
+struct dirent *_dl_readdir(_dl_DIR *dirp);
Index: library_subr.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/libexec/ld.so/library_subr.c,v
retrieving revision 1.35
diff -u -p -r1.35 library_subr.c
--- library_subr.c 28 Nov 2011 20:59:03 -0000 1.35
+++ library_subr.c 28 Feb 2012 02:22:11 -0000
@@ -131,7 +131,7 @@ _dl_find_shlib(struct sod *sodp, const c
struct dirent *dp;
const char *pp;
int match, len;
- DIR *dd;
+ _dl_DIR *dd;
struct sod tsod, bsod; /* transient and best sod */
/* if we are to search default directories, and hints
Index: ldconfig/prebind.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/libexec/ld.so/ldconfig/prebind.c,v
retrieving revision 1.14
diff -u -p -r1.14 prebind.c
--- ldconfig/prebind.c 28 Nov 2011 20:59:03 -0000 1.14
+++ ldconfig/prebind.c 28 Feb 2012 02:22:11 -0000
@@ -1925,7 +1925,7 @@ int
prebind_writenewfile(int infd, char *name, struct stat *st, off_t orig_size,
struct prebind_info *info)
{
- struct timeval tv[2];
+ struct timespec ts[2];
char *newname, *buf;
ssize_t len, wlen;
int outfd;
@@ -1979,9 +1979,9 @@ prebind_writenewfile(int infd, char *nam
prebind_writefile(outfd, info);
/* move new file into place */
- TIMESPEC_TO_TIMEVAL(&tv[0], &st->st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tv[1], &st->st_mtimespec);
- if (futimes(outfd, tv) == -1)
+ ts[0] = st->st_atimespec;
+ ts[1] = st->st_mtimespec;
+ if (futimens(outfd, ts) == -1)
goto fail;
if (fchown(outfd, st->st_uid, st->st_gid) == -1)
goto fail;
Index: ldconfig/prebind_delete.c
===================================================================
RCS file: /home/mdempsky/anoncvs/cvs/src/libexec/ld.so/ldconfig/prebind_delete.c,v
retrieving revision 1.10
diff -u -p -r1.10 prebind_delete.c
--- ldconfig/prebind_delete.c 30 Mar 2010 17:42:50 -0000 1.10
+++ ldconfig/prebind_delete.c 26 Jul 2011 21:22:19 -0000
@@ -216,7 +216,7 @@ done:
int
prebind_newfile(int infd, char *name, struct stat *st, off_t orig_size)
{
- struct timeval tv[2];
+ struct timespec ts[2];
char *newname, *buf;
ssize_t len, wlen;
int outfd;
@@ -269,9 +269,9 @@ prebind_newfile(int infd, char *name, st
goto fail;
/* move new file into place */
- TIMESPEC_TO_TIMEVAL(&tv[0], &st->st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tv[1], &st->st_mtimespec);
- if (futimes(outfd, tv) == -1)
+ ts[0] = st->st_atimespec;
+ ts[1] = st->st_mtimespec;
+ if (futimens(outfd, ts) == -1)
goto fail;
if (fchown(outfd, st->st_uid, st->st_gid) == -1)
goto fail;