chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rtnl: introduce default timeout
[elogind.git]
/
src
/
udev
/
net
/
link-config.c
diff --git
a/src/udev/net/link-config.c
b/src/udev/net/link-config.c
index 0b5916be4c96ab2f45be480a36c39944937b4784..9d6c96b5a5cf1f1ff8f8cd779215875a690f7c37 100644
(file)
--- a/
src/udev/net/link-config.c
+++ b/
src/udev/net/link-config.c
@@
-46,11
+46,14
@@
struct link_config_ctx {
sd_rtnl *rtnl;
char **link_dirs;
sd_rtnl *rtnl;
char **link_dirs;
- usec_t
*
link_dirs_ts_usec;
+ usec_t link_dirs_ts_usec;
};
};
+DEFINE_TRIVIAL_CLEANUP_FUNC(link_config_ctx*, link_config_ctx_free);
+#define _cleanup_link_config_ctx_free_ _cleanup_(link_config_ctx_freep)
+
int link_config_ctx_new(link_config_ctx **ret) {
int link_config_ctx_new(link_config_ctx **ret) {
-
link_config_ctx *ctx
;
+
_cleanup_link_config_ctx_free_ link_config_ctx *ctx = NULL
;
int r;
if (!ret)
int r;
if (!ret)
@@
-61,16
+64,12
@@
int link_config_ctx_new(link_config_ctx **ret) {
return -ENOMEM;
r = ethtool_connect(&ctx->ethtool_fd);
return -ENOMEM;
r = ethtool_connect(&ctx->ethtool_fd);
- if (r < 0) {
- link_config_ctx_free(ctx);
+ if (r < 0)
return r;
return r;
- }
r = sd_rtnl_open(0, &ctx->rtnl);
r = sd_rtnl_open(0, &ctx->rtnl);
- if (r < 0) {
- link_config_ctx_free(ctx);
+ if (r < 0)
return r;
return r;
- }
LIST_HEAD_INIT(ctx->links);
LIST_HEAD_INIT(ctx->links);
@@
-80,22
+79,17
@@
int link_config_ctx_new(link_config_ctx **ret) {
NULL);
if (!ctx->link_dirs) {
log_error("failed to build link config directory array");
NULL);
if (!ctx->link_dirs) {
log_error("failed to build link config directory array");
- link_config_ctx_free(ctx);
return -ENOMEM;
}
return -ENOMEM;
}
+
if (!path_strv_canonicalize_uniq(ctx->link_dirs)) {
log_error("failed to canonicalize link config directories\n");
if (!path_strv_canonicalize_uniq(ctx->link_dirs)) {
log_error("failed to canonicalize link config directories\n");
- link_config_ctx_free(ctx);
- return -ENOMEM;
- }
-
- ctx->link_dirs_ts_usec = calloc(strv_length(ctx->link_dirs), sizeof(usec_t));
- if(!ctx->link_dirs_ts_usec) {
- link_config_ctx_free(ctx);
return -ENOMEM;
}
*ret = ctx;
return -ENOMEM;
}
*ret = ctx;
+ ctx = NULL;
+
return 0;
}
return 0;
}
@@
-126,7
+120,6
@@
void link_config_ctx_free(link_config_ctx *ctx) {
sd_rtnl_unref(ctx->rtnl);
strv_free(ctx->link_dirs);
sd_rtnl_unref(ctx->rtnl);
strv_free(ctx->link_dirs);
- free(ctx->link_dirs_ts_usec);
link_configs_free(ctx);
free(ctx);
link_configs_free(ctx);
free(ctx);
@@
-183,8
+176,8
@@
int link_config_load(link_config_ctx *ctx) {
link_configs_free(ctx);
link_configs_free(ctx);
- /* update timestamp
s
*/
- paths_check_timestamp(ctx->link_dirs, ctx->link_dirs_ts_usec, true);
+ /* update timestamp */
+ paths_check_timestamp(ctx->link_dirs,
&
ctx->link_dirs_ts_usec, true);
r = conf_files_list_strv(&files, ".link", NULL, (const char **)ctx->link_dirs);
if (r < 0) {
r = conf_files_list_strv(&files, ".link", NULL, (const char **)ctx->link_dirs);
if (r < 0) {
@@
-202,7
+195,7
@@
int link_config_load(link_config_ctx *ctx) {
}
bool link_config_should_reload(link_config_ctx *ctx) {
}
bool link_config_should_reload(link_config_ctx *ctx) {
- return paths_check_timestamp(ctx->link_dirs, ctx->link_dirs_ts_usec, false);
+ return paths_check_timestamp(ctx->link_dirs,
&
ctx->link_dirs_ts_usec, false);
}
static bool match_config(link_config *match, struct udev_device *device) {
}
static bool match_config(link_config *match, struct udev_device *device) {
@@
-300,7
+293,7
@@
static int rtnl_set_properties(sd_rtnl *rtnl, int ifindex, const char *name, con
}
if (need_update) {
}
if (need_update) {
- r = sd_rtnl_send_with_reply_and_block(rtnl, message,
5 * USEC_PER_SEC
, NULL);
+ r = sd_rtnl_send_with_reply_and_block(rtnl, message,
0
, NULL);
if (r < 0)
return r;
}
if (r < 0)
return r;
}
@@
-329,12
+322,15
@@
static bool enable_name_policy(void) {
static bool mac_is_random(struct udev_device *device) {
const char *s;
static bool mac_is_random(struct udev_device *device) {
const char *s;
- int type;
+ unsigned type;
+ int r;
s = udev_device_get_sysattr_value(device, "addr_assign_type");
if (!s)
s = udev_device_get_sysattr_value(device, "addr_assign_type");
if (!s)
- return -EINVAL;
- type = strtoul(s, NULL, 0);
+ return false; /* if we don't know, assume it is not random */
+ r = safe_atou(s, &type);
+ if (r < 0)
+ return false;
/* check for NET_ADDR_RANDOM */
return type == 1;
/* check for NET_ADDR_RANDOM */
return type == 1;
@@
-342,12
+338,15
@@
static bool mac_is_random(struct udev_device *device) {
static bool mac_is_permanent(struct udev_device *device) {
const char *s;
static bool mac_is_permanent(struct udev_device *device) {
const char *s;
- int type;
+ unsigned type;
+ int r;
s = udev_device_get_sysattr_value(device, "addr_assign_type");
if (!s)
s = udev_device_get_sysattr_value(device, "addr_assign_type");
if (!s)
- return -EINVAL;
- type = strtoul(s, NULL, 0);
+ return true; /* if we don't know, assume it is permanent */
+ r = safe_atou(s, &type);
+ if (r < 0)
+ return true;
/* check for NET_ADDR_PERM */
return type == 0;
/* check for NET_ADDR_PERM */
return type == 0;
@@
-372,13
+371,13
@@
static int get_mac(struct udev_device *device, bool want_random, struct ether_ad
if (!name) {
name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
if (!name)
if (!name) {
name = udev_device_get_property_value(device, "ID_NET_NAME_PATH");
if (!name)
- return -
1
;
+ return -
ENOENT
;
}
}
/* fetch some persistent data unique to this machine */
r = sd_id128_get_machine(&machine);
if (r < 0)
}
}
/* fetch some persistent data unique to this machine */
r = sd_id128_get_machine(&machine);
if (r < 0)
- return
-1
;
+ return
r
;
/* combine the data */
seed_str = strappenda(name, sd_id128_to_string(machine, machineid_buf));
/* combine the data */
seed_str = strappenda(name, sd_id128_to_string(machine, machineid_buf));