4 * Copyright (c) Tuomo Valkonen 1999-2008.
6 * See the included file LICENSE for details.
14 #include <sys/types.h>
19 #include <libtu/util.h>
20 #include <libtu/optparser.h>
21 #include <libtu/errorlog.h>
22 #include <libtu/prefix.h>
23 #include <libextl/readconfig.h>
24 #include <libmainloop/exec.h>
26 #include <ioncore/common.h>
27 #include <ioncore/global.h>
28 #include <ioncore/ioncore.h>
29 #include <ioncore/exec.h>
30 #include <ioncore/event.h>
31 #include "../version.h"
34 /* Options. Getopt is not used because getopt_long is quite gnu-specific
35 * and they don't know of '-display foo' -style args anyway.
36 * Instead, I've reinvented the wheel in libtu :(.
38 static OptParserOpt pwm_opts[]={
39 {OPT_ID('d'), "display", OPT_ARG, "host:dpy.scr",
40 DUMMY_TR("X display to use")},
42 {'c', "conffile", OPT_ARG, "config_file",
43 DUMMY_TR("Configuration file")},
45 {'s', "searchdir", OPT_ARG, "dir",
46 DUMMY_TR("Add directory to search path")},
48 {OPT_ID('o'), "oneroot", 0, NULL,
49 DUMMY_TR("Manage default screen only")},
51 {OPT_ID('s'), "session", OPT_ARG, "session_name",
52 DUMMY_TR("Name of session (affects savefiles)")},
54 {OPT_ID('S'), "smclientid", OPT_ARG, "client_id",
55 DUMMY_TR("Session manager client ID")},
57 {OPT_ID('N'), "noerrorlog", 0, NULL,
58 DUMMY_TR("Do not create startup error log and display it "
61 {'h', "help", 0, NULL,
62 DUMMY_TR("Show this help")},
64 {'V', "version", 0, NULL,
65 DUMMY_TR("Show program version")},
67 {OPT_ID('a'), "about", 0, NULL,
68 DUMMY_TR("Show about text")},
77 printf(TR("Usage: %s [options]\n\n"), libtu_progname());
78 for(i=0; pwm_opts[i].descr!=NULL; i++)
79 pwm_opts[i].descr=TR(pwm_opts[i].descr);
80 optparser_printhelp(OPTP_MIDLONG, pwm_opts);
85 int main(int argc, char*argv[])
87 const char *cfgfile="cfg_pwm";
88 const char *display=NULL;
95 bool may_continue=FALSE;
96 bool noerrorlog=FALSE;
101 #ifdef CF_RELOCATABLE_PWM3_LOCATION
102 prefix_set(argv[0], CF_RELOCATABLE_PWM3_LOCATION);
105 localedir=prefix_add(LOCALEDIR);
107 if(!ioncore_init("pwm3", argc, argv, localedir))
113 prefix_wrap_simple(extl_add_searchdir, EXTRABINDIR); /* ion-completefile */
114 prefix_wrap_simple(extl_add_searchdir, MODULEDIR);
115 prefix_wrap_simple(extl_add_searchdir, ETCDIR);
117 prefix_wrap_simple(extl_add_searchdir, PWM_ETCDIR);
119 prefix_wrap_simple(extl_add_searchdir, SHAREDIR);
120 prefix_wrap_simple(extl_add_searchdir, LCDIR);
121 extl_set_userdirs("pwm3");
123 optparser_init(argc, argv, OPTP_MIDLONG, pwm_opts);
125 while((opt=optparser_get_opt())){
128 display=optparser_get_arg();
131 cfgfile=optparser_get_arg();
134 extl_add_searchdir(optparser_get_arg());
137 ioncore_g.sm_client_id=optparser_get_arg();
140 stflags|=IONCORE_STARTUP_ONEROOT;
143 extl_set_sessiondir(optparser_get_arg());
152 printf("%s\n", ION_VERSION);
155 printf("%s\n", ioncore_aboutmsg());
158 warn(TR("Invalid command line."));
165 /* We may have to pass the file to xmessage so just using tmpfile()
168 libtu_asprintf(&efnam, "%s/pwm-%d-startup-errorlog", P_tmpdir,
173 ef=fopen(efnam, "wt");
179 cloexec_braindamage_fix(fileno(ef));
180 fprintf(ef, TR("PWM startup error log:\n"));
181 errorlog_begin_file(&el, ef);
186 if(ioncore_startup(display, cfgfile, stflags))
191 warn(TR("Refusing to start due to encountered errors."));
195 if(errorlog_end(&el) && ioncore_g.dpy!=NULL){
199 ioncore_setup_display(DefaultScreen(ioncore_g.dpy));
201 XCloseDisplay(ioncore_g.dpy);
203 close(ioncore_g.conn);
204 libtu_asprintf(&cmd, CF_XMESSAGE " %s", efnam);
207 }else if(system(cmd)==-1){
213 if(!may_continue && pid>0)
214 waitpid(pid, NULL, 0);
228 /* The code should never return here */