Fixed captive-sandbox-server(8) regarding: captive_standalone_init()
[captive.git] / src / libcaptive / client / standalone.c
1 /* $Id$
2  * General + --enable-standalone optional init for static builds of captive
3  * Copyright (C) 2005 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "standalone.h" /* self */
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <glib-object.h>
26 #include <locale.h>
27
28
29 gboolean captive_standalone_init_done=FALSE;
30
31 /* WARNING: Function is called unprotected with SETUID! */
32 void captive_standalone_init(void)
33 {
34         if (captive_standalone_init_done)
35                 return;
36
37 #ifdef ENABLE_STANDALONE
38
39         /* Prevent glibc loading: /usr/lib/gconv/gconv-modules.cache */
40         setenv("GCONV_PATH","/foobar",
41                         1);     /* overwrite */
42
43         /* Not needed: "LIBCHARSET_ALIAS_DIR"
44          * as prevented by: glib-2.6.4-noaliases.patch
45          */
46
47         if (getenv("LC_ALL"))
48                 setenv("LC_MESSAGES",getenv("LC_ALL"),
49                                 1);     /* overwrite */
50         if (!getenv("LC_MESSAGES") && getenv("LANG"))
51                 setenv("LC_MESSAGES",getenv("LANG"),
52                                 1);     /* overwrite */
53         setenv("LC_CTYPE","en_US.utf8",
54                         1);     /* overwrite */
55         unsetenv("LANG");
56         unsetenv("LC_COLLATE");
57         unsetenv("LC_MONETARY");
58         unsetenv("LC_NUMERIC");
59         unsetenv("LC_TIME");
60
61         /* It may differ across distributions. Maybe - just expected. */
62         setenv("LOCPATH",LOCALEDIR,
63                         1);     /* overwrite */
64
65 #endif /* ENABLE_STANDALONE */
66
67         /* Prevent output block buffering if redirecting stdout to file. */
68         setvbuf(stdout,(char *)NULL,_IONBF,0);
69         setvbuf(stderr,(char *)NULL,_IONBF,0);
70
71         /* Initialize the i18n stuff */
72         setlocale(LC_ALL,"");
73         bindtextdomain(PACKAGE,LOCALEDIR);
74         textdomain(PACKAGE);
75
76         /* Initialize GObject subsystem of GLib. */
77         g_type_init();
78
79         captive_standalone_init_done=TRUE;
80 }