Commit 492efabd47d225998f8391e4d31b233915bf79a5

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 09c18925

slirp: Improve error handling in slirp_smb

Make sure for invocations from the monitor that slirp_smb properly
reports errors and doesn't terminate qemu.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Showing 1 changed file with 12 additions and 10 deletions
@@ -697,7 +697,7 @@ static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str, @@ -697,7 +697,7 @@ static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str,
697 #ifndef _WIN32 697 #ifndef _WIN32
698 static const char *legacy_smb_export; 698 static const char *legacy_smb_export;
699 699
700 -static void slirp_smb(SlirpState *s, const char *exported_dir, 700 +static void slirp_smb(SlirpState *s, Monitor *mon, const char *exported_dir,
701 struct in_addr vserver_addr); 701 struct in_addr vserver_addr);
702 #endif 702 #endif
703 703
@@ -864,7 +864,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, @@ -864,7 +864,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,
864 smb_export = legacy_smb_export; 864 smb_export = legacy_smb_export;
865 } 865 }
866 if (smb_export) { 866 if (smb_export) {
867 - slirp_smb(s, smb_export, smbsrv); 867 + slirp_smb(s, mon, smb_export, smbsrv);
868 } 868 }
869 #endif 869 #endif
870 870
@@ -1023,7 +1023,7 @@ static void smb_exit(void) @@ -1023,7 +1023,7 @@ static void smb_exit(void)
1023 system(cmd); 1023 system(cmd);
1024 } 1024 }
1025 1025
1026 -static void slirp_smb(SlirpState* s, const char *exported_dir, 1026 +static void slirp_smb(SlirpState* s, Monitor *mon, const char *exported_dir,
1027 struct in_addr vserver_addr) 1027 struct in_addr vserver_addr)
1028 { 1028 {
1029 char smb_conf[1024]; 1029 char smb_conf[1024];
@@ -1033,15 +1033,17 @@ static void slirp_smb(SlirpState* s, const char *exported_dir, @@ -1033,15 +1033,17 @@ static void slirp_smb(SlirpState* s, const char *exported_dir,
1033 /* XXX: better tmp dir construction */ 1033 /* XXX: better tmp dir construction */
1034 snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid()); 1034 snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid());
1035 if (mkdir(smb_dir, 0700) < 0) { 1035 if (mkdir(smb_dir, 0700) < 0) {
1036 - fprintf(stderr, "qemu: could not create samba server dir '%s'\n", smb_dir);  
1037 - exit(1); 1036 + config_error(mon, "could not create samba server dir '%s'\n", smb_dir);
  1037 + return;
1038 } 1038 }
1039 snprintf(smb_conf, sizeof(smb_conf), "%s/%s", smb_dir, "smb.conf"); 1039 snprintf(smb_conf, sizeof(smb_conf), "%s/%s", smb_dir, "smb.conf");
1040 1040
1041 f = fopen(smb_conf, "w"); 1041 f = fopen(smb_conf, "w");
1042 if (!f) { 1042 if (!f) {
1043 - fprintf(stderr, "qemu: could not create samba server configuration file '%s'\n", smb_conf);  
1044 - exit(1); 1043 + smb_exit();
  1044 + config_error(mon, "could not create samba server "
  1045 + "configuration file '%s'\n", smb_conf);
  1046 + return;
1045 } 1047 }
1046 fprintf(f, 1048 fprintf(f,
1047 "[global]\n" 1049 "[global]\n"
@@ -1071,8 +1073,7 @@ static void slirp_smb(SlirpState* s, const char *exported_dir, @@ -1071,8 +1073,7 @@ static void slirp_smb(SlirpState* s, const char *exported_dir,
1071 SMBD_COMMAND, smb_conf); 1073 SMBD_COMMAND, smb_conf);
1072 1074
1073 if (slirp_add_exec(s->slirp, 0, smb_cmdline, vserver_addr, 139) < 0) { 1075 if (slirp_add_exec(s->slirp, 0, smb_cmdline, vserver_addr, 139) < 0) {
1074 - fprintf(stderr, "conflicting/invalid smbserver address\n");  
1075 - exit(1); 1076 + config_error(mon, "conflicting/invalid smbserver address\n");
1076 } 1077 }
1077 } 1078 }
1078 1079
@@ -1087,7 +1088,8 @@ void net_slirp_smb(const char *exported_dir) @@ -1087,7 +1088,8 @@ void net_slirp_smb(const char *exported_dir)
1087 } 1088 }
1088 legacy_smb_export = exported_dir; 1089 legacy_smb_export = exported_dir;
1089 if (!TAILQ_EMPTY(&slirp_stacks)) { 1090 if (!TAILQ_EMPTY(&slirp_stacks)) {
1090 - slirp_smb(TAILQ_FIRST(&slirp_stacks), exported_dir, vserver_addr); 1091 + slirp_smb(TAILQ_FIRST(&slirp_stacks), NULL, exported_dir,
  1092 + vserver_addr);
1091 } 1093 }
1092 } 1094 }
1093 1095