*flags = ((u32)ntohs(tmp)) << 16;
/* reserved for future use*/
- write(sock, &reserved, sizeof(reserved));
+ if (write(sock, &reserved, sizeof(reserved)) < 0)
+ err("Failed/2.1: %m");
/* Write the export name that we're after */
magic = ntohll(opts_magic);
- write(sock, &magic, sizeof(magic));
+ if (write(sock, &magic, sizeof(magic)) < 0)
+ err("Failed/2.2: %m");
opt = ntohl(NBD_OPT_EXPORT_NAME);
- write(sock, &opt, sizeof(opt));
+ if (write(sock, &opt, sizeof(opt)) < 0)
+ err("Failed/2.3: %m");
namesize = (u32)strlen(name);
namesize = ntohl(namesize);
- write(sock, &namesize, sizeof(namesize));
- write(sock, name, strlen(name));
+ if (write(sock, &namesize, sizeof(namesize)) < 0)
+ err("Failed/2.4: %m");
+ if (write(sock, name, strlen(name)) < 0)
+ err("Failed/2.4: %m");
} else {
if (magic != cliserv_magic)
err("Not enough cliserv_magic");
/* Go daemon */
#ifndef NOFORK
- if(!nofork) daemon(0,0);
+ if(!nofork) {
+ if (daemon(0,0) < 0)
+ err("Cannot detach from terminal");
+ }
#endif
do {
#ifndef NOFORK
if(!servers)
err("programmer error");
- write(net, &smallflags, sizeof(uint16_t));
- read(net, &reserved, sizeof(reserved));
- read(net, &magic, sizeof(magic));
+ if (write(net, &smallflags, sizeof(uint16_t)) < 0)
+ err("Negotiation failed: %m");
+ if (read(net, &reserved, sizeof(reserved)) < 0)
+ err("Negotiation failed: %m");
+ if (read(net, &magic, sizeof(magic)) < 0)
+ err("Negotiation failed: %m");
magic = ntohll(magic);
if(magic != opts_magic) {
close(net);
return NULL;
}
- read(net, &opt, sizeof(opt));
+ if (read(net, &opt, sizeof(opt)) < 0)
+ err("Negotiation failed: %m");
opt = ntohl(opt);
if(opt != NBD_OPT_EXPORT_NAME) {
close(net);
return NULL;
}
- read(net, &namelen, sizeof(namelen));
+ if (read(net, &namelen, sizeof(namelen)) < 0)
+ err("Negotiation failed: %m");
namelen = ntohl(namelen);
name = malloc(namelen+1);
name[namelen]=0;
- read(net, name, namelen);
+ if (read(net, name, namelen) < 0)
+ err("Negotiation failed: %m");
for(i=0; i<servers->len; i++) {
SERVER* serve = &(g_array_index(servers, SERVER, i));
if(!strcmp(serve->servename, name)) {
default:
level=LOG_ERR;
}
- syslog(level, message);
+ syslog(level, "%s", message);
}
#endif