Beispiel #1
0
static void sm_ice_watch_fd(IceConn conn,
                            IcePointer UNUSED(client_data),
                            Bool opening,
                            IcePointer *UNUSED(watch_data))
{
    if(opening){
        if(sm_fd!=-1){ /* shouldn't happen */
            warn(TR("Too many ICE connections."));
        }
        else{
            sm_fd=IceConnectionNumber(conn);
            cloexec_braindamage_fix(sm_fd);
            mainloop_register_input_fd(sm_fd, NULL, &sm_process_messages);
        }
    }
    else{
        if (IceConnectionNumber(conn)==sm_fd){
            mainloop_unregister_input_fd(sm_fd);
            sm_fd=-1;
        }
    }
}
Beispiel #2
0
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;
}