Message ID | 52747027-2915-4c92-a6e9-b0dce1cbe198@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | common/rc: use getent when available | expand |
On Mon, Mar 10, 2025 at 12:55:51PM -0500, Eric Sandeen wrote: > Zorro noticed that on systems using nss-altfiles, some tests failed when > trying to parse /etc/passwd directly. The "getent" command does the > right thing in this case, so let's use it as long as it's available. Are the reevant systyems where it does not exist? It seems to come with glibc and apparenly has for a long time.
On 3/11/25 2:42 AM, Christoph Hellwig wrote: > On Mon, Mar 10, 2025 at 12:55:51PM -0500, Eric Sandeen wrote: >> Zorro noticed that on systems using nss-altfiles, some tests failed when >> trying to parse /etc/passwd directly. The "getent" command does the >> right thing in this case, so let's use it as long as it's available. > > Are the reevant systyems where it does not exist? It seems to come > with glibc and apparenly has for a long time. It's impossible for me to know whether any systems exist that don't have it, so I erred on the safe side to not break things for anyone. (i.e. it could depend on packaging etc, and I simply have no idea.) -Eric
On Mon, Mar 10, 2025 at 12:55:51PM -0500, Eric Sandeen wrote: > Zorro noticed that on systems using nss-altfiles, some tests failed when > trying to parse /etc/passwd directly. The "getent" command does the > right thing in this case, so let's use it as long as it's available. > > Signed-off-by: Eric Sandeen <sandeen@redhat.com> > --- Hahah, you're so fast:) This's similar with what I'm doing, so it's good to me. Reviewed-by: Zorro Lang <zlang@redhat.com> I tend to use getent too, if anyone has any better idea, please feel free to share. Thanks, Zorro > > diff --git a/common/rc b/common/rc > index 6592c835..50312331 100644 > --- a/common/rc > +++ b/common/rc > @@ -2621,7 +2621,11 @@ _yp_active() > _cat_passwd() > { > [ $(_yp_active) -eq 0 ] && ypcat passwd > - cat /etc/passwd > + if type getent &>/dev/null; then > + getent passwd > + else > + cat /etc/passwd > + fi > } > > # cat the group file > @@ -2629,7 +2633,11 @@ _cat_passwd() > _cat_group() > { > [ $(_yp_active) -eq 0 ] && ypcat group > - cat /etc/group > + if type getent &>/dev/null; then > + getent group > + else > + cat /etc/group > + fi > } > > # check if a user exists in the system > >
On Mon, Mar 10, 2025 at 12:55:51PM -0500, Eric Sandeen wrote: > Zorro noticed that on systems using nss-altfiles, some tests failed when > trying to parse /etc/passwd directly. The "getent" command does the > right thing in this case, so let's use it as long as it's available. > > Signed-off-by: Eric Sandeen <sandeen@redhat.com> > --- > > diff --git a/common/rc b/common/rc > index 6592c835..50312331 100644 > --- a/common/rc > +++ b/common/rc > @@ -2621,7 +2621,11 @@ _yp_active() > _cat_passwd() > { > [ $(_yp_active) -eq 0 ] && ypcat passwd > - cat /etc/passwd > + if type getent &>/dev/null; then If you want to be really nitpicky, 'type' isn't defined for posix shells; you're supposed to use command[1]: if command -v getent &>/dev/null; then I don't care that much since fstests is wholly dependent on bashisms so: Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> if you decide to change it or not. --D [1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html > + getent passwd > + else > + cat /etc/passwd > + fi > } > > # cat the group file > @@ -2629,7 +2633,11 @@ _cat_passwd() > _cat_group() > { > [ $(_yp_active) -eq 0 ] && ypcat group > - cat /etc/group > + if type getent &>/dev/null; then > + getent group > + else > + cat /etc/group > + fi > } > > # check if a user exists in the system > >
On 3/11/25 10:30 AM, Darrick J. Wong wrote: > On Mon, Mar 10, 2025 at 12:55:51PM -0500, Eric Sandeen wrote: >> Zorro noticed that on systems using nss-altfiles, some tests failed when >> trying to parse /etc/passwd directly. The "getent" command does the >> right thing in this case, so let's use it as long as it's available. >> >> Signed-off-by: Eric Sandeen <sandeen@redhat.com> >> --- >> >> diff --git a/common/rc b/common/rc >> index 6592c835..50312331 100644 >> --- a/common/rc >> +++ b/common/rc >> @@ -2621,7 +2621,11 @@ _yp_active() >> _cat_passwd() >> { >> [ $(_yp_active) -eq 0 ] && ypcat passwd >> - cat /etc/passwd >> + if type getent &>/dev/null; then > > If you want to be really nitpicky, 'type' isn't defined for posix > shells; you're supposed to use command[1]: > > if command -v getent &>/dev/null; then > > I don't care that much since fstests is wholly dependent on bashisms so: Yup, I started with "command -v," realized it wasn't used anywhere else in fstests, and that we always used "type" - so when in Rome, etc. > Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Thanks, -Eric > if you decide to change it or not. > > --D
diff --git a/common/rc b/common/rc index 6592c835..50312331 100644 --- a/common/rc +++ b/common/rc @@ -2621,7 +2621,11 @@ _yp_active() _cat_passwd() { [ $(_yp_active) -eq 0 ] && ypcat passwd - cat /etc/passwd + if type getent &>/dev/null; then + getent passwd + else + cat /etc/passwd + fi } # cat the group file @@ -2629,7 +2633,11 @@ _cat_passwd() _cat_group() { [ $(_yp_active) -eq 0 ] && ypcat group - cat /etc/group + if type getent &>/dev/null; then + getent group + else + cat /etc/group + fi } # check if a user exists in the system
Zorro noticed that on systems using nss-altfiles, some tests failed when trying to parse /etc/passwd directly. The "getent" command does the right thing in this case, so let's use it as long as it's available. Signed-off-by: Eric Sandeen <sandeen@redhat.com> ---