mostly style fixes

This commit is contained in:
Denis Vlasenko 2006-11-01 10:25:35 +00:00
parent 048c93cc55
commit 9225854144
12 changed files with 156 additions and 161 deletions

View File

@ -444,7 +444,7 @@ void bb_show_usage(void)
format_string = "%s\n\nUsage: %s %s\n\n"; format_string = "%s\n\nUsage: %s %s\n\n";
if (*usage_string == '\b') if (*usage_string == '\b')
format_string = "%s\n\nNo help available.\n\n"; format_string = "%s\n\nNo help available.\n\n";
fprintf (stderr, format_string, bb_msg_full_version, fprintf(stderr, format_string, bb_msg_full_version,
applet_using->name, usage_string); applet_using->name, usage_string);
} }

View File

@ -30,7 +30,7 @@ static const char * idle_string (time_t t)
if (s < 60) if (s < 60)
return "."; return ".";
if (s < (24 * 60 * 60)) { if (s < (24 * 60 * 60)) {
sprintf (str, "%02d:%02d", sprintf(str, "%02d:%02d",
(int) (s / (60 * 60)), (int) (s / (60 * 60)),
(int) ((s % (60 * 60)) / 60)); (int) ((s % (60 * 60)) / 60));
return str; return str;

View File

@ -9818,7 +9818,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
err = journal_bmap(journal, offset, &blocknr); err = journal_bmap(journal, offset, &blocknr);
if (err) { if (err) {
printf ("JBD: bad block at offset %u\n", offset); printf("JBD: bad block at offset %u\n", offset);
return err; return err;
} }
@ -9835,7 +9835,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
} }
if (!buffer_uptodate(bh)) { if (!buffer_uptodate(bh)) {
printf ("JBD: Failed to read block at offset %u\n", offset); printf("JBD: Failed to read block at offset %u\n", offset);
brelse(bh); brelse(bh);
return -EIO; return -EIO;
} }
@ -10049,7 +10049,7 @@ static int do_one_pass(journal_t *journal,
/* Recover what we can, but /* Recover what we can, but
* report failure at the end. */ * report failure at the end. */
success = err; success = err;
printf ("JBD: IO error %d recovering " printf("JBD: IO error %d recovering "
"block %ld in log\n", "block %ld in log\n",
err, io_block); err, io_block);
} else { } else {
@ -10074,7 +10074,7 @@ static int do_one_pass(journal_t *journal,
blocknr, blocknr,
journal->j_blocksize); journal->j_blocksize);
if (nbh == NULL) { if (nbh == NULL) {
printf ("JBD: Out of memory " printf("JBD: Out of memory "
"during recovery.\n"); "during recovery.\n");
err = -ENOMEM; err = -ENOMEM;
brelse(bh); brelse(bh);
@ -10153,7 +10153,7 @@ static int do_one_pass(journal_t *journal,
/* It's really bad news if different passes end up at /* It's really bad news if different passes end up at
* different places (but possible due to IO errors). */ * different places (but possible due to IO errors). */
if (info->end_transaction != next_commit_ID) { if (info->end_transaction != next_commit_ID) {
printf ("JBD: recovery pass %d ended at " printf("JBD: recovery pass %d ended at "
"transaction %u, expected %u\n", "transaction %u, expected %u\n",
pass, next_commit_ID, info->end_transaction); pass, next_commit_ID, info->end_transaction);
if (!success) if (!success)
@ -12335,15 +12335,15 @@ static int ask_yn(const char * string, int def)
int ask (e2fsck_t ctx, const char * string, int def) int ask (e2fsck_t ctx, const char * string, int def)
{ {
if (ctx->options & E2F_OPT_NO) { if (ctx->options & E2F_OPT_NO) {
printf (_("%s? no\n\n"), string); printf(_("%s? no\n\n"), string);
return 0; return 0;
} }
if (ctx->options & E2F_OPT_YES) { if (ctx->options & E2F_OPT_YES) {
printf (_("%s? yes\n\n"), string); printf(_("%s? yes\n\n"), string);
return 1; return 1;
} }
if (ctx->options & E2F_OPT_PREEN) { if (ctx->options & E2F_OPT_PREEN) {
printf ("%s? %s\n\n", string, def ? _("yes") : _("no")); printf("%s? %s\n\n", string, def ? _("yes") : _("no"));
return def; return def;
} }
return ask_yn(string, def); return ask_yn(string, def);
@ -12606,26 +12606,26 @@ static void show_stats(e2fsck_t ctx)
blocks_used, blocks); blocks_used, blocks);
return; return;
} }
printf ("\n%8d inode%s used (%d%%)\n", P_E2("", "s", inodes_used), printf("\n%8d inode%s used (%d%%)\n", P_E2("", "s", inodes_used),
100 * inodes_used / inodes); 100 * inodes_used / inodes);
printf ("%8d non-contiguous inode%s (%0d.%d%%)\n", printf("%8d non-contiguous inode%s (%0d.%d%%)\n",
P_E2("", "s", ctx->fs_fragmented), P_E2("", "s", ctx->fs_fragmented),
frag_percent / 10, frag_percent % 10); frag_percent / 10, frag_percent % 10);
printf (_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"), printf(_(" # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count); ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
printf ("%8d block%s used (%d%%)\n", P_E2("", "s", blocks_used), printf("%8d block%s used (%d%%)\n", P_E2("", "s", blocks_used),
(int) ((long long) 100 * blocks_used / blocks)); (int) ((long long) 100 * blocks_used / blocks));
printf ("%8d large file%s\n", P_E2("", "s", ctx->large_files)); printf("%8d large file%s\n", P_E2("", "s", ctx->large_files));
printf ("\n%8d regular file%s\n", P_E2("", "s", ctx->fs_regular_count)); printf("\n%8d regular file%s\n", P_E2("", "s", ctx->fs_regular_count));
printf ("%8d director%s\n", P_E2("y", "ies", ctx->fs_directory_count)); printf("%8d director%s\n", P_E2("y", "ies", ctx->fs_directory_count));
printf ("%8d character device file%s\n", P_E2("", "s", ctx->fs_chardev_count)); printf("%8d character device file%s\n", P_E2("", "s", ctx->fs_chardev_count));
printf ("%8d block device file%s\n", P_E2("", "s", ctx->fs_blockdev_count)); printf("%8d block device file%s\n", P_E2("", "s", ctx->fs_blockdev_count));
printf ("%8d fifo%s\n", P_E2("", "s", ctx->fs_fifo_count)); printf("%8d fifo%s\n", P_E2("", "s", ctx->fs_fifo_count));
printf ("%8d link%s\n", P_E2("", "s", ctx->fs_links_count - dir_links)); printf("%8d link%s\n", P_E2("", "s", ctx->fs_links_count - dir_links));
printf ("%8d symbolic link%s", P_E2("", "s", ctx->fs_symlinks_count)); printf("%8d symbolic link%s", P_E2("", "s", ctx->fs_symlinks_count));
printf (" (%d fast symbolic link%s)\n", P_E2("", "s", ctx->fs_fast_symlinks_count)); printf(" (%d fast symbolic link%s)\n", P_E2("", "s", ctx->fs_fast_symlinks_count));
printf ("%8d socket%s--------\n\n", P_E2("", "s", ctx->fs_sockets_count)); printf("%8d socket%s--------\n\n", P_E2("", "s", ctx->fs_sockets_count));
printf ("%8d file%s\n", P_E2("", "s", ctx->fs_total_count - dir_links)); printf("%8d file%s\n", P_E2("", "s", ctx->fs_total_count - dir_links));
} }
static void check_mount(e2fsck_t ctx) static void check_mount(e2fsck_t ctx)
@ -12663,7 +12663,7 @@ static void check_mount(e2fsck_t ctx)
"SEVERE filesystem damage.\007\007\007\n\n")); "SEVERE filesystem damage.\007\007\007\n\n"));
cont = ask_yn(_("Do you really want to continue"), -1); cont = ask_yn(_("Do you really want to continue"), -1);
if (!cont) { if (!cont) {
printf (_("check aborted.\n")); printf(_("check aborted.\n"));
exit (0); exit (0);
} }
return; return;

