aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-03-06 19:12:10 +0100
committerJozanLeClerc <bousset.rudy@gmail.com>2020-03-06 19:12:10 +0100
commitf3aab6429d673342f4819f8a3c2857e48610689a (patch)
tree58bdf90289a564a527feab138a61d1304ee9f1d1
parentfork(3) going well, freed a leak (diff)
download42-cub3d-f3aab6429d673342f4819f8a3c2857e48610689a.tar.gz
42-cub3d-f3aab6429d673342f4819f8a3c2857e48610689a.tar.bz2
42-cub3d-f3aab6429d673342f4819f8a3c2857e48610689a.tar.xz
42-cub3d-f3aab6429d673342f4819f8a3c2857e48610689a.tar.zst
42-cub3d-f3aab6429d673342f4819f8a3c2857e48610689a.zip
it's going well
-rw-r--r--src/ft_exit.c2
-rw-r--r--src/ft_music.c3
-rw-r--r--src/ft_warp_level.c12
3 files changed, 13 insertions, 4 deletions
diff --git a/src/ft_exit.c b/src/ft_exit.c
index 3ba1237..973abca 100644
--- a/src/ft_exit.c
+++ b/src/ft_exit.c
@@ -16,6 +16,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <signal.h>
+#include <sys/wait.h>
#include <stdint.h>
static void
@@ -67,6 +68,7 @@ int
if (clist->isoldmus && clist->wlist.inited)
{
kill(clist->mpid, SIGTERM);
+ wait(&clist->mpid);
}
ft_free_lists(clist);
ft_printf("Exiting program\n");
diff --git a/src/ft_music.c b/src/ft_music.c
index 70bb1a1..4d25a3a 100644
--- a/src/ft_music.c
+++ b/src/ft_music.c
@@ -19,10 +19,9 @@
void
ft_music_fork(char *music_cmd)
{
- (void)music_cmd;
while (1)
{
- ft_printf("qweqwe\n");
+ ft_printf("%s\n", music_cmd);
sleep(1);
}
/* execve here */
diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c
index 0d126c1..febff7e 100644
--- a/src/ft_warp_level.c
+++ b/src/ft_warp_level.c
@@ -15,6 +15,9 @@
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/wait.h>
#include <mlx.h>
static void
@@ -65,13 +68,18 @@ static void
{
if (isoldmus && !cl->mlist.ismusic)
{
- /* stop fork() here */
+ kill(cl->mpid, SIGTERM);
+ wait(&cl->mpid);
cl->isoldmus = 0;
}
else if (isoldmus && cl->mlist.ismusic
&& ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1))
{
- /* stop and recreate fork() here */
+ kill(cl->mpid, SIGTERM);
+ wait(&cl->mpid);
+ cl->mpid = fork();
+ if (cl->mpid == 0)
+ ft_music_fork(cl->mlist.music_cmd);
}
else if (isoldmus && cl->mlist.ismusic
&& !ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1))