A Linux program fails to create thread without root permissions

I installed Linux compatibility packages and tried to run commercial Beyond Compare program. It failed:
Code:
% bcompare
[FORMS.PP] ExceptionOccurred 
  Sender=EThread
  Exception=Failed to create new thread
  Stack trace:
  $000000000086FAD8   bcompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
TApplication.HandleException Failed to create new thread
  Stack trace:
  $000000000086FAD8   bcompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
Exception at 000000000086FAD8: EThread:
Failed to create new thread.
However, it perfectly works when launched as root. It's a Qt4 based software.
Any idea what can cause that? Any way to troubleshoot?
Thanks for directions!
 
Probably a resource problem. Something the program need access to, but can't get to as a normal user (because of permissions).
 
Trace it.
Cannot set scheduler: "Operation not permitted". Why?
Code:
....
 38024 BCompare CALL  linux_sched_setscheduler(0x18a1a,0,0x810c06d38)
 38024 BCompare RET   linux_open 0
 38024 BCompare RET   linux_sched_setscheduler -1 errno -1 Operation not permitted
 38024 BCompare CALL  linux_tgkill(0x9488,0x18a1a,0x20)
 38024 BCompare CALL  linux_set_robust_list(0x810c069e0,0x18)
 38024 BCompare RET   linux_set_robust_list 0
 38024 BCompare PSIG  SIGRT1 caught handler=0x802806820 mask=0x0 code=SI_LWP
 38024 BCompare RET   linux_tgkill 0
....

would this be an idea? chmod a+s ./bcompare
Setting SUID is a good work-around (may be dangerous though).
I'd prefer to find the root cause.
 
Cannot set scheduler: "Operation not permitted". Why?

Probably a question for the bug tracker.

Code:
....
38024 BCompare CALL  linux_sched_setscheduler(0x18a1a,0,0x810c06d38)
38024 BCompare RET   linux_open 0
38024 BCompare RET   linux_sched_setscheduler -1 errno -1 Operation not permitted
38024 BCompare CALL  linux_tgkill(0x9488,0x18a1a,0x20)
38024 BCompare CALL  linux_set_robust_list(0x810c069e0,0x18)
38024 BCompare RET   linux_set_robust_list 0
38024 BCompare PSIG  SIGRT1 caught handler=0x802806820 mask=0x0 code=SI_LWP
38024 BCompare RET   linux_tgkill 0
....

I see neither segfault nor thread ids ( kdump -H).
 
I see neither segfault nor thread ids
But who said it segfaults? It catches an exception.
The entire output of kdump -H is attached.
That scheduler error appears on the line 23095.
Thanks!
 

Attachments

  • ktrace.txt
    1.6 MB · Views: 244
Install linux-c7-devtools and try
Code:
% cat nosched.c
int sched_setscheduler() {
  return 0;
}
% /compat/linux/bin/gcc -fPIC -shared nosched.c -o nosched.so
% env LD_PRELOAD="$PWD/nosched.so" BCompare

If that works, then this should be reported to the FreeBSD bug tracker.
 
Looks like I'm missing something:
Code:
% env LD_LIBRARY_PATH=/opt/bc4/lib/beyondcompare env LD_PRELOAD=/opt/bc4/nosched.so /opt/bc4/lib/beyondcompare/BCompare
ld-elf.so.1: Shared object "libc.so.6" not found, required by "nosched.so"
ld-elf.so.1: Shared object "libc.so.6" not found, required by "nosched.so"
ld-elf.so.1: Shared object "libc.so.6" not found, required by "nosched.so"
ld-elf.so.1: Shared object "libc.so.6" not found, required by "nosched.so"
[FORMS.PP] ExceptionOccurred 
  Sender=EThread
  Exception=Failed to create new thread
  Stack trace:
  $000000000086FAD8   BCompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
TApplication.HandleException Failed to create new thread
  Stack trace:
  $000000000086FAD8   BCompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
Exception at 000000000086FAD8: EThread:
Failed to create new thread. 

% env LD_LIBRARY_PATH=/opt/bc4/lib/beyondcompare:/compat/linux/usr/lib64 env LD_PRELOAD=/opt/bc4/nosched.so /opt/bc4/lib/beyondcompare/BCompare
/bin/sh: line 1: 56726 Bus error               (core dumped) pgrep gnome- > /dev/null
/bin/sh: line 1: 56731 Bus error               (core dumped) pgrep kdesktop > /dev/null
/bin/sh: line 1: 56733 Bus error               (core dumped) pgrep plasma-desktop > /dev/null
/bin/sh: line 1: 56735 Bus error               (core dumped) pgrep xfdesktop > /dev/null
[FORMS.PP] ExceptionOccurred 
  Sender=EThread
  Exception=Failed to create new thread
  Stack trace:
  $000000000086FAD8   BCompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
