Commit 09c18925761f932a59f0838c889f31e2d3aa3fcb

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 0a1f851e

slirp: Use shell to erase smb directory

Instead of open-coding this, we can use the power of the shell to remove
the smb_dir on exit.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 4 additions and 26 deletions
@@ -1014,35 +1014,13 @@ void net_slirp_redir(const char *redir_str) @@ -1014,35 +1014,13 @@ void net_slirp_redir(const char *redir_str)
1014 1014
1015 static char smb_dir[1024]; 1015 static char smb_dir[1024];
1016 1016
1017 -static void erase_dir(char *dir_name)  
1018 -{  
1019 - DIR *d;  
1020 - struct dirent *de;  
1021 - char filename[1024];  
1022 -  
1023 - /* erase all the files in the directory */  
1024 - if ((d = opendir(dir_name)) != NULL) {  
1025 - for(;;) {  
1026 - de = readdir(d);  
1027 - if (!de)  
1028 - break;  
1029 - if (strcmp(de->d_name, ".") != 0 &&  
1030 - strcmp(de->d_name, "..") != 0) {  
1031 - snprintf(filename, sizeof(filename), "%s/%s",  
1032 - smb_dir, de->d_name);  
1033 - if (unlink(filename) != 0) /* is it a directory? */  
1034 - erase_dir(filename);  
1035 - }  
1036 - }  
1037 - closedir(d);  
1038 - rmdir(dir_name);  
1039 - }  
1040 -}  
1041 -  
1042 /* automatic user mode samba server configuration */ 1017 /* automatic user mode samba server configuration */
1043 static void smb_exit(void) 1018 static void smb_exit(void)
1044 { 1019 {
1045 - erase_dir(smb_dir); 1020 + char cmd[1024];
  1021 +
  1022 + snprintf(cmd, sizeof(cmd), "rm -rf %s", smb_dir);
  1023 + system(cmd);
1046 } 1024 }
1047 1025
1048 static void slirp_smb(SlirpState* s, const char *exported_dir, 1026 static void slirp_smb(SlirpState* s, const char *exported_dir,