sd_is_socket_unix() only returns true for full path ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

I am working on socket activation in user units, with a working
directory, executable and socket all in /tmp. And i either think there
might be a bug, or the documentation is not as precise as it can be.
The documentation man 3 sd_is_socket_unix speaks about path, but does
not mention if path must be absolute, only or if it can be relative. I
am using version 247.3-7+deb11u4

1) I expected sd_is_socket_unix to return true for each kind of path :
As far as i see,  the function returns true only for absolute path. If
that is the desired behaviour, some additionnal precision could be
added to the manpage. If not, then there might be a but or oversight.

2) i expected the program to not be re-ran since it exited
successfully (restart = no, which is the default value anyway) : but
the program is run 5 times, up to the limit

It is my first project with systemd socket activation, so i might have
missed something.

Thanks in advance,
Nicolas

===== Program =====

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <systemd/sd-daemon.h>

void test_path(int i, char * path) {
    printf("%s = %i\n", path, sd_is_socket_unix(i, SOCK_STREAM, 1, path, 0));
}

int main(int argc, char *argv[]) {
    system("pwd");
    system("ls -l sd*");
    int n = sd_listen_fds(0);
    for (int i=SD_LISTEN_FDS_START; i <SD_LISTEN_FDS_START+n; i++) {
        test_path(i, "sd_test");
        test_path(i, "./sd_test");
        test_path(i, "/tmp/sd_test");
    }
    return 0;
}

===== Compilation =====
gcc -o /tmp/sd a.c -l systemd

===== ~/.config/systemd/user/sd_test.socket =====
[Socket]
ListenStream=/tmp/sd_test
SocketMode=0600

===== ~/.config/systemd/user/sd_test.service =====
[Service]
Type=simple
ExecStart=/tmp/sd
WorkingDirectory=/tmp
Restart=no

===== Running =====
echo "foo" | socat - UNIX-CONNECT:/tmp/sd_test

===== Journalctl =====

systemd[529]: Listening on sd_test.socket.

systemd[529]: Started sd_test.service.
sd[212261]: /tmp
sd[212263]: -rwxr-xr-x 1 user user 16816 Mar  2 23:04 sd
sd[212263]: srw------- 1 user user     0 Mar  2 23:04 sd_test
sd[212260]: sd_test = 0
sd[212260]: ./sd_test = 0
sd[212260]: /tmp/sd_test = 1
systemd[529]: sd_test.service: Succeeded.

systemd[529]: Started sd_test.service.
sd[212265]: /tmp
sd[212267]: -rwxr-xr-x 1 user user 16816 Mar  2 23:04 sd
sd[212267]: srw------- 1 user user     0 Mar  2 23:04 sd_test
sd[212264]: sd_test = 0
sd[212264]: ./sd_test = 0
sd[212264]: /tmp/sd_test = 1
systemd[529]: sd_test.service: Succeeded.

systemd[529]: Started sd_test.service.
sd[212269]: /tmp
sd[212271]: -rwxr-xr-x 1 user user 16816 Mar  2 23:04 sd
sd[212271]: srw------- 1 user user     0 Mar  2 23:04 sd_test
sd[212268]: sd_test = 0
sd[212268]: ./sd_test = 0
sd[212268]: /tmp/sd_test = 1
systemd[529]: sd_test.service: Succeeded.

systemd[529]: Started sd_test.service.
sd[212273]: /tmp
sd[212275]: -rwxr-xr-x 1 user user 16816 Mar  2 23:04 sd
sd[212275]: srw------- 1 user user     0 Mar  2 23:04 sd_test
sd[212272]: sd_test = 0
sd[212272]: ./sd_test = 0
sd[212272]: /tmp/sd_test = 1
systemd[529]: sd_test.service: Succeeded.

systemd[529]: Started sd_test.service.
sd[212277]: /tmp
sd[212279]: -rwxr-xr-x 1 user user 16816 Mar  2 23:04 sd
sd[212279]: srw------- 1 user user     0 Mar  2 23:04 sd_test
sd[212276]: sd_test = 0
sd[212276]: ./sd_test = 0
sd[212276]: /tmp/sd_test = 1
systemd[529]: sd_test.service: Succeeded.

systemd[529]: sd_test.service: Start request repeated too quickly.
systemd[529]: sd_test.service: Failed with result 'start-limit-hit'.
systemd[529]: Failed to start sd_test.service.
systemd[529]: sd_test.socket: Failed with result 'service-start-limit-hit'.



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux