64-bit clean + WARNS=6:
- Convert the (char *) cast+cast backs magic to memcpy(3). Without this, the resulting code is potentially risky with higher optimization levels. - Avoid same name when calling local variables, as well as global symbols. This reduces confusion for both human and compiler. - Add necessary casts, consts - Use new style function defination. - Minor style.Makefile(5) tweak - Bump WARNS?= from 0 to 6 ** for the aout code: changes are intentionally limited to ease maintaince.
This commit is contained in:
@@ -62,14 +62,13 @@
|
|||||||
char **search_dirs;
|
char **search_dirs;
|
||||||
int n_search_dirs;
|
int n_search_dirs;
|
||||||
|
|
||||||
char *standard_search_dirs[] = {
|
const char *standard_search_dirs[] = {
|
||||||
STANDARD_SEARCH_DIRS
|
STANDARD_SEARCH_DIRS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
add_search_dir(name)
|
add_search_dir(const char *name)
|
||||||
char *name;
|
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@@ -269,7 +268,7 @@ search_lib_dir(dir, name, majorp, minorp, do_dot_a)
|
|||||||
int *minorp;
|
int *minorp;
|
||||||
int do_dot_a;
|
int do_dot_a;
|
||||||
{
|
{
|
||||||
int namelen;
|
size_t namelen;
|
||||||
DIR *dd;
|
DIR *dd;
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
int best_dewey[MAXDEWEY];
|
int best_dewey[MAXDEWEY];
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
extern char **search_dirs;
|
extern char **search_dirs;
|
||||||
extern int n_search_dirs;
|
extern int n_search_dirs;
|
||||||
|
|
||||||
void add_search_dir __P((char *));
|
void add_search_dir __P((const char *));
|
||||||
void add_search_path __P((char *));
|
void add_search_path __P((char *));
|
||||||
void std_search_path __P((void));
|
void std_search_path __P((void));
|
||||||
int getdewey __P((int[], char *));
|
int getdewey __P((int[], char *));
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
PROG= ldconfig
|
PROG= ldconfig
|
||||||
SRCS= elfhints.c ldconfig.c shlib.c support.c
|
SRCS= elfhints.c ldconfig.c shlib.c support.c
|
||||||
LDDIR?= ${.CURDIR}/../../libexec/rtld-aout
|
LDDIR?= ${.CURDIR}/../../libexec/rtld-aout
|
||||||
|
WARNS?= 6
|
||||||
CFLAGS+=-I${LDDIR} -DFREEBSD_AOUT
|
CFLAGS+=-I${LDDIR} -DFREEBSD_AOUT
|
||||||
WARNS?= 0
|
|
||||||
MAN= ldconfig.8
|
MAN= ldconfig.8
|
||||||
|
|
||||||
.PATH: ${LDDIR}
|
.PATH: ${LDDIR}
|
||||||
|
|||||||
+26
-21
@@ -74,7 +74,7 @@ static int nostd;
|
|||||||
static int justread;
|
static int justread;
|
||||||
static int merge;
|
static int merge;
|
||||||
static int rescan;
|
static int rescan;
|
||||||
static char *hints_file;
|
static const char *hints_file;
|
||||||
|
|
||||||
struct shlib_list {
|
struct shlib_list {
|
||||||
/* Internal list of shared libraries found */
|
/* Internal list of shared libraries found */
|
||||||
@@ -99,9 +99,7 @@ static int readhints(void);
|
|||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(argc, argv)
|
main(int argc, char **argv)
|
||||||
int argc;
|
|
||||||
char *argv[];
|
|
||||||
{
|
{
|
||||||
int i, c;
|
int i, c;
|
||||||
int rval = 0;
|
int rval = 0;
|
||||||
@@ -380,10 +378,8 @@ int dewey[], ndewey;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
hinthash(cp, vmajor)
|
hinthash(char *cp, int vmajor)
|
||||||
char *cp;
|
|
||||||
int vmajor;
|
|
||||||
{
|
{
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
|
||||||
@@ -406,7 +402,7 @@ buildhints()
|
|||||||
int strtab_sz = 0; /* Total length of strings */
|
int strtab_sz = 0; /* Total length of strings */
|
||||||
int nhints = 0; /* Total number of hints */
|
int nhints = 0; /* Total number of hints */
|
||||||
int fd;
|
int fd;
|
||||||
char *tmpfile;
|
char *_tmpfile;
|
||||||
|
|
||||||
for (shp = shlib_head; shp; shp = shp->next) {
|
for (shp = shlib_head; shp; shp = shp->next) {
|
||||||
strtab_sz += 1 + strlen(shp->name);
|
strtab_sz += 1 + strlen(shp->name);
|
||||||
@@ -447,20 +443,20 @@ buildhints()
|
|||||||
(hinthash(shp->name, shp->major) % hdr.hh_nbucket);
|
(hinthash(shp->name, shp->major) % hdr.hh_nbucket);
|
||||||
|
|
||||||
if (bp->hi_pathx) {
|
if (bp->hi_pathx) {
|
||||||
int i;
|
int j;
|
||||||
|
|
||||||
for (i = 0; i < hdr.hh_nbucket; i++) {
|
for (j = 0; j < hdr.hh_nbucket; j++) {
|
||||||
if (blist[i].hi_pathx == 0)
|
if (blist[j].hi_pathx == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (i == hdr.hh_nbucket) {
|
if (j == hdr.hh_nbucket) {
|
||||||
warnx("bummer!");
|
warnx("bummer!");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (bp->hi_next != -1)
|
while (bp->hi_next != -1)
|
||||||
bp = &blist[bp->hi_next];
|
bp = &blist[bp->hi_next];
|
||||||
bp->hi_next = i;
|
bp->hi_next = j;
|
||||||
bp = blist + i;
|
bp = blist + j;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert strings in string table */
|
/* Insert strings in string table */
|
||||||
@@ -486,10 +482,10 @@ buildhints()
|
|||||||
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
|
errx(1, "str_index(%d) != strtab_sz(%d)", str_index, strtab_sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpfile = concat(hints_file, ".XXXXXXXXXX", "");
|
_tmpfile = concat(hints_file, ".XXXXXXXXXX", "");
|
||||||
umask(0); /* Create with exact permissions */
|
umask(0); /* Create with exact permissions */
|
||||||
if ((fd = mkstemp(tmpfile)) == -1) {
|
if ((fd = mkstemp(_tmpfile)) == -1) {
|
||||||
warn("%s", tmpfile);
|
warn("%s", _tmpfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
fchmod(fd, 0444);
|
fchmod(fd, 0444);
|
||||||
@@ -500,7 +496,7 @@ buildhints()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
|
if (write(fd, blist, hdr.hh_nbucket * sizeof(struct hints_bucket)) !=
|
||||||
hdr.hh_nbucket * sizeof(struct hints_bucket)) {
|
(ssize_t)(hdr.hh_nbucket * sizeof(struct hints_bucket))) {
|
||||||
warn("%s", hints_file);
|
warn("%s", hints_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -519,7 +515,7 @@ buildhints()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rename(tmpfile, hints_file) != 0) {
|
if (rename(_tmpfile, hints_file) != 0) {
|
||||||
warn("%s", hints_file);
|
warn("%s", hints_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -578,7 +574,6 @@ readhints()
|
|||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
blist = (struct hints_bucket *)((char *)addr + hdr->hh_hashtab);
|
|
||||||
strtab = (char *)addr + hdr->hh_strtab;
|
strtab = (char *)addr + hdr->hh_strtab;
|
||||||
|
|
||||||
if (hdr->hh_version >= LD_HINTS_VERSION_2)
|
if (hdr->hh_version >= LD_HINTS_VERSION_2)
|
||||||
@@ -590,16 +585,25 @@ readhints()
|
|||||||
if (rescan)
|
if (rescan)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
blist = malloc(sizeof(struct hints_bucket) * hdr->hh_nbucket);
|
||||||
|
if (blist == NULL)
|
||||||
|
err(1, "readhints");
|
||||||
|
memcpy(blist, (char *)addr + hdr->hh_hashtab,
|
||||||
|
sizeof(struct hints_bucket) * hdr->hh_nbucket);
|
||||||
|
|
||||||
|
|
||||||
for (i = 0; i < hdr->hh_nbucket; i++) {
|
for (i = 0; i < hdr->hh_nbucket; i++) {
|
||||||
struct hints_bucket *bp = &blist[i];
|
struct hints_bucket *bp = &blist[i];
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (bp->hi_namex >= hdr->hh_strtab_sz) {
|
if (bp->hi_namex >= hdr->hh_strtab_sz) {
|
||||||
warnx("bad name index: %#x", bp->hi_namex);
|
warnx("bad name index: %#x", bp->hi_namex);
|
||||||
|
free(blist);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (bp->hi_pathx >= hdr->hh_strtab_sz) {
|
if (bp->hi_pathx >= hdr->hh_strtab_sz) {
|
||||||
warnx("bad path index: %#x", bp->hi_pathx);
|
warnx("bad path index: %#x", bp->hi_pathx);
|
||||||
|
free(blist);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -615,6 +619,7 @@ readhints()
|
|||||||
shlib_tail = &shp->next;
|
shlib_tail = &shp->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(blist);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user