aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-24 14:59:45 +0000
committervda <vda@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-11-24 14:59:45 +0000
commit25eabd26c6001f26087ed48ae920502e73a03e53 (patch)
tree2dde275d11a03e45f7fe4aca444d0195c415a59c
parentaa2fdd67f50302aa6d6f3422f57ce5d42333c1f8 (diff)
downloadbusybox-w32-25eabd26c6001f26087ed48ae920502e73a03e53.tar.gz
busybox-w32-25eabd26c6001f26087ed48ae920502e73a03e53.tar.bz2
busybox-w32-25eabd26c6001f26087ed48ae920502e73a03e53.zip
tar: small fixes:
* size-optimize mapping code * kill double close git-svn-id: svn://busybox.net/trunk/busybox@16655 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--archival/tar.c46
-rw-r--r--libbb/procps.c34
2 files changed, 42 insertions, 38 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 51d34ea19..be661cc32 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -150,7 +150,9 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, struct stat *statbu
150 150
151/* Put an octal string into the specified buffer. 151/* Put an octal string into the specified buffer.
152 * The number is zero padded and possibly null terminated. 152 * The number is zero padded and possibly null terminated.
153 * Returns TRUE if successful. - DISABLED (no caller ever checked) */ 153 * Returns TRUE if successful. - DISABLED (no caller ever checked) */
154/* FIXME: we leave field untouched if value doesn't fit. */
155/* This is not good - what will happen at untar time?? */
154static void putOctal(char *cp, int len, long long value) 156static void putOctal(char *cp, int len, long long value)
155{ 157{
156 int tempLength; 158 int tempLength;
@@ -205,9 +207,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
205 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode & 07777); 207 putOctal(header.mode, sizeof(header.mode), statbuf->st_mode & 07777);
206 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); 208 putOctal(header.uid, sizeof(header.uid), statbuf->st_uid);
207 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid); 209 putOctal(header.gid, sizeof(header.gid), statbuf->st_gid);
208 if (sizeof(header.size) != sizeof("00000000000")) 210 memset(header.size, '0', sizeof(header.size)-1); /* Regular file size is handled later */
209 BUG_tar_header_size();
210 strcpy(header.size, "00000000000"); /* Regular file size is handled later */
211 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime); 211 putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime);
212 strcpy(header.magic, "ustar "); 212 strcpy(header.magic, "ustar ");
213 213
@@ -401,7 +401,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
401 /* tar will be corrupted. So bail out. */ 401 /* tar will be corrupted. So bail out. */
402 /* NB: GNU tar 1.16 warns and pads with zeroes */ 402 /* NB: GNU tar 1.16 warns and pads with zeroes */
403 /* or even seeks back and updates header */ 403 /* or even seeks back and updates header */
404 bb_error_msg_and_die("short read from %s", fileName); 404 bb_error_msg_and_die("short read from %s, aborting", fileName);
405 } 405 }
406 /* Check that file did not grow in between? */ 406 /* Check that file did not grow in between? */
407 /* if (safe_read(inputFileFd,1) == 1) warn but continue? */ 407 /* if (safe_read(inputFileFd,1) == 1) warn but continue? */
@@ -461,8 +461,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
461 dup2(gzipDataPipe[0], 0); 461 dup2(gzipDataPipe[0], 0);
462 close(gzipDataPipe[1]); 462 close(gzipDataPipe[1]);
463 463
464 if (tbInfo.tarFd != 1) 464 dup2(tbInfo.tarFd, 1);
465 dup2(tbInfo.tarFd, 1);
466 465
467 close(gzipStatusPipe[0]); 466 close(gzipStatusPipe[0]);
468 fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */ 467 fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */
@@ -831,7 +830,7 @@ int tar_main(int argc, char **argv)
831 flags = O_RDONLY; 830 flags = O_RDONLY;
832 } 831 }
833 832
834 if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) { 833 if (tar_filename[0] == '-' && !tar_filename[1]) {
835 tar_handle->src_fd = fileno(tar_stream); 834 tar_handle->src_fd = fileno(tar_stream);
836 tar_handle->seek = seek_by_read; 835 tar_handle->seek = seek_by_read;
837 } else { 836 } else {
@@ -860,23 +859,24 @@ int tar_main(int argc, char **argv)
860 writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERENCE, 859 writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERENCE,
861 tar_handle->accept, 860 tar_handle->accept,
862 tar_handle->reject, zipMode); 861 tar_handle->reject, zipMode);
863 } else { 862 /* NB: writeTarFile() closes tar_handle->src_fd */
864 while (get_header_ptr(tar_handle) == EXIT_SUCCESS) 863 return EXIT_SUCCESS;
865 /* nothing */;
866
867 /* Check that every file that should have been extracted was */
868 while (tar_handle->accept) {
869 if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
870 && !find_list_entry(tar_handle->passed, tar_handle->accept->data)
871 ) {
872 bb_error_msg_and_die("%s: not found in archive",
873 tar_handle->accept->data);
874 }
875 tar_handle->accept = tar_handle->accept->link;
876 }
877 } 864 }
878 865
879 if (ENABLE_FEATURE_CLEAN_UP && tar_handle->src_fd != STDIN_FILENO) 866 while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
867 /* nothing */;
868
869 /* Check that every file that should have been extracted was */
870 while (tar_handle->accept) {
871 if (!find_list_entry(tar_handle->reject, tar_handle->accept->data)
872 && !find_list_entry(tar_handle->passed, tar_handle->accept->data)
873 ) {
874 bb_error_msg_and_die("%s: not found in archive",
875 tar_handle->accept->data);
876 }
877 tar_handle->accept = tar_handle->accept->link;
878 }
879 if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */)
880 close(tar_handle->src_fd); 880 close(tar_handle->src_fd);
881 881
882 return EXIT_SUCCESS; 882 return EXIT_SUCCESS;
diff --git a/libbb/procps.c b/libbb/procps.c
index 52203ee9a..2581d03b2 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -35,6 +35,7 @@ void clear_username_cache(void)
35 clear_cache(&groupname); 35 clear_cache(&groupname);
36} 36}
37 37
38#if 0 /* more generic, but we don't need that yet */
38/* Returns -N-1 if not found. */ 39/* Returns -N-1 if not found. */
39/* cp->cache[N] is allocated and must be filled in this case */ 40/* cp->cache[N] is allocated and must be filled in this case */
40static int get_cached(cache_t *cp, unsigned id) 41static int get_cached(cache_t *cp, unsigned id)
@@ -48,25 +49,28 @@ static int get_cached(cache_t *cp, unsigned id)
48 cp->cache[i++].id = id; 49 cp->cache[i++].id = id;
49 return -i; 50 return -i;
50} 51}
52#endif
53
54typedef char* ug_func(char *name, long uid, int bufsize);
55static char* get_cached(cache_t *cp, unsigned id, ug_func* fp)
56{
57 int i;
58 for (i = 0; i < cp->size; i++)
59 if (cp->cache[i].id == id)
60 return cp->cache[i].name;
61 i = cp->size++;
62 cp->cache = xrealloc(cp->cache, cp->size * sizeof(*cp->cache));
63 cp->cache[i].id = id;
64 fp(cp->cache[i].name, id, sizeof(cp->cache[i].name));
65 return cp->cache[i].name;
66}
51const char* get_cached_username(uid_t uid) 67const char* get_cached_username(uid_t uid)
52{ 68{
53 int i = get_cached(&username, uid); 69 return get_cached(&username, uid, bb_getpwuid);
54 if (i < 0) {
55 i = -i - 1;
56 bb_getpwuid(username.cache[i].name, uid,
57 sizeof(username.cache[i].name));
58 }
59 return username.cache[i].name;
60} 70}
61const char* get_cached_groupname(uid_t uid) 71const char* get_cached_groupname(gid_t gid)
62{ 72{
63 int i = get_cached(&groupname, uid); 73 return get_cached(&groupname, gid, bb_getgrgid);
64 if (i < 0) {
65 i = -i - 1;
66 bb_getgrgid(groupname.cache[i].name, uid,
67 sizeof(groupname.cache[i].name));
68 }
69 return username.cache[i].name;
70} 74}
71 75
72 76