2
* luakit.c - luakit main functions
4
* Copyright © 2010-2011 Mason Larobina <mason.larobina@gmail.com>
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "globalconf.h"
22
#include "common/util.h"
33
static void sigchld(int sigint);
38
while(0 < waitpid(-1, NULL, WNOHANG));
42
init_lua(gchar **uris)
47
/* init globalconf structs */
48
globalconf.windows = g_ptr_array_new();
54
/* push a table of the statup uris */
56
for (gint i = 0; uris && (uri = uris[i]); i++) {
57
lua_pushstring(L, uri);
58
lua_rawseti(L, -2, i + 1);
60
lua_setglobal(L, "uris");
64
init_directories(void)
66
/* create luakit directory */
67
globalconf.cache_dir = g_build_filename(g_get_user_cache_dir(), "luakit", NULL);
68
globalconf.config_dir = g_build_filename(g_get_user_config_dir(), "luakit", NULL);
69
globalconf.data_dir = g_build_filename(g_get_user_data_dir(), "luakit", NULL);
70
g_mkdir_with_parents(globalconf.cache_dir, 0771);
71
g_mkdir_with_parents(globalconf.config_dir, 0771);
72
g_mkdir_with_parents(globalconf.data_dir, 0771);
75
/* load command line options into luakit and return uris to load */
77
parseopts(int argc, gchar *argv[], gboolean **nonblock) {
78
GOptionContext *context;
79
gboolean *version_only = NULL;
80
gboolean *check_only = NULL;
83
/* save luakit exec path */
84
globalconf.execpath = g_strdup(argv[0]);
86
/* define command line options */
87
const GOptionEntry entries[] = {
88
{ "uri", 'u', 0, G_OPTION_ARG_STRING_ARRAY, &uris, "uri(s) to load at startup", "URI" },
89
{ "config", 'c', 0, G_OPTION_ARG_STRING, &globalconf.confpath, "configuration file to use", "FILE" },
90
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &globalconf.verbose, "print debugging output", NULL },
91
{ "version", 'V', 0, G_OPTION_ARG_NONE, &version_only, "print version and exit", NULL },
92
{ "check", 'k', 0, G_OPTION_ARG_NONE, &check_only, "check config and exit", NULL },
93
{ "nonblock",'n', 0, G_OPTION_ARG_NONE, nonblock, "run in background", NULL },
94
{ NULL, 0, 0, 0, NULL, NULL, NULL },
97
/* parse command line options */
98
context = g_option_context_new("[URI...]");
99
g_option_context_add_main_entries(context, entries, NULL);
100
g_option_context_add_group(context, gtk_get_option_group(FALSE));
101
// TODO Passing gtk options (like --sync) to luakit causes a segfault right
102
// here. I'm clueless.
103
g_option_context_parse(context, &argc, &argv, NULL);
104
g_option_context_free(context);
106
/* print version and exit */
108
g_printf("luakit %s\n", VERSION);
112
/* check config syntax and exit */
116
if (!luaH_parserc(globalconf.confpath, FALSE)) {
117
g_fprintf(stderr, "Confiuration file syntax error.\n");
120
g_fprintf(stderr, "Configuration file syntax OK.\n");
126
fatal("invalid mix of -u and default uri arguments");
135
main(gint argc, gchar *argv[]) {
136
gboolean *nonblock = NULL;
140
/* clean up any zombies */
141
struct sigaction sigact;
142
sigact.sa_handler=sigchld;
143
sigemptyset (&sigact.sa_mask);
144
sigact.sa_flags = SA_NOCLDSTOP;
145
if (sigaction(SIGCHLD, &sigact, NULL))
146
fatal("Can't install SIGCHLD handler");
148
/* set numeric locale to C (required for compatibility with
149
LuaJIT and luakit scripts) */
151
gtk_disable_setlocale();
152
setlocale(LC_NUMERIC, "C");
154
/* parse command line opts and get uris to load */
155
uris = parseopts(argc, argv, &nonblock);
157
/* if non block mode - respawn, detach and continue in child */
161
fatal("Cannot fork: %d", errno);
162
} else if (pid > 0) {
167
fatal("New SID creation failure: %d", errno);
171
gtk_init(&argc, &argv);
172
if (!g_thread_supported())
178
/* parse and run configuration file */
179
if(!luaH_parserc(globalconf.confpath, TRUE))
180
fatal("couldn't find rc file");
182
if (!globalconf.windows->len)
183
fatal("no windows spawned by rc file, exiting");
189
// vim: ft=c:et:sw=4:ts=8:sts=4:tw=80