瀏覽代碼

Introduce the -d option.

master
Richard Nyberg 19 年之前
父節點
當前提交
c8a115a0f0
共有 1 個檔案被更改,包括 40 行新增29 行删除
  1. +40
    -29
      btpd/btpd.c

+ 40
- 29
btpd/btpd.c 查看文件

@@ -207,30 +207,34 @@ static void
usage() usage()
{ {
printf("Usage: btpd [options]\n" printf("Usage: btpd [options]\n"
"\n"
"Options:\n"
"\n"
"--bw-in n\n"
"\tLimit incoming BitTorrent traffic to n kB/s.\n"
"\tDefault is 0 which means unlimited.\n"
"\n"
"--bw-out n\n"
"\tlimit outgoing BitTorrent traffic to n kB/s.\n"
"\tDefault is 0 which means unlimited.\n"
"\n"
"--ipc key\n"
"\tThe same key must be used by the cli to talk to this\n"
"\tbtpd instance. You shouldn't need to use this option.\n"
"\n"
"--logfile file\n"
"\tLog to the given file. By default btpd logs to ./btpd.log.\n"
"\n"
"-p n, --port n\n"
"\tListen at port n. Default is 6881.\n"
"\n"
"--help\n"
"\tShow this help.\n"
"\n");
"\n"
"Options:\n"
"\n"
"--bw-in n\n"
"\tLimit incoming BitTorrent traffic to n kB/s.\n"
"\tDefault is 0 which means unlimited.\n"
"\n"
"--bw-out n\n"
"\tLimit outgoing BitTorrent traffic to n kB/s.\n"
"\tDefault is 0 which means unlimited.\n"
"\n"
"-d\n"
"\tKeep the btpd process in the foregorund and log to std{out,err}.\n"
"\tThis options is intended for debugging purposes.\n"
"\n"
"--ipc key\n"
"\tThe same key must be used by the cli to talk to this\n"
"\tbtpd instance. You shouldn't need to use this option.\n"
"\n"
"--logfile file\n"
"\tLog to the given file. By default btpd logs to ./btpd.log.\n"
"\n"
"-p n, --port n\n"
"\tListen at port n. Default is 6881.\n"
"\n"
"--help\n"
"\tShow this help.\n"
"\n");
exit(1); exit(1);
} }


@@ -251,12 +255,16 @@ main(int argc, char **argv)
{ {
int error, ch; int error, ch;
char *logfile = NULL, *ipc = NULL; char *logfile = NULL, *ipc = NULL;
int d_opt = 0;

setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
btpd_init(); btpd_init();


while ((ch = getopt_long(argc, argv, "p:", longopts, NULL)) != -1) {
while ((ch = getopt_long(argc, argv, "dp:", longopts, NULL)) != -1) {
switch (ch) { switch (ch) {
case 'd':
d_opt = 1;
break;
case 'p': case 'p':
btpd.port = atoi(optarg); btpd.port = atoi(optarg);
break; break;
@@ -353,12 +361,15 @@ main(int argc, char **argv)
freopen("/dev/null", "r", stdin); freopen("/dev/null", "r", stdin);
if (logfile == NULL) if (logfile == NULL)
logfile = "btpd.log"; logfile = "btpd.log";
freopen(logfile, "w", stdout);
freopen(logfile, "w", stderr);
if (!d_opt) {
freopen(logfile, "w", stdout);
freopen(logfile, "w", stderr);
daemon(1, 1);
}

setlinebuf(stdout); setlinebuf(stdout);
setlinebuf(stderr); setlinebuf(stderr);


daemon(1, 1);


event_init(); event_init();




Loading…
取消
儲存