diff options
Diffstat (limited to 'utility.c')
| -rw-r--r-- | utility.c | 255 |
1 files changed, 148 insertions, 107 deletions
| @@ -25,6 +25,17 @@ | |||
| 25 | */ | 25 | */ |
| 26 | 26 | ||
| 27 | #include "internal.h" | 27 | #include "internal.h" |
| 28 | #if defined (BB_CHMOD_CHOWN_CHGRP) \ | ||
| 29 | || defined (BB_CP_MV) \ | ||
| 30 | || defined (BB_FIND) \ | ||
| 31 | || defined (BB_LS) \ | ||
| 32 | || defined (BB_INSMOD) | ||
| 33 | /* same conditions as recursiveAction */ | ||
| 34 | #define bb_need_name_too_long | ||
| 35 | #endif | ||
| 36 | #define BB_DECLARE_EXTERN | ||
| 37 | #include "messages.c" | ||
| 38 | |||
| 28 | #include <stdio.h> | 39 | #include <stdio.h> |
| 29 | #include <string.h> | 40 | #include <string.h> |
| 30 | #include <errno.h> | 41 | #include <errno.h> |
| @@ -35,6 +46,7 @@ | |||
| 35 | #include <sys/stat.h> | 46 | #include <sys/stat.h> |
| 36 | #include <unistd.h> | 47 | #include <unistd.h> |
| 37 | #include <ctype.h> | 48 | #include <ctype.h> |
| 49 | #include <sys/param.h> /* for PATH_MAX */ | ||
| 38 | 50 | ||
| 39 | #if defined BB_FEATURE_MOUNT_LOOP | 51 | #if defined BB_FEATURE_MOUNT_LOOP |
| 40 | #include <fcntl.h> | 52 | #include <fcntl.h> |
| @@ -58,9 +70,10 @@ const char mtab_file[] = "/etc/mtab"; | |||
| 58 | 70 | ||
| 59 | extern void usage(const char *usage) | 71 | extern void usage(const char *usage) |
| 60 | { | 72 | { |
| 61 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT); | 73 | fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", |
| 74 | BB_VER, BB_BT); | ||
| 62 | fprintf(stderr, "Usage: %s\n", usage); | 75 | fprintf(stderr, "Usage: %s\n", usage); |
| 63 | exit(FALSE); | 76 | exit FALSE; |
| 64 | } | 77 | } |
| 65 | 78 | ||
| 66 | 79 | ||
| @@ -78,9 +91,8 @@ get_kernel_revision() | |||
| 78 | { | 91 | { |
| 79 | FILE *file; | 92 | FILE *file; |
| 80 | int major=0, minor=0, patch=0; | 93 | int major=0, minor=0, patch=0; |
| 81 | char* filename="/proc/sys/kernel/osrelease"; | ||
| 82 | 94 | ||
| 83 | file = fopen(filename,"r"); | 95 | file = fopen("/proc/sys/kernel/osrelease", "r"); |
| 84 | if (file == NULL) { | 96 | if (file == NULL) { |
| 85 | /* bummer, /proc must not be mounted... */ | 97 | /* bummer, /proc must not be mounted... */ |
| 86 | return( 0); | 98 | return( 0); |
| @@ -89,28 +101,34 @@ get_kernel_revision() | |||
| 89 | fclose(file); | 101 | fclose(file); |
| 90 | return major*65536 + minor*256 + patch; | 102 | return major*65536 + minor*256 + patch; |
| 91 | } | 103 | } |
| 104 | #endif /* BB_INIT || BB_PS */ | ||
| 92 | 105 | ||
| 93 | #endif | ||
| 94 | 106 | ||
| 95 | 107 | ||
| 96 | 108 | #if defined (BB_CP_MV) || defined (BB_DU) || defined (BB_LN) | |
| 97 | #if defined (BB_CP) || defined (BB_MV) | ||
| 98 | /* | 109 | /* |
| 99 | * Return TRUE if a fileName is a directory. | 110 | * Return TRUE if a fileName is a directory. |
| 100 | * Nonexistant files return FALSE. | 111 | * Nonexistant files return FALSE. |
| 101 | */ | 112 | */ |
| 102 | int isDirectory(const char *name) | 113 | int isDirectory(const char *fileName, const int followLinks) |
| 103 | { | 114 | { |
| 104 | struct stat statBuf; | 115 | struct stat statBuf; |
| 116 | int status; | ||
| 105 | 117 | ||
| 106 | if (stat(name, &statBuf) < 0) | 118 | if (followLinks == TRUE) |
| 107 | return FALSE; | 119 | status = stat(fileName, &statBuf); |
| 120 | else | ||
| 121 | status = lstat(fileName, &statBuf); | ||
| 122 | |||
| 123 | if (status < 0) | ||
| 124 | return FALSE; | ||
| 108 | if (S_ISDIR(statBuf.st_mode)) | 125 | if (S_ISDIR(statBuf.st_mode)) |
| 109 | return TRUE; | 126 | return TRUE; |
| 110 | return(FALSE); | 127 | return FALSE; |
| 111 | } | 128 | } |
| 129 | #endif | ||
| 112 | 130 | ||
| 113 | 131 | #if defined (BB_CP_MV) | |
| 114 | /* | 132 | /* |
| 115 | * Copy one file to another, while possibly preserving its modes, times, | 133 | * Copy one file to another, while possibly preserving its modes, times, |
| 116 | * and modes. Returns TRUE if successful, or FALSE on a failure with an | 134 | * and modes. Returns TRUE if successful, or FALSE on a failure with an |
| @@ -120,33 +138,33 @@ int isDirectory(const char *name) | |||
| 120 | */ | 138 | */ |
| 121 | int | 139 | int |
| 122 | copyFile( const char *srcName, const char *destName, | 140 | copyFile( const char *srcName, const char *destName, |
| 123 | int setModes, int followLinks) | 141 | int setModes, int followLinks) |
| 124 | { | 142 | { |
| 125 | int rfd; | 143 | int rfd; |
| 126 | int wfd; | 144 | int wfd; |
| 127 | int rcc; | 145 | int rcc; |
| 128 | int result; | 146 | int status; |
| 129 | char buf[BUF_SIZE]; | 147 | char buf[BUF_SIZE]; |
| 130 | struct stat srcStatBuf; | 148 | struct stat srcStatBuf; |
| 131 | struct stat dstStatBuf; | 149 | struct stat dstStatBuf; |
| 132 | struct utimbuf times; | 150 | struct utimbuf times; |
| 133 | 151 | ||
| 134 | /* Grab the source file's stats */ | 152 | if (followLinks == TRUE) |
| 135 | if (followLinks == FALSE) | 153 | status = stat(srcName, &srcStatBuf); |
| 136 | result = stat(srcName, &srcStatBuf); | ||
| 137 | else | 154 | else |
| 138 | result = lstat(srcName, &srcStatBuf); | 155 | status = lstat(srcName, &srcStatBuf); |
| 139 | if (result < 0) { | 156 | |
| 157 | if (status < 0) { | ||
| 140 | perror(srcName); | 158 | perror(srcName); |
| 141 | return FALSE; | 159 | return FALSE; |
| 142 | } | 160 | } |
| 143 | 161 | ||
| 144 | /* Grab the dest file's stats */ | 162 | if (followLinks == TRUE) |
| 145 | if (followLinks == FALSE) | 163 | status = stat(destName, &dstStatBuf); |
| 146 | result = stat(destName, &dstStatBuf); | 164 | else |
| 147 | else | 165 | status = lstat(destName, &dstStatBuf); |
| 148 | result = lstat(destName, &dstStatBuf); | 166 | |
| 149 | if (result < 0) { | 167 | if (status < 0) { |
| 150 | dstStatBuf.st_ino = -1; | 168 | dstStatBuf.st_ino = -1; |
| 151 | dstStatBuf.st_dev = -1; | 169 | dstStatBuf.st_dev = -1; |
| 152 | } | 170 | } |
| @@ -160,45 +178,49 @@ copyFile( const char *srcName, const char *destName, | |||
| 160 | if (S_ISDIR(srcStatBuf.st_mode)) { | 178 | if (S_ISDIR(srcStatBuf.st_mode)) { |
| 161 | //fprintf(stderr, "copying directory %s to %s\n", srcName, destName); | 179 | //fprintf(stderr, "copying directory %s to %s\n", srcName, destName); |
| 162 | /* Make sure the directory is writable */ | 180 | /* Make sure the directory is writable */ |
| 163 | result = mkdir(destName, 0777777 ^ umask(0)); | 181 | status = mkdir(destName, 0777777 ^ umask(0)); |
| 164 | if (result < 0 && errno != EEXIST) { | 182 | if (status < 0 && errno != EEXIST) { |
| 165 | perror(destName); | 183 | perror(destName); |
| 166 | return (FALSE); | 184 | return FALSE; |
| 167 | } | 185 | } |
| 168 | } else if (S_ISLNK(srcStatBuf.st_mode)) { | 186 | } else if (S_ISLNK(srcStatBuf.st_mode)) { |
| 169 | char *link_val; | 187 | char link_val[PATH_MAX + 1]; |
| 170 | int link_size; | 188 | int link_size; |
| 171 | 189 | ||
| 172 | //fprintf(stderr, "copying link %s to %s\n", srcName, destName); | 190 | //fprintf(stderr, "copying link %s to %s\n", srcName, destName); |
| 173 | link_val = (char *) alloca(PATH_MAX + 2); | 191 | /* Warning: This could possibly truncate silently, to PATH_MAX chars */ |
| 174 | link_size = readlink(srcName, link_val, PATH_MAX + 1); | 192 | link_size = readlink(srcName, &link_val[0], PATH_MAX); |
| 175 | if (link_size < 0) { | 193 | if (link_size < 0) { |
| 176 | perror(srcName); | 194 | perror(srcName); |
| 177 | return (FALSE); | 195 | return FALSE; |
| 178 | } | 196 | } |
| 179 | link_val[link_size] = '\0'; | 197 | link_val[link_size] = '\0'; |
| 180 | link_size = symlink(link_val, destName); | 198 | status = symlink(link_val, destName); |
| 181 | if (link_size != 0) { | 199 | if (status < 0) { |
| 182 | perror(destName); | 200 | perror(destName); |
| 183 | return (FALSE); | 201 | return FALSE; |
| 184 | } | 202 | } |
| 185 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | 203 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) |
| 186 | if (setModes == TRUE) { | 204 | if (setModes == TRUE) { |
| 187 | lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); | 205 | if (lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) { |
| 206 | perror(destName); | ||
| 207 | return FALSE; | ||
| 208 | } | ||
| 188 | } | 209 | } |
| 189 | #endif | 210 | #endif |
| 211 | return TRUE; | ||
| 190 | } else if (S_ISFIFO(srcStatBuf.st_mode)) { | 212 | } else if (S_ISFIFO(srcStatBuf.st_mode)) { |
| 191 | //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); | 213 | //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); |
| 192 | if (mkfifo(destName, 0644)) { | 214 | if (mkfifo(destName, 0644) < 0) { |
| 193 | perror(destName); | 215 | perror(destName); |
| 194 | return (FALSE); | 216 | return FALSE; |
| 195 | } | 217 | } |
| 196 | } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) | 218 | } else if (S_ISBLK(srcStatBuf.st_mode) || S_ISCHR(srcStatBuf.st_mode) |
| 197 | || S_ISSOCK (srcStatBuf.st_mode)) { | 219 | || S_ISSOCK (srcStatBuf.st_mode)) { |
| 198 | //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); | 220 | //fprintf(stderr, "copying soc, blk, or chr %s to %s\n", srcName, destName); |
| 199 | if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev)) { | 221 | if (mknod(destName, srcStatBuf.st_mode, srcStatBuf.st_rdev) < 0) { |
| 200 | perror(destName); | 222 | perror(destName); |
| 201 | return (FALSE); | 223 | return FALSE; |
| 202 | } | 224 | } |
| 203 | } else if (S_ISREG(srcStatBuf.st_mode)) { | 225 | } else if (S_ISREG(srcStatBuf.st_mode)) { |
| 204 | //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); | 226 | //fprintf(stderr, "copying regular file %s to %s\n", srcName, destName); |
| @@ -208,7 +230,7 @@ copyFile( const char *srcName, const char *destName, | |||
| 208 | return FALSE; | 230 | return FALSE; |
| 209 | } | 231 | } |
| 210 | 232 | ||
| 211 | wfd = creat(destName, srcStatBuf.st_mode); | 233 | wfd = open(destName, O_WRONLY | O_CREAT | O_TRUNC, srcStatBuf.st_mode); |
| 212 | if (wfd < 0) { | 234 | if (wfd < 0) { |
| 213 | perror(destName); | 235 | perror(destName); |
| 214 | close(rfd); | 236 | close(rfd); |
| @@ -231,24 +253,32 @@ copyFile( const char *srcName, const char *destName, | |||
| 231 | 253 | ||
| 232 | if (setModes == TRUE) { | 254 | if (setModes == TRUE) { |
| 233 | /* This is fine, since symlinks never get here */ | 255 | /* This is fine, since symlinks never get here */ |
| 234 | chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); | 256 | if (chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0) { |
| 235 | chmod(destName, srcStatBuf.st_mode); | 257 | perror(destName); |
| 258 | exit FALSE; | ||
| 259 | } | ||
| 260 | if (chmod(destName, srcStatBuf.st_mode) < 0) { | ||
| 261 | perror(destName); | ||
| 262 | exit FALSE; | ||
| 263 | } | ||
| 236 | times.actime = srcStatBuf.st_atime; | 264 | times.actime = srcStatBuf.st_atime; |
| 237 | times.modtime = srcStatBuf.st_mtime; | 265 | times.modtime = srcStatBuf.st_mtime; |
| 238 | utime(destName, ×); | 266 | if (utime(destName, ×) < 0) { |
| 267 | perror(destName); | ||
| 268 | exit FALSE; | ||
| 269 | } | ||
| 239 | } | 270 | } |
| 240 | 271 | ||
| 241 | return TRUE; | 272 | return TRUE; |
| 242 | 273 | ||
| 243 | 274 | error_exit: | |
| 244 | error_exit: | ||
| 245 | perror(destName); | 275 | perror(destName); |
| 246 | close(rfd); | 276 | close(rfd); |
| 247 | close(wfd); | 277 | close(wfd); |
| 248 | 278 | ||
| 249 | return FALSE; | 279 | return FALSE; |
| 250 | } | 280 | } |
| 251 | #endif | 281 | #endif /* BB_CP_MV */ |
| 252 | 282 | ||
| 253 | 283 | ||
| 254 | 284 | ||
| @@ -296,7 +326,7 @@ const char *modeString(int mode) | |||
| 296 | } | 326 | } |
| 297 | return buf; | 327 | return buf; |
| 298 | } | 328 | } |
| 299 | #endif | 329 | #endif /* BB_TAR || BB_LS */ |
| 300 | 330 | ||
| 301 | 331 | ||
| 302 | #if defined BB_TAR | 332 | #if defined BB_TAR |
| @@ -324,9 +354,9 @@ const char *timeString(time_t timeVal) | |||
| 324 | 354 | ||
| 325 | return buf; | 355 | return buf; |
| 326 | } | 356 | } |
| 327 | #endif | 357 | #endif /* BB_TAR */ |
| 328 | 358 | ||
| 329 | #if defined BB_TAR || defined BB_CP || defined BB_MV | 359 | #if defined BB_TAR || defined BB_CP_MV |
| 330 | /* | 360 | /* |
| 331 | * Write all of the supplied buffer out to a file. | 361 | * Write all of the supplied buffer out to a file. |
| 332 | * This does multiple writes as necessary. | 362 | * This does multiple writes as necessary. |
| @@ -352,7 +382,7 @@ int fullWrite(int fd, const char *buf, int len) | |||
| 352 | 382 | ||
| 353 | return total; | 383 | return total; |
| 354 | } | 384 | } |
| 355 | #endif | 385 | #endif /* BB_TAR || BB_CP_MV */ |
| 356 | 386 | ||
| 357 | 387 | ||
| 358 | #if defined BB_TAR || defined BB_TAIL | 388 | #if defined BB_TAR || defined BB_TAIL |
| @@ -385,10 +415,14 @@ int fullRead(int fd, char *buf, int len) | |||
| 385 | 415 | ||
| 386 | return total; | 416 | return total; |
| 387 | } | 417 | } |
| 388 | #endif | 418 | #endif /* BB_TAR || BB_TAIL */ |
| 389 | 419 | ||
| 390 | 420 | ||
| 391 | #if defined (BB_CHMOD_CHOWN_CHGRP) || defined (BB_CP) || defined (BB_FIND) || defined (BB_LS) || defined (BB_INSMOD) | 421 | #if defined (BB_CHMOD_CHOWN_CHGRP) \ |
| 422 | || defined (BB_CP_MV) \ | ||
| 423 | || defined (BB_FIND) \ | ||
| 424 | || defined (BB_LS) \ | ||
| 425 | || defined (BB_INSMOD) | ||
| 392 | /* | 426 | /* |
| 393 | * Walk down all the directories under the specified | 427 | * Walk down all the directories under the specified |
| 394 | * location, and do something (something specified | 428 | * location, and do something (something specified |
| @@ -399,13 +433,15 @@ int fullRead(int fd, char *buf, int len) | |||
| 399 | * and so isn't sufficiently portable to take over since glibc2.1 | 433 | * and so isn't sufficiently portable to take over since glibc2.1 |
| 400 | * is so stinking huge. | 434 | * is so stinking huge. |
| 401 | */ | 435 | */ |
| 402 | int | 436 | int recursiveAction(const char *fileName, |
| 403 | recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst, | 437 | int recurse, int followLinks, int depthFirst, |
| 404 | int (*fileAction) (const char *fileName, struct stat* statbuf), | 438 | int (*fileAction) (const char *fileName, |
| 405 | int (*dirAction) (const char *fileName, struct stat* statbuf)) | 439 | struct stat* statbuf), |
| 440 | int (*dirAction) (const char *fileName, | ||
| 441 | struct stat* statbuf)) | ||
| 406 | { | 442 | { |
| 407 | int status; | 443 | int status; |
| 408 | struct stat statbuf, statbuf1; | 444 | struct stat statbuf; |
| 409 | struct dirent *next; | 445 | struct dirent *next; |
| 410 | 446 | ||
| 411 | if (followLinks == TRUE) | 447 | if (followLinks == TRUE) |
| @@ -414,16 +450,20 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir | |||
| 414 | status = lstat(fileName, &statbuf); | 450 | status = lstat(fileName, &statbuf); |
| 415 | 451 | ||
| 416 | if (status < 0) { | 452 | if (status < 0) { |
| 417 | //fprintf(stderr, "status=%d followLinks=%d TRUE=%d\n", status, followLinks, TRUE); | 453 | #ifdef BB_DEBUG_PRINT_SCAFFOLD |
| 454 | fprintf(stderr, | ||
| 455 | "status=%d followLinks=%d TRUE=%d\n", | ||
| 456 | status, followLinks, TRUE); | ||
| 457 | #endif | ||
| 418 | perror(fileName); | 458 | perror(fileName); |
| 419 | return (FALSE); | 459 | return FALSE; |
| 420 | } | 460 | } |
| 421 | 461 | ||
| 422 | if ( (followLinks == FALSE) && (S_ISLNK(statbuf.st_mode)) ) { | 462 | if ((followLinks == FALSE) && (S_ISLNK(statbuf.st_mode)) ) { |
| 423 | if (fileAction == NULL) | 463 | if (fileAction == NULL) |
| 424 | return (TRUE); | 464 | return TRUE; |
| 425 | else | 465 | else |
| 426 | return (fileAction(fileName, &statbuf)); | 466 | return fileAction(fileName, &statbuf); |
| 427 | } | 467 | } |
| 428 | 468 | ||
| 429 | if (recurse == FALSE) { | 469 | if (recurse == FALSE) { |
| @@ -431,67 +471,65 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir | |||
| 431 | if (dirAction != NULL) | 471 | if (dirAction != NULL) |
| 432 | return (dirAction(fileName, &statbuf)); | 472 | return (dirAction(fileName, &statbuf)); |
| 433 | else | 473 | else |
| 434 | return (TRUE); | 474 | return TRUE; |
| 435 | } | 475 | } |
| 436 | } | ||
| 437 | |||
| 438 | status = lstat(fileName, &statbuf1); | ||
| 439 | if (status < 0) { | ||
| 440 | perror(fileName); | ||
| 441 | return (FALSE); | ||
| 442 | } | 476 | } |
| 443 | 477 | ||
| 444 | if (S_ISDIR(statbuf.st_mode) && S_ISDIR(statbuf1.st_mode)) { | 478 | if (S_ISDIR(statbuf.st_mode)) { |
| 445 | DIR *dir; | 479 | DIR *dir; |
| 446 | dir = opendir(fileName); | 480 | dir = opendir(fileName); |
| 447 | if (!dir) { | 481 | if (!dir) { |
| 448 | perror(fileName); | 482 | perror(fileName); |
| 449 | return (FALSE); | 483 | return FALSE; |
| 450 | } | 484 | } |
| 451 | if (dirAction != NULL && depthFirst == FALSE) { | 485 | if (dirAction != NULL && depthFirst == FALSE) { |
| 452 | status = dirAction(fileName, &statbuf); | 486 | status = dirAction(fileName, &statbuf); |
| 453 | if (status == FALSE) { | 487 | if (status == FALSE) { |
| 454 | perror(fileName); | 488 | perror(fileName); |
| 455 | return (FALSE); | 489 | return FALSE; |
| 456 | } | 490 | } |
| 457 | } | 491 | } |
| 458 | while ((next = readdir(dir)) != NULL) { | 492 | while ((next = readdir(dir)) != NULL) { |
| 459 | char nextFile[NAME_MAX]; | 493 | char nextFile[PATH_MAX + 1]; |
| 460 | if ((strcmp(next->d_name, "..") == 0) | 494 | if ((strcmp(next->d_name, "..") == 0) |
| 461 | || (strcmp(next->d_name, ".") == 0)) { | 495 | || (strcmp(next->d_name, ".") == 0)) { |
| 462 | continue; | 496 | continue; |
| 463 | } | 497 | } |
| 498 | if (strlen(fileName) + strlen(next->d_name) + 1 > PATH_MAX) { | ||
| 499 | fprintf(stderr, name_too_long, "ftw"); | ||
| 500 | return FALSE; | ||
| 501 | } | ||
| 464 | sprintf(nextFile, "%s/%s", fileName, next->d_name); | 502 | sprintf(nextFile, "%s/%s", fileName, next->d_name); |
| 465 | status = | 503 | status = |
| 466 | recursiveAction(nextFile, TRUE, followLinks, depthFirst, | 504 | recursiveAction(nextFile, TRUE, followLinks, depthFirst, |
| 467 | fileAction, dirAction); | 505 | fileAction, dirAction); |
| 468 | if (status < 0) { | 506 | if (status < 0) { |
| 469 | closedir(dir); | 507 | closedir(dir); |
| 470 | return (FALSE); | 508 | return FALSE; |
| 471 | } | 509 | } |
| 472 | } | 510 | } |
| 473 | status = closedir(dir); | 511 | status = closedir(dir); |
| 474 | if (status < 0) { | 512 | if (status < 0) { |
| 475 | perror(fileName); | 513 | perror(fileName); |
| 476 | return (FALSE); | 514 | return FALSE; |
| 477 | } | 515 | } |
| 478 | if (dirAction != NULL && depthFirst == TRUE) { | 516 | if (dirAction != NULL && depthFirst == TRUE) { |
| 479 | status = dirAction(fileName, &statbuf); | 517 | status = dirAction(fileName, &statbuf); |
| 480 | if (status == FALSE) { | 518 | if (status == FALSE) { |
| 481 | perror(fileName); | 519 | perror(fileName); |
| 482 | return (FALSE); | 520 | return FALSE; |
| 483 | } | 521 | } |
| 484 | } | 522 | } |
| 485 | } else { | 523 | } else { |
| 486 | if (fileAction == NULL) | 524 | if (fileAction == NULL) |
| 487 | return (TRUE); | 525 | return TRUE; |
| 488 | else | 526 | else |
| 489 | return (fileAction(fileName, &statbuf)); | 527 | return fileAction(fileName, &statbuf); |
| 490 | } | 528 | } |
| 491 | return (TRUE); | 529 | return TRUE; |
| 492 | } | 530 | } |
| 493 | 531 | ||
| 494 | #endif | 532 | #endif /* BB_CHMOD_CHOWN_CHGRP || BB_CP_MV || BB_FIND || BB_LS || BB_INSMOD */ |
| 495 | 533 | ||
| 496 | 534 | ||
| 497 | 535 | ||
| @@ -506,25 +544,25 @@ extern int createPath (const char *name, int mode) | |||
| 506 | { | 544 | { |
| 507 | char *cp; | 545 | char *cp; |
| 508 | char *cpOld; | 546 | char *cpOld; |
| 509 | char buf[NAME_MAX]; | 547 | char buf[PATH_MAX + 1]; |
| 510 | int retVal=0; | 548 | int retVal=0; |
| 511 | 549 | ||
| 512 | strcpy( buf, name); | 550 | strcpy( buf, name); |
| 513 | cp = strchr (buf, '/'); | 551 | cp = strchr(buf, '/'); |
| 514 | while (cp) { | 552 | while (cp) { |
| 515 | cpOld = cp; | 553 | cpOld = cp; |
| 516 | cp = strchr (cp + 1, '/'); | 554 | cp = strchr(cp + 1, '/'); |
| 517 | *cpOld = '\0'; | 555 | *cpOld = '\0'; |
| 518 | retVal = mkdir (buf, cp ? 0777 : mode); | 556 | retVal = mkdir(buf, cp ? 0777 : mode); |
| 519 | if (retVal != 0 && errno != EEXIST) { | 557 | if (retVal != 0 && errno != EEXIST) { |
| 520 | perror( buf); | 558 | perror(buf); |
| 521 | return( FALSE); | 559 | return FALSE; |
| 522 | } | 560 | } |
| 523 | *cpOld = '/'; | 561 | *cpOld = '/'; |
| 524 | } | 562 | } |
| 525 | return( TRUE); | 563 | return TRUE; |
| 526 | } | 564 | } |
| 527 | #endif | 565 | #endif /* BB_TAR || BB_MKDIR */ |
| 528 | 566 | ||
| 529 | 567 | ||
| 530 | 568 | ||
| @@ -624,7 +662,7 @@ parse_mode( const char* s, mode_t* theMode) | |||
| 624 | } | 662 | } |
| 625 | 663 | ||
| 626 | 664 | ||
| 627 | #endif | 665 | #endif /* BB_CHMOD_CHOWN_CHGRP || BB_MKDIR */ |
| 628 | 666 | ||
| 629 | 667 | ||
| 630 | 668 | ||
| @@ -712,7 +750,7 @@ my_getgrgid(char* group, gid_t gid) | |||
| 712 | } | 750 | } |
| 713 | 751 | ||
| 714 | 752 | ||
| 715 | #endif | 753 | #endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS */ |
| 716 | 754 | ||
| 717 | 755 | ||
| 718 | 756 | ||
| @@ -804,7 +842,7 @@ int get_console_fd(char* tty_name) | |||
| 804 | } | 842 | } |
| 805 | 843 | ||
| 806 | 844 | ||
| 807 | #endif | 845 | #endif /* BB_CHVT || BB_DEALLOCVT */ |
| 808 | 846 | ||
| 809 | 847 | ||
| 810 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED) | 848 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED) |
| @@ -883,8 +921,7 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno | |||
| 883 | return FALSE; | 921 | return FALSE; |
| 884 | } | 922 | } |
| 885 | 923 | ||
| 886 | 924 | #endif /* ! BB_REGEXP && (BB_GREP || BB_SED) */ | |
| 887 | #endif | ||
| 888 | 925 | ||
| 889 | 926 | ||
| 890 | #if defined BB_FIND | 927 | #if defined BB_FIND |
| @@ -986,7 +1023,7 @@ check_wildcard_match(const char* text, const char* pattern) | |||
| 986 | 1023 | ||
| 987 | return TRUE; | 1024 | return TRUE; |
| 988 | } | 1025 | } |
| 989 | #endif | 1026 | #endif /* BB_FIND */ |
| 990 | 1027 | ||
| 991 | 1028 | ||
| 992 | 1029 | ||
| @@ -1030,7 +1067,7 @@ extern struct mntent *findMountPoint(const char *name, const char *table) | |||
| 1030 | endmntent(mountTable); | 1067 | endmntent(mountTable); |
| 1031 | return mountEntry; | 1068 | return mountEntry; |
| 1032 | } | 1069 | } |
| 1033 | #endif | 1070 | #endif /* BB_DF || BB_MTAB */ |
| 1034 | 1071 | ||
| 1035 | 1072 | ||
| 1036 | 1073 | ||
| @@ -1052,7 +1089,8 @@ extern long getNum (const char *cp) | |||
| 1052 | value = value * 10 + *cp++ - '0'; | 1089 | value = value * 10 + *cp++ - '0'; |
| 1053 | 1090 | ||
| 1054 | switch (*cp++) { | 1091 | switch (*cp++) { |
| 1055 | case 'm': | 1092 | case 'M': |
| 1093 | case 'm': /* `tail' uses it traditionally */ | ||
| 1056 | value *= 1048576; | 1094 | value *= 1048576; |
| 1057 | break; | 1095 | break; |
| 1058 | 1096 | ||
| @@ -1080,7 +1118,7 @@ extern long getNum (const char *cp) | |||
| 1080 | 1118 | ||
| 1081 | return value; | 1119 | return value; |
| 1082 | } | 1120 | } |
| 1083 | #endif | 1121 | #endif /* BB_DD || BB_TAIL */ |
| 1084 | 1122 | ||
| 1085 | 1123 | ||
| 1086 | #if defined BB_INIT || defined BB_HALT || defined BB_REBOOT | 1124 | #if defined BB_INIT || defined BB_HALT || defined BB_REBOOT |
| @@ -1120,9 +1158,12 @@ findInitPid() | |||
| 1120 | } | 1158 | } |
| 1121 | return 0; | 1159 | return 0; |
| 1122 | } | 1160 | } |
| 1123 | #endif | 1161 | #endif /* BB_INIT || BB_HALT || BB_REBOOT */ |
| 1124 | 1162 | ||
| 1125 | #if defined BB_GUNZIP || defined BB_GZIP || defined BB_PRINTF || defined BB_TAIL | 1163 | #if defined BB_GUNZIP \ |
| 1164 | || defined BB_GZIP \ | ||
| 1165 | || defined BB_PRINTF \ | ||
| 1166 | || defined BB_TAIL | ||
| 1126 | extern void *xmalloc (size_t size) | 1167 | extern void *xmalloc (size_t size) |
| 1127 | { | 1168 | { |
| 1128 | void *cp = malloc (size); | 1169 | void *cp = malloc (size); |
| @@ -1138,7 +1179,7 @@ extern void error(char *msg) | |||
| 1138 | fprintf(stderr, "\n%s\n", msg); | 1179 | fprintf(stderr, "\n%s\n", msg); |
| 1139 | exit(1); | 1180 | exit(1); |
| 1140 | } | 1181 | } |
| 1141 | #endif | 1182 | #endif /* BB_GUNZIP || BB_GZIP || BB_PRINTF || BB_TAIL */ |
| 1142 | 1183 | ||
| 1143 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) | 1184 | #if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT) |
| 1144 | extern int vdprintf(int d, const char *format, va_list ap) | 1185 | extern int vdprintf(int d, const char *format, va_list ap) |
| @@ -1149,7 +1190,7 @@ extern int vdprintf(int d, const char *format, va_list ap) | |||
| 1149 | len = vsprintf(buf, format, ap); | 1190 | len = vsprintf(buf, format, ap); |
| 1150 | return write(d, buf, len); | 1191 | return write(d, buf, len); |
| 1151 | } | 1192 | } |
| 1152 | #endif | 1193 | #endif /* BB_SYSLOGD */ |
| 1153 | 1194 | ||
| 1154 | #if defined BB_FEATURE_MOUNT_LOOP | 1195 | #if defined BB_FEATURE_MOUNT_LOOP |
| 1155 | extern int del_loop(const char *device) | 1196 | extern int del_loop(const char *device) |
