void set_nonblocking(int fd)
{
- unsigned v;
+ int v;
+
v = fcntl(fd, F_GETFL, 0);
- fcntl(fd, F_SETFL, v | O_NONBLOCK);
+ if (v == -1) {
+ DEBUG(DEBUG_WARNING, ("Failed to get file status flags - %s\n",
+ strerror(errno)));
+ return;
+ }
+ if (fcntl(fd, F_SETFL, v | O_NONBLOCK) == -1) {
+ DEBUG(DEBUG_WARNING, ("Failed to set non_blocking on fd - %s\n",
+ strerror(errno)));
+ }
}
void set_close_on_exec(int fd)
{
- unsigned v;
+ int v;
+
v = fcntl(fd, F_GETFD, 0);
- fcntl(fd, F_SETFD, v | FD_CLOEXEC);
+ if (v == -1) {
+ DEBUG(DEBUG_WARNING, ("Failed to get file descriptor flags - %s\n",
+ strerror(errno)));
+ return;
+ }
+ if (fcntl(fd, F_SETFD, v | FD_CLOEXEC) != 0) {
+ DEBUG(DEBUG_WARNING, ("Failed to set close_on_exec on fd - %s\n",
+ strerror(errno)));
+ }
}
DEBUG(DEBUG_ALERT,
("ctdb exiting with error: "
"failed to create directory \"%s\" (%s)\n",
- dir, strerror(ret)));
+ dir, strerror(errno)));
exit(1);
}
}
struct ifreq ifr;
ZERO_STRUCT(sall);
+ ZERO_STRUCT(ifr);
+ ZERO_STRUCT(if_hwaddr);
switch (addr->ip.sin_family) {
case AF_INET:
}
DEBUG(DEBUG_DEBUG, (__location__ " Created SOCKET FD:%d for sending arp\n", s));
- strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
close(s);
}
/* get the mac address */
- strcpy(if_hwaddr.ifr_name, iface);
+ strncpy(if_hwaddr.ifr_name, iface, sizeof(if_hwaddr.ifr_name)-1);
ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
if ( ret < 0 ) {
close(s);
}
/* get the mac address */
- strcpy(if_hwaddr.ifr_name, iface);
+ strncpy(if_hwaddr.ifr_name, iface, sizeof(if_hwaddr.ifr_name)-1);
ret = ioctl(s, SIOCGIFHWADDR, &if_hwaddr);
if ( ret < 0 ) {
close(s);
return true;
}
- strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name));
+ strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)-1);
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0 && errno == ENODEV) {
DEBUG(DEBUG_CRIT,(__location__ " interface '%s' not found\n", iface));
close(s);
int n;
snprintf(path, sizeof(path), "/proc/%d/exe", pid);
- n = readlink(path, buf, sizeof(buf));
+ n = readlink(path, buf, sizeof(buf)-1);
if (n < 0) {
return NULL;
}
/* Remove any extra fields */
buf[n] = '\0';
ptr = strtok(buf, " ");
- return strdup(ptr);
+ return (ptr == NULL ? ptr : strdup(ptr));
}
/*
struct ctdb_lock_info curlock;
pid_t pid;
char buf[1024];
- char *ptr;
bool status = false;
if ((fp = fopen("/proc/locks", "r")) == NULL) {
DEBUG(DEBUG_ERR, ("Failed to read locks information"));
return false;
}
- while ((ptr = fgets(buf, sizeof(buf), fp)) != NULL) {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
if (! parse_proc_locks_line(buf, &pid, &curlock)) {
continue;
}
struct ctdb_lock_info curlock;
pid_t pid;
char buf[1024];
- char *ptr;
bool status = false;
if ((fp = fopen("/proc/locks", "r")) == NULL) {
DEBUG(DEBUG_ERR, ("Failed to read locks information"));
return false;
}
- while ((ptr = fgets(buf, sizeof(buf), fp)) != NULL) {
+ while (fgets(buf, sizeof(buf), fp) != NULL) {
if (! parse_proc_locks_line(buf, &pid, &curlock)) {
continue;
}