Projeto-Pindorama / heirloom-ng

A collection of standard Unix utilities that is intended to provide maximum compatibility with traditional Unix while incorporating additional features necessary today.
http://heirloom-ng.pindorama.net.br
Other
28 stars 7 forks source link

feat: Made a GNU-like behavior readlink that support multiple files as input #23

Closed takusuman closed 1 year ago

takusuman commented 1 year ago

"Pinging" all the contributors: @tch69 @arthurbacci @mamccollum

What do you think? Can it enter the main source tree?

Just to clarify: now we have two variants of the readlink command, one that goes to UCBBIN and behaves exactly like original OpenBSD's, and one that goes to DEFBIN and behaves more like the GNU implementation (which is mimicked by toybox and probably others), what means that it supports multiple files as input.

This may be useful for Shell scripting compatibility, mostly because folks doesn't usually follow the "system call kiosk" way that readlink was originally designed. For example, while it would be more correct to write:

for file in /proc/self/fd/*; do
  readlink -f "$file"
done

It is usually done this:

readlink -f /proc/self/fd/*

EDIT: By the way, I hope I'm not breaking any of McCollum's hacks on OpenBSD compatibility.

mamccollum commented 1 year ago

Both readlink binaries compile on OpenBSD 7.1 (in spite of some of the other issues I've yet to fix) and Ubuntu Lunar Lobster/23.04. They also appear to have expected behavior (UCB not taking more than one file while GNU does) and neither have any issues from what I can tell. I say it looks good to me.

takusuman commented 1 year ago

Both readlink binaries compile on OpenBSD 7.1

Well, that was my doubt in the first place, thanks.

Still, it has a bug (and the code's looking terrible too, because of the preprocessor hacks): some files aren't printed on the screen, even with the -f option. For instance, there's a comparison between toybox's readlink and Heirloom NG's:

luiz@S145:/tmp% ls -l /proc/self/fd/*
/proc/self/fd/10: No such file or directory
/proc/self/fd/3: No such file or directory
lrwx------   1 luiz     luiz          64 Apr 11 16:16 /proc/self/fd/0 -> /dev/pts/4
lrwx------   1 luiz     luiz          64 Apr 11 16:16 /proc/self/fd/1 -> /dev/pts/4
lrwx------   1 luiz     luiz          64 Apr 11 16:16 /proc/self/fd/2 -> /dev/pts/4
luiz@S145:/tmp% ./toybox-x86_64 readlink -f /proc/self/fd/*              
/dev/pts/4
/dev/pts/4
/proc/9943/fd/10
/dev/pts/4
/proc/9943/fd/3
luiz@S145:/tmp% ./heirloom-toolchest/readlink/readlink -f /proc/self/fd/* 
/dev/pts/4
/dev/pts/4

Beside this, I'll be pushing into master, since this branch is only about the implementation. If there's any idea of fix, you can push into a new branch called "readlink-fix" or anything like that.