Switch to unified view

a/src/main.cxx b/src/main.cxx
...
...
285
    }
285
    }
286
    MSMode arg_msmode = MSMode(msm);
286
    MSMode arg_msmode = MSMode(msm);
287
    
287
    
288
    UpMpd::Options opts;
288
    UpMpd::Options opts;
289
289
290
    string cachedir;
291
    if (!g_configfilename.empty()) {
290
    if (!g_configfilename.empty()) {
292
        g_config = new ConfSimple(g_configfilename.c_str(), 1, true);
291
        g_config = new ConfSimple(g_configfilename.c_str(), 1, true);
293
        if (!g_config || !g_config->ok()) {
292
        if (!g_config || !g_config->ok()) {
294
            cerr << "Could not open config: " << g_configfilename << endl;
293
            cerr << "Could not open config: " << g_configfilename << endl;
295
            return 1;
294
            return 1;
...
...
336
            }
335
            }
337
            presentationhtml = path_cat(g_datadir, "presentation.html");
336
            presentationhtml = path_cat(g_datadir, "presentation.html");
338
        }
337
        }
339
        g_config->get("iconpath", iconpath);
338
        g_config->get("iconpath", iconpath);
340
        g_config->get("presentationhtml", presentationhtml);
339
        g_config->get("presentationhtml", presentationhtml);
341
        g_config->get("cachedir", cachedir);
340
        g_config->get("cachedir", opts.cachedir);
342
        g_config->get("pidfile", pidfilename);
341
        g_config->get("pidfile", pidfilename);
343
        if (!(op_flags & OPT_i)) {
342
        if (!(op_flags & OPT_i)) {
344
            g_config->get("upnpiface", iface);
343
            g_config->get("upnpiface", iface);
345
            if (iface.empty()) {
344
            if (iface.empty()) {
346
                g_config->get("upnpip", upnpip);
345
                g_config->get("upnpip", upnpip);
...
...
458
        }
457
        }
459
        if (pidfile.write_pid() != 0) {
458
        if (pidfile.write_pid() != 0) {
460
            LOGFAT("Can't write pidfile: " << pidfile.getreason() << endl);
459
            LOGFAT("Can't write pidfile: " << pidfile.getreason() << endl);
461
            return 1;
460
            return 1;
462
        }
461
        }
463
    if (cachedir.empty())
462
    if (opts.cachedir.empty())
464
            cachedir = "/var/cache/upmpdcli";
463
            opts.cachedir = "/var/cache/upmpdcli";
465
    } else {
464
    } else {
466
    if (cachedir.empty())
465
    if (opts.cachedir.empty())
467
            cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
466
            opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
468
    }
467
    }
469
468
470
    string& mcfn = opts.cachefn;
469
    string& mcfn = opts.cachefn;
471
    // no cache access needed or desirable for a pure media server
470
    // no cache access needed or desirable for a pure media server
472
    if (!msonly && ohmetapersist) {
471
    if (!msonly && ohmetapersist) {
473
        opts.cachefn = path_cat(cachedir, "/metacache");
472
        opts.cachefn = path_cat(opts.cachedir, "/metacache");
474
        if (!path_makepath(cachedir, 0755)) {
473
        if (!path_makepath(opts.cachedir, 0755)) {
475
            LOGERR("makepath("<< cachedir << ") : errno : " << errno << endl);
474
            LOGERR("makepath("<< opts.cachedir << ") : errno : " <<
475
                   errno << endl);
476
        } else {
476
        } else {
477
            int fd;
477
            int fd;
478
            if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
478
            if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
479
                LOGERR("creat("<< mcfn << ") : errno : " << errno << endl);
479
                LOGERR("creat("<< mcfn << ") : errno : " << errno << endl);
480
            } else {
480
            } else {
481
                close(fd);
481
                close(fd);
482
                if (geteuid() == 0 && chown(mcfn.c_str(), runas, -1) != 0) {
482
                if (geteuid() == 0 && chown(mcfn.c_str(), runas, -1) != 0) {
483
                    LOGERR("chown("<< mcfn << ") : errno : " << errno << endl);
483
                    LOGERR("chown("<< mcfn << ") : errno : " << errno << endl);
484
                }
484
                }
485
                if (geteuid() == 0 &&
485
                if (geteuid() == 0 && chown(cachedir.c_str(), runas, -1) != 0) {
486
                    chown(opts.cachedir.c_str(), runas, -1) != 0) {
486
                    LOGERR("chown("<< cachedir << ") : errno : " <<errno<< endl);
487
                    LOGERR("chown("<< opts.cachedir << ") : errno : " <<
488
                           errno << endl);
487
                }
489
                }
488
            }
490
            }
489
        }
491
        }
490
    }
492
    }
491
    
493