Changeset 85264 in vbox for trunk/src/VBox/Main/src-server
- Timestamp:
- Jul 12, 2020 12:56:45 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/generic/NetIf-generic.cpp
r82968 r85264 39 39 #include "ProgressImpl.h" 40 40 #include "VirtualBoxImpl.h" 41 #include "Global.h" 41 42 #include "netif.h" 42 43 … … 69 70 RTPROCSTATUS Status; 70 71 rc = RTProcWait(pid, 0, &Status); 71 if ( RT_SUCCESS(rc) 72 && Status.iStatus == 0 73 && Status.enmReason == RTPROCEXITREASON_NORMAL) 74 return VINF_SUCCESS; 72 if (RT_SUCCESS(rc)) 73 { 74 if ( Status.iStatus == 0 75 && Status.enmReason == RTPROCEXITREASON_NORMAL) 76 return VINF_SUCCESS; 77 LogRel(("NetIfAdpCtl: failed to create process for %s: iStats=%d enmReason=%d\n", 78 szAdpCtl, Status.iStatus, Status.enmReason)); 79 rc = VERR_GENERAL_FAILURE; 80 } 75 81 } 76 82 else … … 188 194 /* create a progress object */ 189 195 ComObjPtr<Progress> progress; 190 progress.createObject(); 191 196 HRESULT hrc = progress.createObject(); 197 AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc)); 198 199 /* Note vrc and hrc are competing about tracking the error state here. */ 200 int vrc = VINF_SUCCESS; 192 201 ComPtr<IHost> host; 193 202 HRESULT hrc = pVirtualBox->COMGETTER(Host)(host.asOutParam()); … … 202 211 203 212 char szAdpCtl[RTPATH_MAX]; 204 intrc = RTPathExecDir(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME " add"));205 if (RT_FAILURE( rc))213 vrc = RTPathExecDir(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME " add")); 214 if (RT_FAILURE(vrc)) 206 215 { 207 216 progress->i_notifyComplete(E_FAIL, 208 217 COM_IIDOF(IHostNetworkInterface), 209 218 HostNetworkInterface::getStaticComponentName(), 210 "Failed to get program path, rc=%Rrc\n",rc);211 return rc;219 "Failed to get program path, vrc=%Rrc\n", vrc); 220 return vrc; 212 221 } 213 222 strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " "); … … 221 230 if (strlen(szAdpCtl) < RTPATH_MAX - sizeof(" 2>&1")) 222 231 strcat(szAdpCtl, " 2>&1"); 232 223 233 FILE *fp = popen(szAdpCtl, "r"); 224 225 234 if (fp) 226 235 { … … 240 249 "%s", szBuf); 241 250 pclose(fp); 242 return E_FAIL;251 return Global::vboxStatusCodeFromCOM(E_FAIL); 243 252 } 244 253 … … 246 255 PNETIFINFO pInfo = (PNETIFINFO)RTMemAllocZ(RT_UOFFSETOF_DYN(NETIFINFO, szName[cbNameLen])); 247 256 if (!pInfo) 248 rc = VERR_NO_MEMORY;257 vrc = VERR_NO_MEMORY; 249 258 else 250 259 { 251 260 strcpy(pInfo->szShortName, szBuf); 252 261 strcpy(pInfo->szName, szBuf); 253 rc = NetIfGetConfigByName(pInfo);254 if (RT_FAILURE( rc))262 vrc = NetIfGetConfigByName(pInfo); 263 if (RT_FAILURE(vrc)) 255 264 { 256 265 progress->i_notifyComplete(E_FAIL, … … 271 280 RTMemFree(pInfo); 272 281 } 273 if (( rc = pclose(fp)) != 0)282 if ((vrc = pclose(fp)) != 0) 274 283 { 275 284 progress->i_notifyComplete(E_FAIL, 276 285 COM_IIDOF(IHostNetworkInterface), 277 286 HostNetworkInterface::getStaticComponentName(), 278 "Failed to execute ' " VBOXNETADPCTL_NAME " add' (exit status: %d)",rc);279 rc = VERR_INTERNAL_ERROR;287 "Failed to execute '%s' - exit status: %d", szAdpCtl, vrc); 288 vrc = VERR_INTERNAL_ERROR; 280 289 } 281 290 } … … 283 292 { 284 293 /* Failed to add an interface */ 285 rc = VERR_PERMISSION_DENIED;286 294 progress->i_notifyComplete(E_FAIL, 287 295 COM_IIDOF(IHostNetworkInterface), 288 296 HostNetworkInterface::getStaticComponentName(), 289 "Failed to execute '" VBOXNETADPCTL_NAME " add' (exit status: %d). Check permissions!", rc); 297 "Failed to execute '%s' (errno %d). Check permissions!", 298 szAdpCtl, errno); 290 299 pclose(fp); 300 vrc = VERR_PERMISSION_DENIED; 291 301 } 292 302 } 293 if (RT_SUCCESS(rc)) 294 progress->i_notifyComplete(rc); 303 else 304 { 305 vrc = RTErrConvertFromErrno(errno); 306 progress->i_notifyComplete(E_FAIL, 307 COM_IIDOF(IHostNetworkInterface), 308 HostNetworkInterface::getStaticComponentName(), 309 "Failed to execute '%s' (errno %d / %Rrc). Check permissions!", 310 szAdpCtl, errno, vrc); 311 } 312 if (RT_SUCCESS(vrc)) 313 progress->i_notifyComplete(S_OK); 295 314 else 296 315 hrc = E_FAIL; … … 298 317 } 299 318 300 return hrc;319 return RT_FAILURE(vrc) ? vrc : SUCCEEDED(hrc) ? VINF_SUCCESS : Global::vboxStatusCodeFromCOM(hrc); 301 320 302 321 #else … … 315 334 /* create a progress object */ 316 335 ComObjPtr<Progress> progress; 317 progress.createObject(); 336 HRESULT hrc = progress.createObject(); 337 AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc)); 338 318 339 ComPtr<IHost> host; 319 int rc = VINF_SUCCESS; 320 HRESULT hr = pVirtualBox->COMGETTER(Host)(host.asOutParam()); 321 if (SUCCEEDED(hr)) 322 { 323 Bstr ifname; 340 int vrc = VINF_SUCCESS; 341 hrc = pVirtualBox->COMGETTER(Host)(host.asOutParam()); 342 if (SUCCEEDED(hrc)) 343 { 324 344 ComPtr<IHostNetworkInterface> iface; 325 345 if (FAILED(host->FindHostNetworkInterfaceById(aId.toUtf16().raw(), iface.asOutParam()))) 326 346 return VERR_INVALID_PARAMETER; 347 348 Bstr ifname; 327 349 iface->COMGETTER(Name)(ifname.asOutParam()); 328 350 if (ifname.isEmpty()) 329 351 return VERR_INTERNAL_ERROR; 330 331 rc = progress->init(pVirtualBox, host, 332 "Removing host network interface", 333 FALSE /* aCancelable */); 334 if (SUCCEEDED(rc)) 352 Utf8Str strIfName(ifname); 353 354 hrc = progress->init(pVirtualBox, host, "Removing host network interface", FALSE /* aCancelable */); 355 if (SUCCEEDED(hrc)) 335 356 { 336 357 progress.queryInterfaceTo(aProgress); 337 rc = NetIfAdpCtl(Utf8Str(ifname).c_str(), "remove", NULL, NULL);338 if (RT_FAILURE( rc))358 vrc = NetIfAdpCtl(strIfName.c_str(), "remove", NULL, NULL); 359 if (RT_FAILURE(vrc)) 339 360 progress->i_notifyComplete(E_FAIL, 340 361 COM_IIDOF(IHostNetworkInterface), 341 362 HostNetworkInterface::getStaticComponentName(), 342 "Failed to execute '" VBOXNETADPCTL_NAME "' (exit status: %d)", rc); 363 "Failed to execute '" VBOXNETADPCTL_NAME " %s remove' (%Rrc)", 364 strIfName.c_str(), vrc); 343 365 else 344 366 progress->i_notifyComplete(S_OK); 345 367 } 346 } 347 else 348 { 349 progress->i_notifyComplete(hr); 350 rc = VERR_INTERNAL_ERROR; 351 } 352 return rc; 368 else 369 vrc = Global::vboxStatusCodeFromCOM(hrc); 370 } 371 else 372 vrc = Global::vboxStatusCodeFromCOM(hrc); 373 return vrc; 353 374 #else 354 375 NOREF(pVirtualBox);
Note:
See TracChangeset
for help on using the changeset viewer.