Hi everybody,
I enjoy using initng, but after the last update I made, the bootsplash plugin
didn't work anymore for progressbar animation.
It seems some plugin functions has changed. I grabbed the plugin file and
tried to make it work with 0.6.10.1 version.
It actually works again, but there is a lot of code useless, and even not
used.
I post it into this mailing list, it could interest some people...
Thanks,
Mat
/* Initng, a next generation sysvinit replacement.
* Copyright (C) 2005 Jimmy Wennlund <[EMAIL PROTECTED]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef INITNG_SPLASH_H
#define INITNG_SPLASH_H
#define BOOTSPLASH_FIFO "/proc/splash"
#endif
name : splash
author : Jimmy Wennlund <[EMAIL PROTECTED]>
contributors :
commands :
options :
description : If this plugin is loaded, the service list is duplicated on
the console when executing keyboard splash, ( Alt + KeyUp )
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR} )
ADD_LIBRARY(splash MODULE initng_splash.c)
TARGET_LINK_LIBRARIES(splash initng)
INSTALL_TARGETS(${LIB_INSTALL_DIR}/initng splash)
/* Initng, a next generation sysvinit replacement.
* Copyright (C) 2005 Jimmy Wennlund <[EMAIL PROTECTED]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <initng.h>
#include <stdio.h>
#include <stdlib.h> /* free() exit() */
#include <string.h>
#include <assert.h>
#include <signal.h>
/*#include <time.h> */
#include <initng_handler.h>
#include <initng_global.h>
#include <initng_common.h>
#include <initng_toolbox.h>
#include <initng_static_data_id.h>
#include <initng_static_states.h>
#include <initng_static_service_types.h>
#include <initng_static_event_types.h>
#include <initng_event_hook.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <initng/initng.h>
#include <initng/initng_is.h>
#include <initng/initng_global.h>
#include <initng/initng_process_db.h>
#include <initng/initng_service_cache.h>
#include <initng/initng_handler.h>
#include <initng/initng_active_db.h>
#include <initng/initng_toolbox.h>
#include <initng/initng_plugin_hook.h>
#include <initng/initng_load_module.h>
#include <initng/initng_plugin_callers.h>
#include <initng/initng_global.h>
#include <initng/initng_error.h>
#include <initng/initng_plugin.h>
#include <initng/initng_control_command.h>
#include <initng/initng_static_data_id.h>
#include <initng/initng_static_states.h>
INITNG_PLUGIN_MACRO;
#include "initng_splash.h"
/*
*
* "module global" variables ...
* is it better to pack them all to a struct?
*
*/
FILE *file = NULL ;
char szBuffer;
enum
{
SPLASH_NONE,
BOOTSPLASH
};
static int old_percent = -1;
static int splash_type = BOOTSPLASH;
//static char paint_cmd[200] = "repaint\n";
/*static const char *control_file[] = {
NULL,
BOOTSPLASH_FIFO
};*/
/* static const char* splash_message[] = {
NULL,
"progress %d\nrepaint\n",
"progress %d\n"
}; */
/*
*
* We add a new command, that will install the hooks
* this command is called by the initscript that brings up
* splash
*
* i hope this will increase performance ;)
*
*/
s_command SPLASH_CMD = { 'S', "enable-splash", TRUE_OR_FALSE_COMMAND,
HIDDEN_COMMAND, REQUIRES_OPT,
{(void *) &cmd_splash},
"to be called from splash init scripts"
};
static FILE *try_to_open(const char *file_name)
{
FILE *ret = NULL;
int fd = -1;
if ((fd = open(file_name, O_WRONLY | O_NONBLOCK)) < 0)
{
D_("splash: could not open control file %s\n", file_name);
return (NULL);
}
ret = fdopen(fd, "w");
D_("SPLASH: splash control fifo %s open\n", file_name);
return (ret);
}
static int print_progress(s_event * event)
{
/*
* for now this only works when starting up the system
* 10/03/05 SaTaN0rX: works also for shutdown
*/
active_db_h *service ;
//assert(event->event_type == &EVENT_SIGNAL);
service = event->data;;
int percent = 0;
FILE *fd = NULL;
D_("SPLASH: print_progress()\n");
if (!service)
return (TRUE);
/*
* 11/15/05 SaTaN0rX:
* /proc/splash thing is for bootsplash support.
* bootsplash is in the kernel and needs no extra daemon.
* due to this, we just try to open BOOTSPLASH_FIFO if splash_type == SPLASH_NONE,
* to autodetect bootsplash. IMHO it's an overkill to add an service, just to
* inform this plugin about bootsplash
*/
//if (splash_type == SPLASH_NONE)
{
D_("splash: we are called, but splash_type == SPLASH_NONE, trying to open " BOOTSPLASH_FIFO "\n");
fd = try_to_open(BOOTSPLASH_FIFO);
if (!fd) {
return (TRUE);
}
splash_type = BOOTSPLASH;
}
if (g.sys_state == STATE_STARTING)
{
percent = initng_active_db_percent_started() ;
}
else
{
percent = 100-initng_active_db_percent_stopped();
}
/*
* for some odd reason, the percent can get lower during the boot process...
* this sucks.
* so here's the check
*/
//if ( (percent < 100 || g.sys_state != STATE_STARTING ) && ( shutting_down == 0 && percent > old_percent ) ) { //&& (old_percent == -1 || percent > 0) ) {
if ( g.sys_state != STATE_STARTING || percent > old_percent ) {
//(g.sys_state != STATE_STARTING && percent < old_percent ) ) {
old_percent = percent;
/* open splash control file */
if (!fd) {
fd = try_to_open(BOOTSPLASH_FIFO) ;
}
if (!fd)
{
D_("splash: no control file\n");
return (TRUE);
}
fprintf(fd, "show %d\n", (65535 * percent) / 100);
#if 0 /* this should be done by the just_before plugin now ... IMHO an cleaner solution */
/*
* see if X11 is starting
*/
if (strstr(service->name, "daemon/gdm") ||
strstr(service->name, "daemon/kdm") ||
strstr(service->name, "daemon/xdm") ||
strstr(service->name, "daemon/wdm") || percent == 100) {
if (service->current_state == &LOADING ||
service->current_state == &STARTING ||
service->current_state == &RUNNING ||
service->current_state == &DONE || percent == 100) {
/* X11 is being started or runs, or we have reached 100% */
fprintf(fd, "show 65535\n");
fprintf(fd, "master\n");
old_percent = 101 ;
}
}
#endif
fclose(fd);
}
return (TRUE);
}
#if 0
/*
* we now use the up plugin to do this
* the called script then uses the -S command to
* inform the plugin
*
*/
/*static void print_system_state(h_sys_state state)
{
if (state == STATE_UP)
{
if (!start_new_service_named("system/splash/stop"))
F_("Splash stopper \"system/splash/stop\" could not be executed!\n");
}
else if (state == STATE_STOPPING && !shutting_down)
{
//start_new_service_named("system/splash/shutdown");
old_percent = 0;
shutting_down = 1;
}
}*/
#endif
static int cmd_splash(char *arg)
{
// char *p_cmd;
if (!arg)
return (FALSE);
splash_type = SPLASH_NONE;
if (strstr(arg, "bootsplash"))
{
splash_type = BOOTSPLASH;
}
if (strstr(arg, "shutdown"))
{
//shutting_down = 1;
old_percent = 0;
/* initng_add_hook(ASTATUS_CHANGE, 80, &print_progress); */
}
else if (strstr(arg, "off"))
{
/* initng_del_hook(ASTATUS_CHANGE, &print_progress); */
splash_type = SPLASH_NONE;
return (TRUE);
}
else
{
/*
* if neither shutdown nor off are specified,
* we guess the cmd was boot.
* this way we can mit boot.
*/
//shutting_down = 0;
old_percent = 0;
/* initng_add_hook(ASTATUS_CHANGE, 80, &print_progress); */
}
if (splash_type == SPLASH_NONE)
{
D_("splash: No splash type specified\n");
return (FALSE);
}
/*if ((p_cmd = strstr(arg, "cmd:")))
{
strncpy(paint_cmd, p_cmd + 4, 199);
paint_cmd[199] = '\0';
}*/
return (TRUE);
}
int module_init(int api_version)
{
D_("splash: module_load();\n");
if (api_version != API_VERSION)
{
F_("This module is compiled for api_version %i version and initng is compiled on %i version, won't load this module!\n", INITNG_VERSION, api_version);
return (FALSE);
}
//initng_plugin_hook_add(&g.ASTATUS_CHANGE, 80, &print_progress);
initng_event_hook_register(&EVENT_STATE_CHANGE, &print_progress);
/* initng_add_hook(SWATCHERS, 90, &print_system_state); */
//initng_command_add(&SPLASH_CMD);
//initng_command_register(&SPLASH_CMD);
return (TRUE);
}
void module_unload(void)
{
D_("splash: module_unload();\n");
/*
* maybe this is still loaded ?
* what can happen if we try to unload it and it has already been unloaded ?
*/
initng_event_hook_unregister(&EVENT_STATE_CHANGE, &print_progress);
/*initng_plugin_hook_del(&g.ASTATUS_CHANGE, &print_progress);
initng_command_del(&SPLASH_CMD);*/
/* initng_del_hook(SWATCHERS, &print_system_state); */
}
--
_______________________________________________
Initng mailing list
[email protected]
http://jw.dyndns.org/mailman/listinfo/initng