diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-06 20:43:42 +0100 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-06 20:43:42 +0100 |
commit | 6a89966eed6110d0e7a7ec53727c4473d18ad441 (patch) | |
tree | ce56076af530fdbc94bd41702dda27a815561f2d | |
parent | it's going well (diff) | |
download | 42-cub3d-6a89966eed6110d0e7a7ec53727c4473d18ad441.tar.gz 42-cub3d-6a89966eed6110d0e7a7ec53727c4473d18ad441.tar.bz2 42-cub3d-6a89966eed6110d0e7a7ec53727c4473d18ad441.tar.xz 42-cub3d-6a89966eed6110d0e7a7ec53727c4473d18ad441.tar.zst 42-cub3d-6a89966eed6110d0e7a7ec53727c4473d18ad441.zip |
Fuck execve
Diffstat (limited to '')
-rw-r--r-- | inc/cub3d.h | 2 | ||||
-rw-r--r-- | inc/cub3d_structs.h | 1 | ||||
-rw-r--r-- | src/ft_exit.c | 1 | ||||
-rw-r--r-- | src/ft_get_music.c | 11 | ||||
-rw-r--r-- | src/ft_init_map.c | 5 | ||||
-rw-r--r-- | src/ft_music.c | 22 | ||||
-rw-r--r-- | src/ft_treat_args.c | 2 | ||||
-rw-r--r-- | src/ft_warp_level.c | 11 |
8 files changed, 33 insertions, 22 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index ea55faf..ef05364 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -119,7 +119,7 @@ uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist); */ void ft_set_minimap_scale(t_cub *clist); -void ft_music_fork(char *music_cmd); +void ft_music_fork(char **mcmd_words); void ft_detect(t_cub *cl); void ft_castray(t_cub *cl); int8_t ft_save_to_bmp(t_cub *cl); diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 7e49e14..d253b7b 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -152,6 +152,7 @@ typedef struct s_map char *music_cmd; char *mapl; char **map; + char **mcmd_words; int8_t x_step; int8_t y_step; size_t map_w; diff --git a/src/ft_exit.c b/src/ft_exit.c index 973abca..be4d46e 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -34,6 +34,7 @@ static void ft_memdel((void**)&clist->mlist.music_cmd); ft_memdel((void**)&clist->mlist.mapl); ft_free_words(clist->mlist.map); + ft_free_words(clist->mlist.mcmd_words); if (!clist->wlist.inited) ft_memdel((void**)&clist->wlist.winptr); } diff --git a/src/ft_get_music.c b/src/ft_get_music.c index cdd7039..2383e0a 100644 --- a/src/ft_get_music.c +++ b/src/ft_get_music.c @@ -15,7 +15,7 @@ #include <stdlib.h> #include <stdint.h> -static void +static int8_t ft_set_music_cmd(t_map *mlist) { uint8_t len; @@ -24,9 +24,13 @@ static void len += ft_strlen(FT_MUS_CMD) - 2; ft_memdel((void**)&mlist->music_cmd); if (!(mlist->music_cmd = (char *)malloc((len + 1) * sizeof(char)))) - return ; + return (-1); ft_sprintf(mlist->music_cmd, FT_MUS_CMD, mlist->music_path); + ft_free_words(mlist->mcmd_words); + if (!(mlist->mcmd_words = ft_split(mlist->music_cmd, ' '))) + return (-1); + return (0); } int8_t @@ -54,6 +58,5 @@ int8_t return (-1); } clist->mlist.ismusic = 1; - ft_set_music_cmd(&clist->mlist); - return (0); + return ((ft_set_music_cmd(&clist->mlist) == 0) ? (0) : (-1)); } diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 4fa127c..1c12189 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -30,7 +30,9 @@ static int8_t !(mlist->music_cmd = (char*)ft_calloc(1, sizeof(char))) || !(mlist->mapl = (char*)ft_calloc(1, sizeof(char))) || !(mlist->map = (char**)ft_calloc(2, sizeof(char*))) || - !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char)))) + !(mlist->map[0] = (char*)ft_calloc(1, sizeof(char))) || + !(mlist->mcmd_words = (char**)ft_calloc(2, sizeof(char*))) || + !(mlist->mcmd_words[0] = (char*)ft_calloc(1, sizeof(char)))) return (-1); return (0); } @@ -41,6 +43,7 @@ int8_t if (ft_init_map_callocs(mlist) < 0) return (-1); mlist->map[1] = 0; + mlist->mcmd_words[1] = 0; mlist->map_w = 0; mlist->map_h = 0; mlist->mapl_len = 0; diff --git a/src/ft_music.c b/src/ft_music.c index 4d25a3a..f1801f9 100644 --- a/src/ft_music.c +++ b/src/ft_music.c @@ -11,19 +11,21 @@ /* ************************************************************************** */ #include <libft.h> -#include <cub3d.h> +#include <stddef.h> #include <stdlib.h> - #include <unistd.h> void - ft_music_fork(char *music_cmd) + ft_music_fork(char **mcmd_words) { - while (1) - { - ft_printf("%s\n", music_cmd); - sleep(1); - } - /* execve here */ - /* system(cl->mlist.music_cmd); */ + /* execve(2) here */ + + char *arg[4]; + + arg[0] = "/bin/sh"; + arg[1] = "-c"; + arg[2] = "aplay ./media/sound/DEVANT-LES-KAISSONS.wav"; + arg[3] = NULL; + (void)mcmd_words; + execve("/bin/sh", &arg[0], NULL); } diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c index accf3aa..c4ffc98 100644 --- a/src/ft_treat_args.c +++ b/src/ft_treat_args.c @@ -42,7 +42,7 @@ uint8_t clist->isoldmus = 1; clist->mpid = fork(); if (clist->mpid == 0) - ft_music_fork(clist->mlist.music_cmd); + ft_music_fork(clist->mlist.mcmd_words); } ft_hooks_and_loops(&clist->wlist, clist); } diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index febff7e..9bd8d92 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -35,6 +35,7 @@ static void ft_memdel((void**)&ml->music_cmd); ft_memdel((void**)&ml->mapl); ft_free_words(ml->map); + ft_free_words(ml->mcmd_words); } static void @@ -75,11 +76,11 @@ static void else if (isoldmus && cl->mlist.ismusic && ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) { - kill(cl->mpid, SIGTERM); - wait(&cl->mpid); - cl->mpid = fork(); - if (cl->mpid == 0) - ft_music_fork(cl->mlist.music_cmd); + /* kill(cl->mpid, SIGTERM); */ + /* wait(&cl->mpid); */ + /* cl->mpid = fork(); */ + /* if (cl->mpid == 0) */ + /* ft_music_fork(cl->mlist.mcmd_words); */ } else if (isoldmus && cl->mlist.ismusic && !ft_strncmp(tmp_mup, cl->mlist.music_path, ft_strlen(tmp_mup) + 1)) |