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
;
86 warn(TR("Could not get user configuration file directory."));
90 libtu_asprintf(&oldbeard
, "%s/.welcome_msg_displayed", userdir
);
95 if(access(oldbeard
, F_OK
)==0){
100 libtu_asprintf(&tmp
, TR("%s/welcome.txt"), SHAREDIR
);
103 if(access(tmp
, F_OK
)==0)
104 libtu_asprintf(&cmd
, "%s %s", CF_XMESSAGE
, tmp
);
106 libtu_asprintf(&cmd
, "%s %s/welcome.txt", CF_XMESSAGE
, SHAREDIR
);
111 ret
=ioncore_exec(cmd
);
116 /* This should actually be done when less or xmessage returns,
117 * but that would mean yet another script...
119 mkdir(userdir
, 0700);
120 if(open(oldbeard
, O_CREAT
|O_RDWR
, 0600)<0)
121 warn_err_obj(oldbeard
);
133 printf(TR("Usage: %s [options]\n\n"), libtu_progname());
134 for(i
=0; ion_opts
[i
].descr
!=NULL
; i
++)
135 ion_opts
[i
].descr
=TR(ion_opts
[i
].descr
);
136 optparser_printhelp(OPTP_MIDLONG
, ion_opts
);
141 int main(int argc
, char*argv
[])
143 const char *cfgfile
="cfg_notion";
144 const char *display
=NULL
;
151 bool may_continue
=FALSE
;
152 bool noerrorlog
=FALSE
;
157 #ifdef CF_RELOCATABLE_BIN_LOCATION
158 prefix_set(argv
[0], CF_RELOCATABLE_BIN_LOCATION
);
161 localedir
=prefix_add(LOCALEDIR
);
163 if(!ioncore_init(CF_EXECUTABLE
, argc
, argv
, localedir
))
169 prefix_wrap_simple(extl_add_searchdir
, EXTRABINDIR
); /* ion-completefile */
170 prefix_wrap_simple(extl_add_searchdir
, MODULEDIR
);
171 prefix_wrap_simple(extl_add_searchdir
, ETCDIR
);
172 prefix_wrap_simple(extl_add_searchdir
, SHAREDIR
);
173 prefix_wrap_simple(extl_add_searchdir
, LCDIR
);
174 extl_set_userdirs(CF_EXECUTABLE
);
176 optparser_init(argc
, argv
, OPTP_MIDLONG
, ion_opts
);
178 while((opt
=optparser_get_opt())){
181 display
=optparser_get_arg();
184 cfgfile
=optparser_get_arg();
187 extl_add_searchdir(optparser_get_arg());
190 ioncore_g
.sm_client_id
=optparser_get_arg();
193 stflags
|=IONCORE_STARTUP_ONEROOT
;
196 extl_set_sessiondir(optparser_get_arg());
205 printf("%s\n", ION_VERSION
);
208 printf("%s\n", ioncore_aboutmsg());
211 warn(TR("Invalid command line."));
218 /* We may have to pass the file to xmessage so just using tmpfile()
221 libtu_asprintf(&efnam
, "%s/ion-%d-startup-errorlog", P_tmpdir
,
226 ef
=fopen(efnam
, "wt");
232 cloexec_braindamage_fix(fileno(ef
));
233 fprintf(ef
, TR("Notion startup error log:\n"));
234 errorlog_begin_file(&el
, ef
);
239 if(ioncore_startup(display
, cfgfile
, stflags
))
243 warn(TR("Refusing to start due to encountered errors."));
245 check_new_user_help();
249 if(errorlog_end(&el
) && ioncore_g
.dpy
!=NULL
){
253 ioncore_setup_display(DefaultScreen(ioncore_g
.dpy
));
255 XCloseDisplay(ioncore_g
.dpy
);
257 close(ioncore_g
.conn
);
258 libtu_asprintf(&cmd
, CF_XMESSAGE
" %s", efnam
);
261 }else if(system(cmd
)==-1){
267 if(!may_continue
&& pid
>0)
268 waitpid(pid
, NULL
, 0);
282 /* The code should never return here */