Merge "Add missing #includes."
diff --git a/adb/usb_vendors.c b/adb/usb_vendors.c
index f5aa8cc..b988115 100644
--- a/adb/usb_vendors.c
+++ b/adb/usb_vendors.c
@@ -125,6 +125,8 @@
 #define VENDOR_ID_SONY          0x054C
 // Lab126's USB Vendor ID
 #define VENDOR_ID_LAB126        0x1949
+// Yulong Coolpad's USB Vendor ID
+#define VENDOR_ID_YULONG_COOLPAD 0x1EBF
 
 /** built-in vendor list */
 int builtInVendorIds[] = {
@@ -173,6 +175,7 @@
     VENDOR_ID_INQ_MOBILE,
     VENDOR_ID_SONY,
     VENDOR_ID_LAB126,
+    VENDOR_ID_YULONG_COOLPAD,
 };
 
 #define BUILT_IN_VENDOR_COUNT    (sizeof(builtInVendorIds)/sizeof(builtInVendorIds[0]))
diff --git a/adb/usb_windows.c b/adb/usb_windows.c
index a2fbb79..4936b77 100644
--- a/adb/usb_windows.c
+++ b/adb/usb_windows.c
@@ -255,7 +255,7 @@
 }
 
 int usb_write(usb_handle* handle, const void* data, int len) {
-  unsigned long time_out = 500 + len * 8;
+  unsigned long time_out = 5000;
   unsigned long written = 0;
   int ret;
 
@@ -300,7 +300,7 @@
 }
 
 int usb_read(usb_handle *handle, void* data, int len) {
-  unsigned long time_out = 500 + len * 8;
+  unsigned long time_out = 0;
   unsigned long read = 0;
   int ret;
 
@@ -322,7 +322,7 @@
 
         if (len == 0)
           return 0;
-      } else if (saved_errno != ERROR_SEM_TIMEOUT) {
+      } else {
         // assume ERROR_INVALID_HANDLE indicates we are disconnected
         if (saved_errno == ERROR_INVALID_HANDLE)
           usb_kick(handle);
diff --git a/debuggerd/utility.c b/debuggerd/utility.c
index 2ccf947..8eb52ba 100644
--- a/debuggerd/utility.c
+++ b/debuggerd/utility.c
@@ -267,13 +267,11 @@
      * Search for a match, or for a hole where the match would be.  The list
      * is backward from the file content, so it starts at high addresses.
      */
-    bool found = false;
     map_info_t* map = context->map_info_list;
     map_info_t *next = NULL;
     map_info_t *prev = NULL;
     while (map != NULL) {
         if (addr >= map->start && addr < map->end) {
-            found = true;
             next = map->next;
             break;
         } else if (addr >= map->end) {
diff --git a/fastboot/engine.c b/fastboot/engine.c
index a1b6539..f5215cf 100644
--- a/fastboot/engine.c
+++ b/fastboot/engine.c
@@ -255,6 +255,7 @@
 #else
     fd = fileno(tmpfile());
 #endif
+    /* reset ext4fs info so we can be called multiple times */
     reset_ext4fs_info();
     info.len = image->partition_size;
     make_ext4fs_internal(fd, NULL, NULL, NULL, 0, 1, 0, 0, 0, NULL);
@@ -266,7 +267,7 @@
     close(fd);
 }
 
-int fb_format(Action *a, usb_handle *usb)
+int fb_format(Action *a, usb_handle *usb, int skip_if_not_supported)
 {
     const char *partition = a->cmd;
     char response[FB_RESPONSE_SZ+1];
@@ -281,6 +282,13 @@
     snprintf(cmd, sizeof(cmd), "getvar:partition-type:%s", partition);
     status = fb_command_response(usb, cmd, response);
     if (status) {
+        if (skip_if_not_supported) {
+            fprintf(stderr,
+                    "Erase successful, but not automatically formatting.\n");
+            fprintf(stderr,
+                    "Can't determine partition type.\n");
+            return 0;
+        }
         fprintf(stderr,"FAILED (%s)\n", fb_get_error());
         return status;
     }
@@ -292,6 +300,13 @@
         }
     }
     if (!generator) {
+        if (skip_if_not_supported) {
+            fprintf(stderr,
+                    "Erase successful, but not automatically formatting.\n");
+            fprintf(stderr,
+                    "File system type %s not supported.\n", response);
+            return 0;
+        }
         fprintf(stderr,"Formatting is not supported for filesystem with type '%s'.\n",
                 response);
         return -1;
@@ -301,6 +316,12 @@
     snprintf(cmd, sizeof(cmd), "getvar:partition-size:%s", partition);
     status = fb_command_response(usb, cmd, response);
     if (status) {
+        if (skip_if_not_supported) {
+            fprintf(stderr,
+                    "Erase successful, but not automatically formatting.\n");
+            fprintf(stderr, "Unable to get partition size\n.");
+            return 0;
+        }
         fprintf(stderr,"FAILED (%s)\n", fb_get_error());
         return status;
     }
@@ -329,11 +350,12 @@
     return status;
 }
 
-void fb_queue_format(const char *partition)
+void fb_queue_format(const char *partition, int skip_if_not_supported)
 {
     Action *a;
 
     a = queue_action(OP_FORMAT, partition);
+    a->data = (void*)skip_if_not_supported;
     a->msg = mkmsg("formatting '%s' partition", partition);
 }
 
@@ -547,7 +569,7 @@
         } else if (a->op == OP_NOTICE) {
             fprintf(stderr,"%s\n",(char*)a->data);
         } else if (a->op == OP_FORMAT) {
-            status = fb_format(a, usb);
+            status = fb_format(a, usb, (int)a->data);
             status = a->func(a, status, status ? fb_get_error() : "");
             if (status) break;
         } else {
diff --git a/fastboot/fastboot.c b/fastboot/fastboot.c
index b96d93b..5858e23 100644
--- a/fastboot/fastboot.c
+++ b/fastboot/fastboot.c
@@ -654,7 +654,7 @@
             skip(2);
         } else if(!strcmp(*argv, "format")) {
             require(2);
-            fb_queue_format(argv[1]);
+            fb_queue_format(argv[1], 0);
             skip(2);
         } else if(!strcmp(*argv, "signature")) {
             require(2);
@@ -744,7 +744,9 @@
 
     if (wants_wipe) {
         fb_queue_erase("userdata");
+        fb_queue_format("userdata", 1);
         fb_queue_erase("cache");
+        fb_queue_format("cache", 1);
     }
     if (wants_reboot) {
         fb_queue_reboot();
diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h
index c249a8f..90d8a6a 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -43,7 +43,7 @@
 /* engine.c - high level command queue engine */
 void fb_queue_flash(const char *ptn, void *data, unsigned sz);;
 void fb_queue_erase(const char *ptn);
-void fb_queue_format(const char *ptn);
+void fb_queue_format(const char *ptn, int skip_if_not_supported);
 void fb_queue_require(const char *prod, const char *var, int invert,
         unsigned nvalues, const char **value);
 void fb_queue_display(const char *var, const char *prettyname);
diff --git a/rootdir/init.rc b/rootdir/init.rc
index 698415b..aa1bb92 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -97,7 +97,7 @@
     chown system system /dev/cpuctl/foreground/tasks
     chmod 0666 /dev/cpuctl/foreground/tasks
     write /dev/cpuctl/foreground/cpu.shares 1024
-    write /dev/cpuctl/foreground/cpu.rt_runtime_us 0
+    write /dev/cpuctl/foreground/cpu.rt_runtime_us 100000
     write /dev/cpuctl/foreground/cpu.rt_period_us 1000000
 
     mkdir /dev/cpuctl/bg_non_interactive
@@ -105,7 +105,7 @@
     chmod 0666 /dev/cpuctl/bg_non_interactive/tasks
     # 5.0 %
     write /dev/cpuctl/bg_non_interactive/cpu.shares 52
-    write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 0
+    write /dev/cpuctl/bg_non_interactive/cpu.rt_runtime_us 100000
     write /dev/cpuctl/bg_non_interactive/cpu.rt_period_us 1000000
 
     mkdir /dev/cpuctl/audio_app
@@ -274,6 +274,7 @@
     chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
     chown system system /sys/devices/system/cpu/cpufreq/interactive/boost
     chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/boost
+    chown system system /sys/devices/system/cpu/cpufreq/interactive/boostpulse
     chown system system /sys/devices/system/cpu/cpufreq/interactive/input_boost
     chmod 0660 /sys/devices/system/cpu/cpufreq/interactive/input_boost
 
diff --git a/toolbox/powerd.c b/toolbox/powerd.c
deleted file mode 100644
index 1f29a8b..0000000
--- a/toolbox/powerd.c
+++ /dev/null
@@ -1,441 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/select.h>
-#include <sys/inotify.h>
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
-//#include <linux/input.h> // this does not compile
-
-// from <linux/input.h>
-
-struct input_event {
-	struct timeval time;
-	__u16 type;
-	__u16 code;
-	__s32 value;
-};
-
-#define EVIOCGVERSION		_IOR('E', 0x01, int)			/* get driver version */
-#define EVIOCGID		_IOR('E', 0x02, struct input_id)	/* get device ID */
-#define EVIOCGKEYCODE		_IOR('E', 0x04, int[2])			/* get keycode */
-#define EVIOCSKEYCODE		_IOW('E', 0x04, int[2])			/* set keycode */
-
-#define EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, len)		/* get device name */
-#define EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, len)		/* get physical location */
-#define EVIOCGUNIQ(len)		_IOC(_IOC_READ, 'E', 0x08, len)		/* get unique identifier */
-
-#define EVIOCGKEY(len)		_IOC(_IOC_READ, 'E', 0x18, len)		/* get global keystate */
-#define EVIOCGLED(len)		_IOC(_IOC_READ, 'E', 0x19, len)		/* get all LEDs */
-#define EVIOCGSND(len)		_IOC(_IOC_READ, 'E', 0x1a, len)		/* get all sounds status */
-#define EVIOCGSW(len)		_IOC(_IOC_READ, 'E', 0x1b, len)		/* get all switch states */
-
-#define EVIOCGBIT(ev,len)	_IOC(_IOC_READ, 'E', 0x20 + ev, len)	/* get event bits */
-#define EVIOCGABS(abs)		_IOR('E', 0x40 + abs, struct input_absinfo)		/* get abs value/limits */
-#define EVIOCSABS(abs)		_IOW('E', 0xc0 + abs, struct input_absinfo)		/* set abs value/limits */
-
-#define EVIOCSFF		_IOC(_IOC_WRITE, 'E', 0x80, sizeof(struct ff_effect))	/* send a force effect to a force feedback device */
-#define EVIOCRMFF		_IOW('E', 0x81, int)			/* Erase a force effect */
-#define EVIOCGEFFECTS		_IOR('E', 0x84, int)			/* Report number of effects playable at the same time */
-
-#define EVIOCGRAB		_IOW('E', 0x90, int)			/* Grab/Release device */
-
-/*
- * Event types
- */
-
-#define EV_SYN			0x00
-#define EV_KEY			0x01
-#define EV_REL			0x02
-#define EV_ABS			0x03
-#define EV_MSC			0x04
-#define EV_SW			0x05
-#define EV_LED			0x11
-#define EV_SND			0x12
-#define EV_REP			0x14
-#define EV_FF			0x15
-#define EV_PWR			0x16
-#define EV_FF_STATUS		0x17
-#define EV_MAX			0x1f
-
-#define KEY_POWER		116
-#define KEY_SLEEP		142
-#define SW_0		0x00
-
-// end <linux/input.h>
-
-struct notify_entry {
-    int id;
-    int (*handler)(struct notify_entry *entry, struct inotify_event *event);
-    const char *filename;
-};
-
-int charging_state_notify_handler(struct notify_entry *entry, struct inotify_event *event)
-{
-    static int state = -1;
-    int last_state;
-    char buf[40];
-    int read_len;
-    int fd;
-
-    last_state = state;
-    fd = open(entry->filename, O_RDONLY);
-    read_len = read(fd, buf, sizeof(buf));
-    if(read_len > 0) {
-        //printf("charging_state_notify_handler: \"%s\"\n", buf);
-        state = !(strncmp(buf, "Unknown", 7) == 0 
-                  || strncmp(buf, "Discharging", 11) == 0);
-    }
-    close(fd);
-    //printf("charging_state_notify_handler: %d -> %d\n", last_state, state);
-    return state > last_state;
-}
-
-struct notify_entry watched_files[] = {
-    {
-        .filename = "/sys/android_power/charging_state",
-        .handler = charging_state_notify_handler
-    }
-};
-
-int call_notify_handler(struct inotify_event *event)
-{
-    unsigned int start, i;
-    start = event->wd - watched_files[0].id;
-    if(start >= ARRAY_SIZE(watched_files))
-        start = 0;
-    //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
-    for(i = start; i < ARRAY_SIZE(watched_files); i++) {
-        if(event->wd == watched_files[i].id) {
-            if(watched_files[i].handler) {
-                return watched_files[i].handler(&watched_files[i], event);
-            }
-            return 1;
-        }
-    }
-    for(i = 0; i < start; i++) {
-        if(event->wd == watched_files[i].id) {
-            if(watched_files[i].handler) {
-                return watched_files[i].handler(&watched_files[i], event);
-            }
-            return 1;
-        }
-    }
-    return 0;
-}
-
-int handle_inotify_event(int nfd)
-{
-    int res;
-    int wake_up = 0;
-    struct inotify_event *event;
-    char event_buf[512];
-    int event_pos = 0;
-
-    res = read(nfd, event_buf, sizeof(event_buf));
-    if(res < (int)sizeof(*event)) {
-        if(errno == EINTR)
-            return 0;
-        fprintf(stderr, "could not get event, %s\n", strerror(errno));
-        return 0;
-    }
-    printf("got %d bytes of event information\n", res);
-    while(res >= (int)sizeof(*event)) {
-        int event_size;
-        event = (struct inotify_event *)(event_buf + event_pos);
-        wake_up |= call_notify_handler(event);
-        event_size = sizeof(*event) + event->len;
-        res -= event_size;
-        event_pos += event_size;
-    }
-    return wake_up;
-}
-
-int powerd_main(int argc, char *argv[])
-{
-    int c;
-    unsigned int i;
-    int res;
-    struct timeval tv;
-    int eventfd;
-    int notifyfd;
-    int powerfd;
-    int powerfd_is_sleep;
-    int user_activity_fd;
-    int acquire_partial_wake_lock_fd;
-    int acquire_full_wake_lock_fd;
-    int release_wake_lock_fd;
-    char *eventdev = "/dev/input/event0";
-    const char *android_sleepdev = "/sys/android_power/request_sleep";
-    const char *android_autooff_dev = "/sys/android_power/auto_off_timeout";
-    const char *android_user_activity_dev = "/sys/android_power/last_user_activity";
-    const char *android_acquire_partial_wake_lock_dev = "/sys/android_power/acquire_partial_wake_lock";
-    const char *android_acquire_full_wake_lock_dev = "/sys/android_power/acquire_full_wake_lock";
-    const char *android_release_wake_lock_dev = "/sys/android_power/release_wake_lock";
-    const char *powerdev = "/sys/power/state";
-    const char suspendstring[] = "standby";
-    const char wakelockstring[] = "powerd";
-    fd_set rfds;
-    struct input_event event;
-    struct input_event light_event;
-    struct input_event light_event2;
-    int gotkey = 1;
-    time_t idle_time = 5;
-    const char *idle_time_string = "5";
-    time_t lcd_light_time = 0;
-    time_t key_light_time = 0;
-    int verbose = 1;
-    int event_sleep = 0;
-    int got_power_key_down = 0;
-    struct timeval power_key_down_time = { 0, 0 };
-
-    light_event.type = EV_LED;
-    light_event.code = 4; // bright lcd backlight
-    light_event.value = 0; // light off -- sleep after timeout
-
-    light_event2.type = EV_LED;
-    light_event2.code = 8; // keyboard backlight
-    light_event2.value = 0; // light off -- sleep after timeout
-
-    do {
-        c = getopt(argc, argv, "e:ni:vql:k:");
-        if (c == EOF)
-            break;
-        switch (c) {
-        case 'e':
-            eventdev = optarg;
-            break;
-        case 'n':
-            gotkey = 0;
-            break;
-        case 'i':
-            idle_time = atoi(optarg);
-            idle_time_string = optarg;
-            break;
-        case 'v':
-            verbose = 2;
-            break;
-        case 'q':
-            verbose = 0;
-            break;
-        case 'l':
-            lcd_light_time = atoi(optarg);
-            break;
-        case 'k':
-            key_light_time = atoi(optarg);
-            break;
-        case '?':
-            fprintf(stderr, "%s: invalid option -%c\n",
-                argv[0], optopt);
-            exit(1);
-        }
-    } while (1);
-    if(optind  != argc) {
-        fprintf(stderr,"%s [-e eventdev]\n", argv[0]);
-        return 1;
-    }
-
-    eventfd = open(eventdev, O_RDWR | O_NONBLOCK);
-    if(eventfd < 0) {
-        fprintf(stderr, "could not open %s, %s\n", eventdev, strerror(errno));
-        return 1;
-    }
-    if(key_light_time >= lcd_light_time) {
-        lcd_light_time = key_light_time + 1;
-        fprintf(stderr,"lcd bright backlight time must be longer than keyboard backlight time.\n"
-            "Setting lcd bright backlight time to %ld seconds\n", lcd_light_time);
-    }
-
-    user_activity_fd = open(android_user_activity_dev, O_RDWR);
-    if(user_activity_fd >= 0) {
-        int auto_off_fd = open(android_autooff_dev, O_RDWR);
-        write(auto_off_fd, idle_time_string, strlen(idle_time_string));
-        close(auto_off_fd);
-    }
-
-    powerfd = open(android_sleepdev, O_RDWR);
-    if(powerfd >= 0) {
-        powerfd_is_sleep = 1;
-        if(verbose > 0)
-            printf("Using android sleep dev: %s\n", android_sleepdev);
-    }
-    else {
-        powerfd_is_sleep = 0;
-        powerfd = open(powerdev, O_RDWR);
-        if(powerfd >= 0) {
-            if(verbose > 0)
-                printf("Using linux power dev: %s\n", powerdev);
-        }
-    }
-    if(powerfd < 0) {
-        fprintf(stderr, "could not open %s, %s\n", powerdev, strerror(errno));
-        return 1;
-    }
-
-    notifyfd = inotify_init();
-    if(notifyfd < 0) {
-        fprintf(stderr, "inotify_init failed, %s\n", strerror(errno));
-        return 1;
-    }
-    fcntl(notifyfd, F_SETFL, O_NONBLOCK | fcntl(notifyfd, F_GETFL));
-    for(i = 0; i < ARRAY_SIZE(watched_files); i++) {
-        watched_files[i].id = inotify_add_watch(notifyfd, watched_files[i].filename, IN_MODIFY);
-        printf("Watching %s, id %d\n", watched_files[i].filename, watched_files[i].id);
-    }
-
-    acquire_partial_wake_lock_fd = open(android_acquire_partial_wake_lock_dev, O_RDWR);
-    acquire_full_wake_lock_fd = open(android_acquire_full_wake_lock_dev, O_RDWR);
-    release_wake_lock_fd = open(android_release_wake_lock_dev, O_RDWR);
-
-    if(user_activity_fd >= 0) {
-        idle_time = 60*60*24; // driver handles real timeout
-    }
-    if(gotkey) {
-        tv.tv_sec = idle_time;
-        tv.tv_usec = 0;
-    }
-    else {
-        tv.tv_sec = 0;
-        tv.tv_usec = 500000;
-    }
-    
-    while(1) {
-        FD_ZERO(&rfds);
-        //FD_SET(0, &rfds);
-        FD_SET(eventfd, &rfds);
-        FD_SET(notifyfd, &rfds);
-        res = select(((notifyfd > eventfd) ? notifyfd : eventfd) + 1, &rfds, NULL, NULL, &tv);
-        if(res < 0) {
-            fprintf(stderr, "select failed, %s\n", strerror(errno));
-            return 1;
-        }
-        if(res == 0) {
-            if(light_event2.value == 1)
-                goto light2_off;
-            if(light_event.value == 1)
-                goto light_off;
-            if(user_activity_fd < 0) {
-                if(gotkey && verbose > 0)
-                    printf("Idle - sleep\n");
-                if(!gotkey && verbose > 1)
-                    printf("Reenter sleep\n");
-                goto sleep;
-            }
-            else {
-                tv.tv_sec = 60*60*24;
-                tv.tv_usec = 0;
-            }
-        }
-        if(res > 0) {
-            //if(FD_ISSET(0, &rfds)) {
-            //  printf("goto data on stdin quit\n");
-            //  return 0;
-            //}
-            if(FD_ISSET(notifyfd, &rfds)) {
-                write(acquire_partial_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-                if(handle_inotify_event(notifyfd) > 0) {
-                    write(acquire_full_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-                }
-                write(release_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-            }
-            if(FD_ISSET(eventfd, &rfds)) {
-                write(acquire_partial_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-                res = read(eventfd, &event, sizeof(event));
-                if(res < (int)sizeof(event)) {
-                    fprintf(stderr, "could not get event\n");
-                    write(release_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-                    return 1;
-                }
-                if(event.type == EV_PWR && event.code == KEY_SLEEP) {
-                    event_sleep = event.value;
-                }
-                if(event.type == EV_KEY || (event.type == EV_SW && event.code == SW_0 && event.value == 1)) {
-                    gotkey = 1;
-                    if(user_activity_fd >= 0) {
-                        char buf[32];
-                        int len;
-                        len = sprintf(buf, "%ld%06lu000", event.time.tv_sec, event.time.tv_usec);
-                        write(user_activity_fd, buf, len);
-                    }
-                    if(lcd_light_time | key_light_time) {
-                        tv.tv_sec = key_light_time;
-                        light_event.value = 1;
-                        write(eventfd, &light_event, sizeof(light_event));
-                        light_event2.value = 1;
-                        write(eventfd, &light_event2, sizeof(light_event2));
-                    }
-                    else {
-                        tv.tv_sec = idle_time;
-                    }
-                    tv.tv_usec = 0;
-                    if(verbose > 1)
-                        printf("got %s %s %d%s\n", event.type == EV_KEY ? "key" : "switch", event.value ? "down" : "up", event.code, event_sleep ? " from sleep" : "");
-                    if(event.code == KEY_POWER) {
-                        if(event.value == 0) {
-                            int tmp_got_power_key_down = got_power_key_down;
-                            got_power_key_down = 0;
-                            if(tmp_got_power_key_down) {
-                                // power key released
-                                if(verbose > 0)
-                                    printf("Power key released - sleep\n");
-                                write(release_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-                                goto sleep;
-                            }
-                        }
-                        else if(event_sleep == 0) {
-                            got_power_key_down = 1;
-                            power_key_down_time = event.time;
-                        }
-                    }
-                }
-                if(event.type == EV_SW && event.code == SW_0 && event.value == 0) {
-                    if(verbose > 0)
-                        printf("Flip closed - sleep\n");
-                    power_key_down_time = event.time;
-                    write(release_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-                    goto sleep;
-                }
-                write(release_wake_lock_fd, wakelockstring, sizeof(wakelockstring) - 1);
-            }
-        }
-        if(0) {
-light_off:
-            light_event.value = 0;
-            write(eventfd, &light_event, sizeof(light_event));
-            tv.tv_sec = idle_time - lcd_light_time;
-        }
-        if(0) {
-light2_off:
-            light_event2.value = 0;
-            write(eventfd, &light_event2, sizeof(light_event2));
-            tv.tv_sec = lcd_light_time - key_light_time;
-        }
-        if(0) {
-sleep:
-            if(light_event.value == 1) {
-                light_event.value = 0;
-                write(eventfd, &light_event, sizeof(light_event));
-                light_event2.value = 0;
-                write(eventfd, &light_event2, sizeof(light_event2));
-                tv.tv_sec = idle_time - lcd_light_time;
-            }
-            if(powerfd_is_sleep) {
-                char buf[32];
-                int len;
-                len = sprintf(buf, "%ld%06lu000", power_key_down_time.tv_sec, power_key_down_time.tv_usec);
-                write(powerfd, buf, len);
-            }
-            else
-                write(powerfd, suspendstring, sizeof(suspendstring) - 1);
-            gotkey = 0;
-            tv.tv_sec = 0;
-            tv.tv_usec = 500000;
-        }
-    }
-
-    return 0;
-}