aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-11-06 03:05:54 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-11-06 03:05:54 +0000
commit6bef3d1d2216234454875052220ca0f477a820b4 (patch)
tree717060345370b781d3d1cde7ab4dd29304a066e8 /miscutils
parent1bec1b980e3cf5ad604fb0c2038a3ab83d9ab5f5 (diff)
downloadbusybox-w32-6bef3d1d2216234454875052220ca0f477a820b4.tar.gz
busybox-w32-6bef3d1d2216234454875052220ca0f477a820b4.tar.bz2
busybox-w32-6bef3d1d2216234454875052220ca0f477a820b4.zip
fbset: fix buglet where we were using wrong pointer
readahead: stop using stdio.h *: style fixes
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/devfsd.c37
-rw-r--r--miscutils/hdparm.c3
-rw-r--r--miscutils/readahead.c10
3 files changed, 30 insertions, 20 deletions
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index cd94869ae..9990142c2 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -465,7 +465,8 @@ static void read_config_file(char *path, int optional, unsigned long *event_mask
465 free(p); 465 free(p);
466 return; 466 return;
467 } 467 }
468 if ((fp = fopen(path, "r")) != NULL) { 468 fp = fopen(path, "r");
469 if (fp != NULL) {
469 while (fgets(buf, STRING_LENGTH, fp) != NULL) { 470 while (fgets(buf, STRING_LENGTH, fp) != NULL) {
470 /* Skip whitespace */ 471 /* Skip whitespace */
471 line = buf; 472 line = buf;
@@ -560,7 +561,8 @@ static void process_config_line(const char *line, unsigned long *event_mask)
560 case 4: /* "PERMISSIONS" */ 561 case 4: /* "PERMISSIONS" */
561 new->action.what = AC_PERMISSIONS; 562 new->action.what = AC_PERMISSIONS;
562 /* Get user and group */ 563 /* Get user and group */
563 if ((ptr = strchr(p[0], '.')) == NULL) { 564 ptr = strchr(p[0], '.');
565 if (ptr == NULL) {
564 msg = "UID.GID"; 566 msg = "UID.GID";
565 goto process_config_line_err; /*"missing '.' in UID.GID"*/ 567 goto process_config_line_err; /*"missing '.' in UID.GID"*/
566 } 568 }
@@ -979,8 +981,9 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
979 if ((source_stat->st_mode & S_IFMT) ==(dest_stat->st_mode & S_IFMT)) { 981 if ((source_stat->st_mode & S_IFMT) ==(dest_stat->st_mode & S_IFMT)) {
980 /* Same type */ 982 /* Same type */
981 if (S_ISLNK(source_stat->st_mode)) { 983 if (S_ISLNK(source_stat->st_mode)) {
982 if ((source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1)) < 0 984 source_len = readlink(sourcepath, source_link, STRING_LENGTH - 1);
983 || (dest_len = readlink(destpath , dest_link , STRING_LENGTH - 1)) < 0 985 if ((source_len < 0)
986 || (dest_len = readlink(destpath, dest_link, STRING_LENGTH - 1)) < 0
984 ) 987 )
985 return FALSE; 988 return FALSE;
986 source_link[source_len] = '\0'; 989 source_link[source_len] = '\0';
@@ -999,7 +1002,8 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
999 unlink(destpath); 1002 unlink(destpath);
1000 switch (source_stat->st_mode & S_IFMT) { 1003 switch (source_stat->st_mode & S_IFMT) {
1001 case S_IFSOCK: 1004 case S_IFSOCK:
1002 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) 1005 fd = socket(AF_UNIX, SOCK_STREAM, 0);
1006 if (fd < 0)
1003 break; 1007 break;
1004 un_addr.sun_family = AF_UNIX; 1008 un_addr.sun_family = AF_UNIX;
1005 snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", destpath); 1009 snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s", destpath);
@@ -1009,14 +1013,16 @@ static int copy_inode(const char *destpath, const struct stat *dest_stat,
1009 break; 1013 break;
1010 goto do_chown; 1014 goto do_chown;
1011 case S_IFLNK: 1015 case S_IFLNK:
1012 if ((val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1)) < 0) 1016 val = readlink(sourcepath, symlink_val, STRING_LENGTH - 1);
1017 if (val < 0)
1013 break; 1018 break;
1014 symlink_val[val] = '\0'; 1019 symlink_val[val] = '\0';
1015 if (symlink(symlink_val, destpath) == 0) 1020 if (symlink(symlink_val, destpath) == 0)
1016 return TRUE; 1021 return TRUE;
1017 break; 1022 break;
1018 case S_IFREG: 1023 case S_IFREG:
1019 if ((fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT)) < 0) 1024 fd = open(destpath, O_RDONLY | O_CREAT, new_mode & ~S_IFMT);
1025 if (fd < 0)
1020 break; 1026 break;
1021 close(fd); 1027 close(fd);
1022 if (chmod(destpath, new_mode & ~S_IFMT) != 0) 1028 if (chmod(destpath, new_mode & ~S_IFMT) != 0)
@@ -1082,7 +1088,7 @@ static int get_uid_gid(int flag, const char *string)
1082 if (isdigit(string[0]) ||((string[0] == '-') && isdigit(string[1]))) 1088 if (isdigit(string[0]) ||((string[0] == '-') && isdigit(string[1])))
1083 return atoi(string); 1089 return atoi(string);
1084 1090
1085 if (flag == UID && (pw_ent = getpwnam(string)) != NULL) 1091 if (flag == UID && (pw_ent = getpwnam(string)) != NULL)
1086 return pw_ent->pw_uid; 1092 return pw_ent->pw_uid;
1087 1093
1088 if (flag == GID && (grp_ent = getgrnam(string)) != NULL) 1094 if (flag == GID && (grp_ent = getgrnam(string)) != NULL)
@@ -1197,7 +1203,8 @@ static void dir_operation(int type, const char * dir_name, int var, unsigned lon
1197 struct dirent *de; 1203 struct dirent *de;
1198 char *path; 1204 char *path;
1199 1205
1200 if ((dp = warn_opendir(dir_name)) == NULL) 1206 dp = warn_opendir(dir_name);
1207 if (dp == NULL)
1201 return; 1208 return;
1202 1209
1203 while ((de = readdir(dp)) != NULL) { 1210 while ((de = readdir(dp)) != NULL) {
@@ -1581,7 +1588,8 @@ int st_expr_expand(char *output, unsigned int length, const char *input,
1581 ch = input[1]; 1588 ch = input[1];
1582 if (isspace(ch) ||(ch == '/') ||(ch == '\0')) { 1589 if (isspace(ch) ||(ch == '/') ||(ch == '\0')) {
1583 /* User's own home directory: leave separator for next time */ 1590 /* User's own home directory: leave separator for next time */
1584 if ((env = getenv("HOME")) == NULL) { 1591 env = getenv("HOME");
1592 if (env == NULL) {
1585 info_logger(LOG_INFO, bb_msg_variable_not_found, "HOME"); 1593 info_logger(LOG_INFO, bb_msg_variable_not_found, "HOME");
1586 return FALSE; 1594 return FALSE;
1587 } 1595 }
@@ -1600,7 +1608,8 @@ int st_expr_expand(char *output, unsigned int length, const char *input,
1600 goto st_expr_expand_out; 1608 goto st_expr_expand_out;
1601 safe_memcpy(tmp, input, len); 1609 safe_memcpy(tmp, input, len);
1602 input = ptr - 1; 1610 input = ptr - 1;
1603 if ((pwent = getpwnam(tmp)) == NULL) { 1611 pwent = getpwnam(tmp);
1612 if (pwent == NULL) {
1604 info_logger(LOG_INFO, "no pwent for: %s", tmp); 1613 info_logger(LOG_INFO, "no pwent for: %s", tmp);
1605 return FALSE; 1614 return FALSE;
1606 } 1615 }
@@ -1680,7 +1689,8 @@ static const char *expand_variable(char *buffer, unsigned int length,
1680 1689
1681 safe_memcpy(tmp, input, len); 1690 safe_memcpy(tmp, input, len);
1682 input = ptr - 1; 1691 input = ptr - 1;
1683 if ((env = get_variable_v2(tmp, func, info)) == NULL) { 1692 env = get_variable_v2(tmp, func, info);
1693 if (env == NULL) {
1684 info_logger(LOG_INFO, bb_msg_variable_not_found, tmp); 1694 info_logger(LOG_INFO, bb_msg_variable_not_found, tmp);
1685 return NULL; 1695 return NULL;
1686 } 1696 }
@@ -1740,7 +1750,8 @@ static const char *expand_variable(char *buffer, unsigned int length,
1740 } 1750 }
1741 --ptr; 1751 --ptr;
1742 /* At this point ptr should point to closing brace of "${var:-word}" */ 1752 /* At this point ptr should point to closing brace of "${var:-word}" */
1743 if ((env = get_variable_v2(tmp, func, info)) != NULL) { 1753 env = get_variable_v2(tmp, func, info);
1754 if (env != NULL) {
1744 /* Found environment variable, so skip the input to the closing brace 1755 /* Found environment variable, so skip the input to the closing brace
1745 and return the variable */ 1756 and return the variable */
1746 input = ptr; 1757 input = ptr;
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 93b1aacb3..03a30e6e9 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -1111,7 +1111,8 @@ static void identify(uint16_t *val)
1111 /* reset result */ 1111 /* reset result */
1112 jj = val[HWRST_RSLT]; 1112 jj = val[HWRST_RSLT];
1113 if ((jj & VALID) == VALID_VAL) { 1113 if ((jj & VALID) == VALID_VAL) {
1114 if (!(oo = (jj & RST0))) 1114 oo = (jj & RST0);
1115 if (!oo)
1115 jj >>= 8; 1116 jj >>= 8;
1116 if ((jj & DEV_DET) == JUMPER_VAL) 1117 if ((jj & DEV_DET) == JUMPER_VAL)
1117 strng = " determined by the jumper"; 1118 strng = " determined by the jumper";
diff --git a/miscutils/readahead.c b/miscutils/readahead.c
index 647eb3121..7b375cfff 100644
--- a/miscutils/readahead.c
+++ b/miscutils/readahead.c
@@ -15,17 +15,15 @@
15int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 15int readahead_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
16int readahead_main(int argc, char **argv) 16int readahead_main(int argc, char **argv)
17{ 17{
18 FILE *f;
19 int retval = EXIT_SUCCESS; 18 int retval = EXIT_SUCCESS;
20 19
21 if (argc == 1) bb_show_usage(); 20 if (argc == 1) bb_show_usage();
22 21
23 while (*++argv) { 22 while (*++argv) {
24 if ((f = fopen_or_warn(*argv, "r")) != NULL) { 23 int fd = open_or_warn(*argv, O_RDONLY);
25 int r, fd=fileno(f); 24 if (fd >= 0) {
26 25 int r = readahead(fd, 0, fdlength(fd));
27 r = readahead(fd, 0, fdlength(fd)); 26 close(fd);
28 fclose(f);
29 if (r >= 0) continue; 27 if (r >= 0) continue;
30 } 28 }
31 retval = EXIT_FAILURE; 29 retval = EXIT_FAILURE;