Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chown: link to chgrp in the same bin folder #133

Closed
wants to merge 1 commit into from
Closed

chown: link to chgrp in the same bin folder #133

wants to merge 1 commit into from

Conversation

skhal
Copy link

@skhal skhal commented Mar 21, 2018

chown creates a link from /usr/sbin/chown to /usr/bin/chgrp
instead of staying in the same bin-folder, e.g. /usr/sbin/chgrp.

it makes install world fail if one creates sepearate ZFS datasets
for /usr/bin and /usr/sbin -- cross-filesystem link fails.

BUG

% find /usr/src -type f -name Makefile | \
	xargs grep --color '^LINKS' | \
	grep -v '\(\(BIN\|LIB\|FILES\|SCRIPTS\)DIR\).*\1'
./usr.sbin/chown/Makefile:LINKS=        ${BINDIR}/chown /usr/bin/chgrp

@stesser
Copy link
Member

stesser commented Mar 21, 2018

Moving chgrp into /usr/sbin will break scripts that use it with a hard-coded path (/usr/bin/chgrp).

I had the same problem and have used a symbolic link to resolve it (i.e. SYMLINKS= instead of LINKS= in the Makefile).

chown creates a link from /usr/sbin/chown to /usr/bin/chgrp
instead of staying in the same bin-folder, e.g. /usr/sbin/chgrp.

it makes install world fail if one creates sepearate ZFS datasets
for /usr/bin and /usr/sbin -- cross-filesystem link fails.

BUG

% find /usr/src -type f -name Makefile | \
	xargs grep --color '^LINKS' | \
	grep -v '\(\(BIN\|LIB\|FILES\|SCRIPTS\)DIR\).*\1'
./usr.sbin/chown/Makefile:LINKS=        ${BINDIR}/chown /usr/bin/chgrp
@skhal
Copy link
Author

skhal commented Mar 21, 2018

@stesser , very good point. I updated the PR with LINKS > SYMLINKS:

To keep history clean:

  • commit is amended
  • branch re-pushed

@skhal
Copy link
Author

skhal commented Mar 21, 2018

I assume symlink may not work either as some scripts may try to resolve it or check if chgrp is an actual file.

We could simply copy the executable in this case (the executable is ~10KB):

% ( eval $(stat -s /usr/sbin/chown); echo $st_size)
10352

@stesser
Copy link
Member

stesser commented Mar 21, 2018 via email

@skhal
Copy link
Author

skhal commented Mar 21, 2018

Thanks for sharing the feedback.

The size is 10K (there is no typo). I run a FreeBSD virtual machine in VirtualBox:

% uname -a
FreeBSD freebsd.skhal.net 11.1-RELEASE FreeBSD 11.1-RELEASE #0 r321309: Fri Jul 21 02:08:28 UTC 2017     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64 

@cemeyer
Copy link
Member

cemeyer commented Mar 29, 2018

Since small size is not an object, why use a separate FS for /usr/bin and /usr/sbin? On my CURRENT system, /usr/bin is 203MB and /usr/sbin is only 19MB more. What's the compelling motivation? Thanks.

@stesser
Copy link
Member

stesser commented Mar 29, 2018 via email

@cemeyer
Copy link
Member

cemeyer commented Mar 29, 2018

Thanks. I reckon this is an unsupported "hardening" setup.

I agree the right thing for install to do if (hard)linking fails (due to cross-filesystem) is to just copy.

@cemeyer
Copy link
Member

cemeyer commented Mar 29, 2018

LINKS is executed in bsd.links.mk, using INSTALL_LINK. INSTALL_LINK is defined in own.mk as install -l h.

install -l h ... exits with 71 and prints "Cross-device link" in this situation. install -l m ("mixed") is pretty close to what we want — drop a symlink in the cross-filesystem case. But I'd instead suggest adding new modes to all of this. I'll propose a patch shortly.

@brooksdavis
Copy link
Contributor

Please don't make the install dependent on the layout at install time. The install process should be as close to deterministic as possible and IMO should resemble tar xf foo as much as possible.

@cemeyer
Copy link
Member

cemeyer commented Mar 29, 2018

Does tar attempt to handle links? I agree with "as much as possible," but am unclear on how much is possible. I am also ok just closing this out as unsupported. Another option would be to just stop using LINKS entirely for these programs, which reside in separate directories.

@cemeyer
Copy link
Member

cemeyer commented Mar 29, 2018

Here's an untested proposal: https://reviews.freebsd.org/D14897

@brooksdavis
Copy link
Contributor

tar does support hard links. I don't know how it handles crossing filesystem boundaries. We probably ought to find out if chgrp and chown are going to be in the same package...

@emaste
Copy link
Member

emaste commented Jun 2, 2021

