All pastes #1014543 Raw Edit

clueless

public text v1 · immutable
#1014543 ·published 2008-05-11 08:10 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <pthread.h>#include <fbsplash.h>#include <einit/einit.h>struct fbspl_theme *theme = NULL;extern fbspl_cfg_t config;char *current_mode = NULL;int ttyfd = 0;int splash_verbose = 0;int progress_ratio = 0;int eInit_Connect (int argc, char **argv) {  char *path = getenv ("PATH");  if (path)    einit_global_environment = straddtoenviron (einit_global_environment, "PATH", path);  if ((einit_connect (&argc, argv))<0) {    perror("Could not connect to eInit");    sleep(1);    if ((einit_connect (&argc, argv))<0) {      perror("Could not connect to eInit, giving up");      return -1;    }  }  return 0;}void handle_notice (struct einit_event *ev) { }void handle_enable (struct einit_event *ev) {}void handle_disable (struct einit_event *ev) {}void handle_progress (struct einit_event *ev) {  progress_ratio = ev->integer*10.24;  //printf("Progress: %i\n", progress_ratio);  //char key;  fbsplashr_progress_set(theme, progress_ratio);  fbsplashr_render_screen(theme, false, false, FBSPL_EFF_NONE);  //key = fbsplashr_input_getkey(false);  //if (key == '\x1b')  // break;  }void handle_boot (struct einit_event *ev) {  pid_t child;  if(geteuid() == 0) {    child = vfork();    if(child<0) {      perror("fork:");      return;    } else if(child==0) {      execl(FBSPLASH_DAEMON, NULL);      _exit(EXIT_SUCCESS);    }  }  /* Picard: Make it so. Warp Three. Engage! */  fbsplashr_message_set(theme, "Initializing...");  ttyfd = fbsplash_set_silent();  fbsplashr_input_init();  fbsplashr_tty_silent_init(true);  fbsplashr_tty_silent_update();  fbsplashr_render_screen(theme, true, false, FBSPL_EFF_FADEIN);}void finishSplash(void) {  fbsplashr_render_screen(theme, true, false, FBSPL_EFF_FADEOUT);  fbsplashr_tty_silent_cleanup();  fbsplashr_input_cleanup();  fbsplash_set_verbose(ttyfd);}void handle_modes (struct einit_event *ev) {  current_mode = ev->string;  if(!strcmp(current_mode, "boot")) {    // bootup  } else   if(!strcmp(current_mode, "default")) {    // default     // -- finish screen stuff.    // -- maybe kill daemon?    finishSplash();  } else  if(!strcmp(current_mode, "power-down")) {    // shutdown  } else  if(!strcmp(current_mode, "power-reset")) {    // reboot  }  return;}int fbsplash_PrepareLib(void) {  /* Initalize libfbsplash as spl_bootup for now */  fbsplash_lib_init(fbspl_bootup);  fbsplash_parse_kcmdline(false);  fbsplashr_init(false);  theme = fbsplashr_theme_load();  if(!theme) {    fprintf(stdout,"Failed to load theme.\n");    return -1;  }  return 0;}int main (int argc, char **argv) {  int mode = 0;  if ((eInit_Connect(argc, argv))<0)     return -1;  /* fbsplash library init calls */  if(fbsplash_PrepareLib()<0) {    return -1;  }  /* do stuff */  /* handle early bootup for fbsplash daemon    * - enable daemon   * - parse config   * - set initial state    * - daemonize and detach to FIFO */  event_listen (einit_boot_early, handle_boot);  /* handle bootup progress, and update the    * bootsplash progress with ev->integer count */  event_listen (einit_feedback_switch_progress, handle_progress);  /* handle switching modes on-the-fly */  event_listen (einit_core_switch_mode, handle_modes);  /* handle all services enable/disable events */  event_listen (einit_feedback_notice, handle_notice);  event_listen (einit_core_service_enabled, handle_enable);  event_listen (einit_core_service_disabled, handle_disable);  /* end stuff */  einit_event_loop();  einit_disconnect();  fbsplashr_theme_free(theme);  fbsplashr_cleanup();  fbsplash_lib_cleanup();  return 0;}