Browse Source

Don't use the bsd err and warn family of functions. Solaris doesn't have them.

master
Richard Nyberg 16 years ago
parent
commit
c8285d9b31
8 changed files with 38 additions and 19 deletions
  1. +4
    -4
      cli/add.c
  2. +21
    -6
      cli/btcli.c
  3. +2
    -1
      cli/btcli.h
  4. +6
    -3
      cli/btinfo.c
  5. +1
    -1
      cli/kill.c
  6. +2
    -2
      cli/list.c
  7. +1
    -1
      cli/stat.c
  8. +1
    -1
      cli/stop.c

+ 4
- 4
cli/add.c View File

@@ -54,7 +54,7 @@ cmd_add(int argc, char **argv)
case 'd':
dir = optarg;
if ((dirlen = strlen(dir)) == 0)
errx(1, "bad option value for -d");
diemsg("bad option value for -d.\n");
break;
case 'n':
name = optarg;
@@ -77,7 +77,7 @@ cmd_add(int argc, char **argv)
struct iobuf iob;

if ((mi = mi_load(argv[0], &mi_size)) == NULL)
err(1, "error loading '%s'", argv[0]);
diemsg("error loading '%s' (%s).\n", argv[0], strerror(errno));

iob = iobuf_init(PATH_MAX);
iobuf_write(&iob, dir, dirlen);
@@ -90,7 +90,7 @@ cmd_add(int argc, char **argv)
}
iobuf_swrite(&iob, "\0");
if ((errno = make_abs_path(iob.buf, dpath)) != 0)
err(1, "make_abs_path '%s'", dpath);
diemsg("make_abs_path '%s' failed (%s).\n", dpath, strerror(errno));
code = btpd_add(ipc, mi, mi_size, dpath, name);
if (code == 0 && start) {
struct ipc_torrent tspec;
@@ -99,6 +99,6 @@ cmd_add(int argc, char **argv)
code = btpd_start(ipc, &tspec);
}
if (code != IPC_OK)
errx(1, "%s", ipc_strerror(code));
diemsg("command failed (%s).\n", ipc_strerror(code));
return;
}

+ 21
- 6
cli/btcli.c View File

@@ -1,13 +1,26 @@
#include <stdarg.h>

#include "btcli.h"

const char *btpd_dir;
struct ipc *ipc;

void
diemsg(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
exit(1);
}

void
btpd_connect(void)
{
if ((errno = ipc_open(btpd_dir, &ipc)) != 0)
err(1, "cannot open connection to btpd in %s", btpd_dir);
diemsg("cannot open connection to btpd in %s (%s).\n", btpd_dir,
strerror(errno));
}

enum ipc_err
@@ -17,9 +30,10 @@ handle_ipc_res(enum ipc_err code, const char *cmd, const char *target)
case IPC_OK:
break;
case IPC_COMMERR:
errx(1, "%s", ipc_strerror(code));
diemsg("error in communication with btpd.\n");
default:
warnx("%s '%s': %s", cmd, target, ipc_strerror(code));
fprintf(stderr, "btcli %s '%s': %s.\n", cmd, target,
ipc_strerror(code));
}
return code;
}
@@ -68,7 +82,7 @@ tstate_char(enum ipc_tstate ts)
case IPC_TSTATE_SEED:
return 'S';
}
errx(1, "bad state");
diemsg("unrecognized torrent state.\n");
}

int
@@ -81,7 +95,8 @@ torrent_spec(char *arg, struct ipc_torrent *tp)
return 1;
}
if ((p = mi_load(arg, NULL)) == NULL) {
warnx("bad torrent '%s' (%s)", arg, strerror(errno));
fprintf(stderr, "btcli: bad torrent '%s' (%s).'n", arg,
strerror(errno));
return 0;
}
tp->by_hash = 1;
@@ -170,7 +185,7 @@ main(int argc, char **argv)

if (btpd_dir == NULL)
if ((btpd_dir = find_btpd_dir()) == NULL)
errx(1, "cannot find the btpd directory");
diemsg("cannot find the btpd directory.\n");

optind = 0;
int found = 0;


+ 2
- 1
cli/btcli.h View File

@@ -1,7 +1,6 @@
#ifndef BTCLI_H
#define BTCLI_H

#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <inttypes.h>
@@ -23,6 +22,8 @@
extern const char *btpd_dir;
extern struct ipc *ipc;

__attribute__((noreturn))
void diemsg(const char *fmt, ...);
void btpd_connect(void);
enum ipc_err handle_ipc_res(enum ipc_err err, const char *cmd,
const char *target);


+ 6
- 3
cli/btinfo.c View File

@@ -1,11 +1,11 @@
#include <sys/types.h>

#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "metainfo.h"
@@ -75,8 +75,11 @@ main(int argc, char **argv)
while (argc > 0) {
char *mi = NULL;

if ((mi = mi_load(*argv, NULL)) == NULL)
err(1, "mi_load: %s", *argv);
if ((mi = mi_load(*argv, NULL)) == NULL) {
fprintf(stderr, "failed to load torrent file '%s' (%s).\n",
*argv, strerror(errno));
exit(1);
}

print_metainfo(mi);
free(mi);


+ 1
- 1
cli/kill.c View File

@@ -33,5 +33,5 @@ cmd_kill(int argc, char **argv)

btpd_connect();
if ((code = btpd_die(ipc, seconds)) != 0)
errx(1, "%s", ipc_strerror(code));
diemsg("command failed (%s).\n", ipc_strerror(code));
}

+ 2
- 2
cli/list.c View File

@@ -60,7 +60,7 @@ list_cb(int obji, enum ipc_err objerr, struct ipc_get_res *res, void *arg)
struct items *itms = arg;
struct item *itm = calloc(1, sizeof(*itm));
if (objerr != IPC_OK)
errx(1, "list failed for '%s' (%s)", itms->argv[obji],
diemsg("list failed for '%s' (%s).\n", itms->argv[obji],
ipc_strerror(objerr));
itms->count++;
itm->num = (unsigned)res[IPC_TVAL_NUM].v.num;
@@ -148,7 +148,7 @@ cmd_list(int argc, char **argv)
else
code = btpd_tget(ipc, itms.tps, itms.ntps, keys, nkeys, list_cb, &itms);
if (code != IPC_OK)
errx(1, "%s", ipc_strerror(code));
diemsg("command failed (%s).\n", ipc_strerror(code));
printf("%-40.40s NUM ST HAVE SIZE RATIO\n", "NAME");
print_items(&itms);
}

+ 1
- 1
cli/stat.c View File

@@ -136,7 +136,7 @@ again:
else
err = btpd_tget(ipc, tps, ntps, stkeys, nstkeys, stat_cb, &cba);
if (err != IPC_OK)
errx(1, ipc_strerror(err));
diemsg("command failed (%s).\n", ipc_strerror(err));
if (names)
printf("-------\n");
if (individual)


+ 1
- 1
cli/stop.c View File

@@ -51,7 +51,7 @@ cmd_stop(int argc, char **argv)
if (all) {
enum ipc_err code = btpd_stop_all(ipc);
if (code != IPC_OK)
errx(1, "%s", ipc_strerror(code));
diemsg("command failed (%s).\n", ipc_strerror(code));
} else {
for (int i = 0; i < argc; i++)
if (torrent_spec(argv[i], &t))


Loading…
Cancel
Save