Search code examples
forksystemctlhardening

FORK not working for users other than root user


I am having a systemd service file where I am setting my user and group different from root. This service file is used by a application to run. The application uses fork() in its code to start a new process.

The issue is the fork command is not working i.e it is not able to create child PID. The same is not happening when running the service as root user. Please help with some suggestions. Is there any capabilties, I am missing to add in the service file?

CAP_SYS_ADMIN
CAP_SYS_RESOURCE
CAP_SETPCAP

are already added in my service file.


Solution

  • You should check first the exact return code from fork() as well as the content of errno. You may want to use perror(), to directly get a description of the last occurred error.

    However, it's very unlikely that your error comes from fork(). It's probably a failure from another call that has not been handled as it should.