|
@@ -26,20 +26,7 @@
|
|
|
* 2005/09/16: Dan Howell (modified for cross-development)
|
|
|
*/
|
|
|
|
|
|
-#include <stdio.h>
|
|
|
-#include <stdlib.h>
|
|
|
-#include <stdarg.h>
|
|
|
-#include <string.h>
|
|
|
-#include <ctype.h>
|
|
|
-#include <dirent.h>
|
|
|
-#include <unistd.h>
|
|
|
-#include <link.h>
|
|
|
-#include <fcntl.h>
|
|
|
-#include <errno.h>
|
|
|
-#include <sys/stat.h>
|
|
|
-#include <sys/mman.h>
|
|
|
-#include "bswap.h"
|
|
|
-#include "dl-defs.h"
|
|
|
+#include "porting.h"
|
|
|
|
|
|
#define BUFFER_SIZE 4096
|
|
|
|
|
@@ -72,20 +59,6 @@ struct exec {
|
|
|
|
|
|
char *___strtok = NULL;
|
|
|
|
|
|
-
|
|
|
-#ifndef PATH_MAX
|
|
|
-#include <limits.h>
|
|
|
-#define PATH_MAX _POSIX_PATH_MAX
|
|
|
-#endif
|
|
|
-
|
|
|
-
|
|
|
-#ifndef N_MAGIC
|
|
|
-#define N_MAGIC(exec) ((exec).a_magic & 0xffff)
|
|
|
-#endif
|
|
|
-
|
|
|
-#define EXIT_OK 0
|
|
|
-#define EXIT_FATAL 128
|
|
|
-
|
|
|
char *prog = NULL;
|
|
|
int debug = 0;
|
|
|
int verbose = 0;
|
|
@@ -177,7 +150,7 @@ static void *xmalloc(size_t size)
|
|
|
{
|
|
|
void *ptr;
|
|
|
if ((ptr = malloc(size)) == NULL)
|
|
|
- err(EXIT_FATAL, "out of memory");
|
|
|
+ err(EXIT_FAILURE, "out of memory");
|
|
|
return ptr;
|
|
|
}
|
|
|
|
|
@@ -185,7 +158,7 @@ static char *xstrdup(const char *str)
|
|
|
{
|
|
|
char *ptr;
|
|
|
if ((ptr = strdup(str)) == NULL)
|
|
|
- err(EXIT_FATAL, "out of memory");
|
|
|
+ err(EXIT_FAILURE, "out of memory");
|
|
|
return ptr;
|
|
|
}
|
|
|
|
|
@@ -452,7 +425,7 @@ void scan_dir(const char *rawname)
|
|
|
|
|
|
path = strdup(rawname);
|
|
|
if (!path) {
|
|
|
- err(EXIT_FATAL, "Out of memory!\n");
|
|
|
+ err(EXIT_FAILURE, "Out of memory!\n");
|
|
|
}
|
|
|
|
|
|
path_n = path;
|
|
@@ -678,17 +651,17 @@ void cache_write(void)
|
|
|
return;
|
|
|
|
|
|
if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
|
|
|
- err(EXIT_FATAL, "can't resolve %s in chroot %s (%s)",
|
|
|
+ err(EXIT_FAILURE, "can't resolve %s in chroot %s (%s)",
|
|
|
cachefile, chroot_dir, strerror(errno));
|
|
|
|
|
|
sprintf(tempfile, "%s~", realcachefile);
|
|
|
|
|
|
if (unlink(tempfile) && errno != ENOENT)
|
|
|
- err(EXIT_FATAL, "can't unlink %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't unlink %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
|
|
|
if ((cachefd = creat(tempfile, 0644)) < 0)
|
|
|
- err(EXIT_FATAL, "can't create %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't create %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
|
|
|
if (byteswap) {
|
|
@@ -699,7 +672,7 @@ void cache_write(void)
|
|
|
magic_ptr = &magic;
|
|
|
}
|
|
|
if (write(cachefd, magic_ptr, sizeof(header_t)) != sizeof(header_t))
|
|
|
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
|
|
|
for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) {
|
|
@@ -717,31 +690,31 @@ void cache_write(void)
|
|
|
}
|
|
|
if (write(cachefd, lib_ptr, sizeof(libentry_t)) !=
|
|
|
sizeof(libentry_t))
|
|
|
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
}
|
|
|
|
|
|
for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) {
|
|
|
if ((size_t)write(cachefd, cur_lib->soname, strlen(cur_lib->soname) + 1)
|
|
|
!= strlen(cur_lib->soname) + 1)
|
|
|
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
if ((size_t)write(cachefd, cur_lib->libname, strlen(cur_lib->libname) + 1)
|
|
|
!= strlen(cur_lib->libname) + 1)
|
|
|
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
}
|
|
|
|
|
|
if (close(cachefd))
|
|
|
- err(EXIT_FATAL, "can't close %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't close %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
|
|
|
if (chmod(tempfile, 0644))
|
|
|
- err(EXIT_FATAL, "can't chmod %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't chmod %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
|
|
|
if (rename(tempfile, realcachefile))
|
|
|
- err(EXIT_FATAL, "can't rename %s~ (%s)", cachefile,
|
|
|
+ err(EXIT_FAILURE, "can't rename %s~ (%s)", cachefile,
|
|
|
strerror(errno));
|
|
|
}
|
|
|
|
|
@@ -756,22 +729,22 @@ void cache_print(void)
|
|
|
char realcachefile[BUFFER_SIZE];
|
|
|
|
|
|
if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
|
|
|
- err(EXIT_FATAL, "can't resolve %s in chroot %s (%s)",
|
|
|
+ err(EXIT_FAILURE, "can't resolve %s in chroot %s (%s)",
|
|
|
cachefile, chroot_dir, strerror(errno));
|
|
|
|
|
|
if (stat(realcachefile, &st) || (fd = open(realcachefile, O_RDONLY)) < 0)
|
|
|
- err(EXIT_FATAL, "can't read %s (%s)", cachefile, strerror(errno));
|
|
|
+ err(EXIT_FAILURE, "can't read %s (%s)", cachefile, strerror(errno));
|
|
|
|
|
|
c = mmap(0, st.st_size, PROT_READ, LDSO_CACHE_MMAP_FLAGS, fd, 0);
|
|
|
if (c == MAP_FAILED)
|
|
|
- err(EXIT_FATAL, "can't map %s (%s)", cachefile, strerror(errno));
|
|
|
+ err(EXIT_FAILURE, "can't map %s (%s)", cachefile, strerror(errno));
|
|
|
close(fd);
|
|
|
|
|
|
if (memcmp(((header_t *) c)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN))
|
|
|
- err(EXIT_FATAL, "%s cache corrupt", cachefile);
|
|
|
+ err(EXIT_FAILURE, "%s cache corrupt", cachefile);
|
|
|
|
|
|
if (memcmp(((header_t *) c)->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN))
|
|
|
- err(EXIT_FATAL, "wrong cache version - expected %s",
|
|
|
+ err(EXIT_FAILURE, "wrong cache version - expected %s",
|
|
|
LDSO_CACHE_VER);
|
|
|
|
|
|
header = (header_t *) c;
|
|
@@ -843,7 +816,7 @@ void usage(void)
|
|
|
"\tlib ... :\tlibraries to link\n\n"
|
|
|
#endif
|
|
|
);
|
|
|
- exit(EXIT_FATAL);
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
}
|
|
|
|
|
|
#define DIR_SEP ":, \t\n"
|
|
@@ -916,11 +889,11 @@ int main(int argc, char **argv)
|
|
|
if (chroot_dir && *chroot_dir) {
|
|
|
if (chroot(chroot_dir) < 0) {
|
|
|
if (chdir(chroot_dir) < 0)
|
|
|
- err(EXIT_FATAL, "couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
|
|
|
+ err(EXIT_FAILURE, "couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
|
|
|
chroot_dir = ".";
|
|
|
} else {
|
|
|
if (chdir("/") < 0)
|
|
|
- err(EXIT_FATAL, "couldn't chdir to / (%s)", strerror(errno));
|
|
|
+ err(EXIT_FAILURE, "couldn't chdir to / (%s)", strerror(errno));
|
|
|
chroot_dir = NULL;
|
|
|
}
|
|
|
}
|
|
@@ -932,7 +905,7 @@ int main(int argc, char **argv)
|
|
|
if (printcache) {
|
|
|
|
|
|
cache_print();
|
|
|
- exit(EXIT_OK);
|
|
|
+ exit(EXIT_SUCCESS);
|
|
|
} else if (libmode) {
|
|
|
|
|
|
|
|
@@ -952,7 +925,7 @@ int main(int argc, char **argv)
|
|
|
|
|
|
|
|
|
if ((so = is_shlib(dir, cp, &libtype, &islink, LIB_ANY)) == NULL)
|
|
|
- err(EXIT_FATAL, "%s%s%s is not a shared library",
|
|
|
+ err(EXIT_FAILURE, "%s%s%s is not a shared library",
|
|
|
dir, (*dir && strcmp(dir, "/")) ? "/" : "", cp);
|
|
|
|
|
|
|
|
@@ -1005,5 +978,5 @@ int main(int argc, char **argv)
|
|
|
cache_write();
|
|
|
}
|
|
|
|
|
|
- exit(EXIT_OK);
|
|
|
+ exit(EXIT_SUCCESS);
|
|
|
}
|