Gleb Popov
2018-05-29 20:42:47 UTC
Hello.
I've been debugging a failing Qt (KDE, to be precise) test and found that
process name returned in kinfo_proc structure gets truncated to 19 symbols.
This causes other errors in the application. I'm wondering why is this
field so small and is there possibility to increase it? I think, having
applications with names longer than 19 characters is not that rare.
Relevant header: /usr/include/sys/user.h
Simple testcase to feature the problem:
# cat k.cpp
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
int main()
{
auto pid = getpid();
struct kinfo_proc kp;
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid };
size_t len = sizeof(kp);
u_int mib_len = sizeof(mib)/sizeof(u_int);
if (sysctl(mib, mib_len, &kp, &len, NULL, 0) < 0)
return -1;
puts(kp.ki_tdname);
puts(kp.ki_comm);
return 0;
}
# c++ -o abcdefghijklmnopqrstuvwxyz
# ./abcdefghijklmnopqrstuvwxyz
abcdefghijklmnop
abcdefghijklmnopqrs
I've been debugging a failing Qt (KDE, to be precise) test and found that
process name returned in kinfo_proc structure gets truncated to 19 symbols.
This causes other errors in the application. I'm wondering why is this
field so small and is there possibility to increase it? I think, having
applications with names longer than 19 characters is not that rare.
Relevant header: /usr/include/sys/user.h
Simple testcase to feature the problem:
# cat k.cpp
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
int main()
{
auto pid = getpid();
struct kinfo_proc kp;
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid };
size_t len = sizeof(kp);
u_int mib_len = sizeof(mib)/sizeof(u_int);
if (sysctl(mib, mib_len, &kp, &len, NULL, 0) < 0)
return -1;
puts(kp.ki_tdname);
puts(kp.ki_comm);
return 0;
}
# c++ -o abcdefghijklmnopqrstuvwxyz
# ./abcdefghijklmnopqrstuvwxyz
abcdefghijklmnop
abcdefghijklmnopqrs