all: merge branch 'th/lgtm-com-fixes-1'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/494
This commit is contained in:
Thomas Haller 2020-05-07 14:01:14 +02:00
commit 6325297367
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
27 changed files with 73 additions and 40 deletions

View file

@ -541,6 +541,8 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
if (info->info_type == NMC_GENERIC_INFO_TYPE_CON_SHOW_TIMESTAMP)
return (*out_to_free = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp));
else {
struct tm localtime_result;
if (!timestamp) {
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return _("never");
@ -548,7 +550,7 @@ _metagen_con_show_get_fcn (NMC_META_GENERIC_INFO_GET_FCN_ARGS)
}
timestamp_real = timestamp;
s_mut = g_malloc0 (128);
strftime (s_mut, 64, "%c", localtime (&timestamp_real));
strftime (s_mut, 127, "%c", localtime_r (&timestamp_real, &localtime_result));
return (*out_to_free = s_mut);
}
}
@ -1449,7 +1451,9 @@ nmc_active_connection_details (NMActiveConnection *acon, NmCli *nmc)
gboolean was_output = FALSE;
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) {
/* pass */
} else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;
@ -2074,6 +2078,7 @@ do_connections_show (const NMCCommand *cmd, NmCli *nmc, int argc, const char *co
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
fields_str = NMC_FIELDS_CON_SHOW_COMMON;
else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;
@ -6280,7 +6285,7 @@ nmcli_editor_tab_completion (const char *text, int start, int end)
rl_completion_append_character = '.';
} else
generator_func = gen_property_names;
} else if (num >= 3) {
} else {
if (num == 3 && should_complete_files (NULL, line))
rl_attempted_completion_over = 0;
else if (should_complete_vpn_uuids (NULL, line)) {

View file

@ -1436,6 +1436,7 @@ show_device_info (NMDevice *device, NmCli *nmc)
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
fields_str = NMC_FIELDS_DEV_SHOW_SECTIONS_COMMON;
else if (g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;
@ -1749,6 +1750,7 @@ do_devices_status (const NMCCommand *cmd, NmCli *nmc, int argc, const char *cons
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
fields_str = "DEVICE,TYPE,STATE,CONNECTION";
else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;
@ -3149,6 +3151,7 @@ do_device_wifi_list (const NMCCommand *cmd, NmCli *nmc, int argc, const char *co
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
fields_str = NMC_FIELDS_DEV_WIFI_LIST_COMMON;
else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;
@ -4651,6 +4654,7 @@ do_device_lldp_list (const NMCCommand *cmd, NmCli *nmc, int argc, const char *co
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0)
fields_str = NMC_FIELDS_DEV_LLDP_LIST_COMMON;
else if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;

View file

@ -545,7 +545,9 @@ print_permissions (void *user_data)
}
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) {
/* pass */
} else if (g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;
@ -694,7 +696,9 @@ show_general_logging (NmCli *nmc)
};
if (!nmc->required_fields || g_ascii_strcasecmp (nmc->required_fields, "common") == 0) {
/* pass */
} else if (g_ascii_strcasecmp (nmc->required_fields, "all") == 0) {
/* pass */
} else
fields_str = nmc->required_fields;

View file

@ -30,10 +30,15 @@ show_connection (NMConnection *connection)
s_con = nm_connection_get_setting_connection (connection);
if (s_con) {
struct tm localtime_data;
/* Get various info from NMSettingConnection and show it */
timestamp = nm_setting_connection_get_timestamp (s_con);
timestamp_str = g_strdup_printf ("%" G_GUINT64_FORMAT, timestamp);
strftime (timestamp_real_str, sizeof (timestamp_real_str), "%c", localtime ((time_t *) &timestamp));
strftime (timestamp_real_str,
sizeof (timestamp_real_str),
"%c",
localtime_r ((time_t *) &timestamp, &localtime_data));
val1 = nm_setting_connection_get_id (s_con);
val2 = nm_setting_connection_get_uuid (s_con);

View file

@ -41,7 +41,7 @@ devList = []
for arg in sys.argv[2:]:
path = GetDevicePath(arg)
if path == None:
if path is None:
raise Exception("NetworkManager knows nothing about %s" % arg)
else:
devList.append(path)

View file

@ -4,7 +4,7 @@
# Copyright (C) 2010 Red Hat, Inc.
#
import dbus, sys
import dbus
# This example takes a device interface name as a parameter and tells
# NetworkManager to disconnect that device, closing down any network

View file

@ -4,7 +4,7 @@
# Copyright (C) 2011 - 2012 Red Hat, Inc.
#
import dbus, sys
import dbus
# This example lists basic information about network interfaces known to NM

View file

@ -56,7 +56,6 @@ def get_active_connection_path(uuid):
proxy = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
iface = dbus.Interface(proxy, dbus_interface='org.freedesktop.DBus.Properties')
active_connections = iface.Get('org.freedesktop.NetworkManager', 'ActiveConnections')
all_connections = get_connections()
for a in active_connections:
proxy = bus.get_object('org.freedesktop.NetworkManager', a)

View file

@ -11,7 +11,7 @@
# https://developer.gnome.org/NetworkManager/1.0/ref-settings.html
#
import dbus, sys, time
import dbus, sys
bus = dbus.SystemBus()
service_name = "org.freedesktop.NetworkManager"

View file

@ -10,8 +10,6 @@ import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
import os
###############################################################################
def usage():
@ -136,7 +134,7 @@ def do_adjust_rollback_timeout(client):
sys.exit("Missing timeout")
try:
add_timeout = int(sys.argv[3])
except:
except Exception:
sys.exit("Invalid timeout")
path = validate_path(sys.argv[2], client)

View file

@ -57,7 +57,7 @@ if __name__ == "__main__":
# deactivate the connections
for ac in connections:
if ctype == None or ctype == ac.get_connection_type():
if ctype is None or ctype == ac.get_connection_type():
sys.stdout.write("Deactivating %s (%s)" % (ac.get_id(), ac.get_uuid()))
try:
client.deactivate_connection(ac, None)

View file

@ -4,7 +4,6 @@
# Copyright (C) 2016 Red Hat, Inc.
#
import sys
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM

View file

@ -8,7 +8,7 @@
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
from gi.repository import NM
if __name__ == "__main__":
client = NM.Client.new(None)

View file

@ -8,7 +8,7 @@
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
from gi.repository import NM
if __name__ == "__main__":
client = NM.Client.new(None)

View file

@ -6,7 +6,7 @@
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
from gi.repository import NM
if __name__ == "__main__":
client = NM.Client.new(None)

View file

@ -7,7 +7,7 @@
import sys, socket
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
from gi.repository import NM
#
# This example shows how to get addresses, routes and DNS information

View file

@ -5,7 +5,6 @@
#
import sys
import re
import gi
gi.require_version('NM', '1.0')

View file

@ -5,7 +5,6 @@
#
import sys
import re
import gi
gi.require_version('NM', '1.0')

View file

@ -58,7 +58,6 @@
# nm-wg-set id "$PROFILE" $WG_ARGS
import sys
import re
import os
import gi
@ -443,7 +442,7 @@ if __name__ == '__main__':
secrets = conn.get_secrets(NM.SETTING_WIREGUARD_SETTING_NAME)
if secrets:
conn.update_secrets(NM.SETTING_WIREGUARD_SETTING_NAME, secrets)
except:
except Exception:
pass
if not argv:

View file

@ -82,7 +82,7 @@ def scan_timeout_cb(device):
def start_find_cb(device, async_result, user_data):
try:
r = device.start_find_finish(async_result)
device.start_find_finish(async_result)
except Exception as e:
sys.stderr.write("Error: %s\n" % e)
main_loop.quit()

View file

@ -10,7 +10,7 @@ import os
import gi
gi.require_version('GIRepository', '2.0')
from gi.repository import GIRepository
import argparse, datetime, re, sys
import argparse, re, sys
import xml.etree.ElementTree as ET
try:
@ -47,7 +47,6 @@ dbus_type_name_map = {
'aay': 'array of byte array',
'a(ayuay)': 'array of legacy IPv6 address struct',
'a(ayuayu)': 'array of legacy IPv6 route struct',
'aa{sv}': 'array of vardict',
}
ns_map = {

View file

@ -3,6 +3,9 @@
* Copyright (C) 2014 - 2015 Red Hat, Inc.
*/
#ifndef __NM_TEST_LIBNM_UTILS_H__
#define __NM_TEST_LIBNM_UTILS_H__
#include "NetworkManager.h"
#include "nm-utils/nm-test-utils.h"
@ -82,3 +85,5 @@ nmtstc_client_new (gboolean allow_iterate_main_context)
{
return nmtstc_context_object_new (NM_TYPE_CLIENT, allow_iterate_main_context, NULL);
}
#endif /* __NM_TEST_LIBNM_UTILS_H__ */

View file

@ -81,7 +81,20 @@ _acd_event_to_string (unsigned int event)
return NULL;
}
#define acd_event_to_string_a(event) NM_UTILS_LOOKUP_STR_A (_acd_event_to_string, event)
#define ACD_EVENT_TO_STRING_BUF_SIZE 50
static const char *
_acd_event_to_string_buf (unsigned event, char buffer[ACD_EVENT_TO_STRING_BUF_SIZE])
{
const char *s;
s = _acd_event_to_string (event);
if (s)
return s;
g_snprintf (buffer, ACD_EVENT_TO_STRING_BUF_SIZE, "(%u)", event);
return buffer;
}
static const char *
acd_error_to_string (int error)
@ -172,6 +185,7 @@ acd_event (int fd,
while ( !n_acd_pop_event (self->acd, &event)
&& event) {
char to_string_buffer[ACD_EVENT_TO_STRING_BUF_SIZE];
gs_free char *hwaddr_str = NULL;
gboolean check_probing_done = FALSE;
@ -215,7 +229,7 @@ acd_event (int fd,
nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex));
break;
default:
_LOGD ("unhandled event '%s'", acd_event_to_string_a (event->event));
_LOGD ("unhandled event '%s'", _acd_event_to_string_buf (event->event, to_string_buffer));
break;
}

View file

@ -179,9 +179,9 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
*/
#define NM_NDISC_VLTIME_MULT ((guint32) 48)
clamp_pltime = ndp_msgra_router_lifetime (msgra);
clamp_vltime = (clamp_pltime < G_MAXUINT32 / NM_NDISC_VLTIME_MULT)
? clamp_pltime * NM_NDISC_VLTIME_MULT
: G_MAXUINT32;
/* clamp_pltime has at most 16 bit set, and multiplication cannot overflow. */
clamp_vltime = clamp_pltime * NM_NDISC_VLTIME_MULT;
ndp_msg_opt_for_each_offset (offset, msg, NDP_MSG_OPT_PREFIX) {
guint8 r_plen;

View file

@ -2210,7 +2210,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
gs_free char *perm_hw_addr_fake = NULL;
gsize connection_uuid_len;
gsize perm_hw_addr_fake_len;
int nm_owned = -1;
NMTernary nm_owned;
char *p;
guint32 route_metric_default_effective;
guint32 route_metric_default_aspired;
@ -2252,7 +2252,7 @@ _config_device_state_data_new (int ifindex, GKeyFile *kf)
nm_owned = nm_config_keyfile_get_boolean (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED,
-1);
NM_TERNARY_DEFAULT);
/* metric zero is not a valid metric. While zero valid for IPv4, for IPv6 it is an alias
* for 1024. Since we handle here IPv4 and IPv6 the same, we cannot allow zero. */
@ -2325,9 +2325,11 @@ nm_config_device_state_load (int ifindex)
return NULL;
device_state = _config_device_state_data_new (ifindex, kf);
nm_owned_str = device_state->nm_owned == TRUE ?
", nm-owned=1" :
(device_state->nm_owned == FALSE ? ", nm-owned=0" : "");
nm_owned_str = device_state->nm_owned == NM_TERNARY_TRUE
? ", nm-owned=1"
: ( device_state->nm_owned == NM_TERNARY_FALSE
? ", nm-owned=0"
: "");
_LOGT ("device-state: %s #%d (%s); managed=%s%s%s%s%s%s%s%s, route-metric-default=%"G_GUINT32_FORMAT"-%"G_GUINT32_FORMAT"",
kf ? "read" : "miss",
@ -2390,7 +2392,7 @@ nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
const char *connection_uuid,
int nm_owned,
NMTernary nm_owned,
guint32 route_metric_default_aspired,
guint32 route_metric_default_effective,
const char *next_server,
@ -2429,7 +2431,7 @@ nm_config_device_state_write (int ifindex,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_CONNECTION_UUID,
connection_uuid);
}
if (nm_owned >= 0) {
if (nm_owned != NM_TERNARY_DEFAULT) {
g_key_file_set_boolean (kf,
DEVICE_RUN_STATE_KEYFILE_GROUP_DEVICE,
DEVICE_RUN_STATE_KEYFILE_KEY_DEVICE_NM_OWNED,

View file

@ -243,7 +243,7 @@ struct _NMConfigDeviceStateData {
/* whether the device was nm-owned (0/1) or -1 for
* non-software devices. */
int nm_owned:3;
NMTernary nm_owned:3;
};
NMConfigDeviceStateData *nm_config_device_state_load (int ifindex);
@ -252,7 +252,7 @@ gboolean nm_config_device_state_write (int ifindex,
NMConfigDeviceStateManagedType managed,
const char *perm_hw_addr_fake,
const char *connection_uuid,
int nm_owned,
NMTernary nm_owned,
guint32 route_metric_default_aspired,
guint32 route_metric_default_effective,
const char *next_server,

View file

@ -6552,7 +6552,7 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifind
gboolean perm_hw_addr_is_fake;
guint32 route_metric_default_aspired;
guint32 route_metric_default_effective;
int nm_owned;
NMTernary nm_owned;
NMDhcpConfig *dhcp_config;
const char *next_server = NULL;
const char *root_path = NULL;
@ -6588,7 +6588,9 @@ nm_manager_write_device_state (NMManager *self, NMDevice *device, int *out_ifind
if (perm_hw_addr_fake && !perm_hw_addr_is_fake)
perm_hw_addr_fake = NULL;
nm_owned = nm_device_is_software (device) ? nm_device_is_nm_owned (device) : -1;
nm_owned = nm_device_is_software (device)
? nm_device_is_nm_owned (device)
: NM_TERNARY_DEFAULT;
route_metric_default_effective = _device_route_metric_get (self, ifindex, NM_DEVICE_TYPE_UNKNOWN,
TRUE, &route_metric_default_aspired);