Always use the more portable 3-arg form for open()

This commit is contained in:
Richard Hughes 2019-11-23 10:47:19 +00:00
parent 019a1bc2b0
commit 11d10a00e7
2 changed files with 23 additions and 10 deletions

View File

@ -187,7 +187,7 @@ fu_plugin_thunderbolt_power_kernel_force_power (FuPlugin *plugin, gboolean enabl
return FALSE;
}
g_debug ("Setting force power to %d using kernel", enable);
fd = g_open (data->force_path, O_WRONLY);
fd = g_open (data->force_path, O_WRONLY, 0);
if (fd == -1) {
g_set_error (error,
FWUPD_ERROR,

View File

@ -714,15 +714,28 @@ fu_udev_device_open (FuDevice *device, GError **error)
/* open device */
if (priv->device_file != NULL) {
priv->fd = g_open (priv->device_file, priv->readonly ? O_RDONLY : O_RDWR);
if (priv->fd < 0) {
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"failed to open %s: %s",
priv->device_file,
strerror (errno));
return FALSE;
if (priv->readonly) {
priv->fd = g_open (priv->device_file, O_RDONLY, 0);
if (priv->fd < 0) {
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"failed to open %s for reading: %s",
priv->device_file,
strerror (errno));
return FALSE;
}
} else {
priv->fd = g_open (priv->device_file, O_RDWR, 0);
if (priv->fd < 0) {
g_set_error (error,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"failed to open %s: %s",
priv->device_file,
strerror (errno));
return FALSE;
}
}
}