s3-lib Move event_add_idle() to source3/lib/events.c
authorAndrew Bartlett <abartlet@samba.org>
Mon, 4 Jul 2011 08:52:47 +0000 (18:52 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 4 Jul 2011 08:53:59 +0000 (18:53 +1000)
This allows libauth not to depend on smbd_base.

Andrew Bartlett

source3/include/event.h
source3/lib/events.c
source3/smbd/process.c
source3/smbd/proto.h

index 1e5dfaba5e1585107360f0d23cc34430ec6ca7cd..fad5de7848c8970683e38936add92b6e606752bf 100644 (file)
@@ -2,7 +2,7 @@
    Unix SMB/CIFS implementation.
    event handling
    Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Volker Lendecke 2005
+   Copyright (C) Volker Lendecke 2005-2007
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -36,3 +36,11 @@ bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
                            int *ptimeout);
 bool run_events_poll(struct tevent_context *ev, int pollrtn,
                     struct pollfd *pfds, int num_pfds);
+
+struct idle_event *event_add_idle(struct event_context *event_ctx,
+                                 TALLOC_CTX *mem_ctx,
+                                 struct timeval interval,
+                                 const char *name,
+                                 bool (*handler)(const struct timeval *now,
+                                                 void *private_data),
+                                 void *private_data);
index f077f585812a5dce4ce5d899618dea1e0e2ad2d5..b0d3ce53626dede0caa6650574732d44ea8a880a 100644 (file)
@@ -2,7 +2,7 @@
    Unix SMB/CIFS implementation.
    Timed event library.
    Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Volker Lendecke 2005
+   Copyright (C) Volker Lendecke 2005-2007
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -456,3 +456,83 @@ struct tevent_context *s3_tevent_context_init(TALLOC_CTX *mem_ctx)
        return ev;
 }
 
+struct idle_event {
+       struct timed_event *te;
+       struct timeval interval;
+       char *name;
+       bool (*handler)(const struct timeval *now, void *private_data);
+       void *private_data;
+};
+
+static void smbd_idle_event_handler(struct event_context *ctx,
+                                   struct timed_event *te,
+                                   struct timeval now,
+                                   void *private_data)
+{
+       struct idle_event *event =
+               talloc_get_type_abort(private_data, struct idle_event);
+
+       TALLOC_FREE(event->te);
+
+       DEBUG(10,("smbd_idle_event_handler: %s %p called\n",
+                 event->name, event->te));
+
+       if (!event->handler(&now, event->private_data)) {
+               DEBUG(10,("smbd_idle_event_handler: %s %p stopped\n",
+                         event->name, event->te));
+               /* Don't repeat, delete ourselves */
+               TALLOC_FREE(event);
+               return;
+       }
+
+       DEBUG(10,("smbd_idle_event_handler: %s %p rescheduled\n",
+                 event->name, event->te));
+
+       event->te = event_add_timed(ctx, event,
+                                   timeval_sum(&now, &event->interval),
+                                   smbd_idle_event_handler, event);
+
+       /* We can't do much but fail here. */
+       SMB_ASSERT(event->te != NULL);
+}
+
+struct idle_event *event_add_idle(struct event_context *event_ctx,
+                                 TALLOC_CTX *mem_ctx,
+                                 struct timeval interval,
+                                 const char *name,
+                                 bool (*handler)(const struct timeval *now,
+                                                 void *private_data),
+                                 void *private_data)
+{
+       struct idle_event *result;
+       struct timeval now = timeval_current();
+
+       result = talloc(mem_ctx, struct idle_event);
+       if (result == NULL) {
+               DEBUG(0, ("talloc failed\n"));
+               return NULL;
+       }
+
+       result->interval = interval;
+       result->handler = handler;
+       result->private_data = private_data;
+
+       if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
+               DEBUG(0, ("talloc failed\n"));
+               TALLOC_FREE(result);
+               return NULL;
+       }
+
+       result->te = event_add_timed(event_ctx, result,
+                                    timeval_sum(&now, &interval),
+                                    smbd_idle_event_handler, result);
+       if (result->te == NULL) {
+               DEBUG(0, ("event_add_timed failed\n"));
+               TALLOC_FREE(result);
+               return NULL;
+       }
+
+       DEBUG(10,("event_add_idle: %s %p\n", result->name, result->te));
+       return result;
+}
+
index 39fd3d7cd19df29b60105d432fce6a3125bc3102..ca526267d28eb503db7c63338bc552f726c7438e 100644 (file)
@@ -844,86 +844,6 @@ bool push_deferred_open_message_smb(struct smb_request *req,
                                   private_data, priv_len);
 }
 
