]> granicus.if.org Git - libnl/commitdiff
cache_mngr: Don't modify callback setup of socket
authorThomas Graf <tgraf@redhat.com>
Sat, 21 Apr 2012 08:51:34 +0000 (10:51 +0200)
committerThomas Graf <tgraf@redhat.com>
Sat, 21 Apr 2012 08:51:34 +0000 (10:51 +0200)
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.

lib/cache_mngr.c

index 3c0e0245777c6f1c3759747b2d6349d72f1d40cb..7b75084c6c83b71a5ffc77e63cf363ae13342bad 100644 (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;
+
+       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_default(mngr->cm_handle);
+       err = nl_recvmsgs(mngr->cm_handle, cb);
+       nl_cb_put(cb);
        if (err < 0)
                return err;