# the safewrite wrapper.
sc_avoid_write:
@prohibit='\<write *\(' \
+ exclude='sc_avoid_write' \
in_vc_files='\.c$$' \
halt='consider using safewrite instead of write' \
$(_sc_search_regexp)
# List all syntax-check exemptions:
exclude_file_name_regexp--sc_avoid_strcase = ^tools/vsh\.h$$
-_src1=libvirt-stream|qemu/qemu_monitor|util/vir(command|file|fdstream)|rpc/virnetsocket|lxc/lxc_controller|locking/lock_daemon|logging/log_daemon|remote/remote_ssh_helper
-_test1=shunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupmock|commandhelper
-exclude_file_name_regexp--sc_avoid_write = \
- ^(src/($(_src1))|tools/virsh-console|tests/($(_test1)))\.c$$
+exclude_file_name_regexp--sc_avoid_write = ^src/libvirt-stream\.c$$
exclude_file_name_regexp--sc_bindtextdomain = .*
*/
if (statuswrite != -1) {
char status = 0;
- while (write(statuswrite, &status, 1) == -1 &&
+ while (write(statuswrite, &status, 1) == -1 && /* sc_avoid_write */
errno == EINTR)
;
VIR_FORCE_CLOSE(statuswrite);
if (ret != 0) {
/* Tell parent of daemon what failed */
char status = ret;
- while (write(statuswrite, &status, 1) == -1 &&
+ while (write(statuswrite, &status, 1) == -1 && /* sc_avoid_write */
errno == EINTR)
;
}
*/
if (statuswrite != -1) {
char status = 0;
- while (write(statuswrite, &status, 1) == -1 &&
+ while (write(statuswrite, &status, 1) == -1 && /* sc_avoid_write */
errno == EINTR)
;
VIR_FORCE_CLOSE(statuswrite);
if (ret != 0) {
/* Tell parent of daemon what failed */
char status = ret;
- while (write(statuswrite, &status, 1) == -1 &&
+ while (write(statuswrite, &status, 1) == -1 && /* sc_avoid_write */
errno == EINTR)
;
}
}
rewrite:
- done = write(fd, buf, *len);
+ done = write(fd, buf, *len); /* sc_avoid_write */
if (done == -1 && errno == EINTR)
goto rewrite;
if (done == -1 && errno != EAGAIN) {
buf = mon->msg->txBuffer + mon->msg->txOffset;
len = mon->msg->txLength - mon->msg->txOffset;
if (mon->msg->txFD == -1)
- done = write(mon->fd, buf, len);
+ done = write(mon->fd, buf, len); /* sc_avoid_write */
else
done = qemuMonitorIOWriteWithFD(mon, buf, len, mon->msg->txFD);
if (events & VIR_EVENT_HANDLE_WRITABLE &&
proxy->sockToTerminal.offset) {
ssize_t done;
- done = write(fd,
+ done = write(fd, /* sc_avoid_write */
proxy->sockToTerminal.data,
proxy->sockToTerminal.offset);
if (done < 0) {
void *opaque)
{
virNetSocket *sock = opaque;
- return write(sock->fd, buf, len);
+ return write(sock->fd, buf, len); /* sc_avoid_write */
}
VIR_NET_TLS_HANDSHAKE_COMPLETE) {
ret = virNetTLSSessionWrite(sock->tlsSession, buf, len);
} else {
- ret = write(sock->fd, buf, len);
+ ret = write(sock->fd, buf, len); /* sc_avoid_write */
}
if (ret < 0) {
if (i == virCommandGetNumSendBuffers(cmd))
return 0;
- done = write(fds->fd,
+ done = write(fds->fd, /* sc_avoid_write */
cmd->sendBuffers[i].buffer + cmd->sendBuffers[i].offset,
cmd->sendBuffers[i].buflen - cmd->sendBuffers[i].offset);
if (done < 0) {
fds[i].fd == cmd->inpipe) {
int done;
- done = write(cmd->inpipe, cmd->inbuf + inoff,
+ done = write(cmd->inpipe, cmd->inbuf + inoff, /* sc_avoid_write */
inlen - inoff);
if (done < 0) {
if (errno == EPIPE) {
ret = nbytes;
} else {
retry:
- ret = write(fdst->fd, bytes, nbytes);
+ ret = write(fdst->fd, bytes, nbytes); /* sc_avoid_write */
if (ret < 0) {
VIR_WARNINGS_NO_WLOGICALOP_EQUAL_EXPR
if (errno == EAGAIN || errno == EWOULDBLOCK) {
return nread;
}
-/* Like write(), but restarts after EINTR. Doesn't play
- * nicely with nonblocking FD and EAGAIN, in which case
- * you want to use bare write(). Or even use virSocket()
- * if the FD is related to a socket rather than a plain
+/* Like write(), but restarts after EINTR. Encouraged by sc_avoid_write.
+ * Doesn't play nicely with nonblocking FD and EAGAIN, in which case
+ * you want to use bare write() and mark it's use with sc_avoid_write.
+ * Or even use virSocket() if the FD is related to a socket rather than a plain
* file or pipe. */
ssize_t
safewrite(int fd, const void *buf, size_t count)
{
size_t nwritten = 0;
while (count > 0) {
- ssize_t r = write(fd, buf, count);
+ ssize_t r = write(fd, buf, count); /* sc_avoid_write */
if (r < 0 && errno == EINTR)
continue;
static void sigHandler(int sig)
{
- ignore_value(write(STDERR_FILENO, "FAIL\n", 5));
+ ignore_value(write(STDERR_FILENO, "FAIL\n", 5)); /* sc_avoid_write */
signal(sig, SIG_DFL);
raise(sig);
}
if ((fd = real_open(filepath, O_CREAT|O_WRONLY, 0600)) < 0)
goto cleanup;
- if (write(fd, value, strlen(value)) != strlen(value))
+ if (write(fd, value, strlen(value)) != strlen(value)) /* sc_avoid_write */
goto cleanup;
ret = 0;
{
int *fd = opaque;
- return write(*fd, buf, len);
+ return write(*fd, buf, len); /* sc_avoid_write */
}
static ssize_t testRead(char *buf, size_t len, void *opaque)
con->streamToTerminal.offset) {
ssize_t done;
size_t avail;
- done = write(fd,
+ done = write(fd, /* sc_avoid_write */
con->streamToTerminal.data,
con->streamToTerminal.offset);
if (done < 0) {