<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 1, 2021 at 9:29 AM Rob Landley <<a href="mailto:rob@landley.net">rob@landley.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 6/30/21 6:57 PM, enh via Toybox wrote:<br>
> (Based on someone else's patch.)<br>
> <br>
> Implementing -F with inotify is a lot more work (including more<br>
> portability shims for macOS), so this is a simpler polling<br>
> implementation.<br>
> <br>
> Also fix my earlier mistake where xnotify_add() wasn't actually an 'x'<br>
> function that exits on failure.<br>
<br>
Applied, but:<br>
<br>
struct follow_file {<br>
  char *path;<br>
  int fd;<br>
  dev_t dev;<br>
  ino_t ino;<br>
};<br>
<br>
GLOBALS(<br>
  long n, c, s;<br>
  int file_no, last_fd;<br>
  struct xnotify *not;<br>
  struct follow_file *F;<br>
)<br>
<br>
Means that generated/globals.h has a pointer to an incomplete type, which the<br>
compiler allows (the union member is a pointer and it knows the size of that<br>
regardless what it points to) but makes me uncomfortable.<br>
<br>
What you're doing works, but possibly not for the _reason_ you think it does?<br>
Specifically, this patch has a structure defined before the GLOBALS() block and<br>
another defined after, and they might as well both be defined after because the<br>
one defined before GLOBALS() doesn't wind up in the header everything else<br>
includes, nor is it used to calculate the size of the union. So splitting them<br>
serves no purpose but _looks_ like it does.<br>
<br>
In toysh I'm doing the equivalent of:<br>
<br>
GLOBALS(<br>
  long n, c, s;<br>
  int file_no, last_fd;<br>
  struct xnotify *not;<br>
  struct tail_follow_file {<br>
    char *path;<br>
    int fd;<br>
    dev_t dev;<br>
    ino_t ino;<br>
  } *F;<br>
)<br>
<br>
Which is also a little awkward (nested structure definitions wind up in a global<br>
namespace, type prefixed with command name to avoid collisions in said global<br>
namespace...), but doing that allows me to embed instances of instructures and<br>
not just pointers to them. Elsewhere I've had the global one be a void * and<br>
typecast it on use, which is differntly awkward. This third way isn't<br>
necessarily MORE awkward, but I dislike having 3 ways to do the same thing in<br>
play in the same codebase.<br>
<br>
This is mostly a "code style" thing, I need to work out the preferred style for<br>
dealing with the context switch, and document the issue. (The compiler is<br>
forgiving, but I don't want to confuse people reading the code...)<br></blockquote><div><br></div><div>yeah, i did scratch my head about that one for a bit before deciding to punt the problem to you :-)</div><div><br></div><div>pointer to an incomplete type seemed better than void* but, yeah, moving the struct definition below GLOBALS would have been more in keeping with the rest of the tree.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Rob<br>
</blockquote></div></div>