#include <sys/types.h>
#include <fcntl.h>
#include <errno.h>
+#include <sys/time.h>
+#include <sys/resource.h>
/*
* libcheckers
#include <switchgroup.h>
#include <print.h>
#include <configure.h>
+#include <prio.h>
#include "main.h"
#include "pidfile.h"
pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
+int logsink;
+
/*
* global copy of vecs for use in sig handlers
*/
* remove all current maps not allowed by the
* current configuration
*/
- if (dm_flush_map(ompp->alias, DEFAULT_TARGET)) {
+ if (dm_flush_map(ompp->alias)) {
condlog(0, "%s: unable to flush devmap",
ompp->alias);
/*
}
else {
dm_lib_release();
- condlog(3, "%s devmap removed", ompp->alias);
+ condlog(2, "%s devmap removed", ompp->alias);
}
}
}
sync_map_state(struct multipath *mpp)
{
struct pathgroup *pgp;
- struct path *pp;
+ struct path *pp;
unsigned int i, j;
+ if (!mpp->pg)
+ return;
+
vector_foreach_slot (mpp->pg, pgp, i){
vector_foreach_slot (pgp->paths, pp, j){
- if (pp->state <= PATH_UNCHECKED)
+ if (pp->state == PATH_UNCHECKED ||
+ pp->state == PATH_WILD)
continue;
if ((pp->dmstate == PSTATE_FAILED ||
pp->dmstate == PSTATE_UNDEF) &&
unsigned int i;
struct multipath *mpp;
- vector_foreach_slot (mpvec, mpp, i)
+ vector_foreach_slot (mpvec, mpp, i)
sync_map_state(mpp);
}
* clear references to this map before flushing so we can ignore
* the spurious uevent we may generate with the dm_flush_map call below
*/
- if (dm_flush_map(mpp->alias, DEFAULT_TARGET)) {
+ if (dm_flush_map(mpp->alias)) {
/*
* May not really be an error -- if the map was already flushed
* from the device mapper by dmsetup(8) for instance.
}
else {
dm_lib_release();
- condlog(3, "%s: devmap removed", mpp->alias);
+ condlog(2, "%s: devmap removed", mpp->alias);
}
orphan_paths(vecs->pathvec, mpp);
- remove_map(mpp, vecs, stop_waiter_thread, 1);
+ remove_map_and_stop_waiter(mpp, vecs, 1);
return 0;
}
return 1;
alias = dm_mapname(major, minor);
-
+
if (!alias)
return 1;
-
+
map_present = dm_map_present(alias);
- if (map_present && dm_type(alias, DEFAULT_TARGET) <= 0) {
+ if (map_present && dm_type(alias, TGT_MPATH) <= 0) {
condlog(4, "%s: not a multipath map", alias);
return 0;
}
mpp = find_mp_by_alias(vecs->mpvec, alias);
if (mpp) {
- /*
+ /*
* Not really an error -- we generate our own uevent
* if we create a multipath mapped device as a result
* of uev_add_path
/*
* now we can register the map
*/
- if (map_present && (mpp = add_map_without_path(vecs, minor, alias,
- start_waiter_thread))) {
+ if (map_present && (mpp = add_map_without_path(vecs, minor, alias))) {
sync_map_state(mpp);
- condlog(3, "%s: devmap %s added", alias, dev->kernel);
+ condlog(2, "%s: devmap %s added", alias, dev->kernel);
return 0;
}
refwwid = get_refwwid(dev->kernel, DEV_DEVMAP, vecs->pathvec);
if (refwwid) {
- r = coalesce_paths(vecs, NULL, refwwid);
+ r = coalesce_paths(vecs, NULL, refwwid, 0);
dm_lib_release();
}
-
+
if (!r)
- condlog(3, "%s: devmap %s added", alias, dev->kernel);
+ condlog(2, "%s: devmap %s added", alias, dev->kernel);
else
condlog(0, "%s: uev_add_map %s failed", alias, dev->kernel);
mpp = find_mp_by_str(vecs->mpvec, devname);
if (!mpp) {
- condlog(3, "%s: devmap not registered, can't remove",
+ condlog(2, "%s: devmap not registered, can't remove",
devname);
return 0;
}
return 0;
}
-
+
static int
uev_add_path (struct sysfs_device * dev, struct vectors * vecs)
{
condlog(0, "%s: failed to get path uid", devname);
return 1; /* leave path added to pathvec */
}
- if (filter_path(conf, pp)){
+ if (filter_path(conf, pp) > 0){
int i = find_slot(vecs->pathvec, (void *)pp);
if (i != -1)
vector_del_slot(vecs->pathvec, i);
free_path(pp);
return 2;
- }
+ }
mpp = pp->mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
rescan:
if (mpp) {
condlog(0, "%s: failed in domap for addition of new "
"path %s", mpp->alias, devname);
/*
- * deal with asynchronous uevents :((
- */
+ * deal with asynchronous uevents :((
+ */
if (mpp->action == ACT_RELOAD) {
condlog(0, "%s: uev_add_path sleep", mpp->alias);
sleep(1);
start_waiter_thread(mpp, vecs))
goto out;
- condlog(3, "%s path added to devmap %s", devname, mpp->alias);
+ condlog(2, "%s path added to devmap %s", devname, mpp->alias);
return 0;
out:
- remove_map(mpp, vecs, NULL, 1);
+ remove_map(mpp, vecs, 1);
return 1;
}
static int
uev_remove_path (struct sysfs_device * dev, struct vectors * vecs)
{
+ int retval;
+
condlog(2, "%s: remove path (uevent)", dev->kernel);
- return ev_remove_path(dev->kernel, vecs);
+ retval = ev_remove_path(dev->kernel, vecs);
+ if (!retval)
+ sysfs_device_put(dev);
+
+ return retval;
}
int
{
struct multipath * mpp;
struct path * pp;
- int i;
- int rm_path = 1;
+ int i, retval = 0;
pp = find_path_by_dev(vecs->pathvec, devname);
}
/*
- * avoid referring to the map of an orphanned path
+ * avoid referring to the map of an orphaned path
*/
if ((mpp = pp->mpp)) {
+ /*
+ * transform the mp->pg vector of vectors of paths
+ * into a mp->params string to feed the device-mapper
+ */
+ if (update_mpp_paths(mpp, vecs->pathvec)) {
+ condlog(0, "%s: failed to update paths",
+ mpp->alias);
+ goto out;
+ }
+ if ((i = find_slot(mpp->paths, (void *)pp)) != -1)
+ vector_del_slot(mpp->paths, i);
/*
* remove the map IFF removing the last path
*/
- if (pathcount(mpp, PATH_WILD) > 1) {
- vector rpvec = vector_alloc();
+ if (VECTOR_SIZE(mpp->paths) == 0) {
+ char alias[WWID_SIZE];
/*
- * transform the mp->pg vector of vectors of paths
- * into a mp->params string to feed the device-mapper
- */
- update_mpp_paths(mpp, vecs->pathvec);
- if ((i = find_slot(mpp->paths, (void *)pp)) != -1)
- vector_del_slot(mpp->paths, i);
-
- if (VECTOR_SIZE(mpp->paths) == 0) {
- char alias[WWID_SIZE];
-
- /*
- * flush_map will fail if the device is open
- */
- strncpy(alias, mpp->alias, WWID_SIZE);
- if (flush_map(mpp, vecs))
- rm_path = 0;
- else
- condlog(3, "%s: removed map after removing"
- " multiple paths", alias);
- }
- else {
- if (setup_map(mpp)) {
- condlog(0, "%s: failed to setup map for"
- " removal of path %s", mpp->alias, devname);
- free_pathvec(rpvec, KEEP_PATHS);
- goto out;
- }
- /*
- * reload the map
- */
- mpp->action = ACT_RELOAD;
- if (domap(mpp) <= 0) {
- condlog(0, "%s: failed in domap for "
- "removal of path %s",
- mpp->alias, devname);
- /*
- * Delete path from pathvec so that
- * update_mpp_paths wont find it later
- * when/if another path is removed.
- */
- if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
- vector_del_slot(vecs->pathvec, i);
- free_path(pp);
- return 1;
- }
- /*
- * update our state from kernel
- */
- if (setup_multipath(vecs, mpp)) {
- free_pathvec(rpvec, KEEP_PATHS);
- goto out;
- }
- sync_map_state(mpp);
-
- condlog(3, "%s: path removed from map %s",
- devname, mpp->alias);
+ * flush_map will fail if the device is open
+ */
+ strncpy(alias, mpp->alias, WWID_SIZE);
+ if (!flush_map(mpp, vecs)) {
+ condlog(2, "%s: removed map after"
+ " removing all paths",
+ alias);
+ free_path(pp);
+ return 0;
}
- free_pathvec(rpvec, KEEP_PATHS);
+ /*
+ * Not an error, continue
+ */
}
- else {
- char alias[WWID_SIZE];
+ if (setup_map(mpp)) {
+ condlog(0, "%s: failed to setup map for"
+ " removal of path %s", mpp->alias,
+ devname);
+ goto out;
+ }
+ /*
+ * reload the map
+ */
+ mpp->action = ACT_RELOAD;
+ if (domap(mpp) <= 0) {
+ condlog(0, "%s: failed in domap for "
+ "removal of path %s",
+ mpp->alias, devname);
+ retval = 1;
+ } else {
/*
- * flush_map will fail if the device is open
+ * update our state from kernel
*/
- strncpy(alias, mpp->alias, WWID_SIZE);
- if (flush_map(mpp, vecs))
- rm_path = 0;
- else
- condlog(3, "%s: removed map", alias);
+ if (setup_multipath(vecs, mpp)) {
+ goto out;
+ }
+ sync_map_state(mpp);
+
+ condlog(2, "%s: path removed from map %s",
+ devname, mpp->alias);
}
}
- if (rm_path) {
- if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
- vector_del_slot(vecs->pathvec, i);
- free_path(pp);
- }
+ if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
+ vector_del_slot(vecs->pathvec, i);
- return 0;
+ free_path(pp);
+
+ return retval;
out:
- remove_map(mpp, vecs, stop_waiter_thread, 1);
+ remove_map_and_stop_waiter(mpp, vecs, 1);
return 1;
}
struct multipath * mpp;
unsigned int i;
- if (dm_get_maps(vecs->mpvec, "multipath"))
+ if (dm_get_maps(vecs->mpvec))
return 1;
vector_foreach_slot (vecs->mpvec, mpp, i)
{
struct vectors * vecs;
int r;
-
+
*reply = NULL;
*len = 0;
vecs = (struct vectors *)trigger_data;
return 0;
}
-int
+int
uev_trigger (struct uevent * uev, void * trigger_data)
{
int r = 0;
return 0;
sysdev = sysfs_device_get(uev->devpath);
+ if(!sysdev)
+ return 0;
+
lock(vecs->lock);
/*
}
goto out;
}
-
+
/*
* path add/remove event
*/
if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
- sysdev->kernel) > 0)
+ sysdev->kernel) > 0)
goto out;
if (!strncmp(uev->action, "add", 3)) {
{
if (uevent_listen(&uev_trigger, ap))
fprintf(stderr, "error starting uevent listener");
-
+
return NULL;
}
return NULL;
set_handler_callback(LIST+PATHS, cli_list_paths);
+ set_handler_callback(LIST+PATHS+FMT, cli_list_paths_fmt);
set_handler_callback(LIST+MAPS, cli_list_maps);
+ set_handler_callback(LIST+STATUS, cli_list_status);
set_handler_callback(LIST+MAPS+STATUS, cli_list_maps_status);
set_handler_callback(LIST+MAPS+STATS, cli_list_maps_stats);
set_handler_callback(LIST+MAPS+TOPOLOGY, cli_list_maps_topology);
set_handler_callback(LIST+CONFIG, cli_list_config);
set_handler_callback(LIST+BLACKLIST, cli_list_blacklist);
set_handler_callback(LIST+DEVICES, cli_list_devices);
+ set_handler_callback(LIST+WILDCARDS, cli_list_wildcards);
set_handler_callback(ADD+PATH, cli_add_path);
set_handler_callback(DEL+PATH, cli_del_path);
set_handler_callback(ADD+MAP, cli_add_map);
*
* we can safely return here, because upon map reload, all
* PG will be enabled.
- */
+ */
if (!pp->mpp->pg || !pp->pgindex)
return;
pgp = VECTOR_SLOT(pp->mpp->pg, pp->pgindex - 1);
-
+
if (pgp->status == PGSTATE_DISABLED) {
condlog(2, "%s: enable group #%i", pp->mpp->alias, pp->pgindex);
dm_enablegroup(pp->mpp->alias, pp->pgindex);
vector_foreach_slot (vecs->mpvec, mpp, i) {
if (mpp && mpp->alias && !dm_map_present(mpp->alias)) {
condlog(2, "%s: remove dead map", mpp->alias);
- remove_map(mpp, vecs, stop_waiter_thread, 1);
+ remove_map_and_stop_waiter(mpp, vecs, 1);
i--;
}
}
}
}
+void
+check_path (struct vectors * vecs, struct path * pp)
+{
+ int newstate;
+
+ if (!pp->mpp)
+ return;
+
+ if (pp->tick && --pp->tick)
+ return; /* don't check this path yet */
+
+ /*
+ * provision a next check soonest,
+ * in case we exit abnormaly from here
+ */
+ pp->tick = conf->checkint;
+
+ if (!checker_selected(&pp->checker)) {
+ pathinfo(pp, conf->hwtable, DI_SYSFS);
+ select_checker(pp);
+ }
+ if (!checker_selected(&pp->checker)) {
+ condlog(0, "%s: checker is not set", pp->dev);
+ return;
+ }
+ /*
+ * Set checker in async mode.
+ * Honored only by checker implementing the said mode.
+ */
+ checker_set_async(&pp->checker);
+
+ newstate = checker_check(&pp->checker);
+
+ if (newstate < 0) {
+ condlog(2, "%s: unusable path", pp->dev);
+ pathinfo(pp, conf->hwtable, 0);
+ return;
+ }
+ /*
+ * Async IO in flight. Keep the previous path state
+ * and reschedule as soon as possible
+ */
+ if (newstate == PATH_PENDING) {
+ pp->tick = 1;
+ return;
+ }
+ if (newstate != pp->state) {
+ int oldstate = pp->state;
+ pp->state = newstate;
+ LOG_MSG(1, checker_message(&pp->checker));
+
+ /*
+ * upon state change, reset the checkint
+ * to the shortest delay
+ */
+ pp->checkint = conf->checkint;
+
+ if (newstate == PATH_DOWN || newstate == PATH_SHAKY ||
+ update_multipath_strings(pp->mpp, vecs->pathvec)) {
+ /*
+ * proactively fail path in the DM
+ */
+ if (oldstate == PATH_UP ||
+ oldstate == PATH_GHOST)
+ fail_path(pp, 1);
+ else
+ fail_path(pp, 0);
+
+ /*
+ * cancel scheduled failback
+ */
+ pp->mpp->failback_tick = 0;
+
+ pp->mpp->stat_path_failures++;
+ return;
+ }
+
+ /*
+ * reinstate this path
+ */
+ if (oldstate != PATH_UP &&
+ oldstate != PATH_GHOST)
+ reinstate_path(pp, 1);
+ else
+ reinstate_path(pp, 0);
+
+ /*
+ * schedule [defered] failback
+ */
+ if (pp->mpp->pgfailback > 0)
+ pp->mpp->failback_tick =
+ pp->mpp->pgfailback + 1;
+ else if (pp->mpp->pgfailback == -FAILBACK_IMMEDIATE &&
+ need_switch_pathgroup(pp->mpp, 1))
+ switch_pathgroup(pp->mpp);
+
+ /*
+ * if at least one path is up in a group, and
+ * the group is disabled, re-enable it
+ */
+ if (newstate == PATH_UP)
+ enable_group(pp);
+ }
+ else if (newstate == PATH_UP || newstate == PATH_GHOST) {
+ LOG_MSG(4, checker_message(&pp->checker));
+ /*
+ * double the next check delay.
+ * max at conf->max_checkint
+ */
+ if (pp->checkint < (conf->max_checkint / 2))
+ pp->checkint = 2 * pp->checkint;
+ else
+ pp->checkint = conf->max_checkint;
+
+ pp->tick = pp->checkint;
+ condlog(4, "%s: delay next check %is",
+ pp->dev_t, pp->tick);
+ }
+ else if (newstate == PATH_DOWN)
+ LOG_MSG(2, checker_message(&pp->checker));
+
+ pp->state = newstate;
+
+ /*
+ * path prio refreshing
+ */
+ condlog(4, "path prio refresh");
+ pathinfo(pp, conf->hwtable, DI_PRIO);
+
+ /*
+ * pathgroup failback policy
+ */
+ if (need_switch_pathgroup(pp->mpp, 0)) {
+ if (pp->mpp->pgfailback > 0 &&
+ pp->mpp->failback_tick <= 0)
+ pp->mpp->failback_tick =
+ pp->mpp->pgfailback + 1;
+ else if (pp->mpp->pgfailback ==
+ -FAILBACK_IMMEDIATE)
+ switch_pathgroup(pp->mpp);
+ }
+}
+
static void *
checkerloop (void *ap)
{
struct vectors *vecs;
struct path *pp;
int count = 0;
- int newstate;
unsigned int i;
mlockall(MCL_CURRENT | MCL_FUTURE);
lock(vecs->lock);
condlog(4, "tick");
- vector_foreach_slot (vecs->pathvec, pp, i) {
- if (!pp->mpp)
- continue;
-
- if (pp->tick && --pp->tick)
- continue; /* don't check this path yet */
-
- /*
- * provision a next check soonest,
- * in case we exit abnormaly from here
- */
- pp->tick = conf->checkint;
-
- if (!checker_selected(&pp->checker)) {
- pathinfo(pp, conf->hwtable, DI_SYSFS);
- select_checker(pp);
- }
-
- if (!checker_selected(&pp->checker)) {
- condlog(0, "%s: checker is not set", pp->dev);
- continue;
- }
- newstate = checker_check(&pp->checker);
-
- if (newstate < 0) {
- condlog(2, "%s: unusable path", pp->dev);
- pathinfo(pp, conf->hwtable, 0);
- continue;
- }
-
- if (newstate != pp->state) {
- int oldstate = pp->state;
- pp->state = newstate;
- LOG_MSG(1, checker_message(&pp->checker));
-
- /*
- * upon state change, reset the checkint
- * to the shortest delay
- */
- pp->checkint = conf->checkint;
-
- if (newstate == PATH_DOWN ||
- newstate == PATH_SHAKY ||
- update_multipath_strings(pp->mpp,
- vecs->pathvec)) {
- /*
- * proactively fail path in the DM
- */
- if (oldstate == PATH_UP ||
- oldstate == PATH_GHOST)
- fail_path(pp, 1);
- else
- fail_path(pp, 0);
-
- /*
- * cancel scheduled failback
- */
- pp->mpp->failback_tick = 0;
-
- pp->mpp->stat_path_failures++;
- continue;
- }
-
- /*
- * reinstate this path
- */
- if (oldstate != PATH_UP &&
- oldstate != PATH_GHOST)
- reinstate_path(pp, 1);
- else
- reinstate_path(pp, 0);
-
- /*
- * schedule [defered] failback
- */
- if (pp->mpp->pgfailback > 0)
- pp->mpp->failback_tick =
- pp->mpp->pgfailback + 1;
- else if (pp->mpp->pgfailback == -FAILBACK_IMMEDIATE &&
- need_switch_pathgroup(pp->mpp, 1))
- switch_pathgroup(pp->mpp);
-
- /*
- * if at least one path is up in a group, and
- * the group is disabled, re-enable it
- */
- if (newstate == PATH_UP)
- enable_group(pp);
- }
- else if (newstate == PATH_UP || newstate == PATH_GHOST) {
- LOG_MSG(4, checker_message(&pp->checker));
- /*
- * double the next check delay.
- * max at conf->max_checkint
- */
- if (pp->checkint < (conf->max_checkint / 2))
- pp->checkint = 2 * pp->checkint;
- else
- pp->checkint = conf->max_checkint;
-
- pp->tick = pp->checkint;
- condlog(4, "%s: delay next check %is",
- pp->dev_t, pp->tick);
- }
- else if (newstate == PATH_DOWN)
- LOG_MSG(2, checker_message(&pp->checker));
-
- pp->state = newstate;
-
- /*
- * path prio refreshing
- */
- condlog(4, "path prio refresh");
- pathinfo(pp, conf->hwtable, DI_PRIO);
-
- if (need_switch_pathgroup(pp->mpp, 0)) {
- if (pp->mpp->pgfailback > 0 &&
- pp->mpp->failback_tick <= 0)
- pp->mpp->failback_tick =
- pp->mpp->pgfailback + 1;
- else if (pp->mpp->pgfailback ==
- -FAILBACK_IMMEDIATE)
- switch_pathgroup(pp->mpp);
+ if (vecs->pathvec) {
+ vector_foreach_slot (vecs->pathvec, pp, i) {
+ check_path(vecs, pp);
}
}
- defered_failback_tick(vecs->mpvec);
- retry_count_tick(vecs->mpvec);
-
+ if (vecs->mpvec) {
+ defered_failback_tick(vecs->mpvec);
+ retry_count_tick(vecs->mpvec);
+ }
if (count)
count--;
else {
mpvec_garbage_collector(vecs);
count = MAPGCINT;
}
-
+
lock_cleanup_pop(vecs->lock);
sleep(1);
}
if (!vecs->pathvec && !(vecs->pathvec = vector_alloc()))
return 1;
-
+
if (!vecs->mpvec && !(vecs->mpvec = vector_alloc()))
return 1;
-
+
if (!(mpvec = vector_alloc()))
return 1;
path_discovery(vecs->pathvec, conf, DI_ALL);
vector_foreach_slot (vecs->pathvec, pp, i){
- if (filter_path(conf, pp)){
+ if (filter_path(conf, pp) > 0){
vector_del_slot(vecs->pathvec, i);
free_path(pp);
i--;
- }
+ }
else
pp->checkint = conf->checkint;
}
/*
* create new set of maps & push changed ones into dm
*/
- if (coalesce_paths(vecs, mpvec, NULL))
+ if (coalesce_paths(vecs, mpvec, NULL, 0))
return 1;
/*
/*
* purge dm of old maps
*/
- remove_maps(vecs, NULL);
+ remove_maps(vecs);
/*
* save new set of maps formed by considering current path state
* free old map and path vectors ... they use old conf state
*/
if (VECTOR_SIZE(vecs->mpvec))
- remove_maps(vecs, stop_waiter_thread);
+ remove_maps_and_stop_waiters(vecs);
if (VECTOR_SIZE(vecs->pathvec))
free_pathvec(vecs->pathvec, FREE_PATHS);
if (!vecs)
return NULL;
- vecs->lock =
+ vecs->lock =
(pthread_mutex_t *)MALLOC(sizeof(pthread_mutex_t));
if (!vecs->lock)
static void
setscheduler (void)
{
- int res;
+ int res;
static struct sched_param sched_param = {
.sched_priority = 99
};
- res = sched_setscheduler (0, SCHED_RR, &sched_param);
+ res = sched_setscheduler (0, SCHED_RR, &sched_param);
- if (res == -1)
- condlog(LOG_WARNING, "Could not set SCHED_RR at priority 99");
+ if (res == -1)
+ condlog(LOG_WARNING, "Could not set SCHED_RR at priority 99");
return;
}
fprintf(fp, "%i", val);
fclose(fp);
}
-
+
static int
child (void * param)
{
if (load_config(DEFAULT_CONFIGFILE))
exit(1);
+ if (init_checkers()) {
+ condlog(0, "failed to initialize checkers");
+ exit(1);
+ }
+ if (init_prio()) {
+ condlog(0, "failed to initialize prioritizers");
+ exit(1);
+ }
+
setlogmask(LOG_UPTO(conf->verbosity + 3));
/*
conf->max_checkint = MAX_CHECKINT(conf->checkint);
}
+ if (conf->max_fds) {
+ struct rlimit fd_limit;
+ if (conf->max_fds > 0) {
+ fd_limit.rlim_cur = conf->max_fds;
+ fd_limit.rlim_max = conf->max_fds;
+ }
+ else {
+ fd_limit.rlim_cur = RLIM_INFINITY;
+ fd_limit.rlim_max = RLIM_INFINITY;
+ }
+ if (setrlimit(RLIMIT_NOFILE, &fd_limit) < 0)
+ condlog(0, "can't set open fds limit to %d : %s\n",
+ conf->max_fds, strerror(errno));
+ }
+
if (pidfile_create(DEFAULT_PIDFILE, getpid())) {
if (logsink)
log_thread_stop();
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 64 * 1024);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
+
pthread_create(&check_thr, &attr, checkerloop, vecs);
pthread_create(&uevent_thr, &attr, ueventloop, vecs);
pthread_create(&uxlsnr_thr, &attr, uxlsnrloop, vecs);
* exit path
*/
lock(vecs->lock);
- remove_maps(vecs, stop_waiter_thread);
+ remove_maps_and_stop_waiters(vecs);
free_pathvec(vecs->pathvec, FREE_PATHS);
pthread_cancel(check_thr);
vecs->lock = NULL;
FREE(vecs);
vecs = NULL;
- free_config(conf);
- conf = NULL;
condlog(2, "--------shut down-------");
-
+
if (logsink)
log_thread_stop();
dm_lib_release();
dm_lib_exit();
+ /*
+ * Freeing config must be done after condlog() and dm_lib_exit(),
+ * because logging functions like dlog() and dm_write_log()
+ * reference the config.
+ */
+ free_config(conf);
+ conf = NULL;
+
#ifdef _DEBUG_
dbg_free_final(NULL);
#endif
extern int optind;
int arg;
int err;
-
+
logsink = 1;
dm_init();
err = 0;
else
err = daemonize();
-
+
if (err < 0)
/* error */
exit(1);