Prints messages to wine console instead of with printf(). Also adds a missing CloseServiceHandle().

Tim Schwartz tim at sanityinternet.com
Tue Jun 19 12:34:31 CDT 2007


This is a fix for bug #8554.
-------------- next part --------------
diff --git a/programs/net/net.c b/programs/net/net.c
index 4af72ae..b69345b 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -23,6 +23,12 @@
 #define NET_START 0001
 #define NET_STOP  0002
 
+static void output(const char *message)
+{
+    DWORD count;
+    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), message, strlen(message), &count, NULL);
+}
+
 static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
 {
     LPENUM_SERVICE_STATUS dependencies = NULL;
@@ -31,6 +37,7 @@ static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
     BOOL result;
     SC_HANDLE dependent_serviceHandle;
     SERVICE_STATUS_PROCESS ssp;
+    char message[2048];
 
     result = EnumDependentServices(serviceHandle, SERVICE_ACTIVE, dependencies, buffer_size, &buffer_size, &count);
 
@@ -41,11 +48,17 @@ static BOOL StopService(SC_HANDLE SCManager, SC_HANDLE serviceHandle)
         {
             for(counter = 0; counter < count; counter++)
             {
-                printf("Stopping dependent service: %s\n", dependencies[counter].lpDisplayName);
+                sprintf(message, "Stopping dependent service: %s\n", dependencies[counter].lpDisplayName);
+                output(message);
                 dependent_serviceHandle = OpenService(SCManager, dependencies[counter].lpServiceName, SC_MANAGER_ALL_ACCESS);
                 if(dependent_serviceHandle) result = StopService(SCManager, dependent_serviceHandle);
-                if(!result) printf("Could not stop service %s\n", dependencies[counter].lpDisplayName);
-           }
+                CloseServiceHandle(dependent_serviceHandle);
+                if(!result)
+                {
+                    sprintf(message, "Could not stop service %s\n", dependencies[counter].lpDisplayName);
+                    output(message);
+                }
+            }
         }
     }
 
@@ -60,17 +73,20 @@ static BOOL net_service(int operation, char *service_name)
     BOOL result = 0;
     char service_display_name[4096];
     DWORD buffer_size = sizeof(service_display_name);
+    char message[2048];
 
     SCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
     if(!SCManager)
     {
-        printf("Couldn't get handle to SCManager.\n");
+        sprintf(message, "Couldn't get handle to SCManager.\n");
+        output(message);
         return FALSE;
     }
     serviceHandle = OpenService(SCManager, service_name, SC_MANAGER_ALL_ACCESS);
     if(!serviceHandle)
     {
-        printf("Couldn't get handle to service.\n");
+        sprintf(message, "Couldn't get handle to service.\n");
+        output(message);
         CloseServiceHandle(SCManager);
         return FALSE;
     }
@@ -82,20 +98,26 @@ static BOOL net_service(int operation, char *service_name)
     switch(operation)
     {
     case NET_START:
-        printf("The %s service is starting.\n", service_display_name);
+        sprintf(message, "The %s service is starting.\n", service_display_name);
+        output(message);
         result = StartService(serviceHandle, 0, NULL);
 
-        printf("The %s service ", service_display_name);
-        if(!result) printf("failed to start.\n");
-        else printf("was started successfully.\n");
+        sprintf(message, "The %s service ", service_display_name);
+        output(message);
+        if(!result) sprintf(message, "failed to start.\n");
+        else sprintf(message, "was started successfully.\n");
+        output(message);
         break;
     case NET_STOP:
-        printf("The %s service is stopping.\n", service_display_name);
+        sprintf(message, "The %s service is stopping.\n", service_display_name);
+        output(message);
         result = StopService(SCManager, serviceHandle);
 
-        printf("The %s service ", service_display_name);
-        if(!result) printf("failed to stop.\n");
-        else printf("was stopped successfully.\n");
+        sprintf(message, "The %s service ", service_display_name);
+        output(message);
+        if(!result) sprintf(message, "failed to stop.\n");
+        else sprintf(message, "was stopped successfully.\n");
+        output(message);
         break;
     }
 
@@ -109,24 +131,24 @@ int main(int argc, char *argv[])
 
     if (argc < 2)
     {
-        printf("The syntax of this command is:\n\n");
-        printf("NET [ HELP | START | STOP ]\n");
+        output("The syntax of this command is:\n\n");
+        output("NET [ HELP | START | STOP ]\n");
         return 1;
     }
 
     if(!strcasecmp(argv[1], "help"))
     {
-        printf("The syntax of this command is:\n\n");
-        printf("NET HELP command\n    -or-\nNET command /HELP\n\n");
-        printf("   Commands available are:\n");
-        printf("   NET HELP    NET START    NET STOP\n");
+        output("The syntax of this command is:\n\n");
+        output("NET HELP command\n    -or-\nNET command /HELP\n\n");
+        output("   Commands available are:\n");
+        output("   NET HELP    NET START    NET STOP\n");
     }
 
     if(!strcasecmp(argv[1], "start"))
     {
         if(argc < 3)
         {
-            printf("Specify service name to start.\n");
+            output("Specify service name to start.\n");
             return 1;
         }
 
@@ -141,7 +163,7 @@ int main(int argc, char *argv[])
     {
         if(argc < 3)
         {
-            printf("Specify service name to stop.\n");
+            output("Specify service name to stop.\n");
             return 1;
         }
 


More information about the wine-patches mailing list