karl@??? writes:
> src/monitor gives warnings and an error:
>
> gcc -Iinclude -O2 -g -W -Wall -Wno-pointer-sign -Wno-sign-compare -Wno-implicit-fallthrough -fno-inline-functions -fno-inline-small-functions -fno-inline-functions-called-once -c -o tmp/monitor.o src/monitor.c
> src/monitor.c: In function ?dummy_handler?:
> src/monitor.c:588:27: error: parameter name omitted
> 588 | static void dummy_handler(int)
> | ^~~
This is valid C23:
The declarator in a function definition specifies the name of the
function being defined and the types (and optionally the names) of all
the parameters; the declarator also serves as a function prototype for
later calls to the same function in the same translation unit. The type
of each parameter is adjusted as described in 6.7.7.4.
[6.9.2|8]
but not valid C99:
If the declarator includes a parameter type list, the declaration of
each parameter shall include an identifier, except for the special case
of a parameter list consisting of a single parameter of type void, in
which case there shall not be an identifier. No declaration list shall
follow.
[6.9.1|5]
The advantage of omitting the name when the parameter isn't meant to be
used is that it avoids a warning about an unused parameter. But I think
this should support C99 and hence, will change it accordingly.
> src/monitor.c: In function ?send_fail?:
> src/monitor.c:346:5: warning: ignoring return value of ?write? declared with attribute ?warn_unused_result? [-Wunused-result]
> 346 | write(sk, r_msg, sizeof(r_msg));
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> src/monitor.c: In function ?send_success?:
> src/monitor.c:354:5: warning: ignoring return value of ?write? declared with attribute ?warn_unused_result? [-Wunused-result]
> 354 | write(sk, r_msg, sizeof(r_msg));
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> make: *** [Makefile:92: tmp/monitor.o] Error 1
>
[...]
> About the writes, if you really doesn't care whether they fail or not,
> what is the point of having them ?
This a write on a connected AF_UNIX stream socket (from accept) and
supposed to tell the client which connected the outcome of the requested
operation. This can only fail if the kernel is out of memory (soft brown
mass going to hit the fan real soon now) or the client
disconnected. There is no way to handle the former and the latter is not
interesting: If the client disconnected, it probably didn't want the
reply.
> If it is acceptable that they fail "sometimes", or if you "know" that
> they won't fail, you can make that clear by writing (void) write(etc.).
As someone once put it: C functions may return a value the caller might
find useful. Or not. I don't get this warning (with gcc 12.2),
otherwise' I'd have disabled it as useless noise. Which is what I'm
going to do.
Thanks for having a look at this.