Skip to content

Commit

Permalink
Merge pull request #68 from wenningerk/fail_earlier_on_empty_diskname
Browse files Browse the repository at this point in the history
Refactor: fail earlier on empty diskname
  • Loading branch information
wenningerk authored Feb 1, 2019
2 parents 1829c40 + 8301cba commit f949aa8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
51 changes: 32 additions & 19 deletions src/sbd-inquisitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,36 @@ void recruit_servant(const char *devname, pid_t pid)
struct servants_list_item *newbie;

if (lookup_servant_by_dev(devname)) {
cl_log(LOG_DEBUG, "Servant %s already exists", devname);
return;
cl_log(LOG_DEBUG, "Servant %s already exists", devname);
return;
}

newbie = malloc(sizeof(*newbie));
if (!newbie) {
fprintf(stderr, "malloc failed in recruit_servant.\n");
exit(1);
if (newbie) {
memset(newbie, 0, sizeof(*newbie));
newbie->devname = strdup(devname);
newbie->pid = pid;
newbie->first_start = 1;
}
if (!newbie || !newbie->devname) {
fprintf(stderr, "heap allocation failed in recruit_servant.\n");
exit(1);
}

/* some sanity-check on our newbie */
if (sbd_is_disk(newbie)) {
cl_log(LOG_INFO, "Monitoring %s", devname);
disk_count++;
} else if (sbd_is_pcmk(newbie) || sbd_is_cluster(newbie)) {
/* alive just after pcmk and cluster servants have shown up */
newbie->outdated = 1;
} else {
/* toss our newbie */
cl_log(LOG_ERR, "Refusing to recruit unrecognized servant %s", devname);
free((void *) newbie->devname);
free(newbie);
return;
}
memset(newbie, 0, sizeof(*newbie));
newbie->devname = strdup(devname);
newbie->pid = pid;
newbie->first_start = 1;

if (!s) {
servants_leader = newbie;
Expand All @@ -65,12 +82,6 @@ void recruit_servant(const char *devname, pid_t pid)
}

servant_count++;
if(sbd_is_disk(newbie)) {
cl_log(LOG_INFO, "Monitoring %s", devname);
disk_count++;
} else {
newbie->outdated = 1;
}
}

int assign_servant(const char* devname, functionp_t functionp, int mode, const void* argp)
Expand Down Expand Up @@ -148,7 +159,7 @@ void servant_start(struct servants_list_item *s)
if (sbd_is_disk(s)) {
#if SUPPORT_SHARED_DISK
DBGLOG(LOG_INFO, "Starting servant for device %s", s->devname);
s->pid = assign_servant(s->devname, servant, start_mode, s);
s->pid = assign_servant(s->devname, servant_md, start_mode, s);
#else
cl_log(LOG_ERR, "Shared disk functionality not supported");
return;
Expand Down Expand Up @@ -785,12 +796,14 @@ parse_device_line(const char *line)

if (lpc > last) {
entry = calloc(1, 1 + lpc - last);
if (!entry) {
fprintf(stderr, "heap allocation failed parsing device-line.\n");
exit(1);
}
rc = sscanf(line + last, "%[^;]", entry);
}

if (entry == NULL) {
/* Skip */
} else if (rc != 1) {
if (rc != 1) {
cl_log(LOG_WARNING, "Could not parse (%d %d): %s", last, lpc, line + last);
} else {
cl_log(LOG_DEBUG, "Adding '%s'", entry);
Expand Down
7 changes: 1 addition & 6 deletions src/sbd-md.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ static int servant_check_timeout_inconsistent(struct sector_header_s *hdr)
return 0;
}

int servant(const char *diskname, int mode, const void* argp)
int servant_md(const char *diskname, int mode, const void* argp)
{
struct sector_mbox_s *s_mbox = NULL;
struct sector_node_s *s_node = NULL;
Expand All @@ -1046,11 +1046,6 @@ int servant(const char *diskname, int mode, const void* argp)
char uuid[37];
const struct servants_list_item *s = argp;

if (!diskname) {
cl_log(LOG_ERR, "Empty disk name %s.", diskname);
return -1;
}

cl_log(LOG_INFO, "Servant starting for device %s", diskname);

/* Block most of the signals */
Expand Down
2 changes: 1 addition & 1 deletion src/sbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int ping_via_slots(const char *name, struct servants_list_item *servants);
int dump_headers(struct servants_list_item *servants);
unsigned long get_first_msgwait(struct servants_list_item *servants);
int messenger(const char *name, const char *msg, struct servants_list_item *servants);
int servant(const char *diskname, int mode, const void* argp);
int servant_md(const char *diskname, int mode, const void* argp);
#endif

int servant_pcmk(const char *diskname, int mode, const void* argp);
Expand Down

0 comments on commit f949aa8

Please sign in to comment.