Ubic icon indicating copy to clipboard operation
Ubic copied to clipboard

Failed to change group from ... to ...: Operation not permitted (wrong $LOGNAME)

Open eserte opened this issue 8 years ago • 1 comments

The test suite fails on all my FreeBSD 11 and 12 smokers:

#   Failed test 'Ubic::Cmd logged something on start'
#   at t/cmd.t line 25.
#                   'Starting sleeping-daemon... Failed to change group from cpansand to wheel: Operation not permitted at lib/Ubic/Credentials/OS/POSIX.pm line 178.
#
# '
#     doesn't match '(?^:^Starting\ sleeping\-daemon\.\.\.\ started\ \(pid\ \d+\)\n$)'
Failed to change group from cpansand to wheel: Operation not permitted at lib/Ubic/Credentials/OS/POSIX.pm line 178.

# Looks like your test exited with 1 just after 1.
t/cmd.t ........................
Dubious, test returned 1 (wstat 256, 0x100)
Failed 8/8 subtests
(etc)

I don't see this failure on FreeBSD 9 + 10 smokers. In all cases the user "cpansand" is not member of the "wheel" group.

eserte avatar Dec 29 '17 15:12 eserte

OK, I found the issue: this happens because I use sudo su cpansand to change the user before starting the smokers etc. On FreeBSD systems it seems that sudo changes $LOGNAME, but the subsequent su does not change it, so $LOGNAME stays as root which leads to the problems.

I see two solutions:

  • use $USERNAME instead of $LOGNAME --- this one has the correct value
  • use (getpwuid($<))[0]

I would prefer the latter. In my experience getpwuid (if it's available) gives the most accurate results.

eserte avatar Dec 29 '17 15:12 eserte