char *write_dev, char *read_dev)
{
pid_t child;
- char *argv[] = { "tapdisk", write_dev, read_dev, NULL };
+ char opt_facility[32];
+ char *argv[] = { "tapdisk", opt_facility, write_dev, read_dev, NULL };
const char *tapdisk;
int i;
i != STDERR_FILENO)
close(i);
+ snprintf(opt_facility, sizeof(opt_facility),
+ "-l%d", tapdisk_daemon_log_facility);
+
tapdisk = getenv("TAPDISK");
if (!tapdisk)
tapdisk = argv[0];
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <signal.h>
+#include <getopt.h>
+#define SYSLOG_NAMES
+#include <syslog.h>
#include <xs.h>
#include "disktypes.h"
} tapdisk_daemon_t;
static tapdisk_daemon_t tapdisk_daemon;
+int tapdisk_daemon_log_facility;
#define tapdisk_daemon_for_each_channel(c, tmp) \
list_for_each_entry_safe(c, tmp, &tapdisk_daemon.channels, list)
int i, size;
DPRINTF("blktap-daemon: v1.0.2\n");
+ DPRINTF("Syslog facility %d\n", tapdisk_daemon_log_facility);
size = sizeof(dtypes) / sizeof(disk_info_t *);
for (i = 0; i < size; i++)
close(channel->write_fd);
}
+static void
+tapdisk_daemon_openlog(const char *ident, const char *facility_name)
+{
+ static char buf[128];
+ int facility;
+
+ facility = LOG_DAEMON;
+
+ if (facility_name) {
+ char *endptr;
+
+ facility = strtol(facility_name, &endptr, 0);
+ if (*endptr != 0) {
+ CODE *c;
+
+ facility = LOG_DAEMON;
+ for (c = facilitynames; c->c_name != NULL; ++c)
+ if (!strcmp(c->c_name, facility_name))
+ facility = c->c_val;
+ }
+ }
+
+ snprintf(buf, sizeof(buf), "%s[%d]", ident, getpid());
+ openlog(buf, LOG_CONS | LOG_ODELAY, facility);
+ tapdisk_daemon_log_facility = facility;
+}
+
+static const char *program;
+
+static void
+usage(FILE *stream)
+{
+ fprintf(stream, "Usage: %s [-h] [-l <syslog_facility>]\n", program);
+}
+
int
main(int argc, char *argv[])
{
int err;
- char buf[128];
+ const char *facility;
+
+ program = basename(argv[0]);
+ facility = "daemon";
+
+ do {
+ char c;
+
+ c = getopt(argc, argv, "hl:");
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case 'h':
+ usage(stdout);
+ return 0;
+ case 'l':
+ facility = optarg;
+ break;
+ default:
+ goto usage;
+ }
+ } while (1);
daemon(0, 0);
}
#endif
- snprintf(buf, sizeof(buf), "BLKTAP-DAEMON[%d]", getpid());
- openlog(buf, LOG_CONS | LOG_ODELAY, LOG_DAEMON);
+ tapdisk_daemon_openlog("BLKTAP-DAEMON", facility);
err = tapdisk_daemon_write_pidfile(getpid());
if (err)
out:
closelog();
-
return err ? 1 : 0;
+
+usage:
+ usage(stderr);
+ return EINVAL;
+
}
struct xs_handle *xsh;
};
+extern int tapdisk_daemon_log_facility;
+
typedef struct tapdisk_channel tapdisk_channel_t;
int strsep_len(const char *str, char c, unsigned int len);
if (err)
return err;
- tapdisk_start_logging("tapdisk-diff");
+ tapdisk_start_logging("tapdisk-diff", "daemon");
err = tapdisk_server_initialize(NULL, NULL);
if (err)
return err;
}
- tapdisk_start_logging("tapdisk-stream");
+ tapdisk_start_logging("tapdisk-stream", "daemon");
err = tapdisk_stream_open(&stream, path, type, count, skip);
if (err)
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
+#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
+#define SYSLOG_NAMES
+#include <syslog.h>
+
#include "tapdisk.h"
#include "disktypes.h"
#include "blktaplib.h"
#include "tapdisk-utils.h"
void
-tapdisk_start_logging(const char *name)
+tapdisk_start_logging(const char *ident, const char *facility_name)
{
static char buf[128];
+ int facility;
+
+ facility = LOG_DAEMON;
+
+ if (facility_name) {
+ char *endptr;
+
+ facility = strtol(facility_name, &endptr, 0);
+ if (*endptr != 0) {
+ CODE *c;
+
+ facility = LOG_DAEMON;
+ for (c = facilitynames; c->c_name != NULL; ++c)
+ if (!strcmp(c->c_name, facility_name))
+ facility = c->c_val;
+ }
+ }
- snprintf(buf, sizeof(buf), "%s[%d]", name, getpid());
- openlog(buf, LOG_CONS | LOG_ODELAY, LOG_DAEMON);
+ snprintf(buf, sizeof(buf), "%s[%d]", ident, getpid());
+ openlog(buf, LOG_CONS | LOG_ODELAY, facility);
open_tlog("/tmp/tapdisk.log", (64 << 10), TLOG_WARN, 0);
}
#define MAX_NAME_LEN 1000
-void tapdisk_start_logging(const char *);
+void tapdisk_start_logging(const char *, const char *);
void tapdisk_stop_logging(void);
int tapdisk_set_resource_limits(void);
int tapdisk_namedup(char **, const char *);
{ "detach", 0, 0, 'D' }
};
int err, detach = 0;
-
- program = basename(argv[0]);
+ const char *facility;
+ const char *ipc_read, *ipc_write;
+
+ program = basename(argv[0]);
+ facility = "daemon";
do {
int c;
- c = getopt_long(argc, argv, "hD", longopts, NULL);
+ c = getopt_long(argc, argv, "hDl:", longopts, NULL);
if (c == -1)
break;
switch (c) {
+ case 'l':
+ facility = optarg;
+ break;
case 'h':
usage(stdout);
return 0;
if (argc - optind < 2)
goto usage;
-
+
+ ipc_read = argv[optind++];
+ ipc_write = argv[optind++];
+
+ if (argc - optind)
+ goto usage;
+
if (detach) {
/* NB. This is expected to rarely, if ever, be
used. Blktapctrl is already detached, and breaking
}
}
- tapdisk_start_logging("TAPDISK");
+ tapdisk_start_logging("TAPDISK", facility);
- err = tapdisk_server_initialize(argv[1], argv[2]);
+ err = tapdisk_server_initialize(ipc_read, ipc_write);
if (err) {
EPRINTF("failed to initialize tapdisk server: %d\n", err);
goto out;
int err, type;
chdir("/");
- tapdisk_start_logging("tapdisk2");
err = tapdisk2_set_child_fds();
if (err)
{
int c;
char *params;
+ const char *facility;
- params = NULL;
+ params = NULL;
+ facility = "daemon";
- while ((c = getopt(argc, argv, "n:h")) != -1) {
+ while ((c = getopt(argc, argv, "n:hl:")) != -1) {
switch (c) {
+ case 'l':
+ facility = optarg;
+ break;
case 'n':
params = optarg;
break;
printf("fork failed: %d\n", errno);
return errno;
case 0:
+ tapdisk_start_logging("tapdisk2", facility);
return tapdisk2_create_device(params);
default:
return tapdisk2_wait_for_device();