fix searchpath handling
This commit is contained in:
parent
91a2f9a8ce
commit
d5578f6073
@ -44,6 +44,8 @@ pid_t pidfile_check(const char *filename, int remove_stale)
|
|||||||
int len = read(fd, buf, sizeof(buf) -1);
|
int len = read(fd, buf, sizeof(buf) -1);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
pid_t pid = strtol(buf, &tmp, 10);
|
pid_t pid = strtol(buf, &tmp, 10);
|
||||||
if (len == 0 || tmp == buf)
|
if (len == 0 || tmp == buf)
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "pidfile.h"
|
#include "pidfile.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "signals.h"
|
#include "signals.h"
|
||||||
|
#include "torrentfile.h"
|
||||||
|
|
||||||
#define DEFAULT_CONFIG "torrent-stats.conf"
|
#define DEFAULT_CONFIG "torrent-stats.conf"
|
||||||
#define DEFAULT_LOGFILE "torrent-stats.log"
|
#define DEFAULT_LOGFILE "torrent-stats.log"
|
||||||
@ -114,6 +115,9 @@ int main(int argc, char *argv[])
|
|||||||
signal_set_callback(SIGHUP, event_loop_break);
|
signal_set_callback(SIGHUP, event_loop_break);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
if (torrentfile_init() < 0)
|
||||||
|
break;
|
||||||
|
|
||||||
if (ctcs_init() < 0)
|
if (ctcs_init() < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@
|
|||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "torrentfile.h"
|
#include "torrentfile.h"
|
||||||
|
|
||||||
|
static const char *searchpath;
|
||||||
|
static const char *ctorrent_bin;
|
||||||
|
static const char *statserv;
|
||||||
|
|
||||||
LIST_HEAD(torrent_list);
|
LIST_HEAD(torrent_list);
|
||||||
|
|
||||||
struct torrent_file * find_create_torrent(const char *fullpath)
|
struct torrent_file * find_create_torrent(const char *fullpath)
|
||||||
@ -112,14 +116,8 @@ static int null_read(int fd, void *privdata)
|
|||||||
|
|
||||||
int seed_torrent(struct torrent_file *torrent)
|
int seed_torrent(struct torrent_file *torrent)
|
||||||
{
|
{
|
||||||
const char *path = config_get_string("global", "search-path", NULL);
|
|
||||||
if (path == NULL) {
|
|
||||||
log_print(LOG_WARN, "requesting torrentfile, but no search path given");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int len = snprintf(buf, sizeof(buf), "%s/%s", path, torrent->name);
|
int len = snprintf(buf, sizeof(buf), "%s/%s", searchpath, torrent->name);
|
||||||
if (len < 0 || len >= sizeof(buf)) {
|
if (len < 0 || len >= sizeof(buf)) {
|
||||||
log_print(LOG_WARN, "filename > max");
|
log_print(LOG_WARN, "filename > max");
|
||||||
return -1;
|
return -1;
|
||||||
@ -131,11 +129,9 @@ int seed_torrent(struct torrent_file *torrent)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *ctorrent_bin = config_get_string("global", "ctorrent-bin", "/usr/bin/ctorrent");
|
|
||||||
const char *statserv = config_get_string("global", "statserv", "127.0.0.1:2780");
|
|
||||||
char *const args[] = { (char *)ctorrent_bin, "-S", (char *)statserv, "-f", buf, NULL };
|
char *const args[] = { (char *)ctorrent_bin, "-S", (char *)statserv, "-f", buf, NULL };
|
||||||
|
|
||||||
torrent->child = childproc_alloc(args, path);
|
torrent->child = childproc_alloc(args, searchpath);
|
||||||
if (childproc_fork(torrent->child, child_exit, torrent) < 0) {
|
if (childproc_fork(torrent->child, child_exit, torrent) < 0) {
|
||||||
log_print(LOG_ERROR, "spawn_child(%s)", args[0]);
|
log_print(LOG_ERROR, "spawn_child(%s)", args[0]);
|
||||||
childproc_free(torrent->child);
|
childproc_free(torrent->child);
|
||||||
@ -151,3 +147,15 @@ int seed_torrent(struct torrent_file *torrent)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int torrentfile_init(void)
|
||||||
|
{
|
||||||
|
searchpath = config_get_string("global", "search-path", NULL);
|
||||||
|
if (searchpath == NULL)
|
||||||
|
log_print(LOG_WARN, "disable torrent autostart");
|
||||||
|
|
||||||
|
ctorrent_bin = config_get_string("global", "ctorrent-bin", "/usr/bin/ctorrent");
|
||||||
|
statserv = config_get_string("global", "statserv", "127.0.0.1:2780");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -28,4 +28,6 @@ int destroy_torrent(struct torrent_file *torrent);
|
|||||||
|
|
||||||
int seed_torrent(struct torrent_file *torrent);
|
int seed_torrent(struct torrent_file *torrent);
|
||||||
|
|
||||||
|
int torrentfile_init(void);
|
||||||
|
|
||||||
#endif /* _TORRENTFILE_H_ */
|
#endif /* _TORRENTFILE_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user