2

The following program executed in my host KDE Neon machine (up to date upgraded to 18.04) outputs Hello World! 1 as expected while it outputs Hello World! 0 when executed from a Docker container built using the Dockerfile below and running with sudo docker run -it qdir.

Does QDir need dbus or another service running ?

C++ program:

#include <QDir>
#include <iostream>


int main(int argc [[maybe_unused]], char** argv [[maybe_unused]])
{
    QDir d("/");
    std::cout << "Hello World! " << d.exists() << std::endl;
    return 0;
}

Dockerfile:

FROM kdeneon/plasma:user-lts

USER root

RUN apt-get install -y qt5-default

WORKDIR /
COPY qdir /
CMD /bin/bash

Edit, CMakeLists.txt to build the program:

project(qdir)

cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.3.0")

find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core)

include_directories(${Qt5Core_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})

set(qdir_SRCS main.cpp)

add_executable(qdir ${qdir_SRCS})
target_link_libraries(qdir ${Qt5Core_LIBRARIES})

install(TARGETS qdir RUNTIME DESTINATION bin)

Edit2: I created a github project regrouping all of the above. To reproduce the problem, if you have the Qt SDK, cmake, ninja and docker, just do:

git clone https://github.com/kleag/qdirtest
cd qdirtest
./test.sh

This is the output I get:

$ ./test.sh
[…]
Successfully built f710cbb7a3c9
Successfully tagged qdir:latest
Hello World! 1
Hello World! 0
Kleag
  • 642
  • 7
  • 14
  • Can you include the command to run the c++ – maxm Oct 08 '18 at 16:12
  • @maxm, I have edited the question to add the cmake file for building the C++ program. – Kleag Oct 08 '18 at 19:38
  • Please extract a [mcve], which means eliminating Qt from source code. Reason is that you're asking a question about code within Qt, while the code you show just calls that. – Ulrich Eckhardt Oct 08 '18 at 19:57
  • 1
    @ulrich eckhardt, now the I have added the cmakelists.txt, it is minimal, complete and verifiable. I cannot remove Qt as the problem I try to solve is a wrong behavior of the QDir object. – Kleag Oct 08 '18 at 20:01
  • You need to extract exactly that failing code from Qt. Since your code indirectly includes all of Qt, it is far from minimal. – Ulrich Eckhardt Oct 08 '18 at 20:05
  • I use only the QDir class but I must link with the QtCore library which contains it. Changing the way Qt itself is built is not an option. – Kleag Oct 08 '18 at 20:08
  • 1
    Just copy the code together into one file. Then remove the parts that aren't needed. BTW: Another way to find out what's wrong is to run the executable with `strace`, it will show you the system calls that are made. The fewer code is involved the better though, and "few code" isn't something that's usually associated with Qt. ;) – Ulrich Eckhardt Oct 08 '18 at 20:36
  • @UlrichEckhardt: I don’t think minimal implies avoiding Qt here: the code *given* is already very simple, and including all the dependencies would make hello-world complicated. – Davis Herring Oct 08 '18 at 20:53
  • I have created a github project to reproduce the problem. See the Edit2. – Kleag Oct 09 '18 at 07:50
  • Have you tried any other path you know exists, like `/bin` or `/usr`? Do those work? Maybe this is simply a limitation of the filesystem root – Felix Oct 09 '18 at 08:29
  • I started with a path known to my project when I got this problem. I simplified it to / to obtain a MCV example. – Kleag Oct 09 '18 at 08:32
  • I just tried this on an Arch-Linux Host and Docker Image and it works as expected (both 1) - my guess is that either this is a bug in an older Qt version, or an incompability between your host and the docker image. Try to build the application inside the docker container and see if that makes any difference. – Felix Oct 09 '18 at 08:57
  • @Felix, I tried building inside the image and got the same result. I then tried using an ubuntu 18.04 image instead of the KDE Neon one and this time the test gives 1. (I added the respective Dockerfiles in the github project). Qt versions are respectively 5.9 and 5.11. But the host is KDE Neon too. – Kleag Oct 09 '18 at 11:00
  • I just tried it with the `Dockerfile-neon.build_in` on my arch linux host and the test returns 1, i.e. it works. So whatever the error is, it is somehow related to your host system (which is kind of funny, as the docker containers should work the same on any host) My docker version is 18.06.1-ce, for reference – Felix Oct 09 '18 at 13:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/181555/discussion-between-felix-and-kleag). – Felix Oct 09 '18 at 13:26

1 Answers1

1

I got the answer from apachelogger on KDE forums:

Since 5.10 Qt is using somewhat new syscalls. One of them is statx and last I checked the syscall was not whitelisted in docker, nor was it whitelistable because the libseccomp used for the upstream docker build was too old and didn't know what statx is. Chances are the problem you see is that. If so, seccomp=unconfined would make it work.

Kleag
  • 642
  • 7
  • 14