cache_mngr: Don't modify callback setup of socket

Instead, clone it and modify a temporary copy. Although it is not
recommended to use the same socket for requests and to serve a
cache manager, this change might prevent some unwanted side effects
if done so.
This commit is contained in:
Thomas Graf 2012-04-21 10:51:34 +02:00
parent e78975aea8
commit b32011254d

View file

@ -175,9 +175,6 @@ int nl_cache_mngr_alloc(struct nl_sock *sk, int protocol, int flags,
if (!mngr->cm_assocs)
goto errout;
nl_socket_modify_cb(mngr->cm_handle, NL_CB_VALID, NL_CB_CUSTOM,
event_input, mngr);
/* Required to receive async event notifications */
nl_socket_disable_seq_check(mngr->cm_handle);
@ -359,8 +356,19 @@ int nl_cache_mngr_poll(struct nl_cache_mngr *mngr, int timeout)
int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr)
{
int err;
struct nl_cb *cb;
err = nl_recvmsgs_default(mngr->cm_handle);
NL_DBG(2, "Cache manager %p, reading new data from fd %d\n",
mngr, nl_socket_get_fd(mngr->cm_handle));
cb = nl_cb_clone(mngr->cm_handle->s_cb);
if (cb == NULL)
return -NLE_NOMEM;
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, event_input, mngr);
err = nl_recvmsgs(mngr->cm_handle, cb);
nl_cb_put(cb);
if (err < 0)
return err;