Skip to content

Allow running zoneserver under systemd - #95

Closed
pillarsdotnet wants to merge 1 commit into
samboy:masterfrom
pillarsdotnet:master
Closed

Allow running zoneserver under systemd#95
pillarsdotnet wants to merge 1 commit into
samboy:masterfrom
pillarsdotnet:master

Conversation

@pillarsdotnet

Copy link
Copy Markdown

When invoking zoneserver directly from systemd, the PGID is
already set to the PID of the main zoneserver process, and
attempting to call setpgid(0,0) results in an ENOPERM error.

When invoking zoneserver directly from systemd, the PGID is
already set to the PID of the main zoneserver process, and
attempting to call setpgid(0,0) results in an ENOPERM error.

@samboy samboy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the getpgid() manual page:

getpgid() returns the PGID of the process specified by pid. If pid is zero, the process ID of the calling process is used. (Retrieving the PGID of a process other than the caller is rarely necessary, and the POSIX.1 getpgrp() is preferred for that task.) <<

That in mind, I think it would be better to use getpgrp() instead of getpgid(0). Let’s avoid Linuxisms in Mara’s code.

@samboy

samboy commented Mar 16, 2021

Copy link
Copy Markdown
Owner

Let’s look at this code:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main() {
        printf("getpgid(0) %d\n",getpgid(0));
        printf("getpgrp() %d\n",getpgrp());
        printf("getpid() %d\n",getpid());
}

This shows that getpgid(0) returns the same value as getpgrp().

Rejecting merge request: Do things the POSIX way whenever possible, and avoid Linuxisms.

@samboy samboy closed this Mar 16, 2021
samboy pushed a commit that referenced this pull request Mar 16, 2021
@samboy

samboy commented Mar 17, 2021

Copy link
Copy Markdown
Owner

Original patch:

if(getpgid(0) != getpid() && setpgid(0,0)) {

The patch I actually applied:

if(setpgid(0,0) && getpgrp() != getpid()) {

I have released MaraDNS 3.5.0019 with this change (and, in addition, another example coLunacyDNS script: Give coLunacyDNS 10.1.2.3.ip4.internal., and coLunacyDNS gives you 10.1.2.3 back; this script works for all IPv4 IPs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants