2 * kernel.c - the core of fbcondecor_helper
4 * Copyright (C) 2004-2007, Michal Januszewski <spock@gentoo.org>
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License v2. See the file COPYING in the main directory of this archive for
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
21 #include <linux/tiocl.h>
25 #include "fbcon_decor.h"
30 * Opens /dev/console as stdout and stderr. This will not work if console
31 * is set to a serial console, because ttySx are not initialized at the
32 * point where this function is used.
38 fd
= open(PATH_DEV
"/console", O_WRONLY
);
46 int handle_init(bool update
)
51 #ifdef CONFIG_FBCON_DECOR
52 bool fbcon_decor
= true;
55 /* If possible, make sure that the error messages don't go straight
56 * to /dev/null and are displayed on the screen instead. */
62 /* Parse the kernel command line to get splash settings. */
63 mkdir(PATH_PROC
,0700);
64 h
= mount("proc", PATH_PROC
, "proc", 0, NULL
);
65 fbsplash_parse_kcmdline(true);
69 if (config
.reqmode
== FBSPL_MODE_OFF
)
72 /* We don't want to use any effects if we're just updating the image.
73 * Nor do we want to mess with the verbose mode. */
75 config
.effects
= FBSPL_EFF_NONE
;
76 #ifdef CONFIG_FBCON_DECOR
81 theme
= fbsplashr_theme_load();
85 #ifdef CONFIG_FBCON_DECOR
86 fd_fbcondecor
= fbcon_decor_open(true);
87 if (fd_fbcondecor
== -1) {
88 fprintf(stderr
, "Failed to open the fbcon_decor control device.\n");
92 if (!update
&& (config
.reqmode
& FBSPL_MODE_VERBOSE
) && fbcon_decor
) {
93 if (fbcon_decor_setcfg(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, theme
))
96 if (fbcon_decor_setpic(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, theme
))
104 /* Activate verbose mode if it was explicitly requested. If silent mode
105 * was requested, the verbose background image will be set after the
106 * switch to the silent tty is complete. */
107 if (config
.reqmode
== FBSPL_MODE_VERBOSE
) {
108 #ifdef CONFIG_FBCON_DECOR
109 /* Activate fbcon_decor on the first tty if the picture and
110 * the config file were successfully loaded. */
112 fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, 1);
115 fprintf(stderr
, "Failed to get background decoration image.\n");
119 fprintf(stderr
, "This version of splashutils was compiled without support for fbcondecor.\n"
120 "Verbose mode will not be activated\n");
125 if (!(theme
->modes
& FBSPL_MODE_SILENT
))
128 fd_tty0
= open("/dev/console", O_RDWR
);
130 fbsplash_set_silent();
131 fbsplashr_tty_silent_init(true);
132 fbsplashr_tty_silent_update();
134 /* Redirect all kernel messages to tty1 so that they don't get
135 * printed over our silent splash image. */
136 buf
[0] = TIOCL_SETKMSGREDIRECT
;
138 ioctl(fd_tty
[config
.tty_s
], TIOCLINUX
, buf
);
140 if (config
.kdmode
== KD_GRAPHICS
)
141 ioctl(fd_tty
[config
.tty_s
], KDSETMODE
, KD_GRAPHICS
);
143 fbsplashr_render_screen(theme
, true, true, config
.effects
);
145 #ifdef CONFIG_FBCON_DECOR
146 if (fbcon_decor
&& config
.reqmode
& FBSPL_MODE_VERBOSE
)
147 fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_USER
, arg_vc
, 1);
150 /* We're the kernel helper. We try to do our task as efficiently
151 * as possible and don't care about any cleanup. */
155 int main(int argc
, char **argv
)
164 fbsplash_lib_init(fbspl_undef
);
166 if (strcmp(argv
[1],"2") && strcmp(argv
[1], "1")) {
167 fprintf(stderr
, "Splash protocol mismatch: %s\n", argv
[1]);
168 fprintf(stderr
, "This version of splashutils supports splash protocol v1 and v2.\n");
173 if (argc
> 3 && argv
[3])
174 arg_vc
= atoi(argv
[3]);
181 if (!strcmp(argv
[1],"1")) {
185 /* On 'init' the theme isn't defined yet, and thus NULL is passed
186 * instead of any meaningful value. */
187 if (argc
> i
&& argv
[i
]) {
188 fbsplash_acc_theme_set(argv
[i
]);
190 mkdir(PATH_SYS
, 0700);
191 if (!mount("sysfs", PATH_SYS
, "sysfs", 0, NULL
))
195 if (!strcmp(argv
[2],"init")) {
196 err
= handle_init(false);
197 } else if (!strcmp(argv
[2],"repaint")) {
198 err
= handle_init(true);
200 #ifdef CONFIG_FBCON_DECOR
201 else if (config
.theme
) {
204 fbsplashr_init(false);
206 fd_fbcondecor
= fbcon_decor_open(true);
207 if (fd_fbcondecor
== -1) {
208 fprintf(stderr
, "Failed to open the fbcon_decor control device.\n");
213 theme
= fbsplashr_theme_load();
215 fprintf(stderr
, "Failed to load theme '%s'.\n", config
.theme
);
220 if (!strcmp(argv
[2],"getpic")) {
221 err
= fbcon_decor_setpic(FBCON_DECOR_IO_ORIG_KERNEL
, arg_vc
, theme
);
222 } else if (!strcmp(argv
[2],"modechange")) {
223 if ((err
= fbcon_decor_setcfg(FBCON_DECOR_IO_ORIG_KERNEL
, arg_vc
, theme
)))
226 if ((err
= fbcon_decor_setpic(FBCON_DECOR_IO_ORIG_KERNEL
, arg_vc
, theme
)))
229 err
= fbcon_decor_setstate(FBCON_DECOR_IO_ORIG_KERNEL
, arg_vc
, 1);
234 fprintf(stderr
, "Unrecognized splash command: %s.\n", argv
[2]);
239 umount2(PATH_SYS
, 0);
241 #ifdef CONFIG_FBCON_DECOR
242 if (fd_fbcondecor
!= -1)
243 close(fd_fbcondecor
);