<commit_before>#include <string.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libdevmapper.h>
#include <signal.h>
#include <wait.h>
#include <sched.h>
#include <errno.h>
#include <sys/mount.h>
#include <sys/mman.h>

/*
 * libsysfs
 */
#include <sysfs/libsysfs.h>
#include <sysfs/dlist.h>

/*
 * libcheckers
 */
#include <checkers.h>
#include <path_state.h>

/*
 * libmultipath
 */
#include <parser.h>
#include <vector.h>
#include <memory.h>
#include <config.h>
#include <callout.h>
#include <util.h>
#include <blacklist.h>
#include <hwtable.h>
#include <defaults.h>
#include <structs.h>
#include <dmparser.h>
#include <devmapper.h>
#include <dict.h>
#include <discovery.h>
#include <debug.h>
#include <propsel.h>
#include <uevent.h>

#include "main.h"
#include "copy.h"
#include "clone_platform.h"
#include "pidfile.h"

#define FILE_NAME_SIZE 256
#define CMDSIZE 160

#define CALLOUT_DIR "/var/cache/multipathd"

#define LOG_MSG(a,b) \
	if (strlen(a)) { \
		log_safe(LOG_WARNING, "%s: %s", b, a); \
		memset(a, 0, MAX_CHECKER_MSG_SIZE); \
	}

#ifdef LCKDBG
#define lock(a) \
	fprintf(stderr, "%s:%s(%i) lock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
	pthread_mutex_lock(a)
#define unlock(a) \
	fprintf(stderr, "%s:%s(%i) unlock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
	pthread_mutex_unlock(a)
#else
#define lock(a) pthread_mutex_lock(a)
#define unlock(a) pthread_mutex_unlock(a)
#endif

/*
 * global vars
 */
int pending_event = 0;
pthread_mutex_t *event_lock;
pthread_cond_t *event;

/*
 * structs
 */
struct paths {
	pthread_mutex_t *lock;
	vector pathvec;
};

struct event_thread {
	pthread_t *thread;
	pthread_mutex_t *waiter_lock;
	int lease;
	int event_nr;
	char mapname[WWID_SIZE];
	struct paths *allpaths;
};

int 
uev_trigger (struct uevent * uev, void * trigger_data)
{
	int r = 0;
	int i;
	char devname[32];
	struct path * pp;
	struct paths * allpaths;

	allpaths = (struct paths *)trigger_data;

	if (strncmp(uev->devpath, "/block", 6))
		goto out;

	basename(uev->devpath, devname);
	lock(allpaths->lock);
	pp = find_path_by_dev(allpaths->pathvec, devname);

	r = 1;

	if (pp && !strncmp(uev->action, "remove", 6)) {
		condlog(2, "remove %s path checker", devname);
		i = find_slot(allpaths->pathvec, (void *)pp);
		vector_del_slot(allpaths->pathvec, i);
		free_path(pp);
	}
	if (!pp && !strncmp(uev->action, "add", 3)) {
		condlog(2, "add %s path checker", devname);
		store_pathinfo(allpaths->pathvec, conf->hwtable, devname);
	}
	unlock(allpaths->lock);

	r = 0;
out:
	FREE(uev);
	return r;
}

static void *
ueventloop (void * ap)
{
	uevent_listen(&uev_trigger, ap);

	return NULL;<commit_msg>[multipathd] Apply blacklist to uevents too. Indeed, we don't want too add a checker on /dev/dm-0 when this devmap comes up.<commit_after>#include <string.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <linux/unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libdevmapper.h>
#include <signal.h>
#include <wait.h>
#include <sched.h>
#include <errno.h>
#include <sys/mount.h>
#include <sys/mman.h>

/*
 * libsysfs
 */
#include <sysfs/libsysfs.h>
#include <sysfs/dlist.h>

/*
 * libcheckers
 */
#include <checkers.h>
#include <path_state.h>

/*
 * libmultipath
 */
#include <parser.h>
#include <vector.h>
#include <memory.h>
#include <config.h>
#include <callout.h>
#include <util.h>
#include <blacklist.h>
#include <hwtable.h>
#include <defaults.h>
#include <structs.h>
#include <dmparser.h>
#include <devmapper.h>
#include <dict.h>
#include <discovery.h>
#include <debug.h>
#include <propsel.h>
#include <uevent.h>

#include "main.h"
#include "copy.h"
#include "clone_platform.h"
#include "pidfile.h"

#define FILE_NAME_SIZE 256
#define CMDSIZE 160

#define CALLOUT_DIR "/var/cache/multipathd"

#define LOG_MSG(a,b) \
	if (strlen(a)) { \
		log_safe(LOG_WARNING, "%s: %s", b, a); \
		memset(a, 0, MAX_CHECKER_MSG_SIZE); \
	}

#ifdef LCKDBG
#define lock(a) \
	fprintf(stderr, "%s:%s(%i) lock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
	pthread_mutex_lock(a)
#define unlock(a) \
	fprintf(stderr, "%s:%s(%i) unlock %p\n", __FILE__, __FUNCTION__, __LINE__, a); \
	pthread_mutex_unlock(a)
#else
#define lock(a) pthread_mutex_lock(a)
#define unlock(a) pthread_mutex_unlock(a)
#endif

/*
 * global vars
 */
int pending_event = 0;
pthread_mutex_t *event_lock;
pthread_cond_t *event;

/*
 * structs
 */
struct paths {
	pthread_mutex_t *lock;
	vector pathvec;
};

struct event_thread {
	pthread_t *thread;
	pthread_mutex_t *waiter_lock;
	int lease;
	int event_nr;
	char mapname[WWID_SIZE];
	struct paths *allpaths;
};

int 
uev_trigger (struct uevent * uev, void * trigger_data)
{
	int r = 0;
	int i;
	char devname[32];
	struct path * pp;
	struct paths * allpaths;

	allpaths = (struct paths *)trigger_data;

	if (strncmp(uev->devpath, "/block", 6))
		goto out;

	basename(uev->devpath, devname);

	if (blacklist(conf->blist, devname))
		goto out;

	lock(allpaths->lock);
	pp = find_path_by_dev(allpaths->pathvec, devname);

	r = 1;

	if (pp && !strncmp(uev->action, "remove", 6)) {
		condlog(2, "remove %s path checker", devname);
		i = find_slot(allpaths->pathvec, (void *)pp);
		vector_del_slot(allpaths->pathvec, i);
		free_path(pp);
	}
	if (!pp && !strncmp(uev->action, "add", 3)) {
		condlog(2, "add %s path checker", devname);
		store_pathinfo(allpaths->pathvec, conf->hwtable, devname);
	}
	unlock(allpaths->lock);

	r = 0;
out:
	FREE(uev);
	return r;
}

static void *
ueventloop (void * ap)
{
	uevent_listen(&uev_trigger, ap);

	return NULL;
{'fraction_non_alphanumeric': 0.1713329811586547, 'fraction_numerical': 0.0065152315548512064, 'mean_word_length': 4.790010193679919, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 100, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462124', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2378, 'n_words': 534}