4 * Copyright (c) Tuomo Valkonen 1999-2007.
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 <libextl/readconfig.h>
23 #include <libmainloop/exec.h>
25 #include <ioncore/common.h>
26 #include <ioncore/global.h>
27 #include <ioncore/ioncore.h>
28 #include <ioncore/exec.h>
29 #include <ioncore/event.h>
30 #include "../version.h"
33 /* Options. Getopt is not used because getopt_long is quite gnu-specific
34 * and they don't know of '-display foo' -style args anyway.
35 * Instead, I've reinvented the wheel in libtu :(.
37 static OptParserOpt pwm_opts[]={
38 {OPT_ID('d'), "display", OPT_ARG, "host:dpy.scr",
39 DUMMY_TR("X display to use")},
41 {'c', "conffile", OPT_ARG, "config_file",
42 DUMMY_TR("Configuration file")},
44 {'s', "searchdir", OPT_ARG, "dir",
45 DUMMY_TR("Add directory to search path")},
47 {OPT_ID('o'), "oneroot", 0, NULL,
48 DUMMY_TR("Manage default screen only")},
50 {OPT_ID('s'), "session", OPT_ARG, "session_name",
51 DUMMY_TR("Name of session (affects savefiles)")},
53 {OPT_ID('S'), "smclientid", OPT_ARG, "client_id",
54 DUMMY_TR("Session manager client ID")},
56 {OPT_ID('N'), "noerrorlog", 0, NULL,
57 DUMMY_TR("Do not create startup error log and display it "
60 {'h', "help", 0, NULL,
61 DUMMY_TR("Show this help")},
63 {'V', "version", 0, NULL,
64 DUMMY_TR("Show program version")},
66 {OPT_ID('a'), "about", 0, NULL,
67 DUMMY_TR("Show about text")},
76 printf(TR("Usage: %s [options]\n\n"), libtu_progname());
77 for(i=0; pwm_opts[i].descr!=NULL; i++)
78 pwm_opts[i].descr=TR(pwm_opts[i].descr);
79 optparser_printhelp(OPTP_MIDLONG, pwm_opts);
84 int main(int argc, char*argv[])
86 const char *cfgfile="cfg_pwm";
87 const char *display=NULL;
94 bool may_continue=FALSE;
95 bool noerrorlog=FALSE;
99 if(!ioncore_init("pwm3", argc, argv, LOCALEDIR))
102 extl_add_searchdir(EXTRABINDIR); /* ion-completefile */
103 extl_add_searchdir(MODULEDIR);
104 extl_add_searchdir(ETCDIR);
106 extl_add_searchdir(PWM_ETCDIR);
108 extl_add_searchdir(SHAREDIR);
109 extl_add_searchdir(LCDIR);
110 extl_set_userdirs("pwm3");
112 optparser_init(argc, argv, OPTP_MIDLONG, pwm_opts);
114 while((opt=optparser_get_opt())){
117 display=optparser_get_arg();
120 cfgfile=optparser_get_arg();
123 extl_add_searchdir(optparser_get_arg());
126 ioncore_g.sm_client_id=optparser_get_arg();
129 stflags|=IONCORE_STARTUP_ONEROOT;
132 extl_set_sessiondir(optparser_get_arg());
141 printf("%s\n", ION_VERSION);
144 printf("%s\n", ioncore_aboutmsg());
147 warn(TR("Invalid command line."));
154 /* We may have to pass the file to xmessage so just using tmpfile()
157 libtu_asprintf(&efnam, "%s/pwm-%d-startup-errorlog", P_tmpdir,
162 ef=fopen(efnam, "wt");
168 cloexec_braindamage_fix(fileno(ef));
169 fprintf(ef, TR("PWM startup error log:\n"));
170 errorlog_begin_file(&el, ef);
175 if(ioncore_startup(display, cfgfile, stflags))
180 warn(TR("Refusing to start due to encountered errors."));
184 if(errorlog_end(&el) && ioncore_g.dpy!=NULL){
188 ioncore_setup_display(DefaultScreen(ioncore_g.dpy));
190 XCloseDisplay(ioncore_g.dpy);
192 close(ioncore_g.conn);
193 libtu_asprintf(&cmd, CF_XMESSAGE " %s", efnam);
196 }else if(system(cmd)==-1){
202 if(!may_continue && pid>0)
203 waitpid(pid, NULL, 0);
217 /* The code should never return here */