Reputation: 41
I test a simple example program for a UDP service with systemd:
int main(int argc, char *argv[], char **envp)
{
int cnt;
char Buffer[100];
struct sockaddr_in clientaddr;
socklen_t clen = sizeof (clientaddr);
int Nbytes;
if ((cnt = sd_listen_fds(0)) != 1) {
fprintf(stderr, "No or too many file descriptors received: %d\n", cnt);
exit(1);
}
fprintf(stderr, "Socket-activated.\n");
fd = SD_LISTEN_FDS_START + 0;
if ((Nbytes = recvfrom (fd, Buffer, 100, MSG_PEEK, (struct sockaddr *) &clientaddr, &clen)) < 0)
{
fprintf (stderr, "Receive failed: %s\n", strerror(errno));
exit (1);
}
fprintf (stderr, "Buffer:%s\n", Buffer);
close (fd);
exit (0);
} /* MAIN */
example.service:
[Unit]
Description=example
[Service]
ExecStart=/opt/VdLrp2/bin/udpg
example.socket:
[Unit]
Description=example
[Socket]
ListenDatagram=0.0.0.0:12300
# Restart is by default "no"
[Install]
WantedBy=sockets.target
I am testing the service with:
echo "xx" >/dev/udp/10.0.1.2/12300
I expect the service to be started once, and then finished. The service is started so often until the start limit is reached:
Mar 03 18:09:49 VdLrp2 systemd[1]: Reloading.
Mar 03 18:10:01 VdLrp2 systemd[1]: Listening on example.
Mar 03 18:10:06 VdLrp2 systemd[1]: Started example.
Mar 03 18:10:06 VdLrp2 udpg[1164]: Socket-activated.
Mar 03 18:10:06 VdLrp2 udpg[1164]: Buffer:xx
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Succeeded.
Mar 03 18:10:06 VdLrp2 systemd[1]: Started example.
Mar 03 18:10:06 VdLrp2 udpg[1165]: Socket-activated.
Mar 03 18:10:06 VdLrp2 udpg[1165]: Buffer:xx
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Succeeded.
Mar 03 18:10:06 VdLrp2 systemd[1]: Started example.
Mar 03 18:10:06 VdLrp2 udpg[1166]: Socket-activated.
Mar 03 18:10:06 VdLrp2 udpg[1166]: Buffer:xx
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Succeeded.
Mar 03 18:10:06 VdLrp2 systemd[1]: Started example.
Mar 03 18:10:06 VdLrp2 udpg[1167]: Socket-activated.
Mar 03 18:10:06 VdLrp2 udpg[1167]: Buffer:xx
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Succeeded.
Mar 03 18:10:06 VdLrp2 systemd[1]: Started example.
Mar 03 18:10:06 VdLrp2 udpg[1168]: Socket-activated.
Mar 03 18:10:06 VdLrp2 udpg[1168]: Buffer:xx
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Succeeded.
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Start request repeated too quickly.
Mar 03 18:10:06 VdLrp2 systemd[1]: example.service: Failed with result 'start-limit-hit'.
Mar 03 18:10:06 VdLrp2 systemd[1]: Failed to start example.
Mar 03 18:10:06 VdLrp2 systemd[1]: example.socket: Failed with result 'service-start-limit-hit'.
I have tried all possible variations with "Type =" etc., just everything I found in the "systemd" manuals. But the result is always the same. The version of systemd is 246.
What am I doing wrong?
Thanks in advance, Poldi
Upvotes: 1
Views: 166
Reputation: 41
I answer the question myself:
the problem is the "MSG_PEEK"-Flag.The buffer is not emptied
Upvotes: 2