static void pol_new(struct dev_policy **pol, char *name, const char *val,
const char *metadata)
{
- struct dev_policy *n = malloc(sizeof(*n));
+ struct dev_policy *n = xmalloc(sizeof(*n));
const char *real_metadata = NULL;
int i;
if (!real_metadata) {
static const char *prev = NULL;
if (prev != metadata) {
- fprintf(stderr, Name ": metadata=%s unrecognised - ignoring rule\n",
+ pr_err("metadata=%s unrecognised - ignoring rule\n",
metadata);
prev = metadata;
}
if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
continue;
closedir(by_path);
- return strdup(ent->d_name);
+ return xstrdup(ent->d_name);
}
closedir(by_path);
/* A NULL path isn't really acceptable - use the devname.. */
nm[rv] = 0;
dname = strrchr(nm, '/');
if (dname)
- return strdup(dname + 1);
+ return xstrdup(dname + 1);
}
- return strdup("unknown");
+ return xstrdup("unknown");
}
char type_part[] = "part";
if (strncmp(w, name, len) != 0 ||
w[len] != '=')
return 0;
- r = malloc(sizeof(*r));
+ r = xmalloc(sizeof(*r));
r->next = *rp;
r->name = name;
- r->value = strdup(w+len+1);
+ r->value = xstrdup(w+len+1);
r->dups = NULL;
*rp = r;
return 1;
if (config_rules_end == NULL)
config_rules_end = &config_rules;
- pr = malloc(sizeof(*pr));
+ pr = xmalloc(sizeof(*pr));
pr->type = type;
pr->rule = NULL;
for (w = dl_next(line); w != line ; w = dl_next(w)) {
! try_rule(w, pol_act, &pr->rule) &&
! try_rule(w, pol_domain, &pr->rule) &&
! try_rule(w, pol_auto, &pr->rule))
- fprintf(stderr, Name ": policy rule %s unrecognised and ignored\n",
+ pr_err("policy rule %s unrecognised and ignored\n",
w);
}
pr->next = config_rules;
struct pol_rule *pr;
char *name, *val;
- pr = malloc(sizeof(*pr));
+ pr = xmalloc(sizeof(*pr));
pr->type = type;
pr->rule = NULL;
struct rule *r;
val = va_arg(ap, char*);
- r = malloc(sizeof(*r));
+ r = xmalloc(sizeof(*r));
r->next = pr->rule;
r->name = name;
- r->value = strdup(val);
+ r->value = xstrdup(val);
r->dups = NULL;
pr->rule = r;
}
pr->next = config_rules;
config_rules = pr;
+ va_end(ap);
}
void policy_free(void)
dom = *domp;
}
if (dom == NULL || strcmp(dom->dom, domain) != 0) {
- dom = malloc(sizeof(*dom));
+ dom = xmalloc(sizeof(*dom));
dom->next = *domp;
dom->dom = domain;
*domp = dom;
FILE *f = NULL;
if (mkdir(FAILED_SLOTS_DIR, S_IRWXU) < 0 && errno != EEXIST) {
- fprintf(stderr, Name ": can't create file to save path "
+ pr_err("can't create file to save path "
"to old disk: %s\n", strerror(errno));
return;
}
snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path);
f = fopen(path, "w");
if (!f) {
- fprintf(stderr, Name ": can't create file to"
+ pr_err("can't create file to"
" save path to old disk: %s\n",
strerror(errno));
return;
array->metadata,
array->uuid[0], array->uuid[1],
array->uuid[2], array->uuid[3]) <= 0)
- fprintf(stderr, Name ": Failed to write to "
- "<id_path> cookie\n");
+ pr_err("Failed to write to "
+ "<id_path> cookie\n");
fclose(f);
}
char udev_rule_file[PATH_MAX];
if (rule_name) {
- strcpy(udev_rule_file, rule_name);
+ strncpy(udev_rule_file, rule_name, sizeof(udev_rule_file) - 6);
+ udev_rule_file[sizeof(udev_rule_file) - 6] = '\0';
strcat(udev_rule_file, ".temp");
fd = creat(udev_rule_file,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);