fixed a shutdown issue where sometimes services were unregistered twice

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@895641 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java
index ed0a36b..fb617ec 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ServiceImpl.java
@@ -322,25 +322,30 @@
     }
 
     public synchronized void start() {
-        m_serviceRegistration = m_context.registerService(ServiceComponent.class.getName(), this, null);
-    	State oldState, newState;
-        synchronized (m_dependencies) {
-        	oldState = m_state;
-            newState = new State((List) m_dependencies.clone(), true, m_isInstantiated, m_isBound);
-            m_state = newState;
-        }
-        calculateStateChanges(oldState, newState);
+    	if (m_serviceRegistration == null) {
+	        m_serviceRegistration = m_context.registerService(ServiceComponent.class.getName(), this, null);
+	    	State oldState, newState;
+	        synchronized (m_dependencies) {
+	        	oldState = m_state;
+	            newState = new State((List) m_dependencies.clone(), true, m_isInstantiated, m_isBound);
+	            m_state = newState;
+	        }
+	        calculateStateChanges(oldState, newState);
+    	}
     }
 
     public synchronized void stop() {
-    	State oldState, newState;
-        synchronized (m_dependencies) {
-        	oldState = m_state;
-            newState = new State((List) m_dependencies.clone(), false, m_isInstantiated, m_isBound);
-            m_state = newState;
-        }
-        calculateStateChanges(oldState, newState);
-        m_serviceRegistration.unregister();
+    	if (m_serviceRegistration != null) {
+	    	State oldState, newState;
+	        synchronized (m_dependencies) {
+	        	oldState = m_state;
+	            newState = new State((List) m_dependencies.clone(), false, m_isInstantiated, m_isBound);
+	            m_state = newState;
+	        }
+	        calculateStateChanges(oldState, newState);
+	        m_serviceRegistration.unregister();
+	        m_serviceRegistration = null;
+    	}
     }
 
     public synchronized Service setInterface(String serviceName, Dictionary properties) {