From 72b204dfe659241a8270378247c8baa30dad9e0b Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 21 May 2014 19:11:28 -0600 Subject: [PATCH] Use SIGBREAK to stop VPCS on Windows. --- gns3server/modules/iou/__init__.py | 1 + gns3server/modules/vpcs/__init__.py | 1 + gns3server/modules/vpcs/vpcs_device.py | 12 ++++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gns3server/modules/iou/__init__.py b/gns3server/modules/iou/__init__.py index 9b71e2bb..ac412913 100644 --- a/gns3server/modules/iou/__init__.py +++ b/gns3server/modules/iou/__init__.py @@ -580,6 +580,7 @@ class IOU(IModule): ignore_ports=self._allocated_udp_ports) except Exception as e: self.send_custom_error(str(e)) + return self._allocated_udp_ports.append(port) log.info("{} [id={}] has allocated UDP port {} with host {}".format(iou_instance.name, diff --git a/gns3server/modules/vpcs/__init__.py b/gns3server/modules/vpcs/__init__.py index ea270e0c..7e539e4b 100644 --- a/gns3server/modules/vpcs/__init__.py +++ b/gns3server/modules/vpcs/__init__.py @@ -494,6 +494,7 @@ class VPCS(IModule): ignore_ports=self._allocated_udp_ports) except Exception as e: self.send_custom_error(str(e)) + return self._allocated_udp_ports.append(port) log.info("{} [id={}] has allocated UDP port {} with host {}".format(vpcs_instance.name, diff --git a/gns3server/modules/vpcs/vpcs_device.py b/gns3server/modules/vpcs/vpcs_device.py index d9bdb33e..6a5a6397 100644 --- a/gns3server/modules/vpcs/vpcs_device.py +++ b/gns3server/modules/vpcs/vpcs_device.py @@ -21,6 +21,7 @@ order to run an VPCS instance. """ import os +import sys import subprocess import signal import shutil @@ -343,11 +344,14 @@ class VPCSDevice(object): log.info("starting VPCS: {}".format(self._command)) self._vpcs_stdout_file = os.path.join(self._working_dir, "vpcs.log") log.info("logging to {}".format(self._vpcs_stdout_file)) + if sys.platform.startswith("win32"): + flags = subprocess.CREATE_NEW_PROCESS_GROUP with open(self._vpcs_stdout_file, "w") as fd: self._process = subprocess.Popen(self._command, stdout=fd, stderr=subprocess.STDOUT, - cwd=self._working_dir) + cwd=self._working_dir, + creationflags=flags) log.info("VPCS instance {} started PID={}".format(self._id, self._process.pid)) self._started = True except OSError as e: @@ -363,7 +367,11 @@ class VPCSDevice(object): # stop the VPCS process if self.is_running(): log.info("stopping VPCS instance {} PID={}".format(self._id, self._process.pid)) - self._process.send_signal(signal.SIGTERM) # send SIGTERM will stop VPCS + if sys.platform.startswith("win32"): + self._process.send_signal(signal.CTRL_BREAK_EVENT) + else: + self._process.terminate() + self._process.wait() self._process = None