|
a/src/main.cxx |
|
b/src/main.cxx |
|
... |
|
... |
167 |
string g_cachedir("/var/cache/upmpdcli");
|
167 |
string g_cachedir("/var/cache/upmpdcli");
|
168 |
|
168 |
|
169 |
// Global
|
169 |
// Global
|
170 |
string g_configfilename;
|
170 |
string g_configfilename;
|
171 |
ConfSimple *g_config;
|
171 |
ConfSimple *g_config;
|
|
|
172 |
ConfSimple *g_state;
|
172 |
bool g_enableL16 = false;
|
173 |
bool g_enableL16 = false;
|
173 |
bool g_lumincompat = false;
|
174 |
bool g_lumincompat = false;
|
174 |
|
175 |
|
175 |
static void onsig(int)
|
176 |
static void onsig(int)
|
176 |
{
|
177 |
{
|
|
... |
|
... |
535 |
opts.cachedir = "/var/cache/upmpdcli";
|
536 |
opts.cachedir = "/var/cache/upmpdcli";
|
536 |
} else {
|
537 |
} else {
|
537 |
if (opts.cachedir.empty())
|
538 |
if (opts.cachedir.empty())
|
538 |
opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
|
539 |
opts.cachedir = path_cat(path_tildexpand("~") , "/.cache/upmpdcli");
|
539 |
}
|
540 |
}
|
|
|
541 |
|
540 |
g_cachedir = opts.cachedir;
|
542 |
g_cachedir = opts.cachedir;
|
|
|
543 |
if (!path_makepath(opts.cachedir, 0755)) {
|
|
|
544 |
LOGERR("makepath("<< opts.cachedir << ") : errno : " << errno << endl);
|
|
|
545 |
cerr << "Can't create " << opts.cachedir << endl;
|
|
|
546 |
return 1;
|
|
|
547 |
}
|
|
|
548 |
|
|
|
549 |
string statefn = path_cat(opts.cachedir, "/upmstate");
|
|
|
550 |
g_state = new ConfSimple(statefn.c_str());
|
541 |
|
551 |
|
542 |
string& mcfn = opts.cachefn;
|
552 |
opts.cachefn.clear();
|
543 |
// no cache access needed or desirable for a pure media server
|
|
|
544 |
if (!msonly && ohmetapersist) {
|
553 |
if (!msonly && ohmetapersist) {
|
545 |
opts.cachefn = path_cat(opts.cachedir, "/metacache");
|
554 |
opts.cachefn = path_cat(opts.cachedir, "/metacache");
|
546 |
if (!path_makepath(opts.cachedir, 0755)) {
|
555 |
int fd;
|
|
|
556 |
if ((fd = open(opts.cachefn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
|
547 |
LOGERR("makepath("<< opts.cachedir << ") : errno : " <<
|
557 |
LOGERR("creat("<< opts.cachefn << ") : errno : " << errno << endl);
|
548 |
errno << endl);
|
|
|
549 |
} else {
|
558 |
} else {
|
550 |
int fd;
|
|
|
551 |
if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
|
|
|
552 |
LOGERR("creat("<< mcfn << ") : errno : " << errno << endl);
|
|
|
553 |
} else {
|
|
|
554 |
close(fd);
|
559 |
close(fd);
|
555 |
if (geteuid() == 0) {
|
|
|
556 |
if (chown(mcfn.c_str(), runas, -1) != 0) {
|
|
|
557 |
LOGERR("chown("<< mcfn << ") : errno : " <<
|
|
|
558 |
errno << endl);
|
|
|
559 |
}
|
|
|
560 |
if (chown(opts.cachedir.c_str(), runas, -1) != 0) {
|
|
|
561 |
LOGERR("chown("<< opts.cachedir << ") : errno : " <<
|
|
|
562 |
errno << endl);
|
|
|
563 |
}
|
|
|
564 |
}
|
|
|
565 |
}
|
|
|
566 |
}
|
560 |
}
|
567 |
}
|
561 |
}
|
568 |
|
562 |
|
569 |
if ((op_flags & OPT_D)) {
|
563 |
if ((op_flags & OPT_D)) {
|
570 |
if (daemon(1, 0)) {
|
564 |
if (daemon(1, 0)) {
|
|
... |
|
... |
572 |
return 1;
|
566 |
return 1;
|
573 |
}
|
567 |
}
|
574 |
}
|
568 |
}
|
575 |
|
569 |
|
576 |
if (geteuid() == 0) {
|
570 |
if (geteuid() == 0) {
|
577 |
// Need to rewrite pid, it may have changed with the daemon call
|
571 |
// Need to rewrite pid, it may have changed with the daemon call. Also
|
|
|
572 |
// adjust file ownership and access.
|
578 |
pidfile.write_pid();
|
573 |
pidfile.write_pid();
|
579 |
if (!logfilename.empty() && logfilename.compare("stderr")) {
|
574 |
if (!logfilename.empty() && logfilename.compare("stderr")) {
|
580 |
if (chown(logfilename.c_str(), runas, -1) < 0 && errno != ENOENT) {
|
575 |
if (chown(logfilename.c_str(), runas, -1) < 0 && errno != ENOENT) {
|
581 |
LOGERR("chown("<<logfilename<<") : errno : " << errno << endl);
|
576 |
LOGERR("chown("<<logfilename<<") : errno : " << errno << endl);
|
|
|
577 |
}
|
|
|
578 |
}
|
|
|
579 |
if (chown(opts.cachedir.c_str(), runas, -1) != 0) {
|
|
|
580 |
LOGERR("chown("<< opts.cachedir << ") : errno : " << errno << endl);
|
|
|
581 |
}
|
|
|
582 |
if (chown(statefn.c_str(), runas, -1) != 0) {
|
|
|
583 |
LOGERR("chown("<< statefn << ") : errno : " << errno << endl);
|
|
|
584 |
}
|
|
|
585 |
if (!opts.cachefn.empty()) {
|
|
|
586 |
if (chown(opts.cachefn.c_str(), runas, -1) != 0) {
|
|
|
587 |
LOGERR("chown("<< opts.cachefn << ") : errno : " <<
|
|
|
588 |
errno << endl);
|
582 |
}
|
589 |
}
|
583 |
}
|
590 |
}
|
584 |
if (!g_configfilename.empty()) {
|
591 |
if (!g_configfilename.empty()) {
|
585 |
ensureconfreadable(g_configfilename.c_str(), upmpdcliuser.c_str(),
|
592 |
ensureconfreadable(g_configfilename.c_str(), upmpdcliuser.c_str(),
|
586 |
runas, runasg);
|
593 |
runas, runasg);
|