|
a/src/main.cxx |
|
b/src/main.cxx |
|
... |
|
... |
491 |
|
491 |
|
492 |
// If started by root, we use the pidfile and we will change the
|
492 |
// If started by root, we use the pidfile and we will change the
|
493 |
// uid (later). First part follows
|
493 |
// uid (later). First part follows
|
494 |
uid_t runas(0);
|
494 |
uid_t runas(0);
|
495 |
gid_t runasg(0);
|
495 |
gid_t runasg(0);
|
|
|
496 |
struct passwd *pass = getpwnam(upmpdcliuser.c_str());
|
|
|
497 |
if (pass) {
|
|
|
498 |
runas = pass->pw_uid;
|
|
|
499 |
runasg = pass->pw_gid;
|
|
|
500 |
}
|
496 |
if (geteuid() == 0) {
|
501 |
if (geteuid() == 0) {
|
497 |
struct passwd *pass = getpwnam(upmpdcliuser.c_str());
|
|
|
498 |
if (pass == 0) {
|
502 |
if (runas == 0) {
|
499 |
LOGFAT("upmpdcli won't run as root and user " << upmpdcliuser <<
|
503 |
LOGFAT("upmpdcli won't run as root and user " << upmpdcliuser <<
|
500 |
" does not exist " << endl);
|
504 |
" does not exist " << endl);
|
501 |
return 1;
|
505 |
return 1;
|
502 |
}
|
506 |
}
|
503 |
runas = pass->pw_uid;
|
507 |
runas = pass->pw_uid;
|
|
... |
|
... |
511 |
}
|
515 |
}
|
512 |
if (pidfile.write_pid() != 0) {
|
516 |
if (pidfile.write_pid() != 0) {
|
513 |
LOGFAT("Can't write pidfile: " << pidfile.getreason() << endl);
|
517 |
LOGFAT("Can't write pidfile: " << pidfile.getreason() << endl);
|
514 |
return 1;
|
518 |
return 1;
|
515 |
}
|
519 |
}
|
|
|
520 |
if (opts.cachedir.empty())
|
|
|
521 |
opts.cachedir = "/var/cache/upmpdcli";
|
|
|
522 |
} else if (runas == geteuid()) {
|
|
|
523 |
// Already running as upmpdcli user. There are actually 2
|
|
|
524 |
// possibilities: either we were initially started as
|
|
|
525 |
// upmpdcli, and we should be using ~upmpdcli/.cache as work
|
|
|
526 |
// directory, or we were exec'd by a master process started as
|
|
|
527 |
// root, and we should be using /var/cache/upmpdcli. We have
|
|
|
528 |
// no way to decide actually, another command line option
|
|
|
529 |
// would be needed. For now, behave as if exec'd by a master
|
|
|
530 |
// process, because this is what happens if the default
|
|
|
531 |
// package was installed. One way to fix this if this if it is
|
|
|
532 |
// wrong is to set cachedir in the configuration file
|
|
|
533 |
// (opts.cachedir will be non-empty then).
|
516 |
if (opts.cachedir.empty())
|
534 |
if (opts.cachedir.empty())
|
517 |
opts.cachedir = "/var/cache/upmpdcli";
|
535 |
opts.cachedir = "/var/cache/upmpdcli";
|
518 |
} else {
|
536 |
} else {
|
519 |
if (opts.cachedir.empty())
|
537 |
if (opts.cachedir.empty())
|
520 |
opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
|
538 |
opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
|