aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_exit.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-13 05:39:06 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-13 05:39:06 +0100
commita2ed84f6da6b5ca2226e2bbc5cc65e142810d8c6 (patch)
tree6fc0f9c1701cd729d65ca110c3c9a089c321a694 /src/ft_exit.c
parentI fucking love it (diff)
download42-cub3d-a2ed84f6da6b5ca2226e2bbc5cc65e142810d8c6.tar.gz
42-cub3d-a2ed84f6da6b5ca2226e2bbc5cc65e142810d8c6.tar.bz2
42-cub3d-a2ed84f6da6b5ca2226e2bbc5cc65e142810d8c6.tar.xz
42-cub3d-a2ed84f6da6b5ca2226e2bbc5cc65e142810d8c6.tar.zst
42-cub3d-a2ed84f6da6b5ca2226e2bbc5cc65e142810d8c6.zip
New sfx, clean exit
Diffstat (limited to 'src/ft_exit.c')
-rw-r--r--src/ft_exit.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index b0d7ada..5bcc653 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -68,6 +68,25 @@ static void
mlx_destroy_image(clist->wlist.wlx, clist->tlist[15].img);
}
+static void
+ ft_kill_forks(t_cub *clist)
+{
+ pid_t tmp;
+
+ if (!(tmp = waitpid(clist->mpid, NULL, WNOHANG)))
+ kill(clist->mpid, SIGTERM);
+ wait(&clist->mpid);
+ if (!(tmp = waitpid(clist->death_pid, NULL, WNOHANG)))
+ kill(clist->death_pid, SIGTERM);
+ wait(&clist->death_pid);
+ if (!(tmp = waitpid(clist->trap_pid, NULL, WNOHANG)))
+ kill(clist->trap_pid, SIGTERM);
+ wait(&clist->trap_pid);
+ if (!(tmp = waitpid(clist->pain_pid, NULL, WNOHANG)))
+ kill(clist->pain_pid, SIGTERM);
+ wait(&clist->pain_pid);
+}
+
int
ft_exit(uint8_t exit_code, t_cub *clist)
{
@@ -81,11 +100,7 @@ int
mlx_destroy_window(clist->wlist.wlx, clist->wlist.winptr);
clist->wlist.winptr = NULL;
}
- if (clist->isoldmus && clist->wlist.inited)
- {
- kill(clist->mpid, SIGTERM);
- wait(&clist->mpid);
- }
+ ft_kill_forks(clist);
ft_free_lists(clist);
ft_printf("Exiting program\n");
exit(exit_code);