diff --git a/lib/args.c b/lib/args.c index 89c82ca7736dfc020ac14cfaa976abdf37b6fd3f..f7a426809dfb8744ab5e3c0cb437df13a97be0aa 100644 --- a/lib/args.c +++ b/lib/args.c @@ -132,6 +132,7 @@ struct getoptflagstate // Use getoptflagstate to parse one command line option from argv static int gotflag(struct getoptflagstate *gof, struct opts *opt) { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, opt_dex[0]=%llu, opt_dex[1]=%llu, opt_dex[2]=%llu, fun=%s, line=%d", toys.optflags, opt->dex[0],opt->dex[1], opt->dex[2] __FILE__, __LINE__); int type; // Did we recognize this option? @@ -140,6 +141,7 @@ static int gotflag(struct getoptflagstate *gof, struct opts *opt) help_exit("Unknown option '%s'", gof->arg); } + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, opt_dex[0]=%llu, fun=%s, line=%d", toys.optflags, opt->dex[0], __FILE__, __LINE__); // Might enabling this switch off something else? if (toys.optflags & opt->dex[0]) { struct opts *clr; @@ -149,10 +151,12 @@ static int gotflag(struct getoptflagstate *gof, struct opts *opt) for (clr=gof->opts, i=1; clr; clr = clr->next, i<<=1) if (clr->arg && (i & toys.optflags & opt->dex[0])) *clr->arg = 0; toys.optflags &= ~opt->dex[0]; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, opt_dex[0]=%llu, fun=%s, line=%d", toys.optflags, opt->dex[0], __FILE__, __LINE__); } // Set flags toys.optflags |= opt->dex[1]; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, opt_dex[1]=%llu, fun=%s, line=%d", toys.optflags, opt->dex[1], __FILE__, __LINE__); gof->excludes |= opt->dex[2]; if (opt->flags&2) gof->stopearly=2; @@ -326,9 +330,11 @@ void parse_optflaglist(struct getoptflagstate *gof) // Initialize enable/disable/exclude masks and pointers to store arguments. // (This goes right to left so we need the whole list before we can start.) idx = 0; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, new_dex[0]=%llu, new_dex[1]=%llu, new_dex[2]=%llu, idx=%d, fun=%s, line=%d", toys.optflags, new->dex[0], new->dex[1], new->dex[2], idx, __FILE__, __LINE__); for (new = gof->opts; new; new = new->next) { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, new_dex[0]=%llu, new_dex[1]=%llu, new_dex[2]=%llu, idx=%d, fun=%s, line=%d", toys.optflags, new->dex[0], new->dex[1], new->dex[2], idx, __FILE__, __LINE__); unsigned long long u = 1L<dex[0], new->dex[1], new->dex[2], idx, u, __FILE__, __LINE__); if (new->c == 1) new->c = 0; new->dex[1] = u; if (new->flags & 1) gof->requires |= u; @@ -443,19 +449,24 @@ void get_optflags(void) } // Long option parsed, handle option. + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, catch_dex[0]=%llu, catch_dex[1]=%llu, catch_dex[2]=%llu, fun=%s, line=%d", toys.optflags, catch->dex[0], catch->dex[1], catch->dex[2], __FILE__, __LINE__); gotflag(&gof, catch); continue; } // Handle things that don't start with a dash. } else { - if (gof.nodash_now) toys.optflags |= FLAGS_NODASH; - else goto notflag; + if (gof.nodash_now) { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, FLAGS_NODASH=%llu, fun=%s, line=%d", toys.optflags, FLAGS_NODASH, __FILE__, __LINE__); + toys.optflags |= FLAGS_NODASH; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, FLAGS_NODASH=%llu, fun=%s, line=%d", toys.optflags, __FILE__, __LINE__); + } else goto notflag; } // At this point, we have the args part of -args. Loop through // each entry (could be -abc meaning -a -b -c) saveflags = toys.optflags; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, saveflags=%llu, fun=%s, line=%d", toys.optflags, saveflags, __FILE__, __LINE__); while (*gof.arg) { // Identify next option char. @@ -464,8 +475,10 @@ void get_optflags(void) if (!((catch->flags&4) && gof.arg[1])) break; // Handle option char (advancing past what was used) + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, catch_dex[0]=%llu, catch_dex[1]=%llu, catch_dex[2]=%llu, fun=%s, line=%d", toys.optflags, catch->dex[0], catch->dex[1], catch->dex[2], __FILE__, __LINE__); if (gotflag(&gof, catch) ) { toys.optflags = saveflags; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys_optflags=%llu, saveflags=%llu, fun=%s, line=%d", toys.optflags, saveflags, __FILE__, __LINE__); gof.arg = toys.argv[gof.argc]; goto notflag; } @@ -475,6 +488,7 @@ void get_optflags(void) // Not a flag, save value in toys.optargs[] notflag: if (gof.stopearly) gof.stopearly++; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:toys.optargs=%s, fun=%s, line=%d", toys.argv[gof.argc], __FILE__, __LINE__); toys.optargs[toys.optc++] = toys.argv[gof.argc]; } diff --git a/lib/lib.c b/lib/lib.c index 2d928df8d916c2e409720a92229c82e497e61bf3..9decddf8c42f89495b32fa2bf232128c6e2cb3d2 100644 --- a/lib/lib.c +++ b/lib/lib.c @@ -1197,6 +1197,7 @@ int human_readable_long(char *buf, unsigned long long num, int dgt, int unit, // Give 3 digit estimate + units ala 999M or 1.7T int human_readable(char *buf, unsigned long long num, int style) { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:num=%llu, style=%d, fun=%s, line=%d", num, style, __FILE__, __LINE__); return human_readable_long(buf, num, 3, 0, style); } diff --git a/main.c b/main.c index 611f19de256edf7f93763bf8b18572d0b34d2f21..12144a32cd0fc0e905d4bb6b8e37532244611a9e 100644 --- a/main.c +++ b/main.c @@ -94,6 +94,7 @@ static void toy_singleinit(struct toy_list *which, char *argv[]) } } + MY_LOCAL_LOG_WITH_TIME("ls_TEST:options=%d, NEED_OPTIONS=%lu, fun=%s, line=%d", (which->options != NULL), NEED_OPTIONS, __FILE__, __LINE__); if (NEED_OPTIONS && which->options) get_optflags(); else { toys.optargs = argv+1; diff --git a/toys.h b/toys.h index e49d9e3fc6f200fb3912979b398b1d213dd59ce4..2f041018b4f4efd0d124a0bf216566c0ffdd60a7 100644 --- a/toys.h +++ b/toys.h @@ -78,6 +78,20 @@ #include "generated/globals.h" #include "generated/tags.h" +#define MY_LOCAL_LOG_WITH_TIME(fmt, args...) \ +do { \ + FILE *file = fopen("/data/local/tmp/toybox_log.txt", "a+"); \ + struct timeval time; \ + gettimeofday(&time, NULL); \ + struct tm *local_time = localtime(&time.tv_sec); \ + if (file) { \ + if (local_time) \ + fprintf(file, "[%d-%02d-%02d %02d:%02d:%02d][%s][%d]:" fmt "\n", local_time->tm_year + 1900, \ + local_time->tm_mon + 1, local_time->tm_mday, local_time->tm_hour, local_time->tm_min, \ + local_time->tm_sec, __func__, __LINE__, ##args); \ + fclose(file); \ + } \ + } while (0) // These live in main.c struct toy_list *toy_find(char *name); diff --git a/toys/posix/ls.c b/toys/posix/ls.c index 13f916478d8f792f2e9dd565400b2ae393feb3c5..1db74027fa8775964ea73317fd3040f1f4120622 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -130,7 +130,9 @@ static int numlen(long long ll) static int print_with_h(char *s, long long value, int blocks) { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:value=%lld, blocks=%d, fun=%s, line=%d", value, blocks, __FILE__, __LINE__); if (blocks) value = (value * 1024) / TT.block_size; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:value=%lld, TT.block_size=%lld, fun=%s, line=%d", value, TT.block_size, __FILE__, __LINE__); if (FLAG(h)) return human_readable(s, value, 0); else return sprintf(s, "%lld", value); } @@ -155,11 +157,16 @@ static void entrylen(struct dirtree *dt, unsigned *len) // cheating slightly here: assuming minor is always 3 digits to avoid // tracking another column len[5] = numlen(dev_major(st->st_rdev))+5; - } else len[5] = print_with_h(tmp, st->st_size, 0); + MY_LOCAL_LOG_WITH_TIME("ls_TEST:len[5]=%u, fun=%s, line=%d", len[5], __FILE__, __LINE__); + } else { + len[5] = print_with_h(tmp, st->st_size, 0); + MY_LOCAL_LOG_WITH_TIME("ls_TEST:len[5]=%u, fun=%s, line=%d", len[5], __FILE__, __LINE__); + } } - + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(s)=%d, FLAG(Z)=%d, fun=%s, line=%d", FLAG(s), FLAG(Z), __FILE__, __LINE__); len[6] = FLAG(s) ? print_with_h(tmp, st->st_blocks, 1) : 0; len[7] = FLAG(Z) ? strwidth((char *)dt->extra) : 0; + MY_LOCAL_LOG_WITH_TIME("ls_TEST:len[6]=%u, len[7]=%u, fun=%s, line=%d", len[6], len[7], __FILE__, __LINE__); } // Perform one or more comparisons on a pair of files. @@ -285,14 +292,17 @@ static int filter(struct dirtree *new) return 0; } + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, toys.optflags=%llu, FLAG_Z=%llu, CFG_TOYBOX_LSM_NONE=%d, fun=%s, line=%d", FLAG(Z), toys.optflags, FLAG_Z, CFG_TOYBOX_LSM_NONE, __FILE__, __LINE__); + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, new_extra=%s, fun=%s, line=%d", FLAG(Z), (char *)new->extra, __FILE__, __LINE__); if (FLAG(Z)) { if (!CFG_TOYBOX_LSM_NONE) { // Linux doesn't support fgetxattr(2) on O_PATH file descriptors (though // bionic works around that), and there are no *xattrat(2) calls, so we // just use lgetxattr(2). char *path = dirtree_path(new, 0); - + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, new_extra=%s, fun=%s, line=%d", FLAG(Z), (char *)new->extra, __FILE__, __LINE__); (FLAG(L) ? lsm_get_context : lsm_lget_context)(path,(char **)&new->extra); + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, new_extra=%s, fun=%s, line=%d", FLAG(Z), (char *)new->extra, __FILE__, __LINE__); free(path); } if (CFG_TOYBOX_LSM_NONE || !new->extra) new->extra = (long)xstrdup("?"); @@ -386,7 +396,6 @@ static void listfiles(int dirfd, struct dirtree *indir) memset(totals, 0, sizeof(totals)); memset(len, 0, sizeof(len)); - // Top level directory was already populated by main() if (!indir->parent) { // Silently descend into single directory listed by itself on command line. @@ -394,7 +403,7 @@ static void listfiles(int dirfd, struct dirtree *indir) dt = indir->child; if (dt && S_ISDIR(dt->st.st_mode) && !dt->next && !(FLAG(d)||FLAG(R))) { listfiles(open(dt->name, 0), TT.singledir = dt); - + return; } @@ -438,7 +447,9 @@ static void listfiles(int dirfd, struct dirtree *indir) totpad = totals[1]+!!totals[1]+totals[6]+!!totals[6]+totals[7]+!!totals[7]; if ((FLAG(h)||FLAG(l)||FLAG(o)||FLAG(n)||FLAG(g)||FLAG(s)) && indir->parent) { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:tmp=%s, blocks=%lu, fun=%s, line=%d", tmp, blocks, __FILE__, __LINE__); print_with_h(tmp, blocks, 1); + MY_LOCAL_LOG_WITH_TIME("ls_TEST:total=%s, blocks=%lu, fun=%s, line=%d", tmp, blocks, __FILE__, __LINE__); xprintf("total %s\n", tmp); } } @@ -491,6 +502,7 @@ static void listfiles(int dirfd, struct dirtree *indir) // Handle padding and wrapping for display purposes entrylen(dt, len); + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, totals[7]=%d, extra=%s fun=%s, line=%d", FLAG(Z), (int)totals[7], (char *)dt->extra, __FILE__, __LINE__); if (ul) { if (FLAG(m)) xputc(','); if (FLAG(C)||FLAG(x)) { @@ -540,6 +552,8 @@ static void listfiles(int dirfd, struct dirtree *indir) crunch_qb); } } + + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, extra=%s, fun=%s, line=%d", FLAG(Z), (char *)dt->extra, __FILE__, __LINE__); if (FLAG(Z)) printf(" %-*s "+!FLAG(l), -(int)totals[7], (char *)dt->extra); if (FLAG(l)||FLAG(o)||FLAG(n)||FLAG(g)) { @@ -550,6 +564,7 @@ static void listfiles(int dirfd, struct dirtree *indir) printf("% *d,% 4d", totals[5]-4, dev_major(st->st_rdev), dev_minor(st->st_rdev)); else { + MY_LOCAL_LOG_WITH_TIME("ls_TEST:tmp=%s, st_size=%llu, fun=%s, line=%d", tmp, st->st_size, __FILE__, __LINE__); print_with_h(tmp, st->st_size, 0); zprint(zap, "s", totals[5]+1, (unsigned long)tmp); } @@ -613,7 +628,7 @@ void ls_main(void) { char **s, *noargs[] = {".", 0}; struct dirtree *dt; - + MY_LOCAL_LOG_WITH_TIME("ls_TEST:FLAG(Z)=%d, toys.optflags=%llu, FLAG_Z=%llu, CFG_TOYBOX_LSM_NONE=%d, fun=%s, line=%d", FLAG(Z), toys.optflags, FLAG_Z, CFG_TOYBOX_LSM_NONE, __FILE__, __LINE__); if (FLAG(full_time)) { toys.optflags |= FLAG_l; TT.l = 2;