@brooksdavis I found that both BSD tar and GNU tar fail to create the link in this case. As far as I can tell this issue existed before hard link support was added to xinstall and used by the share/mk infrastructure, so no regression. I agree though that trying a link and falling back to copy if it fails is reasonable.

@brooksdavis
Copy link
Contributor

IMO this most consistent option is to make one of them unconditionally a relative symlink. Then there's no target-dependent difference.

Given this is an extremely uncommon configuration, I'd be somewhat tempted to add a WITH(OUT)_ option to enable whatever behavior we choose rather than making it automatic. If we don't have a way to do it globally we end up with weird asymmetry depending how you populate the system.

@bsdimp
Copy link
Member

bsdimp commented Jun 23, 2021

Is there some action that can be done to move forward this pull request? @brooksdavis @emaste can we come to some conclusion about what to do? I see @cemeyer has abandoned his proposal, so that's not an option. If not, we should close this pull request.

@emaste
Copy link
Member

emaste commented Aug 4, 2021

I think @cemeyer's proposal is decent, but will need someone to push it forward.

@stesser
Copy link
Member

stesser commented Aug 4, 2021 via email

@emaste
Copy link
Member

emaste commented Apr 26, 2022

One solution might be to just use "install -lmr" instead of "ln".

It's already using install:

bsd.own.mk:

HRDLINK?=       -l h -o ${_LINKOWN} -g ${_LINKGRP} -m ${_LINKMODE}
MANHRDLINK?=    -l h -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
SYMLINK?=       -l s -o ${_SYMLINKOWN} -g ${_SYMLINKGRP} -m ${_SYMLINKMODE}
LSYMLINK?=      -l s -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE}
RSYMLINK?=      -l rs -o ${_SYMLINKOWN} -g ${_SYMLINKGRP} -m ${_SYMLINKMODE}

INSTALL_LINK?=          ${INSTALL} ${HRDLINK}
INSTALL_MANLINK?=       ${INSTALL} ${MANHRDLINK}
INSTALL_SYMLINK?=       ${INSTALL} ${SYMLINK}
INSTALL_LIBSYMLINK?=    ${INSTALL} ${LSYMLINK}
INSTALL_RSYMLINK?=      ${INSTALL} ${RSYMLINK}

bsd.links.mk:

.for s t in ${LINKS}
        ${INSTALL_LINK} ${TAG_ARGS} ${DESTDIR}${s} ${DESTDIR}${t}
.endfor
.for s t in ${SYMLINKS}
        ${INSTALL_SYMLINK} ${TAG_ARGS} ${s} ${DESTDIR}${t}
.endfor

We could either use -mr unconditionally for ${INSTALL_LINK} or add a new ${MIXEDLINKS}

LINKS= ${BINDIR}/chown /usr/bin/chgrp
MAN= chgrp.1 chown.8
PROG= chown
SYMLINKS= ${BINDIR}/chown ${BINDIR}/chgrp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd likely need to have this line as well

SYMLINKS+= ${BINDIR}/chown /usr/bin/chgrp

to ensure maximum compatibility. With that, I'd think the change would be fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it, I think the simplest thing would be to change LINKS to SYMLINKS and leave the directory where it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too bad this doesn't work.

@bsdimp
Copy link
Member

bsdimp commented Feb 8, 2023

diff --git a/usr.sbin/chown/Makefile b/usr.sbin/chown/Makefile
index b9dff0785363..8bdcb4f00d26 100644
--- a/usr.sbin/chown/Makefile
+++ b/usr.sbin/chown/Makefile
@@ -4,7 +4,7 @@
 .include <src.opts.mk>

 PROG=  chown
-LINKS= ${BINDIR}/chown /usr/bin/chgrp
+SYMLINKS= ${BINDIR}/chown ../bin/chgrp
 MAN=   chgrp.1 chown.8

 HAS_TESTS=

seems the simplest approach. Neither of these binaries is used often, especially chgrp, so the overhead of a symlink would be in the noise.

@bsdimp
Copy link
Member

bsdimp commented Feb 8, 2023

https://reviews.freebsd.org/D38456 has my take on what we should do... and if there's no consensus on this round, I'm going to close the PR.

@bsdimp
Copy link
Member

bsdimp commented Feb 27, 2023

55f35c5 has ed's suggestion. I'm closing this now. We're done.
further development of this issue should be done in new PRs (for code that's ready) or discussed elsewhere.

@bsdimp bsdimp closed this Feb 27, 2023
freebsd-git pushed a commit that referenced this pull request Feb 27, 2023
emaste suggested this in #133
and it works. It will do the right thing by default, and handle the weird
cases 133 was trying to fix.
bsdjhb pushed a commit to bsdjhb/cheribsd that referenced this pull request Mar 29, 2023
emaste suggested this in freebsd/freebsd-src#133
and it works. It will do the right thing by default, and handle the weird
cases 133 was trying to fix.
@emaste emaste added the merged label Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants