NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: PR/53998 CVS commit: src/sys/kern
The following reply was made to PR kern/53998; it has been noted by GNATS.
From: Christos Zoulas <christos%zoulas.com@localhost>
To: "gnats-bugs%netbsd.org@localhost" <gnats-bugs%NetBSD.org@localhost>
Cc: kern-bug-people%netbsd.org@localhost,
gnats-admin%netbsd.org@localhost,
netbsd-bugs%netbsd.org@localhost,
joel.bertrand%systella.fr@localhost
Subject: Re: PR/53998 CVS commit: src/sys/kern
Date: Sat, 23 Feb 2019 09:43:40 -0500
The original program was incorrect; here's a fixed version that works as =
expected.
christos
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
#include <sys/stat.h>
#include <fcntl.h>
static void
sem_create(sem_t **semaphore)
{
char name[15];
sprintf(name, "/TEST-%d", getpid());
printf("> %s\n", name);
fflush(NULL);
if ((*semaphore =3D sem_open(name, O_RDWR | O_CREAT | O_EXCL,
S_IRUSR | S_IWUSR, 0)) =3D=3D SEM_FAILED)
{
perror("sem_open()");
fflush(NULL);
}
return;
}
static void
sem_delete(sem_t **semaphore)
{
char name[15];
sprintf(name, "/TEST-%d", getpid());
printf("< %s\n", name);
fflush(NULL);
if (sem_close(*semaphore) !=3D 0)
{
perror("sem_close");
fflush(NULL);
}
printf("After sem_close()\n");
sem_unlink(name);
return;
}
int
main()
{
int pid;
sem_t *semaphore;
sem_create(&semaphore);
pid =3D fork();
if (pid > 0)
{
printf("Parent process\n");
sem_delete(&semaphore);
printf("End of parent process\n");
fflush(NULL);
_exit(EXIT_SUCCESS);
}
sleep(1);
setsid();
pid =3D fork();
if (pid > 0)
{
printf("End of second process\n");
fflush(NULL);
_exit(EXIT_SUCCESS);
}
printf("Daemonized process\n");
fflush(NULL);
sem_create(&semaphore);
printf("Closing semaphore\n");
fflush(NULL);
sem_delete(&semaphore);
printf("End\n");
fflush(NULL);
sleep(1);
exit(EXIT_SUCCESS);
}
Home |
Main Index |
Thread Index |
Old Index