Skip to content

Commit

Permalink
Fixed warnings about unused return values for read, write, dup.
Browse files Browse the repository at this point in the history
FIXME explain better.
  • Loading branch information
mvidner committed Apr 29, 2015
1 parent 7894cdd commit 0b893b5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 6 additions & 3 deletions base/tools/startshell/startshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ inst_start_shell (char *tty_tv)
fclose (stdout);
fclose (stderr);
setsid ();
fd_ii = open (tty_tv, O_RDWR);
fd_ii = open (tty_tv, O_RDWR); /* stdin at tty */
ioctl (fd_ii, TIOCSCTTY, (void *)1);
dup (fd_ii);
dup (fd_ii);
/* we don't need the fd numbers;
and if an error occurs we don't have a fd to write it to */
int dupfd __attribute__ ((unused));
dupfd = dup (fd_ii); /* stdout at tty */
dupfd = dup (fd_ii); /* stderr at tty */

execve ("/bin/bash", args_apci, env_pci);
fprintf (stderr, "Couldn't start shell (errno = %d)\n", errno);
Expand Down
2 changes: 1 addition & 1 deletion liby2/src/Y2ProgramComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void Y2ProgramComponent::sendToExternal(const string& value)
// result (..) from the input pipe, which is very important. Otherwise the
// result value would be dropped.

write(to_external[1], "\n", 1);
(void) (write(to_external[1], "\n", 1) == 1);
}


Expand Down
19 changes: 13 additions & 6 deletions liby2/src/Y2SerialComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,23 +344,25 @@ bool Y2SerialComponent::initializeConnection()

// first write one space so the other side gets
// fullfilled its necessities
write(fd_serial, space_buf, 1);
(void) (write(fd_serial, space_buf, 1) == 1);

// now wait for a space to be read
// (the other side has the same behaviour)
if (await_readable(TIMEOUT))
{
read(fd_serial, buf, 1); // read one byte
size_t r = read(fd_serial, buf, 1); // read one byte

if (buf[0] == ' ') spaces_read++; // was a space
else spaces_read = 0; // trash read --> reset
if (r == 1 && buf[0] == ' ')
spaces_read++; // was a space
else
spaces_read = 0; // trash read --> reset
}
}

// now that we've got our NUMSPACES spaces write 2 * NUMSPACES spaces to
// the other side to avoid syncing problems. the remote parser will kindly
// ignore them.
write(fd_serial, space_buf, 2 * NUMSPACES);
(void) (write(fd_serial, space_buf, 2 * NUMSPACES) == 2 * NUMSPACES);

// now set our parser to the serial line to start communication
parser.setInput(fd_serial, device_name.c_str());
Expand All @@ -378,7 +380,12 @@ void Y2SerialComponent::sendToSerial(const YCPValue& v)
{
string s = "(" + v->toString() + ")\n"; // store string in string variable ..
const char *cs = s.c_str(); // c_str is valid als long as s
write(fd_serial, cs, strlen(cs));
size_t len = s.length();
size_t w = write(fd_serial, cs, len);
if (w != len)
{
y2error ("wrote only %zu of %zu bytes: %s", w, len, strerror(errno));
}
}

YCPValue Y2SerialComponent::receiveFromSerial()
Expand Down
10 changes: 9 additions & 1 deletion liby2/src/Y2StdioComponent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ Y2StdioComponent::send (const YCPValue& v) const
{
string s = "(" + (v.isNull () ? "(nil)" : v->toString ()) + ")\n";
y2debug ("send begin %s", s.c_str ());
write (to_stderr ? STDERR_FILENO : STDOUT_FILENO, s.c_str (), s.length ());

int fd = to_stderr ? STDERR_FILENO : STDOUT_FILENO;
size_t len = s.length ();
size_t w = write (fd, s.c_str (), len);
if (w != len)
{
y2error ("wrote only %zu of %zu bytes: %s", w, len, strerror(errno));
}

y2debug ("send end %s", s.c_str ());
}

Expand Down

0 comments on commit 0b893b5

Please sign in to comment.