4 * Copyright (c) Tuomo Valkonen 1999-2007.
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 pwm_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 screen only")},
53 {OPT_ID('s'), "session", OPT_ARG, "session_name",
54 DUMMY_TR("Name of session (affects savefiles)")},
56 {OPT_ID('S'), "smclientid", OPT_ARG, "client_id",
57 DUMMY_TR("Session manager client ID")},
59 {OPT_ID('N'), "noerrorlog", 0, NULL,
60 DUMMY_TR("Do not create startup error log and display it "
63 {'h', "help", 0, NULL,
64 DUMMY_TR("Show this help")},
66 {'V', "version", 0, NULL,
67 DUMMY_TR("Show program version")},
69 {OPT_ID('a'), "about", 0, NULL,
70 DUMMY_TR("Show about text")},
79 printf(TR("Usage: %s [options]\n\n"), prog_execname());
80 for(i=0; pwm_opts[i].descr!=NULL; i++)
81 pwm_opts[i].descr=TR(pwm_opts[i].descr);
82 optparser_printhelp(OPTP_MIDLONG, pwm_opts);
87 int main(int argc, char*argv[])
89 const char *cfgfile="cfg_pwm";
90 const char *display=NULL;
97 bool may_continue=FALSE;
98 bool noerrorlog=FALSE;
102 if(!ioncore_init("pwm3", argc, argv, LOCALEDIR))
105 extl_add_searchdir(EXTRABINDIR); /* ion-completefile */
106 extl_add_searchdir(MODULEDIR);
107 extl_add_searchdir(ETCDIR);
109 extl_add_searchdir(PWM_ETCDIR);
111 extl_add_searchdir(SHAREDIR);
112 extl_add_searchdir(LCDIR);
113 extl_set_userdirs("pwm3");
115 optparser_init(argc, argv, OPTP_MIDLONG, pwm_opts);
117 while((opt=optparser_get_opt())){
120 display=optparser_get_arg();
123 cfgfile=optparser_get_arg();
126 extl_add_searchdir(optparser_get_arg());
129 ioncore_g.sm_client_id=optparser_get_arg();
132 stflags|=IONCORE_STARTUP_ONEROOT;
135 extl_set_sessiondir(optparser_get_arg());
144 printf("%s\n", ION_VERSION);
147 printf("%s\n", ioncore_aboutmsg());
150 warn(TR("Invalid command line."));
157 /* We may have to pass the file to xmessage so just using tmpfile()
160 libtu_asprintf(&efnam, "%s/pwm-%d-startup-errorlog", P_tmpdir,
165 ef=fopen(efnam, "wt");
171 cloexec_braindamage_fix(fileno(ef));
172 fprintf(ef, TR("PWM startup error log:\n"));
173 errorlog_begin_file(&el, ef);
178 if(ioncore_startup(display, cfgfile, stflags))
183 warn(TR("Refusing to start due to encountered errors."));
187 if(errorlog_end(&el) && ioncore_g.dpy!=NULL){
191 ioncore_setup_environ(DefaultScreen(ioncore_g.dpy));
193 XCloseDisplay(ioncore_g.dpy);
195 close(ioncore_g.conn);
196 libtu_asprintf(&cmd, CF_XMESSAGE " %s", efnam);
199 }else if(system(cmd)==-1){
205 if(!may_continue && pid>0)
206 waitpid(pid, NULL, 0);
220 /* The code should never return here */