[uclibc-ng-devel] about "implement fexecve from glibc"

Yann Sionneau ysionneau at kalray.eu
Wed Nov 6 11:27:09 CET 2019


Hello,

About 
https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/commit/?id=858ffad217076227089cc17eb832db0bd1497792

I'm not sure why exactly sizeof(int)*3 in the following line:

char buf[sizeof "/proc/self/fd/" + sizeof (int) * 3];

IIUC, this is supposed to give room for the ascii decimal representation 
of the file descriptor number.

Maybe we could read the max file descriptor number configured in the 
kernel from "/proc/sys/fs/file-max" (or "/proc/sys/file-max" for old 
systems?).

So:

1/ fopen("/proc/sys/fs/file-max", "r");

2/ fscanf(fp, "%d", &fdmax);

3/ fdmax_length = log10(fdmax);

Then use fdmax_length

Or, much simpler: take for granted that fd is always an int, and thus 
max 32 bits, and hard code that max "string length" of a file descriptor 
is 10 chars.

But in any case maybe add a comment on top of the line to explain the 
"magic number".

Cheers!

-- 

Yann



More information about the devel mailing list