New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add libxo support to du #1145
Add libxo support to du #1145
Conversation
usr.bin/du/du.c
Outdated
|
||
#define SI_OPT (CHAR_MAX + 1) | ||
|
||
#define UNITS_2 1 | ||
#define UNITS_2 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems gratuitous.
usr.bin/du/du.c
Outdated
@@ -62,7 +63,7 @@ struct ignentry { | |||
|
|||
static int linkchk(FTSENT *); | |||
static void usage(void); | |||
static void prthumanval(int64_t); | |||
static void prthumanval(const char*, int64_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FreeBSD's style is const char *
with a space after the char.
@@ -273,15 +280,17 @@ main(int argc, char *argv[]) | |||
if (p->fts_level <= depth && threshold <= | |||
threshold_sign * howmany(p->fts_bignum * | |||
cblocksize, blocksize)) { | |||
xo_open_instance("paths"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unless I'm missing something, and maybe I am, why are we opening this twice? Here and at line 263?
@@ -309,36 +318,40 @@ main(int argc, char *argv[]) | |||
howmany(p->fts_statp->st_blocks, cblocksize); | |||
|
|||
if (aflag || p->fts_level == 0) { | |||
xo_open_instance("paths"); | |||
if (hflag > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question.
usr.bin/du/du.c
Outdated
/* Malloc one if we have to. */ | ||
le = malloc(sizeof(struct links_entry)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good change, but it's gratuitous since you're not changing adjacent lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two minor nits that I see, and either a double push of paths, or something that I don't understand.
I've updated the pull request to address the style issues. The two xo_open_instance("paths") calls happen in two different code paths during the filesystem traversal. One path is taken if you are reporting on a file and one path if you are reporting on a directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I had left these comments last week, but apparently failed to click submit. :(
usr.bin/du/du.c
Outdated
@@ -107,6 +108,10 @@ main(int argc, char *argv[]) | |||
depth = INT_MAX; | |||
SLIST_INIT(&ignores); | |||
|
|||
argc = xo_parse_args(argc, argv); | |||
if (argc < 0) | |||
exit(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be more consistent to use EX_USAGE
like usage() does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an in tree example of what you would like to see here? I'm trying to be consistent and all of the examples I'm finding just exit in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant, this line should be exit(EX_USAGE)
. It's unusual to exit with status -1.
usr.bin/du/du.c
Outdated
/* Malloc one if we have to. */ | ||
le = malloc(sizeof(struct links_entry)); | ||
} | ||
if (le == NULL) { | ||
stop_allocating = 1; | ||
warnx("No more memory for tracking hard links"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some warnx() calls were not converted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using df as a template. It didn't look like they converted the warnx on malloc failures. Does xo_warnx allocate? I figured it might and that is why df does it the way it does, but maybe I should check for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default I believe that xo_warnx() etc. just output unstructured data to standard error, and they don't appear to allocate memory. (And libxo will print an error if it hits an internal memory allocation failure.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In tree examples seem somewhat inconsistent here so I don't have any issues converting the rest of the calls.
usr.bin/du/du.c
Outdated
savednumber * cblocksize, blocksize)); | ||
} | ||
} | ||
|
||
ignoreclean(); | ||
xo_close_container("disk-usage-information"); | ||
xo_finish(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not very consistent about it in the tree yet, but we should check for errors from xo_finish():
if (xo_finish() < 0)
xo_err(1, "stdout");
@@ -488,13 +502,13 @@ prthumanval(int64_t bytes) | |||
|
|||
humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE, flags); | |||
|
|||
(void)printf("%4s", buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The width of the string here is coupled with the size of buf
, so this change isn't quite right. Should we instead have the caller pass a buffer to prthumanval()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this PR changes the behavior here. It changes from printf("%4s", buf) to an xo_emit with a format string that also always uses "%4s". There might be an issue here, but if so I think it is pre-existing.
Convert du to use libxo enabling structured output. Signed-off-by: Nathan Huff <nhuff@acm.org>
I've updated the pull request to address most of the comments from @markjdb. I didn't address the last comment since I don't think the behavior differs from the current implementation in any relevant way. |
my eyeballs say that this is ready. Will run some tests and either give feedback or push. |
savednumber * cblocksize, blocksize)); | ||
} | ||
} | ||
|
||
ignoreclean(); | ||
xo_close_container("disk-usage-information"); | ||
if(xo_finish() <0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why this wasn't flagged with the style checker. if space ( and there needs to be a space after <.
if (hflag > 0) { | ||
prthumanval(p->fts_bignum); | ||
(void)printf("\t%s\n", p->fts_path); | ||
prthumanval("{:blocks/%4s}",p->fts_bignum); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs a space after the comma.
|
||
if (cflag) { | ||
if (hflag > 0) { | ||
prthumanval(savednumber); | ||
(void)printf("\ttotal\n"); | ||
prthumanval("{:total-blocks/%4s}\ttotal\n",savednumber); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also needs a space before saved number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the style issues tagged.
this looks like it will work... and spot checking shows that it does. Just a couple style issue to fix. |
Convert du to use libxo enabling structured output. [[ minor style fixes by imp ]] Signed-off-by: Nathan Huff <nhuff@acm.org> Reviewed by: imp Pull Request: #1145
On second thought, the style issues were relatively minor and easy to fix while staging. |
Convert du to use libxo enabling structured output.
Signed-off-by: Nathan Huff nhuff@acm.org