* Sync up to trunk head (r60691).
[reactos.git] / ntoskrnl / po / events.c
index 8417f27..ed549be 100644 (file)
@@ -64,9 +64,6 @@ PopGetSysButtonCompletion(
        PSYS_BUTTON_CONTEXT SysButtonContext = Context;
        ULONG SysButton;
 
-       if (Irp->PendingReturned)
-               IoMarkIrpPending(Irp);
-
        /* The DeviceObject can be NULL, so use the one we stored */
        DeviceObject = SysButtonContext->DeviceObject;
 
@@ -79,6 +76,14 @@ PopGetSysButtonCompletion(
                if (SysButton & SYS_BUTTON_LID) DbgPrint(" LID");
                if (SysButton == 0) DbgPrint(" WAKE");
                DbgPrint(" )\n");
+        
+        if (SysButton & SYS_BUTTON_POWER)
+        {
+            /* FIXME: Read registry for the action we should perform here */
+            DPRINT1("Initiating shutdown after power button event\n");
+            
+            ZwShutdownSystem(ShutdownNoReboot);
+        }
        }
 
        /* Allocate a new workitem to send the next IOCTL_GET_SYS_BUTTON_EVENT */
@@ -157,7 +162,7 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
        BOOLEAN Arrival;
        ULONG Caps;
        NTSTATUS Status;
-       UNICODE_STRING DeviceName;
+    UNICODE_STRING DeviceName;
        UNICODE_STRING DeviceNamePrefix = RTL_CONSTANT_STRING(L"\\??\\");
 
        DPRINT("PopAddRemoveSysCapsCallback(%p %p)\n",
@@ -168,9 +173,9 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
                return STATUS_REVISION_MISMATCH;
        if (Notification->Size != sizeof(DEVICE_INTERFACE_CHANGE_NOTIFICATION))
                return STATUS_INVALID_PARAMETER;
-       if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_ARRIVAL, sizeof(GUID) == sizeof(GUID)))
+       if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_ARRIVAL, sizeof(GUID)) == sizeof(GUID))
                Arrival = TRUE;
-       else if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_REMOVAL, sizeof(GUID) == sizeof(GUID)))
+       else if (RtlCompareMemory(&Notification->Event, &GUID_DEVICE_INTERFACE_REMOVAL, sizeof(GUID)) == sizeof(GUID))
                Arrival = FALSE;
        else
                return STATUS_INVALID_PARAMETER;
@@ -179,7 +184,7 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
        {
                DPRINT("Arrival of %wZ\n", Notification->SymbolicLinkName);
 
-               DeviceName.Length = 0;
+        DeviceName.Length = 0;
                DeviceName.MaximumLength = Notification->SymbolicLinkName->MaximumLength + DeviceNamePrefix.MaximumLength;
                DeviceName.Buffer = ExAllocatePool(PagedPool, DeviceName.MaximumLength);
                if (!DeviceName.Buffer) return STATUS_INSUFFICIENT_RESOURCES;
@@ -203,21 +208,22 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
                        &IoStatusBlock,
                        FILE_SHARE_READ | FILE_SHARE_WRITE,
                        0);
+        RtlFreeUnicodeString(&DeviceName);
                if (!NT_SUCCESS(Status))
                {
-                       DPRINT("ZwOpenFile() failed with status 0x%08lx\n", Status);
+                       DPRINT1("ZwOpenFile() failed with status 0x%08lx\n", Status);
                        return Status;
                }
                Status = ObReferenceObjectByHandle(
                        FileHandle,
                        FILE_READ_DATA,
                        IoFileObjectType,
-                       ExGetPreviousMode(),
+                       KernelMode,
                        (PVOID*)&FileObject,
                        NULL);
                if (!NT_SUCCESS(Status))
                {
-                       DPRINT("ObReferenceObjectByHandle() failed with status 0x%08lx\n", Status);
+                       DPRINT1("ObReferenceObjectByHandle() failed with status 0x%08lx\n", Status);
                        ZwClose(FileHandle);
                        return Status;
                }
@@ -238,7 +244,7 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
                        &IoStatusBlock);
                if (!Irp)
                {
-                       DPRINT("IoBuildDeviceIoControlRequest() failed\n");
+                       DPRINT1("IoBuildDeviceIoControlRequest() failed\n");
                        ZwClose(FileHandle);
                        return STATUS_INSUFFICIENT_RESOURCES;
                }
@@ -251,24 +257,24 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
                }
                if (!NT_SUCCESS(Status))
                {
-                       DPRINT("Sending IOCTL_GET_SYS_BUTTON_CAPS failed with status 0x%08x\n", Status);
+                       DPRINT1("Sending IOCTL_GET_SYS_BUTTON_CAPS failed with status 0x%08x\n", Status);
                        ZwClose(FileHandle);
                        return STATUS_INSUFFICIENT_RESOURCES;
                }
 
                /* FIXME: What do do with the capabilities? */
                {
-                       DPRINT1("Device capabilities: 0x%x (", Caps);
-                       if (Caps & SYS_BUTTON_POWER) DbgPrint(" POWER");
-                       if (Caps & SYS_BUTTON_SLEEP) DbgPrint(" SLEEP");
-                       if (Caps & SYS_BUTTON_LID) DbgPrint(" LID");
-                       DbgPrint(" )\n");
+                       DPRINT("Device capabilities: 0x%x (", Caps);
+                       if (Caps & SYS_BUTTON_POWER) DPRINT(" POWER");
+                       if (Caps & SYS_BUTTON_SLEEP) DPRINT(" SLEEP");
+                       if (Caps & SYS_BUTTON_LID) DPRINT(" LID");
+                       DPRINT(" )\n");
                }
 
                SysButtonContext = ExAllocatePool(NonPagedPool, sizeof(SYS_BUTTON_CONTEXT));
                if (!SysButtonContext)
                {
-                       DPRINT("ExAllocatePool() failed\n");
+                       DPRINT1("ExAllocatePool() failed\n");
                        ZwClose(FileHandle);
                        return STATUS_INSUFFICIENT_RESOURCES;
                }
@@ -278,7 +284,7 @@ PopAddRemoveSysCapsCallback(IN PVOID NotificationStructure,
                SysButtonContext->DeviceObject = DeviceObject;
                if (!SysButtonContext->WorkItem)
                {
-                       DPRINT("IoAllocateWorkItem() failed\n");
+                       DPRINT1("IoAllocateWorkItem() failed\n");
                        ZwClose(FileHandle);
                        ExFreePool(SysButtonContext);
                        return STATUS_INSUFFICIENT_RESOURCES;