View File

@ -23,5 +23,5 @@ void print_fs_state(FILE *f, unsigned short state)
{ {
fprintf(f, (state & EXT2_VALID_FS ? " clean" : " not clean")); fprintf(f, (state & EXT2_VALID_FS ? " clean" : " not clean"));
if (state & EXT2_ERROR_FS) if (state & EXT2_ERROR_FS)
fprintf (f, " with errors"); fprintf(f, " with errors");
} }

View File

@ -56,20 +56,20 @@ typedef int (*action_fp)(const char *fileName, struct stat *statbuf, void *);
typedef struct { typedef struct {
action_fp f; action_fp f;
} action; } action;
#define SACT(name, arg...) typedef struct { action a; arg; } action_##name; #define ACTS(name, arg...) typedef struct { action a; arg; } action_##name;
#define SFUNC(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap) #define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
SACT(print) ACTS(print)
SACT(name, char *pattern;) ACTS(name, char *pattern;)
USE_FEATURE_FIND_PRINT0(SACT(print0)) USE_FEATURE_FIND_PRINT0(ACTS(print0))
USE_FEATURE_FIND_TYPE( SACT(type, int type_mask;)) USE_FEATURE_FIND_TYPE( ACTS(type, int type_mask;))
USE_FEATURE_FIND_PERM( SACT(perm, char perm_char; int perm_mask;)) USE_FEATURE_FIND_PERM( ACTS(perm, char perm_char; int perm_mask;))
USE_FEATURE_FIND_MTIME( SACT(mtime, char mtime_char; int mtime_days;)) USE_FEATURE_FIND_MTIME( ACTS(mtime, char mtime_char; int mtime_days;))
USE_FEATURE_FIND_MMIN( SACT(mmin, char mmin_char; int mmin_mins;)) USE_FEATURE_FIND_MMIN( ACTS(mmin, char mmin_char; int mmin_mins;))
USE_FEATURE_FIND_NEWER( SACT(newer, time_t newer_mtime;)) USE_FEATURE_FIND_NEWER( ACTS(newer, time_t newer_mtime;))
USE_FEATURE_FIND_INUM( SACT(inum, ino_t inode_num;)) USE_FEATURE_FIND_INUM( ACTS(inum, ino_t inode_num;))
USE_FEATURE_FIND_EXEC( SACT(exec, char **exec_argv; int *subst_count; int exec_argc;)) USE_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; int *subst_count; int exec_argc;))
USE_DESKTOP( SACT(paren, action ***subexpr;)) USE_DESKTOP( ACTS(paren, action ***subexpr;))
USE_DESKTOP( SACT(prune)) USE_DESKTOP( ACTS(prune))
static action ***actions; static action ***actions;
static int need_print = 1; static int need_print = 1;
@ -131,7 +131,7 @@ static int exec_actions(action ***appp, const char *fileName, struct stat *statb
} }
SFUNC(name) ACTF(name)
{ {
const char *tmp = strrchr(fileName, '/'); const char *tmp = strrchr(fileName, '/');
if (tmp == NULL) if (tmp == NULL)
@ -141,13 +141,13 @@ SFUNC(name)
return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0; return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0;
} }
#if ENABLE_FEATURE_FIND_TYPE #if ENABLE_FEATURE_FIND_TYPE
SFUNC(type) ACTF(type)
{ {
return ((statbuf->st_mode & S_IFMT) == ap->type_mask); return ((statbuf->st_mode & S_IFMT) == ap->type_mask);
} }
#endif #endif
#if ENABLE_FEATURE_FIND_PERM #if ENABLE_FEATURE_FIND_PERM
SFUNC(perm) ACTF(perm)
{ {
return !((isdigit(ap->perm_char) && (statbuf->st_mode & 07777) == ap->perm_mask) return !((isdigit(ap->perm_char) && (statbuf->st_mode & 07777) == ap->perm_mask)
|| (ap->perm_char == '-' && (statbuf->st_mode & ap->perm_mask) == ap->perm_mask) || (ap->perm_char == '-' && (statbuf->st_mode & ap->perm_mask) == ap->perm_mask)
@ -155,7 +155,7 @@ SFUNC(perm)
} }
#endif #endif
#if ENABLE_FEATURE_FIND_MTIME #if ENABLE_FEATURE_FIND_MTIME
SFUNC(mtime) ACTF(mtime)
{ {
time_t file_age = time(NULL) - statbuf->st_mtime; time_t file_age = time(NULL) - statbuf->st_mtime;
time_t mtime_secs = ap->mtime_days * 24 * 60 * 60; time_t mtime_secs = ap->mtime_days * 24 * 60 * 60;
@ -166,7 +166,7 @@ SFUNC(mtime)
} }
#endif #endif
#if ENABLE_FEATURE_FIND_MMIN #if ENABLE_FEATURE_FIND_MMIN
SFUNC(mmin) ACTF(mmin)
{ {
time_t file_age = time(NULL) - statbuf->st_mtime; time_t file_age = time(NULL) - statbuf->st_mtime;
time_t mmin_secs = ap->mmin_mins * 60; time_t mmin_secs = ap->mmin_mins * 60;
@ -177,19 +177,19 @@ SFUNC(mmin)
} }
#endif #endif
#if ENABLE_FEATURE_FIND_NEWER #if ENABLE_FEATURE_FIND_NEWER
SFUNC(newer) ACTF(newer)
{ {
return (ap->newer_mtime >= statbuf->st_mtime); return (ap->newer_mtime >= statbuf->st_mtime);
} }
#endif #endif
#if ENABLE_FEATURE_FIND_INUM #if ENABLE_FEATURE_FIND_INUM
SFUNC(inum) ACTF(inum)
{ {
return (statbuf->st_ino != ap->inode_num); return (statbuf->st_ino != ap->inode_num);
} }
#endif #endif
#if ENABLE_FEATURE_FIND_EXEC #if ENABLE_FEATURE_FIND_EXEC
SFUNC(exec) ACTF(exec)
{ {
int i, rc; int i, rc;
char *argv[ap->exec_argc+1]; char *argv[ap->exec_argc+1];
@ -207,21 +207,21 @@ SFUNC(exec)
#endif #endif
#if ENABLE_FEATURE_FIND_PRINT0 #if ENABLE_FEATURE_FIND_PRINT0
SFUNC(print0) ACTF(print0)
{ {
printf("%s%c", fileName, '\0'); printf("%s%c", fileName, '\0');
return TRUE; return TRUE;
} }
#endif #endif
SFUNC(print) ACTF(print)
{ {
puts(fileName); puts(fileName);
return TRUE; return TRUE;
} }
#if ENABLE_DESKTOP #if ENABLE_DESKTOP
SFUNC(paren) ACTF(paren)
{ {
return exec_actions(ap->subexpr, fileName, statbuf); return exec_actions(ap->subexpr, fileName, statbuf);
} }
@ -231,7 +231,7 @@ SFUNC(paren)
* Example: * Example:
* find dir -name 'asm-*' -prune -o -name '*.[chS]' -print * find dir -name 'asm-*' -prune -o -name '*.[chS]' -print
*/ */
SFUNC(prune) ACTF(prune)
{ {
return SKIP; return SKIP;
} }
@ -501,6 +501,7 @@ action*** parse_params(char **argv)
int find_main(int argc, char **argv) int find_main(int argc, char **argv)
{ {
int dereference = FALSE; int dereference = FALSE;
char *arg;
char **argp; char **argp;
int i, firstopt, status = EXIT_SUCCESS; int i, firstopt, status = EXIT_SUCCESS;
@ -524,10 +525,9 @@ int find_main(int argc, char **argv)
// We implement: -follow, -xdev // We implement: -follow, -xdev
/* Process options, and replace then with -a */ /* Process options, and replace then with -a */
/* (that will be ignored by recursive parser later) */ /* (-a will be ignored by recursive parser later) */
argp = &argv[firstopt]; argp = &argv[firstopt];
while (*argp) { while ((arg = argp[0])) {
char *arg = argp[0];
if (strcmp(arg, "-follow") == 0) { if (strcmp(arg, "-follow") == 0) {
dereference = TRUE; dereference = TRUE;
argp[0] = "-a"; argp[0] = "-a";

View File

@ -107,7 +107,7 @@ int mt_main(int argc, char **argv)
case MTTELL: case MTTELL:
if (ioctl(fd, MTIOCPOS, &position) < 0) if (ioctl(fd, MTIOCPOS, &position) < 0)
bb_perror_msg_and_die("%s", file); bb_perror_msg_and_die("%s", file);
printf ("At block %d.\n", (int) position.mt_blkno); printf("At block %d.\n", (int) position.mt_blkno);
break; break;
default: default:

View File

@ -455,14 +455,14 @@ static int iproute_flush_cache(void)
char *buffer = "-1"; char *buffer = "-1";
if (flush_fd < 0) { if (flush_fd < 0) {
fprintf (stderr, "Cannot open \"%s\"\n", ROUTE_FLUSH_PATH); fprintf(stderr, "Cannot open \"%s\"\n", ROUTE_FLUSH_PATH);
return -1; return -1;
} }
len = strlen (buffer); len = strlen (buffer);
if ((write (flush_fd, (void *)buffer, len)) < len) { if ((write (flush_fd, (void *)buffer, len)) < len) {
fprintf (stderr, "Cannot flush routing cache\n"); fprintf(stderr, "Cannot flush routing cache\n");
return -1; return -1;
} }
close(flush_fd); close(flush_fd);

View File

@ -72,8 +72,7 @@ int ps_main(int argc, char **argv)
safe_strncpy(sbuf, "unknown", 7); safe_strncpy(sbuf, "unknown", 7);
} }
len = printf("%5u %-32s %s ", (unsigned)p->pid, sbuf, p->state); len = printf("%5u %-32s %s ", (unsigned)p->pid, sbuf, p->state);
} } else
else
#endif #endif
if (p->rss == 0) if (p->rss == 0)
len = printf("%5u %-8s %s ", (unsigned)p->pid, p->user, p->state); len = printf("%5u %-8s %s ", (unsigned)p->pid, p->user, p->state);

View File

@ -10,14 +10,7 @@
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <ctype.h>
#include <fcntl.h>
#include <getopt.h> #include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>
#include "busybox.h" #include "busybox.h"
/* Copied from linux/rtc.h to eliminate the kernel dependency */ /* Copied from linux/rtc.h to eliminate the kernel dependency */
@ -42,59 +35,62 @@ struct linux_rtc_time {
# endif # endif
#endif #endif
static time_t read_rtc(int utc) static int xopen_rtc(int flags)
{ {
int rtc; int rtc;
rtc = open("/dev/rtc", flags);
if (rtc < 0) {
rtc = open("/dev/misc/rtc", flags);
if (rtc < 0)
bb_perror_msg_and_die("cannot access RTC");
}
return rtc;
}
static time_t read_rtc(int utc)
{
struct tm tm; struct tm tm;
char *oldtz = 0; char *oldtz = 0;
time_t t = 0; time_t t = 0;
int rtc = xopen_rtc(O_RDONLY);
if (( rtc = open ( "/dev/rtc", O_RDONLY )) < 0 ) { memset(&tm, 0, sizeof(struct tm));
if (( rtc = open ( "/dev/misc/rtc", O_RDONLY )) < 0 ) if (ioctl(rtc, RTC_RD_TIME, &tm) < 0 )
bb_perror_msg_and_die ( "cannot access RTC" ); bb_perror_msg_and_die("cannot read time from RTC");
}
memset ( &tm, 0, sizeof( struct tm ));
if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 )
bb_perror_msg_and_die ( "cannot read time from RTC" );
tm.tm_isdst = -1; /* not known */ tm.tm_isdst = -1; /* not known */
close ( rtc ); close(rtc);
if ( utc ) { if (utc) {
oldtz = getenv ( "TZ" ); oldtz = getenv("TZ");
setenv ( "TZ", "UTC 0", 1 ); setenv("TZ", "UTC 0", 1);
tzset ( ); tzset();
} }
t = mktime ( &tm ); t = mktime(&tm);
if ( utc ) { if (utc) {
if ( oldtz ) if (oldtz)
setenv ( "TZ", oldtz, 1 ); setenv("TZ", oldtz, 1);
else else
unsetenv ( "TZ" ); unsetenv("TZ");
tzset ( ); tzset();
} }
return t; return t;
} }
static void write_rtc(time_t t, int utc) static void write_rtc(time_t t, int utc)
{ {
int rtc;
struct tm tm; struct tm tm;
int rtc = xopen_rtc(O_WRONLY);
if (( rtc = open ( "/dev/rtc", O_WRONLY )) < 0 ) { tm = *(utc ? gmtime(&t) : localtime(&t));
if (( rtc = open ( "/dev/misc/rtc", O_WRONLY )) < 0 )
bb_perror_msg_and_die ( "cannot access RTC" );
}
tm = *( utc ? gmtime ( &t ) : localtime ( &t ));
tm.tm_isdst = 0; tm.tm_isdst = 0;
if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) if (ioctl(rtc, RTC_SET_TIME, &tm) < 0)
bb_perror_msg_and_die ( "cannot set the RTC time" ); bb_perror_msg_and_die("cannot set the RTC time");
close ( rtc ); close(rtc);
} }
static int show_clock(int utc) static int show_clock(int utc)
@ -103,15 +99,15 @@ static int show_clock(int utc)
time_t t; time_t t;
RESERVE_CONFIG_BUFFER(buffer, 64); RESERVE_CONFIG_BUFFER(buffer, 64);
t = read_rtc ( utc ); t = read_rtc(utc);
ptm = localtime ( &t ); /* Sets 'tzname[]' */ ptm = localtime(&t); /* Sets 'tzname[]' */
safe_strncpy ( buffer, ctime ( &t ), 64); safe_strncpy(buffer, ctime(&t), 64);
if ( buffer [0] ) if (buffer[0])
buffer [strlen ( buffer ) - 1] = 0; buffer[strlen(buffer) - 1] = 0;
//printf ( "%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : ( ptm-> tm_isdst ? tzname [1] : tzname [0] )); //printf("%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : (ptm->tm_isdst ? tzname [1] : tzname [0]));
printf ( "%s %.6f seconds\n", buffer, 0.0 ); printf( "%s %.6f seconds\n", buffer, 0.0);
RELEASE_CONFIG_BUFFER(buffer); RELEASE_CONFIG_BUFFER(buffer);
return 0; return 0;
@ -122,10 +118,10 @@ static int to_sys_clock(int utc)
struct timeval tv = { 0, 0 }; struct timeval tv = { 0, 0 };
const struct timezone tz = { timezone/60 - 60*daylight, 0 }; const struct timezone tz = { timezone/60 - 60*daylight, 0 };
tv.tv_sec = read_rtc ( utc ); tv.tv_sec = read_rtc(utc);
if ( settimeofday ( &tv, &tz )) if (settimeofday(&tv, &tz))
bb_perror_msg_and_die ( "settimeofday() failed" ); bb_perror_msg_and_die("settimeofday() failed");
return 0; return 0;
} }
@ -135,10 +131,10 @@ static int from_sys_clock(int utc)
struct timeval tv = { 0, 0 }; struct timeval tv = { 0, 0 };
struct timezone tz = { 0, 0 }; struct timezone tz = { 0, 0 };
if ( gettimeofday ( &tv, &tz )) if (gettimeofday(&tv, &tz))
bb_perror_msg_and_die ( "gettimeofday() failed" ); bb_perror_msg_and_die("gettimeofday() failed");
write_rtc ( tv.tv_sec, utc ); write_rtc(tv.tv_sec, utc);
return 0; return 0;
} }
@ -150,25 +146,25 @@ static int from_sys_clock(int utc)
static int check_utc(void) static int check_utc(void)
{ {
int utc = 0; int utc = 0;
FILE *f = fopen ( ADJTIME_PATH, "r" ); FILE *f = fopen(ADJTIME_PATH, "r");
if ( f ) { if (f) {
RESERVE_CONFIG_BUFFER(buffer, 128); RESERVE_CONFIG_BUFFER(buffer, 128);
while ( fgets ( buffer, sizeof( buffer ), f )) { while (fgets(buffer, sizeof(buffer), f)) {
int len = strlen ( buffer ); int len = strlen(buffer);
while ( len && isspace ( buffer [len - 1] )) while (len && isspace(buffer[len - 1]))
len--; len--;
buffer [len] = 0; buffer[len] = 0;
if ( strncmp ( buffer, "UTC", 3 ) == 0 ) { if (strncmp(buffer, "UTC", 3) == 0 ) {
utc = 1; utc = 1;
break; break;
} }
} }
fclose ( f ); fclose(f);
RELEASE_CONFIG_BUFFER(buffer); RELEASE_CONFIG_BUFFER(buffer);
} }
return utc; return utc;
@ -180,13 +176,13 @@ static int check_utc(void)
#define HWCLOCK_OPT_HCTOSYS 0x08 #define HWCLOCK_OPT_HCTOSYS 0x08
#define HWCLOCK_OPT_SYSTOHC 0x10 #define HWCLOCK_OPT_SYSTOHC 0x10
int hwclock_main ( int argc, char **argv ) int hwclock_main(int argc, char **argv )
{ {
unsigned opt; unsigned opt;
int utc; int utc;
#if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS #if ENABLE_FEATURE_HWCLOCK_LONG_OPTIONS
static const struct option hwclock_long_options[] = { static const struct option hwclock_long_options[] = {
{ "localtime", 0, 0, 'l' }, { "localtime", 0, 0, 'l' },
{ "utc", 0, 0, 'u' }, { "utc", 0, 0, 'u' },
{ "show", 0, 0, 'r' }, { "show", 0, 0, 'r' },
@ -196,7 +192,6 @@ static const struct option hwclock_long_options[] = {
}; };
applet_long_options = hwclock_long_options; applet_long_options = hwclock_long_options;
#endif #endif
opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l"; opt_complementary = "?:r--ws:w--rs:s--wr:l--u:u--l";
opt = getopt32(argc, argv, "lursw"); opt = getopt32(argc, argv, "lursw");
@ -207,12 +202,12 @@ static const struct option hwclock_long_options[] = {
utc = check_utc(); utc = check_utc();
if (opt & HWCLOCK_OPT_HCTOSYS) { if (opt & HWCLOCK_OPT_HCTOSYS) {
return to_sys_clock ( utc ); return to_sys_clock(utc);
} }
else if (opt & HWCLOCK_OPT_SYSTOHC) { else if (opt & HWCLOCK_OPT_SYSTOHC) {
return from_sys_clock ( utc ); return from_sys_clock(utc);
} else { } else {
/* default HWCLOCK_OPT_SHOW */ /* default HWCLOCK_OPT_SHOW */
return show_clock ( utc ); return show_clock(utc);
} }
} }

View File

@ -44,19 +44,20 @@ static const char defaultpro[] = "/proc/profile";
int readprofile_main(int argc, char **argv) int readprofile_main(int argc, char **argv)
{ {
FILE *map; FILE *map;
const char *mapFile, *proFile, *mult=0; const char *mapFile, *proFile, *mult = 0;
unsigned long indx=1; unsigned long indx = 1;
size_t len; size_t len;
uint64_t add0=0; uint64_t add0 = 0;
unsigned int step; unsigned int step;
unsigned int *buf, total, fn_len; unsigned int *buf, total, fn_len;
unsigned long long fn_add, next_add; /* current and next address */ unsigned long long fn_add, next_add; /* current and next address */
char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */ char fn_name[S_LEN], next_name[S_LEN]; /* current and next name */
char mode[8];
int optAll=0, optInfo=0, optReset=0, optVerbose=0, optNative=0;
int optBins=0, optSub=0;
char mapline[S_LEN]; char mapline[S_LEN];
int maplineno=1; char mode[8];
int optAll = 0, optInfo = 0, optReset = 0;
int optVerbose = 0, optNative = 0;
int optBins = 0, optSub = 0;
int maplineno = 1;
int header_printed; int header_printed;
#define next (current^1) #define next (current^1)
@ -85,9 +86,9 @@ int readprofile_main(int argc, char **argv)
to_write = 1; /* sth different from sizeof(int) */ to_write = 1; /* sth different from sizeof(int) */
} }
fd = xopen(defaultpro,O_WRONLY); fd = xopen(defaultpro, O_WRONLY);
if (write(fd, &multiplier, to_write) != to_write) if (full_write(fd, &multiplier, to_write) != to_write)
bb_perror_msg_and_die("error writing %s", defaultpro); bb_perror_msg_and_die("error writing %s", defaultpro);
close(fd); close(fd);
@ -101,7 +102,7 @@ int readprofile_main(int argc, char **argv)
buf = xmalloc_open_read_close(proFile, &len); buf = xmalloc_open_read_close(proFile, &len);
if (!optNative) { if (!optNative) {
int entries = len/sizeof(*buf); int entries = len/sizeof(*buf);
int big = 0,small = 0,i; int big = 0, small = 0, i;
unsigned *p; unsigned *p;
for (p = buf+1; p < buf+entries; p++) { for (p = buf+1; p < buf+entries; p++) {
@ -135,12 +136,12 @@ int readprofile_main(int argc, char **argv)
map = xfopen(mapFile, "r"); map = xfopen(mapFile, "r");
while (fgets(mapline,S_LEN,map)) { while (fgets(mapline, S_LEN, map)) {
if (sscanf(mapline,"%llx %s %s",&fn_add,mode,fn_name) != 3) if (sscanf(mapline, "%llx %s %s", &fn_add, mode, fn_name) != 3)
bb_error_msg_and_die("%s(%i): wrong map line", bb_error_msg_and_die("%s(%i): wrong map line",
mapFile, maplineno); mapFile, maplineno);
if (!strcmp(fn_name,"_stext")) /* only elf works like this */ { if (!strcmp(fn_name, "_stext")) /* only elf works like this */ {
add0 = fn_add; add0 = fn_add;
break; break;
} }
@ -153,10 +154,10 @@ int readprofile_main(int argc, char **argv)
/* /*
* Main loop. * Main loop.
*/ */
while (fgets(mapline,S_LEN,map)) { while (fgets(mapline, S_LEN, map)) {
unsigned int this = 0; unsigned int this = 0;
if (sscanf(mapline,"%llx %s %s",&next_add,mode,next_name) != 3) if (sscanf(mapline, "%llx %s %s", &next_add, mode, next_name) != 3)
bb_error_msg_and_die("%s(%i): wrong map line", bb_error_msg_and_die("%s(%i): wrong map line",
mapFile, maplineno); mapFile, maplineno);
@ -176,10 +177,10 @@ int readprofile_main(int argc, char **argv)
while (indx < (next_add-add0)/step) { while (indx < (next_add-add0)/step) {
if (optBins && (buf[indx] || optAll)) { if (optBins && (buf[indx] || optAll)) {
if (!header_printed) { if (!header_printed) {
printf ("%s:\n", fn_name); printf("%s:\n", fn_name);
header_printed = 1; header_printed = 1;
} }
printf ("\t%"PRIx64"\t%u\n", (indx - 1)*step + add0, buf[indx]); printf("\t%"PRIx64"\t%u\n", (indx - 1)*step + add0, buf[indx]);
} }
this += buf[indx++]; this += buf[indx++];
} }
@ -187,15 +188,15 @@ int readprofile_main(int argc, char **argv)
if (optBins) { if (optBins) {
if (optVerbose || this > 0) if (optVerbose || this > 0)
printf (" total\t\t\t\t%u\n", this); printf(" total\t\t\t\t%u\n", this);
} else if ((this || optAll) && } else if ((this || optAll) &&
(fn_len = next_add-fn_add) != 0) { (fn_len = next_add-fn_add) != 0) {
if (optVerbose) if (optVerbose)
printf("%016llx %-40s %6i %8.4f\n", fn_add, printf("%016llx %-40s %6i %8.4f\n", fn_add,
fn_name,this,this/(double)fn_len); fn_name, this, this/(double)fn_len);
else else
printf("%6i %-40s %8.4f\n", printf("%6i %-40s %8.4f\n",
this,fn_name,this/(double)fn_len); this, fn_name, this/(double)fn_len);
if (optSub) { if (optSub) {
unsigned long long scan; unsigned long long scan;
@ -212,7 +213,7 @@ int readprofile_main(int argc, char **argv)
} }
fn_add = next_add; fn_add = next_add;
strcpy(fn_name,next_name); strcpy(fn_name, next_name);
maplineno++; maplineno++;
} }
@ -223,10 +224,10 @@ int readprofile_main(int argc, char **argv)
/* trailer */ /* trailer */
if (optVerbose) if (optVerbose)
printf("%016x %-40s %6i %8.4f\n", printf("%016x %-40s %6i %8.4f\n",
0,"total",total,total/(double)(fn_add-add0)); 0, "total", total, total/(double)(fn_add-add0));
else else
printf("%6i %-40s %8.4f\n", printf("%6i %-40s %8.4f\n",
total,"total",total/(double)(fn_add-add0)); total, "total", total/(double)(fn_add-add0));
fclose(map); fclose(map);
free(buf); free(buf);

View File

@ -35,7 +35,7 @@ static void delete_contents(char *directory)
struct stat st; struct stat st;
// Don't descend into other filesystems // Don't descend into other filesystems
if (lstat(directory,&st) || st.st_dev != rootdev) return; if (lstat(directory, &st) || st.st_dev != rootdev) return;
// Recursively delete the contents of directories. // Recursively delete the contents of directories.
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
@ -71,8 +71,8 @@ int switch_root_main(int argc, char *argv[])
// Parse args (-c console) // Parse args (-c console)
opt_complementary="-2"; opt_complementary = "-2";
getopt32(argc,argv,"c:",&console); getopt32(argc, argv, "c:", &console);
// Change to new root directory and verify it's a different fs. // Change to new root directory and verify it's a different fs.
@ -81,7 +81,7 @@ int switch_root_main(int argc, char *argv[])
if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) || if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) ||
st1.st_dev == st2.st_dev) st1.st_dev == st2.st_dev)
{ {
bb_error_msg_and_die("bad newroot %s",newroot); bb_error_msg_and_die("bad newroot %s", newroot);
} }
rootdev=st2.st_dev; rootdev=st2.st_dev;
@ -111,12 +111,12 @@ int switch_root_main(int argc, char *argv[])
if (console) { if (console) {
close(0); close(0);
if(open(console, O_RDWR) < 0) if(open(console, O_RDWR) < 0)
bb_error_msg_and_die("bad console '%s'",console); bb_error_msg_and_die("bad console '%s'", console);
dup2(0, 1); dup2(0, 1);
dup2(0, 2); dup2(0, 2);
} }
// Exec real init. (This is why we must be pid 1.) // Exec real init. (This is why we must be pid 1.)
execv(argv[optind],argv+optind); execv(argv[optind], argv+optind);
bb_error_msg_and_die("bad init '%s'",argv[optind]); bb_error_msg_and_die("bad init '%s'", argv[optind]);
} }