From afff1260ebea7bc3dcbba762a1f19ce9ab9db9f1 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 1 Nov 2007 13:59:55 +0000 Subject: [PATCH] Final status messages go to stdout. Fix two harmless file descriptor leaks. Don't return an error when readback fails or doesn't match, it might be OK. git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5001 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 4 ++++ tools/i2cset.c | 28 +++++++++++++--------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CHANGES b/CHANGES index fe2a93e..baedcd5 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ i2c-tools CHANGES ----------------- +SVN + i2cset: Final status messages go to stdout + Return success even when readback fails or doesn't match + 3.0.0 (2007-10-14) Initial release diff --git a/tools/i2cset.c b/tools/i2cset.c index b62c3dc..7a873de 100644 --- a/tools/i2cset.c +++ b/tools/i2cset.c @@ -48,7 +48,6 @@ int main(int argc, char *argv[]) char *end; int res, i2cbus, address, size, file; int value, daddress, vmask = 0; - int e1; char filename[20]; unsigned long funcs; int pec = 0; @@ -232,6 +231,7 @@ int main(int argc, char *argv[]) if (ioctl(file, I2C_PEC, 1) < 0) { fprintf(stderr, "Error: Could not set PEC: %s\n", strerror(errno)); + close(file); exit(1); } if (!(funcs & (I2C_FUNC_SMBUS_PEC | I2C_FUNC_I2C))) { @@ -240,15 +240,15 @@ int main(int argc, char *argv[]) } } - e1 = 0; if (size == I2C_SMBUS_WORD_DATA) { res = i2c_smbus_write_word_data(file, daddress, value); } else { res = i2c_smbus_write_byte_data(file, daddress, value); } if (res < 0) { - fprintf(stderr, "Warning - write failed\n"); - e1++; + fprintf(stderr, "Error: Write failed\n"); + close(file); + exit(1); } if (pec) { @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Error: Could not clear PEC: %s\n", strerror(errno)); close(file); - exit(e1); + exit(1); } } @@ -268,19 +268,17 @@ int main(int argc, char *argv[]) close(file); if (res < 0) { - fprintf(stderr, "Warning - readback failed\n"); - e1++; + printf("Warning - readback failed\n"); } else if (res != value) { - e1++; - fprintf(stderr, "Warning - data mismatch - wrote " - "0x%0*x, read back 0x%0*x\n", - size == I2C_SMBUS_WORD_DATA ? 4 : 2, value, - size == I2C_SMBUS_WORD_DATA ? 4 : 2, res); + printf("Warning - data mismatch - wrote " + "0x%0*x, read back 0x%0*x\n", + size == I2C_SMBUS_WORD_DATA ? 4 : 2, value, + size == I2C_SMBUS_WORD_DATA ? 4 : 2, res); } else { - fprintf(stderr, "Value 0x%0*x written, readback matched\n", - size == I2C_SMBUS_WORD_DATA ? 4 : 2, value); + printf("Value 0x%0*x written, readback matched\n", + size == I2C_SMBUS_WORD_DATA ? 4 : 2, value); } - exit(e1); + exit(0); }