Skip to content

Commit

Permalink
Fuse all global configuration into one gconf_t struct
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Aug 29, 2012
1 parent 6f98d3d commit 1ed762d
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 159 deletions.
14 changes: 6 additions & 8 deletions src/api/httpcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,10 @@ static int
hc_binreplace(http_connection_t *hc, const char *remain, void *opaque,
http_cmd_t method)
{
extern char *showtime_bin;
extern int enable_bin_replace;
if(showtime_bin == NULL)
if(gconf.binary == NULL)
return HTTP_STATUS_PRECONDITION_FAILED;

if(!enable_bin_replace)
if(!gconf.enable_bin_replace)
return 403;

size_t len;
Expand All @@ -255,9 +253,9 @@ hc_binreplace(http_connection_t *hc, const char *remain, void *opaque,
return 405;

TRACE(TRACE_INFO, "BINREPLACE", "Replacing %s with %d bytes received",
showtime_bin, (int)len);
gconf.binary, (int)len);

int fd = open(showtime_bin, O_TRUNC | O_RDWR, 0777);
int fd = open(gconf.binary, O_TRUNC | O_RDWR, 0777);
if(fd == -1) {
TRACE(TRACE_ERROR, "BINREPLACE", "Unable to open file");
return HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE;
Expand Down Expand Up @@ -323,7 +321,7 @@ hc_diagnostics(http_connection_t *hc, const char *remain, void *opaque,

for(i = 0; i <= 5; i++) {
struct stat st;
snprintf(p1, sizeof(p1), "%s/log/showtime.log.%d", showtime_cache_path,i);
snprintf(p1, sizeof(p1), "%s/log/showtime.log.%d", gconf.cache_path,i);
if(stat(p1, &st))
continue;
char timestr[32];
Expand Down Expand Up @@ -362,7 +360,7 @@ hc_logfile(http_connection_t *hc, const char *remain, void *opaque,
size_t size;

char p1[500];
snprintf(p1, sizeof(p1), "%s/log/showtime.log.%d", showtime_cache_path, n);
snprintf(p1, sizeof(p1), "%s/log/showtime.log.%d", gconf.cache_path, n);
char *buf = fa_load(p1, &size, NULL, NULL, 0, NULL, 0, NULL, NULL);

if(buf == NULL)
Expand Down
3 changes: 1 addition & 2 deletions src/arch/linux/linux_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ linux_init_monitors(void)
void
arch_init(void)
{
extern int concurrency;
concurrency = get_system_concurrency();
gconf.concurrency = get_system_concurrency();
posix_init();
}

Expand Down
12 changes: 6 additions & 6 deletions src/arch/posix/arch_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ posix_init(void)

signal(SIGPIPE, SIG_IGN);

TRACE(TRACE_INFO, "core", "Using %d CPU(s)", concurrency);
TRACE(TRACE_INFO, "core", "Using %d CPU(s)", gconf.concurrency);

#ifdef RLIMIT_AS
do {
Expand All @@ -122,7 +122,7 @@ posix_init(void)

net_initialize();

if(trace_to_syslog)
if(gconf.trace_to_syslog)
openlog("showtime", 0, LOG_USER);
}

Expand Down Expand Up @@ -164,7 +164,7 @@ trace_arch(int level, const char *prefix, const char *str)

fprintf(stderr, "%s%s %s%s\n", sgr, prefix, str, sgroff);

if(trace_to_syslog)
if(gconf.trace_to_syslog)
syslog(prio, "%s %s", prefix, str);
}

Expand Down Expand Up @@ -194,19 +194,19 @@ arch_set_default_paths(int argc, char **argv)
return;

snprintf(buf, sizeof(buf), "%s/.cache/showtime", homedir);
showtime_cache_path = strdup(buf);
gconf.cache_path = strdup(buf);


snprintf(buf, sizeof(buf), "%s/.hts/showtime", homedir);
showtime_persistent_path = strdup(buf);
gconf.persistent_path = strdup(buf);
}

int64_t
arch_cache_avail_bytes(void)
{
struct statvfs buf;

if(showtime_cache_path == NULL || statvfs(showtime_cache_path, &buf))
if(gconf.cache_path == NULL || statvfs(gconf.cache_path, &buf))
return 0;

return buf.f_bfree * buf.f_bsize;
Expand Down
26 changes: 8 additions & 18 deletions src/arch/ps3/arch_ps3.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ memlogger_fn(callout_t *co, void *aux)

}



static char *symbuf;

static void
Expand Down Expand Up @@ -161,15 +159,10 @@ load_syms(void)
void
arch_init(void)
{
extern int trace_level;
extern int concurrency;
extern int showtime_can_standby;

concurrency = 2;
gconf.concurrency = 2;
gconf.can_standby = 1;
gconf.trace_level = TRACE_DEBUG;

showtime_can_standby = 1;

trace_level = TRACE_DEBUG;
sysprop = prop_create(prop_get_global(), "system");
memprop = prop_create(sysprop, "mem");
callout_arm(&memlogger, memlogger_fn, NULL, 1);
Expand All @@ -191,10 +184,8 @@ arch_exit(int retcode)
if(retcode == 10)
Lv2Syscall3(379, 0x100, 0, 0 );

extern char *showtime_bin;

if(retcode == SHOWTIME_EXIT_RESTART)
sysProcessExitSpawn2(showtime_bin, 0, 0, 0, 0, 1200, 0x70);
sysProcessExitSpawn2(gconf.binary, 0, 0, 0, 0, 1200, 0x70);

exit(retcode);
}
Expand Down Expand Up @@ -459,7 +450,6 @@ arch_sd_init(void)

static int trace_fd = -1;
static struct sockaddr_in log_server;
extern const char *showtime_logtarget;

void
my_trace(const char *fmt, ...)
Expand All @@ -477,7 +467,7 @@ my_trace(const char *fmt, ...)
log_server.sin_len = sizeof(log_server);
log_server.sin_family = AF_INET;

snprintf(msg, sizeof(msg), "%s", showtime_logtarget);
snprintf(msg, sizeof(msg), "%s", SHOWTIME_DEFAULT_LOGTARGET);
p = strchr(msg, ':');
if(p != NULL) {
*p++ = 0;
Expand Down Expand Up @@ -600,11 +590,11 @@ arch_set_default_paths(int argc, char **argv)
}
x++;
*x = 0;
showtime_path = strdup(buf);
gconf.dirname = strdup(buf);
strcpy(x, "settings");
showtime_persistent_path = strdup(buf);
gconf.persistent_path = strdup(buf);
strcpy(x, "cache");
showtime_cache_path = strdup(buf);
gconf.cache_path = strdup(buf);
SysLoadModule(SYSMODULE_RTC);

thread_info_t *ti = malloc(sizeof(thread_info_t));
Expand Down
8 changes: 4 additions & 4 deletions src/backend/spotify/spotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -3831,15 +3831,15 @@ find_cachedir(char *path, size_t pathlen)
int i, fd;
char buf[PATH_MAX];

snprintf(buf, sizeof(buf), "%s/libspotify", showtime_cache_path);
snprintf(buf, sizeof(buf), "%s/libspotify", gconf.cache_path);
if(mkdir(buf, 0770)) {
if(errno != EEXIST)
return -1;
}

i = 0;
for(i = 0; i < 64; i++) {
snprintf(buf, sizeof(buf), "%s/libspotify/%d.lock", showtime_cache_path, i);
snprintf(buf, sizeof(buf), "%s/libspotify/%d.lock", gconf.cache_path, i);

fd = open(buf, O_CREAT | O_RDWR, 0770);
if(fd == -1)
Expand All @@ -3850,12 +3850,12 @@ find_cachedir(char *path, size_t pathlen)
continue;
}

snprintf(path, pathlen, "%s/libspotify/%d.cache", showtime_cache_path, i);
snprintf(path, pathlen, "%s/libspotify/%d.cache", gconf.cache_path, i);
return 0;
}
#endif

snprintf(path, pathlen, "%s/libspotify", showtime_cache_path);
snprintf(path, pathlen, "%s/libspotify", gconf.cache_path);
if(mkdir(path, 0770)) {
if(errno != EEXIST)
return 1;
Expand Down
28 changes: 14 additions & 14 deletions src/blobcache_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ make_filename(char *buf, size_t len, uint64_t hash, int for_write)
{
uint8_t dir = hash;
if(for_write) {
snprintf(buf, len, "%s/bc2/%02x", showtime_cache_path, dir);
snprintf(buf, len, "%s/bc2/%02x", gconf.cache_path, dir);
mkdir(buf, 0777);
}
snprintf(buf, len, "%s/bc2/%02x/%016"PRIx64, showtime_cache_path, dir, hash);
snprintf(buf, len, "%s/bc2/%02x/%016"PRIx64, gconf.cache_path, dir, hash);
}


Expand All @@ -159,7 +159,7 @@ save_index(void)
blobcache_item_t *p;
blobcache_diskitem_t *di;
size_t siz;
snprintf(filename, sizeof(filename), "%s/bc2/index.dat", showtime_cache_path);
snprintf(filename, sizeof(filename), "%s/bc2/index.dat", gconf.cache_path);

int fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0666);
if(fd == -1)
Expand Down Expand Up @@ -215,7 +215,7 @@ load_index(void)
struct stat st;
uint8_t digest[20];

snprintf(filename, sizeof(filename), "%s/bc2/index.dat", showtime_cache_path);
snprintf(filename, sizeof(filename), "%s/bc2/index.dat", gconf.cache_path);

int fd = open(filename, O_RDONLY, 0);
if(fd == -1)
Expand Down Expand Up @@ -498,22 +498,22 @@ prune_stale(void)
char path3[PATH_MAX];
uint64_t k;

snprintf(path, sizeof(path), "%s/bc2", showtime_cache_path);
snprintf(path, sizeof(path), "%s/bc2", gconf.cache_path);

if((d1 = opendir(path)) == NULL)
return;

while((de1 = readdir(d1)) != NULL) {
if(de1->d_name[0] != '.') {
snprintf(path2, sizeof(path2), "%s/bc2/%s",
showtime_cache_path, de1->d_name);
gconf.cache_path, de1->d_name);

if((d2 = opendir(path2)) != NULL) {
while((de2 = readdir(d2)) != NULL) {
if(de2->d_name[0] != '.') {

snprintf(path3, sizeof(path3), "%s/bc2/%s/%s",
showtime_cache_path, de1->d_name,
gconf.cache_path, de1->d_name,
de2->d_name);

if(sscanf(de2->d_name, "%016"PRIx64, &k) != 1 ||
Expand Down Expand Up @@ -622,21 +622,21 @@ blobcache_prune_old(void)
char path2[PATH_MAX];
char path3[PATH_MAX];

snprintf(path, sizeof(path), "%s/blobcache", showtime_cache_path);
snprintf(path, sizeof(path), "%s/blobcache", gconf.cache_path);

if((d1 = opendir(path)) != NULL) {

while((de1 = readdir(d1)) != NULL) {
if(de1->d_name[0] != '.') {
snprintf(path2, sizeof(path2), "%s/blobcache/%s",
showtime_cache_path, de1->d_name);
gconf.cache_path, de1->d_name);

if((d2 = opendir(path2)) != NULL) {
while((de2 = readdir(d2)) != NULL) {
if(de2->d_name[0] != '.') {

snprintf(path3, sizeof(path3), "%s/blobcache/%s/%s",
showtime_cache_path, de1->d_name,
gconf.cache_path, de1->d_name,
de2->d_name);
unlink(path3);
}
Expand All @@ -650,11 +650,11 @@ blobcache_prune_old(void)
rmdir(path);
}

snprintf(path, sizeof(path), "%s/cachedb/cache.db", showtime_cache_path);
snprintf(path, sizeof(path), "%s/cachedb/cache.db", gconf.cache_path);
unlink(path);
snprintf(path, sizeof(path), "%s/cachedb/cache.db-shm", showtime_cache_path);
snprintf(path, sizeof(path), "%s/cachedb/cache.db-shm", gconf.cache_path);
unlink(path);
snprintf(path, sizeof(path), "%s/cachedb/cache.db-wal", showtime_cache_path);
snprintf(path, sizeof(path), "%s/cachedb/cache.db-wal", gconf.cache_path);
unlink(path);
}

Expand Down Expand Up @@ -688,7 +688,7 @@ blobcache_init(void)
char buf[256];

blobcache_prune_old();
snprintf(buf, sizeof(buf), "%s/bc2", showtime_cache_path);
snprintf(buf, sizeof(buf), "%s/bc2", gconf.cache_path);
if(mkdir(buf, 0777) && errno != EEXIST)
TRACE(TRACE_ERROR, "blobcache", "Unable to create cache dir %s -- %s",
buf, strerror(errno));
Expand Down
5 changes: 2 additions & 3 deletions src/db/kvstore.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,11 @@ void
kvstore_init(void)
{
sqlite3 *db;
extern char *showtime_persistent_path;
char buf[256];

snprintf(buf, sizeof(buf), "%s/kvstore", showtime_persistent_path);
snprintf(buf, sizeof(buf), "%s/kvstore", gconf.persistent_path);
mkdir(buf, 0770);
snprintf(buf, sizeof(buf), "%s/kvstore/kvstore.db", showtime_persistent_path);
snprintf(buf, sizeof(buf), "%s/kvstore/kvstore.db", gconf.persistent_path);

// unlink(buf);

Expand Down
2 changes: 1 addition & 1 deletion src/db/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ vfs_open(sqlite3_vfs *pVfs, const char *zName, sqlite3_file *id, int flags,
if(zName == NULL) {
v = atomic_add(&tmpfiletally, 1);
snprintf(tmpfile, sizeof(tmpfile), "%s/sqlite.tmp.%d",
showtime_cache_path, v);
gconf.cache_path, v);
zName = tmpfile;
}

Expand Down
14 changes: 6 additions & 8 deletions src/htsmsg/htsmsg_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@

#define SETTINGS_STORE_DELAY 2 // seconds

extern char *showtime_persistent_path;
static char *showtime_settings_path;

LIST_HEAD(pending_store_list, pending_store);


Expand All @@ -53,6 +50,7 @@ static int rename_cant_overwrite;
static struct pending_store_list pending_stores;
static callout_t pending_store_callout;
static hts_mutex_t pending_store_mutex;
static char *showtime_settings_path;

/**
*
Expand Down Expand Up @@ -193,11 +191,11 @@ htsmsg_store_init(void)

hts_mutex_init(&pending_store_mutex);

if(showtime_persistent_path == NULL)
if(gconf.persistent_path == NULL)
return;

snprintf(p1, sizeof(p1), "%s/settings",
showtime_persistent_path);
gconf.persistent_path);

showtime_settings_path = strdup(p1);

Expand All @@ -209,16 +207,16 @@ htsmsg_store_init(void)
DIR *dir;
struct dirent *d;

if((dir = opendir(showtime_persistent_path)) != NULL) {
if((dir = opendir(gconf.persistent_path)) != NULL) {
while((d = readdir(dir)) != NULL) {
if(d->d_name[0] == '.')
continue;

snprintf(p1, sizeof(p1), "%s/%s",
showtime_persistent_path, d->d_name);
gconf.persistent_path, d->d_name);

snprintf(p2, sizeof(p2), "%s/settings/%s",
showtime_persistent_path, d->d_name);
gconf.persistent_path, d->d_name);

rename(p1, p2);
}
Expand Down
Loading

0 comments on commit 1ed762d

Please sign in to comment.