Fix misc compile-time warnings.
Version 1.02.03 -
============================
+ Rename _log to dm_log and export.
Add dm_tree_skip_lockfs.
Fix dm_strdup debug definition.
Fix hash function to avoid using a negative array offset.
#include <malloc.h>
#endif
-/* FIXME Use dm library */
-#define dbg_malloc(x...) malloc(x)
-#define dbg_strdup(x...) strdup(x)
-#define dbg_free(x...) free(x)
-
/* List (un)link macros. */
#define LINK(x, head) list_add(head, &(x)->list)
#define LINK_DSO(dso) LINK(dso, &dso_registry)
struct dso_data *dso_data;/* DSO this thread accesses. */
char *device_path; /* Mapped device path. */
- int event_nr; /* event number */
+ uint32_t event_nr; /* event number */
int processing; /* Set when event is being processed */
enum dm_event_type events; /* bitfield for event filter. */
enum dm_event_type current_events;/* bitfield for occured events. */
static struct thread_status *alloc_thread_status(struct message_data *data,
struct dso_data *dso_data)
{
- struct thread_status *ret = (typeof(ret)) dbg_malloc(sizeof(*ret));
+ struct thread_status *ret = (typeof(ret)) dm_malloc(sizeof(*ret));
if (ret) {
if (!memset(ret, 0, sizeof(*ret)) ||
- !(ret->device_path = dbg_strdup(data->device_path))) {
- dbg_free(ret);
+ !(ret->device_path = dm_strdup(data->device_path))) {
+ dm_free(ret);
ret = NULL;
} else {
ret->dso_data = dso_data;
static void free_thread_status(struct thread_status *thread)
{
- dbg_free(thread->device_path);
- dbg_free(thread);
+ dm_free(thread->device_path);
+ dm_free(thread);
}
/* Allocate/free DSO data. */
static struct dso_data *alloc_dso_data(struct message_data *data)
{
- struct dso_data *ret = (typeof(ret)) dbg_malloc(sizeof(*ret));
+ struct dso_data *ret = (typeof(ret)) dm_malloc(sizeof(*ret));
if (ret) {
if (!memset(ret, 0, sizeof(*ret)) ||
- !(ret->dso_name = dbg_strdup(data->dso_name))) {
- dbg_free(ret);
+ !(ret->dso_name = dm_strdup(data->dso_name))) {
+ dm_free(ret);
ret = NULL;
}
}
static void free_dso_data(struct dso_data *data)
{
- dbg_free(data->dso_name);
- dbg_free(data);
+ dm_free(data->dso_name);
+ dm_free(data);
}
/* FIXME: Factor out. */
if ((p = strchr(*src, delimiter)))
*p = 0;
- if ((*ptr = dbg_strdup(*src))) {
+ if ((*ptr = dm_strdup(*src))) {
if ((len = strlen(*ptr)))
*src += len;
else {
- dbg_free(*ptr);
+ dm_free(*ptr);
*ptr = NULL;
}
static void free_message(struct message_data *message_data)
{
if (message_data->dso_name)
- dbg_free(message_data->dso_name);
+ dm_free(message_data->dso_name);
if (message_data->device_path)
- dbg_free(message_data->device_path);
+ dm_free(message_data->device_path);
}
/* Parse a register message from the client. */
* Free string representaion of events.
* Not needed an more.
*/
- dbg_free(message_data->events.str);
+ dm_free(message_data->events.str);
message_data->events.field = i;
}
if (message_data->timeout.str) {
uint32_t secs = atoi(message_data->timeout.str);
- dbg_free(message_data->timeout.str);
+ dm_free(message_data->timeout.str);
message_data->timeout.secs = secs ? secs :
DM_EVENT_DEFAULT_TIMEOUT;
}
if ((len = snprintf(pid, sizeof(pid), "%u\n", getpid())) < 0)
return 0;
- if (len > sizeof(pid))
- len = sizeof(pid);
+ if (len > (int) sizeof(pid))
+ len = (int) sizeof(pid);
- if (write(lf, pid, len) != len)
+ if (write(lf, pid, (size_t) len) != len)
return 0;
fsync(lf);
}
/* Device monitoring thread. */
+static void *monitor_thread(void *arg)
+ __attribute((noreturn));
static void *monitor_thread(void *arg)
{
struct thread_status *thread = arg;
static char prefix[] = "libdevmapper-event-";
static char suffix[] = ".so";
- if ((ret = dbg_malloc(strlen(prefix) +
+ if ((ret = dm_malloc(strlen(prefix) +
strlen(dso_name) +
strlen(suffix) + 1)))
sprintf(ret, "%s%s%s", prefix, dso_name, suffix);
dlclose(dl);
free_dso_file:
- dbg_free(dso_file);
+ dm_free(dso_file);
return ret;
}
*/
static int client_read(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
- int bytes = 0, ret = 0;
+ unsigned bytes = 0;
+ int ret = 0;
fd_set fds;
errno = 0;
*/
static int client_write(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
- int bytes = 0, ret = 0;
+ unsigned bytes = 0;
+ int ret = 0;
fd_set fds;
errno = 0;
#define EXIT_FIFO_FAILURE 5
#define EXIT_CHDIR_FAILURE 6
-void dmeventd(void);
+void dmeventd(void)
+ __attribute((noreturn));
#endif /* __DMEVENTD_DOT_H__ */
if ((p = strchr(*src, delimiter)))
*p = 0;
- if ((ret = strdup(*src)))
+ if ((ret = dm_strdup(*src)))
*src += strlen(ret) + 1;
if (p)
*/
static int daemon_read(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
- int bytes = 0, ret = 0;
+ unsigned bytes = 0;
+ int ret = 0;
fd_set fds;
memset(msg, 0, sizeof(*msg));
/* Write message to daemon. */
static int daemon_write(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
- int bytes = 0, ret = 0;
+ unsigned bytes = 0;
+ int ret = 0;
fd_set fds;
while (bytes < sizeof(*msg)) {
*/
msg->opcode.cmd = cmd;
- if (sizeof(msg->msg) <= snprintf(msg->msg, sizeof(msg->msg),
- "%s %s %u %"PRIu32,
- dso_name ? dso_name : "",
- device ? device : "",
- events, timeout)) {
+ if (sizeof(msg->msg) <= (unsigned) snprintf(msg->msg, sizeof(msg->msg),
+ "%s %s %u %"PRIu32,
+ dso_name ? dso_name : "",
+ device ? device : "",
+ events, timeout)) {
stack;
return -ENAMETOOLONG;
}
struct dm_event_daemon_message msg;
if (!device_exists(device_path)) {
- log_error("%s: device not found");
+ log_error("%s: device not found", device_path);
return 0;
}
struct dm_event_daemon_message msg;
if (!device_exists(device_path)) {
- log_error("%s: device not found");
+ log_error("%s: device not found", device_path);
return 0;
}
if (next){
if (*dso_name)
- free(*dso_name);
+ dm_free(*dso_name);
if (*device_path)
- free(*device_path);
+ dm_free(*device_path);
*dso_name = dso_name_arg;
*device_path = device_path_arg;
} else {
static int _message(int argc, char **argv, void *data)
{
- int r = 0, sz = 1, i;
+ int r = 0, i;
+ size_t sz = 1;
struct dm_task *dmt;
char *str;
argv++;
}
- if (!dm_task_set_sector(dmt, atoll(argv[1])))
+ if (!dm_task_set_sector(dmt, (uint64_t) atoll(argv[1])))
goto out;
argc -= 2;
}
return _simple(DM_DEVICE_WAITEVENT, name,
- (argc > 1) ? atoi(argv[argc - 1]) : 0, 1);
+ (argc > 1) ? (uint32_t) atoi(argv[argc - 1]) : 0, 1);
}
static int _process_all(int argc, char **argv,
return r;
}
-static void _display_dev(struct dm_task *dmt, char *name)
+static void _display_dev(struct dm_task *dmt, const char *name)
{
struct dm_info info;
return dm_mknodes(argc > 1 ? argv[1] : NULL);
}
-static int _exec_command(char *name)
+static int _exec_command(const char *name)
{
int n;
static char path[PATH_MAX];
return 0;
n = snprintf(path, sizeof(path), "%s/%s", dm_dir(), name);
- if (n < 0 || n > sizeof(path) - 1)
+ if (n < 0 || n > (int) sizeof(path) - 1)
return 0;
if (!argc) {
char *params;
int cmd;
struct dm_names *names = (struct dm_names *) data;
- char *name = NULL;
+ const char *name = NULL;
int matched = 0;
int ls_only = 0;
struct dm_info info;
goto out;
if (!name)
- name = (char *) dm_task_get_name(dmt);
+ name = dm_task_get_name(dmt);
/* Fetch targets and print 'em */
do {
#define _LOG_ERR 3
#define _LOG_FATAL 2
-extern dm_log_fn _log;
+extern dm_log_fn dm_log;
-#define plog(l, x...) _log(l, __FILE__, __LINE__, ## x)
+#define plog(l, x...) dm_log(l, __FILE__, __LINE__, ## x)
#define log_error(x...) plog(_LOG_ERR, x)
#define log_print(x...) plog(_LOG_WARN, x)
dm_lib_exit
dm_driver_version
dm_get_library_version
+dm_log
dm_log_init
dm_log_init_verbose
dm_task_create
*/
static inline int _test_word(uint32_t test, int bit)
{
- while (bit < DM_BITS_PER_INT) {
+ while (bit < (int) DM_BITS_PER_INT) {
if (test & (0x1 << bit))
return bit;
bit++;
last_bit++; /* otherwise we'll return the same bit again */
- while (last_bit < bs[0]) {
+ /*
+ * bs[0] holds number of bits
+ */
+ while (last_bit < (int) bs[0]) {
word = last_bit >> INT_SHIFT;
test = bs[word + 1];
bit = last_bit & (DM_BITS_PER_INT - 1);
if (bufsize < 8)
return 0;
- r = snprintf(buf, bufsize, "%u:%u", dev_major, dev_minor);
+ r = snprintf(buf, (size_t) bufsize, "%u:%u", dev_major, dev_minor);
if (r < 0 || r > bufsize - 1)
return 0;
struct target *t = dm_malloc(sizeof(*t));
if (!t) {
- log_error("create_target: malloc(%d) failed", sizeof(*t));
+ log_error("create_target: malloc(%" PRIsize_t ") failed",
+ sizeof(*t));
return NULL;
}
*/
typedef void (*dm_log_fn) (int level, const char *file, int line,
- const char *f, ...);
+ const char *f, ...)
+ __attribute__ ((format(printf, 4, 5)));
/*
* The library user may wish to register their own
fprintf(stdout, "\n");
}
-dm_log_fn _log = _default_log;
+dm_log_fn dm_log = _default_log;
void dm_log_init(dm_log_fn fn)
{
if (fn)
- _log = fn;
+ dm_log = fn;
else
- _log = _default_log;
+ dm_log = _default_log;
}
void dm_log_init_verbose(int level)
struct dm_task *dmt = dm_malloc(sizeof(*dmt));
if (!dmt) {
- log_error("dm_task_create: malloc(%d) failed", sizeof(*dmt));
+ log_error("dm_task_create: malloc(%" PRIsize_t ") failed",
+ sizeof(*dmt));
return NULL;
}
n = vsnprintf(buf, bufsize, format, ap);
va_end(ap);
- if (n < 0 || (n > bufsize - 1))
+ if (n < 0 || (n > (int) bufsize - 1))
return -1;
return n;
#include <fcntl.h>
#include <dirent.h>
-#ifdef linux
-# include <malloc.h>
-#endif
-
static int _create_dir_recursive(const char *dir)
{
char *orig, *s;
log_verbose("Creating directory \"%s\"", dir);
/* Create parent directories */
- orig = s = strdup(dir);
+ orig = s = dm_strdup(dir);
while ((s = strchr(s, '/')) != NULL) {
*s = '\0';
if (*orig) {
if (rc < 0 && errno != EEXIST) {
log_error("%s: mkdir failed: %s", orig,
strerror(errno));
- free(orig);
+ dm_free(orig);
return 0;
}
}
*s++ = '/';
}
- free(orig);
+ dm_free(orig);
/* Create final directory */
rc = mkdir(dir, 0777);
}
str[sizeof(str) - 1] = '\0';
- _log(_LOG_INFO, mb->file, mb->line,
- "block %d at %p, size %" PRIsize_t "\t [%s]",
- mb->id, mb->magic, mb->length, str);
+ dm_log(_LOG_INFO, mb->file, mb->line,
+ "block %d at %p, size %" PRIsize_t "\t [%s]",
+ mb->id, mb->magic, mb->length, str);
tot += mb->length;
}
/* have we got room ? */
if (!c || (c->begin > c->end) || (c->end - c->begin < s)) {
/* allocate new chunk */
- int needed = s + alignment + sizeof(struct chunk);
+ size_t needed = s + alignment + sizeof(struct chunk);
c = _new_chunk(p, (needed > p->chunk_size) ?
needed : p->chunk_size);
* different architectures.
*/
-#define _log(level, file, line, format, args...) _log(format, args)
+#define dm_log(level, file, line, format, args...) dm_log(format, args)