4 * Copyright (c) Tuomo Valkonen 1999-2006.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
17 #include <sys/types.h>
22 #include <libtu/util.h>
23 #include <libtu/optparser.h>
24 #include <libtu/errorlog.h>
25 #include <libextl/readconfig.h>
26 #include <libmainloop/exec.h>
28 #include <ioncore/common.h>
29 #include <ioncore/global.h>
30 #include <ioncore/ioncore.h>
31 #include <ioncore/exec.h>
32 #include <ioncore/event.h>
33 #include "../version.h"
36 /* Options. Getopt is not used because getopt_long is quite gnu-specific
37 * and they don't know of '-display foo' -style args anyway.
38 * Instead, I've reinvented the wheel in libtu :(.
40 static OptParserOpt ion_opts[]={
41 {OPT_ID('d'), "display", OPT_ARG, "host:dpy.scr",
42 DUMMY_TR("X display to use")},
44 {'c', "conffile", OPT_ARG, "config_file",
45 DUMMY_TR("Configuration file")},
47 {'s', "searchdir", OPT_ARG, "dir",
48 DUMMY_TR("Add directory to search path")},
50 {OPT_ID('o'), "oneroot", 0, NULL,
51 DUMMY_TR("Manage default root window/non-Xinerama screen only")},
53 #if defined(CF_XINERAMA) || defined(CF_SUN_XINERAMA)
54 {OPT_ID('x'), "xinerama", OPT_ARG, "1|0",
55 DUMMY_TR("Use Xinerama screen information (default: 1/yes)")},
57 {OPT_ID('x'), "xinerama", OPT_ARG, "?",
58 DUMMY_TR("Ignored: not compiled with Xinerama support")},
61 {OPT_ID('s'), "session", OPT_ARG, "session_name",
62 DUMMY_TR("Name of session (affects savefiles)")},
64 {OPT_ID('S'), "smclientid", OPT_ARG, "client_id",
65 DUMMY_TR("Session manager client ID")},
67 {OPT_ID('N'), "noerrorlog", 0, NULL,
68 DUMMY_TR("Do not create startup error log and display it "
71 {'h', "help", 0, NULL,
72 DUMMY_TR("Show this help")},
74 {'V', "version", 0, NULL,
75 DUMMY_TR("Show program version")},
77 {OPT_ID('a'), "about", 0, NULL,
78 DUMMY_TR("Show about text")},
84 void check_new_user_help()
86 const char *userdir=extl_userdir();
88 char *tmp=NULL, *cmd=NULL;
93 warn(TR("Could not get user configuration file directory."));
97 libtu_asprintf(&oldbeard, "%s/.welcome_msg_displayed", userdir);
102 if(access(oldbeard, F_OK)==0){
107 libtu_asprintf(&tmp, TR("%s/welcome.txt"), SHAREDIR);
110 if(access(tmp, F_OK)==0)
111 libtu_asprintf(&cmd, "%s %s", CF_XMESSAGE, tmp);
113 libtu_asprintf(&cmd, "%s %s/welcome.txt", CF_XMESSAGE, SHAREDIR);
118 ret=ioncore_exec(cmd);
123 /* This should actually be done when less or xmessage returns,
124 * but that would mean yet another script...
126 mkdir(userdir, 0700);
127 if(open(oldbeard, O_CREAT|O_RDWR, 0600)<0)
128 warn_err_obj(oldbeard);
140 printf(TR("Usage: %s [options]\n\n"), prog_execname());
141 for(i=0; ion_opts[i].descr!=NULL; i++)
142 ion_opts[i].descr=TR(ion_opts[i].descr);
143 optparser_printhelp(OPTP_MIDLONG, ion_opts);
148 int main(int argc, char*argv[])
150 const char *cfgfile="cfg_ion";
151 const char *display=NULL;
158 bool may_continue=FALSE;
159 bool noerrorlog=FALSE;
163 if(!ioncore_init("ion3", argc, argv, LOCALEDIR))
166 extl_add_searchdir(EXTRABINDIR); /* ion-completefile */
167 extl_add_searchdir(MODULEDIR);
168 extl_add_searchdir(ETCDIR);
169 extl_add_searchdir(SHAREDIR);
170 extl_add_searchdir(LCDIR);
171 extl_set_userdirs("ion3");
173 optparser_init(argc, argv, OPTP_MIDLONG, ion_opts);
175 while((opt=optparser_get_opt())){
178 display=optparser_get_arg();
181 cfgfile=optparser_get_arg();
184 extl_add_searchdir(optparser_get_arg());
187 ioncore_g.sm_client_id=optparser_get_arg();
190 stflags|=IONCORE_STARTUP_ONEROOT;
194 const char *p=optparser_get_arg();
195 if(strcmp(p, "1")==0)
196 stflags&=~IONCORE_STARTUP_NOXINERAMA;
197 else if(strcmp(p, "0")==0)
198 stflags|=IONCORE_STARTUP_NOXINERAMA;
200 warn(TR("Invalid parameter to -xinerama."));
204 extl_set_sessiondir(optparser_get_arg());
213 printf("%s\n", ION_VERSION);
216 printf("%s\n", ioncore_aboutmsg());
219 warn(TR("Invalid command line."));
226 /* We may have to pass the file to xmessage so just using tmpfile()
229 libtu_asprintf(&efnam, "%s/ion-%d-startup-errorlog", P_tmpdir,
234 ef=fopen(efnam, "wt");
240 cloexec_braindamage_fix(fileno(ef));
241 fprintf(ef, TR("Ion startup error log:\n"));
242 errorlog_begin_file(&el, ef);
247 if(ioncore_startup(display, cfgfile, stflags))
252 warn(TR("Refusing to start due to encountered errors."));
254 check_new_user_help();
258 if(errorlog_end(&el) && ioncore_g.dpy!=NULL){
262 ioncore_setup_environ(DefaultScreen(ioncore_g.dpy));
264 XCloseDisplay(ioncore_g.dpy);
266 close(ioncore_g.conn);
267 libtu_asprintf(&cmd, CF_XMESSAGE " %s", efnam);
270 }else if(system(cmd)==-1){
276 if(!may_continue && pid>0)
277 waitpid(pid, NULL, 0);
291 /* The code should never return here */