Switch to unified view

a/src/main.cxx b/src/main.cxx
...
...
472
472
473
    // If started by root, we use the pidfile and we will change the
473
    // If started by root, we use the pidfile and we will change the
474
    // uid (later). First part follows
474
    // uid (later). First part follows
475
    uid_t runas(0);
475
    uid_t runas(0);
476
    gid_t runasg(0);
476
    gid_t runasg(0);
477
    struct passwd *pass = getpwnam(upmpdcliuser.c_str());
478
    if (pass) {
479
        runas = pass->pw_uid;
480
        runasg = pass->pw_gid;
481
    }
477
    if (geteuid() == 0) {
482
    if (geteuid() == 0) {
478
        struct passwd *pass = getpwnam(upmpdcliuser.c_str());
479
        if (pass == 0) {
483
        if (runas == 0) {
480
            LOGFAT("upmpdcli won't run as root and user " << upmpdcliuser << 
484
            LOGFAT("upmpdcli won't run as root and user " << upmpdcliuser << 
481
                   " does not exist " << endl);
485
                   " does not exist " << endl);
482
            return 1;
486
            return 1;
483
        }
487
        }
484
        runas = pass->pw_uid;
488
        runas = pass->pw_uid;
...
...
492
        }
496
        }
493
        if (pidfile.write_pid() != 0) {
497
        if (pidfile.write_pid() != 0) {
494
            LOGFAT("Can't write pidfile: " << pidfile.getreason() << endl);
498
            LOGFAT("Can't write pidfile: " << pidfile.getreason() << endl);
495
            return 1;
499
            return 1;
496
        }
500
        }
501
  if (opts.cachedir.empty())
502
            opts.cachedir = "/var/cache/upmpdcli";
503
    } else if (runas == geteuid()) {
504
        // Already running as upmpdcli user. There are actually 2
505
        // possibilities: either we were initially started as
506
        // upmpdcli, and we should be using ~upmpdcli/.cache as work
507
        // directory, or we were exec'd by a master process started as
508
        // root, and we should be using /var/cache/upmpdcli. We have
509
        // no way to decide actually, another command line option
510
        // would be needed. For now, behave as if exec'd by a master
511
        // process, because this is what happens if the default
512
        // package was installed. One way to fix this if this if it is
513
        // wrong is to set cachedir in the configuration file
514
        // (opts.cachedir will be non-empty then).
497
    if (opts.cachedir.empty())
515
    if (opts.cachedir.empty())
498
            opts.cachedir = "/var/cache/upmpdcli";
516
            opts.cachedir = "/var/cache/upmpdcli";
499
    } else {
517
    } else {
500
    if (opts.cachedir.empty())
518
    if (opts.cachedir.empty())
501
            opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
519
            opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");