-struct idle_event {
-       struct timed_event *te;
-       struct timeval interval;
-       char *name;
-       bool (*handler)(const struct timeval *now, void *private_data);
-       void *private_data;
-};
-
-static void smbd_idle_event_handler(struct event_context *ctx,
-                                   struct timed_event *te,
-                                   struct timeval now,
-                                   void *private_data)
-{
-       struct idle_event *event =
-               talloc_get_type_abort(private_data, struct idle_event);
-
-       TALLOC_FREE(event->te);
-
-       DEBUG(10,("smbd_idle_event_handler: %s %p called\n",
-                 event->name, event->te));
-
-       if (!event->handler(&now, event->private_data)) {
-               DEBUG(10,("smbd_idle_event_handler: %s %p stopped\n",
-                         event->name, event->te));
-               /* Don't repeat, delete ourselves */
-               TALLOC_FREE(event);
-               return;
-       }
-
-       DEBUG(10,("smbd_idle_event_handler: %s %p rescheduled\n",
-                 event->name, event->te));
-
-       event->te = event_add_timed(ctx, event,
-                                   timeval_sum(&now, &event->interval),
-                                   smbd_idle_event_handler, event);
-
-       /* We can't do much but fail here. */
-       SMB_ASSERT(event->te != NULL);
-}
-
-struct idle_event *event_add_idle(struct event_context *event_ctx,
-                                 TALLOC_CTX *mem_ctx,
-                                 struct timeval interval,
-                                 const char *name,
-                                 bool (*handler)(const struct timeval *now,
-                                                 void *private_data),
-                                 void *private_data)
-{
-       struct idle_event *result;
-       struct timeval now = timeval_current();
-
-       result = talloc(mem_ctx, struct idle_event);
-       if (result == NULL) {
-               DEBUG(0, ("talloc failed\n"));
-               return NULL;
-       }
-
-       result->interval = interval;
-       result->handler = handler;
-       result->private_data = private_data;
-
-       if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
-               DEBUG(0, ("talloc failed\n"));
-               TALLOC_FREE(result);
-               return NULL;
-       }
-
-       result->te = event_add_timed(event_ctx, result,
-                                    timeval_sum(&now, &interval),
-                                    smbd_idle_event_handler, result);
-       if (result->te == NULL) {
-               DEBUG(0, ("event_add_timed failed\n"));
-               TALLOC_FREE(result);
-               return NULL;
-       }
-
-       DEBUG(10,("event_add_idle: %s %p\n", result->name, result->te));
-       return result;
-}
-
 static void smbd_sig_term_handler(struct tevent_context *ev,
                                  struct tevent_signal *se,
                                  int signum,
index adeaf688996ec22dfbb9e2c6a5dff727077a4574..ae63f0adf25eaf82584b0614306f318b6d45245a 100644 (file)
@@ -791,13 +791,6 @@ bool push_deferred_open_message_smb(struct smb_request *req,
                                struct file_id id,
                                char *private_data,
                                size_t priv_len);
-struct idle_event *event_add_idle(struct event_context *event_ctx,
-                                 TALLOC_CTX *mem_ctx,
-                                 struct timeval interval,
-                                 const char *name,
-                                 bool (*handler)(const struct timeval *now,
-                                                 void *private_data),
-                                 void *private_data);
 NTSTATUS allow_new_trans(struct trans_state *list, uint64_t mid);
 void reply_outbuf(struct smb_request *req, uint8 num_words, uint32 num_bytes);
 const char *smb_fn_name(int type);