为什么 ulimit 显示不同的输出?

为什么 ulimit 显示不同的输出?

我很困惑,我尝试了很多方法,但还是没有找到任何方法来解决错误。我发布了同样的帖子。我希望有人能帮助我。

我的问题是,

当我运行时ulimit -n 它显示12000

当我跑步时rsh localhost ulimit -n,它显示12000

到目前为止,一切都进展顺利。但实际问题出现了,我对 rsh 做了一些更改,通过添加一个功能和其他一些功能,它构建了一个名为 的新 rsh modified-rsh。请不要索要代码,因为那不是公开的,也不要说转移到 ssh ,因为 rsh 不安全。

这些我都知道。

当我运行命令时,modified-rsh localhost ulimit -n它显示 1024。为什么 ??

你能告诉我这些事情发生的背后是什么原因吗?

我感到很无助。请帮我解决这种情况。提前谢谢。期待您的回复。

编辑 3

我认为这个编辑会有所帮助。这个编辑显示了在 modified-rsh 跟踪期间访问 ulimit 的位置和时间

命令 :- strace -o log.txt modified-rsh localhost ulimit -n

writev(3, [{"service\0", 8}, {"service\0", 8}, {"ulimit -n\0", 10}], 3) = 26
read(3, "\0", 1)                        = 1
rt_sigprocmask(SIG_SETMASK, [], [URG], 8) = 0
setuid(500)                             = 0
rt_sigprocmask(SIG_BLOCK, [INT QUIT TERM], [], 8) = 0
rt_sigaction(SIGINT, {0x1, [INT], SA_RESTORER|SA_RESTART, 0x3454030330}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGINT, {0x401650, [INT], SA_RESTORER|SA_RESTART, 0x3454030330}, {0x1, [INT], SA_RESTORER|SA_RESTART, 0x3454030330}, 8) = 0
rt_sigaction(SIGQUIT, {0x1, [QUIT], SA_RESTORER|SA_RESTART, 0x3454030330}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGQUIT, {0x401650, [QUIT], SA_RESTORER|SA_RESTART, 0x3454030330}, {0x1, [QUIT], SA_RESTORER|SA_RESTART, 0x3454030330}, 8) = 0
rt_sigaction(SIGTERM, {0x1, [TERM], SA_RESTORER|SA_RESTART, 0x3454030330}, {SIG_DFL, [], 0}, 8) = 0
rt_sigaction(SIGTERM, {0x401650, [TERM], SA_RESTORER|SA_RESTART, 0x3454030330}, {0x1, [TERM], SA_RESTORER|SA_RESTART, 0x3454030330}, 8) = 0
clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x2b749c27cd80) = 4583
ioctl(5, FIONBIO, [1])                  = 0
ioctl(3, FIONBIO, [1])                  = 0
rt_sigprocmask(SIG_SETMASK, [], [INT QUIT TERM], 8) = 0
select(6, [3 5], NULL, NULL, NULL)      = 1 (in [3])
read(3, "1024\n", 8192)                 = 5
write(1, "1024\n", 5)                   = 5
select(6, [3 5], NULL, NULL, NULL)      = 1 (in [3])
read(3, "", 8192)                       = 0
select(6, [5], NULL, NULL, NULL)        = 1 (in [5])
read(5, "", 8192)                       = 0
kill(4583, SIGKILL)                     = 0
exit_group(0)                           = ?

看到read system call读取的是 1024。但应该读取的是 12000,问题出在哪里,你现在能识别出来吗?

编辑4

strace -e 打开修改后的 rsh 本地主机 ulimit -n

open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib64/libcrypt.so.1", O_RDONLY)  = 3
open("/lib64/libutil.so.1", O_RDONLY)   = 3
open("/lib64/libc.so.6", O_RDONLY)      = 3
open("/etc/nsswitch.conf", O_RDONLY)    = 3
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib64/libnss_files.so.2", O_RDONLY) = 3
open("/etc/passwd", O_RDONLY)           = 3
open("/etc/services", O_RDONLY)         = 3
open("/etc/resolv.conf", O_RDONLY)      = 3
open("/etc/host.conf", O_RDONLY)        = 3
open("/etc/hosts", O_RDONLY)            = 3
open("/etc/hosts", O_RDONLY)            = 3

这些打开的系统调用是按顺序调用的,其中有 3 个是命令。其中只有四个是可读的,即 /etc/nsswitch.conf、/etc/passwd、/etc/services、/etc/resolv.conf

strace -e 打开 rsh 本地主机 ulimit -n

  1 open("/etc/ld.so.cache", O_RDONLY)      = 3
  2 open("/lib64/libcrypt.so.1", O_RDONLY)  = 3
  3 open("/lib64/libutil.so.1", O_RDONLY)   = 3
  4 open("/lib64/libc.so.6", O_RDONLY)      = 3
  5 open("/etc/nsswitch.conf", O_RDONLY)    = 3
  6 open("/etc/ld.so.cache", O_RDONLY)      = 3
  7 open("/lib64/libnss_files.so.2", O_RDONLY) = 3
  8 open("/etc/passwd", O_RDONLY)           = 3
  9 open("/etc/services", O_RDONLY)         = 3
 10 open("/etc/host.conf", O_RDONLY)        = 3
 11 open("/etc/resolv.conf", O_RDONLY)      = 3
 12 open("/etc/hosts", O_RDONLY)            = 3
 13 open("/etc/hosts", O_RDONLY)            = 3
 14 open("/etc/hosts", O_RDONLY)            = 3

cat /etc/services | grep rsh

kshell          544/tcp         krcmd           # Kerberized `rsh' (v5)
rsh-spx         222/tcp                         # Berkeley rshd with SPX auth
rsh-spx         222/udp                         # Berkeley rshd with SPX auth
carrius-rshell  1197/tcp                        # Carrius Remote Access
carrius-rshell  1197/udp                        # Carrius Remote Access
airshot         3975/tcp                        # Air Shot
airshot         3975/udp                        # Air Shot
watershed-lm    6143/tcp                        # Watershed License Manager
watershed-lm    6143/udp                        # Watershed License Manager
modified-rsh    2529/tcp

我使用的以下命令是该论坛上的一个问题所使用的,其链接在这里

[root@jhamb ~]# sudo grep limits /etc/pam.d/*

/etc/pam.d/atd:# To enable PAM user limits for atd, please uncomment the
/etc/pam.d/atd:# following line and configure /etc/security/limits.conf:
/etc/pam.d/atd:# session    required   pam_limits.so
/etc/pam.d/runuser:session           required   pam_limits.so
/etc/pam.d/sudo:session    required  pam_limits.so
/etc/pam.d/sudo-i:session    required   pam_limits.so
/etc/pam.d/system-auth:session     required      pam_limits.so
/etc/pam.d/system-auth-ac:session     required      pam_limits.so

答案1

您应该使用 strace 连接到 rsh 守护进程并查找 setrlimit 调用:

strace -p $PID -f -e trace=setrlimit

这两个版本应该有所不同。这应该能帮你找到问题所在。

相关内容