2 * notion/notion/notion.c
4 * Copyright (c) the Notion team 2013.
5 * Copyright (c) Tuomo Valkonen 1999-2009.
7 * See the included file LICENSE for details.
15 #include <sys/types.h>
20 #include <libtu/util.h>
21 #include <libtu/optparser.h>
22 #include <libtu/errorlog.h>
23 #include <libtu/prefix.h>
24 #include <libextl/readconfig.h>
25 #include <libmainloop/exec.h>
27 #include <ioncore/common.h>
28 #include <ioncore/global.h>
29 #include <ioncore/ioncore.h>
30 #include <ioncore/exec.h>
31 #include <ioncore/event.h>
32 #include "../version.h"
35 #define P_tmpdir "/tmp"
38 /* Options. Getopt is not used because getopt_long is quite gnu-specific
39 * and they don't know of '-display foo' -style args anyway.
40 * Instead, I've reinvented the wheel in libtu :(.
42 static OptParserOpt ion_opts
[]={
43 {OPT_ID('d'), "display", OPT_ARG
, "host:dpy.scr",
44 DUMMY_TR("X display to use")},
46 {'c', "conffile", OPT_ARG
, "config_file",
47 DUMMY_TR("Configuration file")},
49 {'s', "searchdir", OPT_ARG
, "dir",
50 DUMMY_TR("Add directory to search path")},
52 {OPT_ID('o'), "oneroot", 0, NULL
,
53 DUMMY_TR("Manage default screen only")},
55 {OPT_ID('s'), "session", OPT_ARG
, "session_name",
56 DUMMY_TR("Name of session (affects savefiles)")},
58 {OPT_ID('S'), "smclientid", OPT_ARG
, "client_id",
59 DUMMY_TR("Session manager client ID")},
61 {OPT_ID('N'), "noerrorlog", 0, NULL
,
62 DUMMY_TR("Do not create startup error log and display it "
65 {'h', "help", 0, NULL
,
66 DUMMY_TR("Show this help")},
68 {'V', "version", 0, NULL
,
69 DUMMY_TR("Show program version")},
71 {OPT_ID('a'), "about", 0, NULL
,
72 DUMMY_TR("Show about text")},
78 void check_new_user_help()
80 const char *userdir
=extl_userdir();
82 char *tmp
=NULL
, *cmd
=NULL
;
87 warn(TR("Could not get user configuration file directory."));
91 libtu_asprintf(&oldbeard
, "%s/.welcome_msg_displayed", userdir
);
96 if(access(oldbeard
, F_OK
)==0){
101 libtu_asprintf(&tmp
, TR("%s/welcome.txt"), SHAREDIR
);
104 if(access(tmp
, F_OK
)==0)
105 libtu_asprintf(&cmd
, "%s %s", CF_XMESSAGE
, tmp
);
107 libtu_asprintf(&cmd
, "%s %s/welcome.txt", CF_XMESSAGE
, SHAREDIR
);
112 ret
=ioncore_exec(cmd
);
117 /* This should actually be done when less or xmessage returns,
118 * but that would mean yet another script...
120 mkdir(userdir
, 0700);
121 if(open(oldbeard
, O_CREAT
|O_RDWR
, 0600)<0)
122 warn_err_obj(oldbeard
);
134 printf(TR("Usage: %s [options]\n\n"), libtu_progname());
135 for(i
=0; ion_opts
[i
].descr
!=NULL
; i
++)
136 ion_opts
[i
].descr
=TR(ion_opts
[i
].descr
);
137 optparser_printhelp(OPTP_MIDLONG
, ion_opts
);
142 int main(int argc
, char*argv
[])
144 const char *cfgfile
="cfg_notion";
145 const char *display
=NULL
;
152 bool may_continue
=FALSE
;
153 bool noerrorlog
=FALSE
;
158 #ifdef CF_RELOCATABLE_BIN_LOCATION
159 prefix_set(argv
[0], CF_RELOCATABLE_BIN_LOCATION
);
162 localedir
=prefix_add(LOCALEDIR
);
164 if(!ioncore_init(CF_EXECUTABLE
, argc
, argv
, localedir
))
170 prefix_wrap_simple(extl_add_searchdir
, EXTRABINDIR
); /* ion-completefile */
171 prefix_wrap_simple(extl_add_searchdir
, MODULEDIR
);
172 prefix_wrap_simple(extl_add_searchdir
, ETCDIR
);
173 prefix_wrap_simple(extl_add_searchdir
, SHAREDIR
);
174 prefix_wrap_simple(extl_add_searchdir
, LCDIR
);
175 extl_set_userdirs(CF_EXECUTABLE
);
177 optparser_init(argc
, argv
, OPTP_MIDLONG
, ion_opts
);
179 while((opt
=optparser_get_opt())){
182 display
=optparser_get_arg();
185 cfgfile
=optparser_get_arg();
188 extl_add_searchdir(optparser_get_arg());
191 ioncore_g
.sm_client_id
=optparser_get_arg();
194 stflags
|=IONCORE_STARTUP_ONEROOT
;
197 extl_set_sessiondir(optparser_get_arg());
206 printf("%s\n", ION_VERSION
);
209 printf("%s\n", ioncore_aboutmsg());
212 warn(TR("Invalid command line."));
219 /* We may have to pass the file to xmessage so just using tmpfile()
222 libtu_asprintf(&efnam
, "%s/ion-%d-startup-errorlog", P_tmpdir
,
227 ef
=fopen(efnam
, "wt");
233 cloexec_braindamage_fix(fileno(ef
));
234 fprintf(ef
, TR("Notion startup error log:\n"));
235 errorlog_begin_file(&el
, ef
);
240 if(ioncore_startup(display
, cfgfile
, stflags
))
245 warn(TR("Refusing to start due to encountered errors."));
247 check_new_user_help();
251 if(errorlog_end(&el
) && ioncore_g
.dpy
!=NULL
){
255 ioncore_setup_display(DefaultScreen(ioncore_g
.dpy
));
257 XCloseDisplay(ioncore_g
.dpy
);
259 close(ioncore_g
.conn
);
260 libtu_asprintf(&cmd
, CF_XMESSAGE
" %s", efnam
);
263 }else if(system(cmd
)==-1){
269 if(!may_continue
&& pid
>0)
270 waitpid(pid
, NULL
, 0);
284 /* The code should never return here */