Strange behavier of "getgroups" - linux

I'm working on a little learning project,need to call "getgroups(int gidsetsize, gid_t grouplist[])"
I'v got "0" result of an id should have a list.
while checking all possibilities,I found out the user's group must not be "0",or the function won't return none 0 result.
but i'm only meet this problem on my own computer which running archlinux.
I checked virtual machine which use manjaro or ubuntu,none of them has the problem ,
a co-league has an vps which use arch too do not has the problem.
arch bbs replied "the gid of user should not be 0",but it couldn't explain why my machine is the only one has the problem.
I'v compared id output before the post.
Only the physical machine give me NULL list,and the strace output is different
my machine result
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
getgroups(0, NULL) = 0
getgroups(0, []) = 0
newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=359, ...}, 0) = 0
other machine's the first getgroups will return none 0 result,and then,the 2nd will use the result as the 1st para to get a list.
I couldn't find the difference by myself.
The ubuntu vm result
getgroups(0, NULL) = 7
getgroups(7, [0, 4, 24, 27, 30, 46, 110]) = 7
"id" command only return the none zero result to get "self" result but not other's because of different execution branch.
Tried edit the user's gid to none 0,after reboot,the result going to normal
Change gid back to 0 again,after reboot,the result is NULL again.
Might be something about user namespace?
Any suggestions?
edit,more info:
Seems the problem is related to "WHO IS THE FATHER".
When the process is child(or grand child etc.) of
/usr/lib/systemd/systemd --user
getgroups will give bad result.
When not(running on i3wm ,the process has no father)the result is good

following the trace of systemd,arch bbs give me this.
User service not running with supplementary groups
------------EDIT---------------
It's not the same problem,possible another bug.

Related

ERROR: GETH_NEWDATE: Strange length for ODATE: 20

While setting up the WPS for WRF, i getting the following error while running the file metgrid.exe.
Processing domain 1 of 1
ERROR: GETH_NEWDATE: Strange length for ODATE: 20
application called MPI_Abort(MPI_COMM_WORLD, 0) - process 0
Had this same problem, and realized it was caused by either and extra or missing quote on start_date or end_date in namelist.wps.

DPI aware screen capture

I used AutoIt's _ScreenCapture_Capture() before without any trouble. But on Windows 10 with a 4k resolution screen I'm using DPI scaling at 200%. _ScreenCapture_capture() now gets something 2x zoomed in and half the location I asked for.
For instance :
_ScreenCapture_Capture("c:\a.bmp", 100, 100, 200, 200)
; Path, X1, Y1, X2, Y2
Does not return a 100x100 pixel square of the screen (at 100,100 to 200,200). It returns a 100x100 pixel square (at 50,50 to 100,100) instead.
I did find a solution :
DllCall("User32.dll", "bool", "SetProcessDPIAware")
However this screws up the GUI looks. So I then found this code:
GUISetFont(8.5 * _GDIPlus_GraphicsGetDPIRatio()[0])
Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
Local $aResults[2] = [1, 1]
_GDIPlus_Startup()
Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
If #error Then Return SetError(1, #extended, $aResults)
#forcedef $__g_hGDIPDll, $ghGDIPDll
$aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
If #error Then Return SetError(2, #extended, $aResults)
Local $iDPI = $aResult[2]
Local $aresults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
_GDIPlus_GraphicsDispose($hGfx)
_GDIPlus_Shutdown()
Return $aresults
EndFunc ;==>_GDIPlus_GraphicsGetDPIRatio
Which works great for the GUI but doesn't help for _ScreenCapture_Capture() calls. Seems I can either have a good looking- or a functioning program, not both.
How could I combine these two solutions to get both a good GUI and a functioning program? If I knew how to do the opposite of :
DllCall("User32.dll", "bool", "SetProcessDPIAware")
Then when I need to capture a screen portion I could turn on compatibility, then immediately turn it off when done capturing. But I don't know how to 'UNsetprocessdpiaware'.
If you are using Windows 10 A update (10.0.14393) you can spin up a separate thread and make the thread alone Per Monitor DPI aware, and leave your main GUI as dpi unaware.
See
SetThreadDpiAwarenessContext function
If you are building using a version of visual studio before 2015 you can declare a pointer to the function prototype
DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext(
_In_ DPI_AWARENESS_CONTEXT dpiContext
);
and use GetProcAddress to test for the presence of the function before you call it. Anything in that thread will give you raw physical information if you used
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
Note that this function is not available on Windows 10 10.0.10586. You must test for its availability.

