int main(int argc, char*argv[]) { const char *mod=NULL; char *mod2=NULL; int loaded=0; int opt; bool quiet=FALSE; #ifndef CF_NO_LOCALE if(setlocale(LC_ALL, "")==NULL) warn("setlocale() call failed."); #endif configtab=extl_table_none(); libtu_init(argv[0]); #ifdef CF_RELOCATABLE_BIN_LOCATION prefix_set(argv[0], CF_RELOCATABLE_BIN_LOCATION); #endif extl_init(); if(!statusd_register_exports()) return EXIT_FAILURE; prefix_wrap_simple(extl_add_searchdir, EXTRABINDIR); prefix_wrap_simple(extl_add_searchdir, MODULEDIR); prefix_wrap_simple(extl_add_searchdir, ETCDIR); prefix_wrap_simple(extl_add_searchdir, SHAREDIR); prefix_wrap_simple(extl_add_searchdir, LCDIR); extl_set_userdirs(CF_ION_EXECUTABLE); optparser_init(argc, argv, OPTP_MIDLONG, ion_opts); extl_read_config("ioncore_luaext", NULL, TRUE); while((opt=optparser_get_opt())){ switch(opt){ /*case OPT_ID('d'): display=optparser_get_arg(); break;*/ case 's': extl_add_searchdir(optparser_get_arg()); break; /*case OPT_ID('s'): extl_set_sessiondir(optparser_get_arg()); break;*/ case 'h': help(); return EXIT_SUCCESS; case 'V': printf("%s\n", ION_VERSION); return EXIT_SUCCESS; case OPT_ID('a'): printf("%s\n\n%s", statusd_copy, TR(statusd_license)); return EXIT_SUCCESS; case 'c': { ExtlTab t; const char *f=optparser_get_arg(); if(extl_read_savefile(f, &t)){ extl_unref_table(configtab); configtab=t; }else{ warn(TR("Unable to load configuration file %s"), f); } } break; case 'q': quiet=TRUE; break; case 'm': mod=optparser_get_arg(); if(strchr(mod, '/')==NULL && strchr(mod, '.')==NULL){ mod2=scat("statusd_", mod); if(mod2==NULL) return EXIT_FAILURE; mod=mod2; } if(extl_read_config(mod, NULL, !quiet)) loaded++; if(mod2!=NULL) free(mod2); break; default: warn(TR("Invalid command line.")); help(); return EXIT_FAILURE; } } if(loaded==0 && !quiet){ warn(TR("No meters loaded.")); return EXIT_FAILURE; } mainloop(); return EXIT_SUCCESS; }
int main(int argc, char*argv[]) { const char *cfgfile="cfg_notion"; const char *display=NULL; char *cmd=NULL; int stflags=0; int opt; ErrorLog el; FILE *ef=NULL; char *efnam=NULL; bool may_continue=FALSE; bool noerrorlog=FALSE; char *localedir; libtu_init(argv[0]); #ifdef CF_RELOCATABLE_BIN_LOCATION prefix_set(argv[0], CF_RELOCATABLE_BIN_LOCATION); #endif localedir=prefix_add(LOCALEDIR); if(!ioncore_init(CF_EXECUTABLE, argc, argv, localedir)) return EXIT_FAILURE; if(localedir!=NULL) free(localedir); prefix_wrap_simple(extl_add_searchdir, EXTRABINDIR); /* ion-completefile */ prefix_wrap_simple(extl_add_searchdir, MODULEDIR); prefix_wrap_simple(extl_add_searchdir, ETCDIR); prefix_wrap_simple(extl_add_searchdir, SHAREDIR); prefix_wrap_simple(extl_add_searchdir, LCDIR); extl_set_userdirs(CF_EXECUTABLE); optparser_init(argc, argv, OPTP_MIDLONG, ion_opts); while((opt=optparser_get_opt())){ switch(opt){ case OPT_ID('d'): display=optparser_get_arg(); break; case 'c': cfgfile=optparser_get_arg(); break; case 's': extl_add_searchdir(optparser_get_arg()); break; case OPT_ID('S'): ioncore_g.sm_client_id=optparser_get_arg(); break; case OPT_ID('o'): stflags|=IONCORE_STARTUP_ONEROOT; break; case OPT_ID('s'): extl_set_sessiondir(optparser_get_arg()); break; case OPT_ID('N'): noerrorlog=TRUE; break; case 'h': help(); return EXIT_SUCCESS; case 'V': printf("%s\n", ION_VERSION); return EXIT_SUCCESS; case OPT_ID('a'): printf("%s\n", ioncore_aboutmsg()); return EXIT_SUCCESS; default: warn(TR("Invalid command line.")); help(); return EXIT_FAILURE; } } if(!noerrorlog){ /* We may have to pass the file to xmessage so just using tmpfile() * isn't sufficient. */ libtu_asprintf(&efnam, "%s/ion-%d-startup-errorlog", P_tmpdir, getpid()); if(efnam==NULL){ warn_err(); }else{ ef=fopen(efnam, "wt"); if(ef==NULL){ warn_err_obj(efnam); free(efnam); efnam=NULL; }else{ cloexec_braindamage_fix(fileno(ef)); fprintf(ef, TR("Notion startup error log:\n")); errorlog_begin_file(&el, ef); } } } if(ioncore_startup(display, cfgfile, stflags)) may_continue=TRUE; if(!may_continue) warn(TR("Refusing to start due to encountered errors.")); else check_new_user_help(); if(ef!=NULL){ pid_t pid=-1; if(errorlog_end(&el) && ioncore_g.dpy!=NULL){ fclose(ef); pid=fork(); if(pid==0){ ioncore_setup_display(DefaultScreen(ioncore_g.dpy)); if(!may_continue) XCloseDisplay(ioncore_g.dpy); else close(ioncore_g.conn); libtu_asprintf(&cmd, CF_XMESSAGE " %s", efnam); if(cmd==NULL){ warn_err(); }else if(system(cmd)==-1){ warn_err_obj(cmd); } unlink(efnam); exit(EXIT_SUCCESS); } if(!may_continue && pid>0) waitpid(pid, NULL, 0); }else{ fclose(ef); } if(pid<0) unlink(efnam); free(efnam); } if(!may_continue) return EXIT_FAILURE; ioncore_mainloop(); /* The code should never return here */ return EXIT_SUCCESS; }