TApplication.HandleException Failed to create new thread
  Stack trace:
  $000000000086FAD8   BCompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
Exception at 000000000086FAD8: EThread:
Failed to create new thread.

% env LD_LIBRARY_PATH=/opt/bc4/lib/beyondcompare:/compat/linux/usr/lib env LD_PRELOAD=/opt/bc4/nosched.so /opt/bc4/lib/beyondcompare/BCompare
ld-elf.so.1: /compat/linux/usr/lib/libc.so.6: unsupported file layout
ld-elf.so.1: /compat/linux/usr/lib/libc.so.6: unsupported file layout
ld-elf.so.1: /compat/linux/usr/lib/libc.so.6: unsupported file layout
ld-elf.so.1: /compat/linux/usr/lib/libc.so.6: unsupported file layout
[FORMS.PP] ExceptionOccurred 
  Sender=EThread
  Exception=Failed to create new thread
  Stack trace:
  $000000000086FAD8   BCompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
TApplication.HandleException Failed to create new thread
  Stack trace:
  $000000000086FAD8   BCompare ($0000000000400000)   TTHREAD.SYSCREATE,  tthread.inc line 160
Exception at 000000000086FAD8: EThread:
Failed to create new thread.
 
So, this is a file compare program (with a lot of fancy words in the advertising). Makes me wonder if this exercise (trying to get it to run on FreeBSD) is going to be worth it at all. Perhaps time is better spent looking for a file compare program that already works on FreeBSD. Just my 0.02 eurocents.
 
Here you go:
Code:
% cat nosched.c
#define _GNU_SOURCE

#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>

int pthread_noop() {
  fprintf(stderr, "%s(...)\n", __func__);
  return 0;
}

// https://stackoverflow.com/questions/15599026/how-can-i-intercept-dlsym-calls-using-ld-preload/18825060#18825060
void* _dl_sym(void*, const char*, void*);

static void* (*libc_dlsym)(void*, const char*) = NULL;

void* dlsym(void* handle, const char* symbol) {

  if (!libc_dlsym) {
    libc_dlsym = _dl_sym(RTLD_NEXT, "dlsym", dlsym);
  }

  //~ fprintf(stderr, "%s(_, %s)\n", __func__, symbol);

  if (strcmp(symbol, "pthread_attr_setinheritsched") == 0) {
    return pthread_noop;
  }

  return libc_dlsym(handle, symbol);
}
% /compat/linux/bin/gcc -Wall -fPIC -shared nosched.c -ldl -o nosched.so
% env LD_LIBRARY_PATH=/opt/bc4/lib/beyondcompare LD_PRELOAD=/opt/bc4/nosched.so /opt/bc4/lib/beyondcompare/BCompare

EDIT: removed accidental -m32
 
So, this is a file compare program (with a lot of fancy words in the advertising). Makes me wonder if this exercise (trying to get it to run on FreeBSD) is going to be worth it at all. Perhaps time is better spent looking for a file compare program that already works on FreeBSD. Just my 0.02 eurocents.

It's a very basic exercise.
 
if this exercise (trying to get it to run on FreeBSD) is going to be worth it at all
Well, since FreeBSD officially supports Linux executables, why shouldn't we improve it by understanding and fixing issues?
Perhaps time is better spent looking for a file compare program that already works on FreeBSD
There is a few arguments you may or may not accept:
1. Beyond Compare is a de facto standard source comparison tool in the company I work for. It is used in all Linux and Windows boxes within the company.
2. In terms of productivity it is really useful for large hierarchical projects or for entire filesystems comparisons for embedded systems.
3. BC automatically detects and compares text, binary and graphics.

In everyday activities I use regular diff(). For the GUI I couldn't find anything meaningful, e.g. textproc/meld works fine, but it's a toy compared to BC...
 
  • Like
Reactions: a6h
Well, since FreeBSD officially supports Linux executables, why shouldn't we improve it by understanding and fixing issues?
Of course, that is a valid reason.
There is a few arguments you may or may not accept:
1. Beyond Compare is a de facto standard source comparison tool in the company I work for. It is used in all Linux and Windows boxes within the company.
2. In terms of productivity it is really useful for large hierarchical projects or for entire filesystems comparisons for embedded systems.
3. BC automatically detects and compares text, binary and graphics.
Your reason number 1 is a very good reason for this exercise.
If your initial post had included a reason for this exercise, I wouldn't have written my "perhaps" post.
 
Thanks aragats & shkhln I have consolidated your fixes and my bcompare installation script into a port.
There are some core dumps happening in the background still, but it doesn't prevent correct execution.
I submitted it last week and it should land into the ports repo someday.
It's also on github in the meantime

 
Back
Top