summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-08-01 10:59:36 +0200
committerThomas Haller <thaller@redhat.com>2019-08-08 10:53:03 +0200
commit1bad35061fb3d0807048601b404619ad816be28b (patch)
tree112b58d4a4199f328dab4ae02d7309913a3f059c /src
parent041a95229722c57a21492f69d3fbb9805bfe05e6 (diff)
downloadNetworkManager-1bad35061fb3d0807048601b404619ad816be28b.tar.gz
shared: let nm_utils_file_set_contents() return a errno error code
nm_utils_file_set_contents() is a re-implementation of g_file_set_contents(), as such it returned merely a boolean success value. It's sometimes interesting to get the native error code. Let the function deviate from glib's original g_file_set_contents() and return the error code (as negative value) instead. This requires all callers to change. Also, it's potentially a dangerous change, as this is easy to miss. Note that nm_utils_file_get_contents() also returns an errno, and already deviates from g_file_get_contents() in the same way. This patch resolves at least the inconsistency with nm_utils_file_get_contents().
Diffstat (limited to 'src')
-rw-r--r--src/initrd/nm-initrd-generator.c2
-rw-r--r--src/nm-core-utils.c10
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c10
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-utils.c2
-rw-r--r--src/settings/plugins/keyfile/nms-keyfile-writer.c4
5 files changed, 14 insertions, 14 deletions
diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c
index c916459d5c..6a1bf35a0d 100644
--- a/src/initrd/nm-initrd-generator.c
+++ b/src/initrd/nm-initrd-generator.c
@@ -63,7 +63,7 @@ output_conn (gpointer key, gpointer value, gpointer user_data)
filename = nm_keyfile_utils_create_filename (basename, TRUE);
full_filename = g_build_filename (connections_dir, filename, NULL);
- if (!nm_utils_file_set_contents (full_filename, data, len, 0600, &error))
+ if (nm_utils_file_set_contents (full_filename, data, len, 0600, &error) < 0)
goto err_out;
} else
g_print ("\n*** Connection '%s' ***\n\n%s", basename, data);
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index d896d4d33d..a851430c57 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -2695,11 +2695,11 @@ _host_id_read (guint8 **out_host_id,
nm_log_warn (LOGD_CORE, "secret-key: failure to generate good random data for secret-key (use non-persistent key)");
else if (nm_utils_get_testing ()) {
/* for test code, we don't write the generated secret-key to disk. */
- } else if (!nm_utils_file_set_contents (SECRET_KEY_FILE,
- (const char *) new_content,
- len,
- 0600,
- &error)) {
+ } else if (nm_utils_file_set_contents (SECRET_KEY_FILE,
+ (const char *) new_content,
+ len,
+ 0600,
+ &error) < 0) {
nm_log_warn (LOGD_CORE, "secret-key: failure to persist secret key in \"%s\" (%s) (use non-persistent key)",
SECRET_KEY_FILE, error->message);
g_clear_error (&error);
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
index 38dc5c8dbb..883e1f4f8e 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
@@ -301,11 +301,11 @@ write_blobs (GHashTable *blobs, GError **error)
* can use paths from now on instead of pushing around the certificate
* data itself.
*/
- if (!nm_utils_file_set_contents (filename,
- (const char *) g_bytes_get_data (blob, NULL),
- g_bytes_get_size (blob),
- 0600,
- &write_error)) {
+ if (nm_utils_file_set_contents (filename,
+ (const char *) g_bytes_get_data (blob, NULL),
+ g_bytes_get_size (blob),
+ 0600,
+ &write_error) < 0) {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED,
"Could not write certificate to file \"%s\": %s",
filename,
diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c
index ea03e1b611..eef6ae6e82 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-utils.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c
@@ -266,7 +266,7 @@ nms_keyfile_nmmeta_write (const char *dirname,
contents = g_key_file_to_data (kf, &length, NULL);
- if (!nm_utils_file_set_contents (full_filename, contents, length, 0600, NULL)) {
+ if (nm_utils_file_set_contents (full_filename, contents, length, 0600, NULL) < 0) {
NM_SET_OUT (out_full_filename, g_steal_pointer (&full_filename_tmp));
return FALSE;
}
diff --git a/src/settings/plugins/keyfile/nms-keyfile-writer.c b/src/settings/plugins/keyfile/nms-keyfile-writer.c
index 5fbbb7a1c8..c89b50db4d 100644
--- a/src/settings/plugins/keyfile/nms-keyfile-writer.c
+++ b/src/settings/plugins/keyfile/nms-keyfile-writer.c
@@ -126,8 +126,8 @@ cert_writer (NMConnection *connection,
new_path = g_strdup_printf ("%s/%s-%s.%s", info->keyfile_dir, nm_connection_get_uuid (connection),
cert_data->vtable->file_suffix, ext);
- success = nm_utils_file_set_contents (new_path, (const char *) blob_data,
- blob_len, 0600, &local);
+ success = (nm_utils_file_set_contents (new_path, (const char *) blob_data,
+ blob_len, 0600, &local) >= 0);
if (success) {
/* Write the path value to the keyfile.
* We know, that basename(new_path) starts with a UUID, hence no conflict with "data:;base64," */