Could it be that users are added/removed in the background from /etc/passwd?

from pwd import getpwuid
getpwuid(48).pw_name
This Python program prints apache 99% of the time. 48 is the id that appears in /etc/passwd for the apache user. Without any apparent reason, Python sometimes prints the error:
KeyError: 'getpwuid(): uid not found: 48'
I need to understand why this happen sometimes. Can the apache user be removed from the file for some reason?
Here is the CPython 2.7 source code for the pwd module, particularly the getpwuid() call: https://github.com/python/cpython/blob/2.7/Modules/pwdmodule.c#L114 It looks like a wrapper around the system getpwuid call with not very much code - Python doesn't read from /etc/passwd directly.
Here's a current Ubuntu manpage (you didn't mention any particular OS) for (3) getpwuid: http://manpages.ubuntu.com/manpages/wily/man3/getpwuid.3posix.html which includes:
ERRORS
The getpwuid() and getpwuid_r() functions may fail if:
EIO An I/O error has occurred.
EINTR A signal was caught during getpwuid().
EMFILE {OPEN_MAX} file descriptors are currently open in the calling
process.
ENFILE The maximum allowable number of files is currently open in the
system.
Since you haven't mentioned any user management processes which might be regenerating your user accounts, I'm going to answer that no, apache doesn't get removed from /etc/passwd, but your webserver does hit some heavy IO or too many open files condition where reading /etc/passwd becomes impossible.
That’s a very interesting phenomenon (and a great question) but I doubt that Apache is being removed from your /etc/passwd file.
On a GNU/Linux system, there are a number of different authentication mechanisms that can be used. In modern systems, the Name Service Switch (NSS) is used to resolve user names and IDs. This is configured in the passwd line of /etc/nsswitch.conf, e.g., the following configuration means that the /etc/passwd will be searched first and if the user or ID is not found, then a configured NIS server is used to determine the user name/ID.
passwd: files nis
However, in some systems, the NSS library functions might not actually be used to resolve a name request. Some systems may have a service such as nscd running. This is a daemon that caches name service requests, e.g., if the Apache user had previously been looked up, its name would be stored in the nscd cache and it would return the correct name or ID without /etc/passwd being searched.
Debugging
I would try debugging this issue by running the Python program through strace. At the very end of the output file, you should see the system calls that are used to retrieve the name of the user.
strace -o getpwuid_test.trace getpwuid_test.py
You would need to run this command enough times to catch the call to getpwuid failing to see why it failed. I, for one, would be interested to see the results.
Examples
Here’s an example of the output where no caching daemon is running and NSS is used to read the /etc/passwd file:
open("/etc/nsswitch.conf", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=1717, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fa9000
read(3, "#\n# /etc/nsswitch.conf\n#\n# An ex"..., 4096) = 1717
read(3, "", 4096) = 0
close(3) = 0
...
open("/etc/passwd", O_RDONLY) = 3
fcntl64(3, F_GETFD) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
fstat64(3, {st_mode=S_IFREG|0644, st_size=3012, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fa9000
read(3, "root:x:0:0:root:/root:/bin/bash\n"..., 4096) = 3012
close(3) = 0
...
write(1, "apache\n", 7)
Here’s an example where the nscd service is running and the NSS library is bypassed:
socket(PF_FILE, SOCK_STREAM, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"...}, 110) = 0
send(3, "\2\0\0\0\v\0\0\0\7\0\0\0passwd\0", 19, MSG_NOSIGNAL) = 19
poll([{fd=3, events=POLLIN|POLLERR|POLLHUP}], 1, 5000) = 1 ([{fd=3, revents=POLLIN|POLLHUP}])
recvmsg(3, {msg_name(0)=NULL, msg_iov(2)=[{"passwd\0", 7}, {"\270O\3\0\0\0\0\0", 8}], msg_controllen=16, {cmsg_len=16, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, {4}}, msg_flags=0}, 0) = 15
...
write(1, "apache\n", 7)

Force lshosts command to return megabytes for "maxmem" and "maxswp" parameters

When I type "lshosts" I am given:
HOST_NAME type model cpuf ncpus maxmem maxswp server RESOURCES
server1 X86_64 Intel_EM 60.0 12 191.9G 159.7G Yes ()
server2 X86_64 Intel_EM 60.0 12 191.9G 191.2G Yes ()
server3 X86_64 Intel_EM 60.0 12 191.9G 191.2G Yes ()
I am trying to return maxmem and maxswp as megabytes, not gigabytes when lshosts is called. I am trying to send Xilinx ISE jobs to my LSF, however the software expects integer, megabyte values for maxmem and maxswp. By doing debugging, it appears that the software grabs these parameters using the lshosts command.
I have already checked in my lsf.conf file that:
LSF_UNIT_FOR_LIMTS=MB
I have tried searching the IBM Knowledge Base, but to no avail.
Do you use a specific command to specify maxmem and maxswp units within the lsf.conf, lsf.shared, or other config files?
Or does LSF force return the most practical unit?
Any way to override this?
LSF_UNIT_FOR_LIMITS should work, if you completely drained the cluster of all running, pending, and finished jobs. According to the docs, MB is the default, so I'm surprised.
That said, you can use something like this to transform the results:
$ cat to_mb.awk
function to_mb(s) {
e = index("KMG", substr(s, length(s)))
m = substr(s, 0, length(s) - 1)
return m * 10^((e-2) * 3)
}
{ print $1 " " to_mb($6) " " to_mb($7) }
$ lshosts | tail -n +2 | awk -f to_mb.awk
server1 191900 159700
server2 191900 191200
server3 191900 191200
The to_mb function should also handle 'K' or 'M' units, should those pop up.
If LSF_UNIT_FOR_LIMITS is defined in lsf.conf, lshosts will always print the output as a floating point number, and in some versions of LSF the parameter is defined as 'KB' in lsf.conf upon installation.
Try searching for any definitions of the parameter in lsf.conf and commenting them all out so that the parameter is left undefined, I think in that case it defaults to printing it out as an integer in megabytes.
(Don't ask me why it works this way)

I want to evaluate the OS(operating system) system property to load the environment corresponding configuration file

I want to evaluate the OS (operating system) system property to load the environment corresponding configuration file. E.g. if OS evaluates to Windows, the properties-win.xml will be loaded or if OS evaluates to Unix or Linux, the properties-unix.xml will be loaded.
The below spel works fine
{(systemProperties['os.name'].indexOf('nix') >= 0 or
systemProperties['os.name'].indexOf('nux') >= 0 or
systemProperties['os.name'].indexOf('aix') > 0
) ? 'linux'
: ((systemProperties['os.name'].indexOf('Win') >= 0)
? 'windows' : 'Unknow OS')}
But in place of evaluating the systemProperties['os.name'] each time, I want to have this in a variable and then wants to match the condition. I saw the #this variable usage and tried to make the below spel
{systemProperties['os.name'].?
((#this.indexOf('nix') >= 0 or
#this.indexOf('nux') >= 0 or
this.indexOf('aix') > 0
) ? 'unix' : (#this.indexOf('win') >= 0) ? 'windows' : 'Unknown')}
But somehow, it's giving parsing exception.
Does anyone can suggest anything? Thanks a lot in advance!

Resources