As I have been working on trying to reduce files copied from musl, 
specifically those that use syscall by using the macro approach I described 
earlier, I have come across 3 files that use syscall but also use socket() 
call differently than musl.

And I think we have a problem in 2 of those.

In this commit 
https://github.com/cloudius-systems/osv/commit/c4df1043285b7597709f5199d619658909a22794,
 
Nadav copied if_nameindex.c from musl into libc/network but also changed 
socket call like this:

<       int s = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
---
>       int s = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, 0);

because AF_UNIX domain is not supported in OSv (read the commit).

Now 2 other files - if_indextoname.c, if_nametoindex.c - have socket() call 
that uses AF_UNIX which most likely (we do not have unit tests for these) 
fails:

socket(AF_UNIX, SOCK_DGRAM, 0))

So I think we should change AF_UNIX to AF_INET in those as well, right?

Also it seems these 2 files were copied from older musl and new musl adds 
protocol option  SOCK_CLOEXEC and there is no reason we should have it 
different - see this diff between OSv and musl:

DIFF: [/network/if_indextoname.c]
6c6
< #include "syscall.h"
---
> #include "unistd.h"
13c13
<       if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 
0;
---
>       if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) return 0;
16c16
<       __syscall(SYS_close, fd);
---
>       close(fd);

Finally, I think we can solve the socket call changes (AF_UNIX->AF_INET) 
with --include libc/network/socket_mod.h option where this header looks 
like so:

#include <sys/socket.h>
#undef socket
#define socket(domain,type,protocol) socket(AF_INET,type,protocol)

We should also enhance existing tests/tst-ifaddrs.cc to test if_indextoname 
and if_nametoindex.

Waldek

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/10a723ef-a02d-4f90-b20c-998c6de449b0n%40googlegroups.com.

Reply via email to