Lines Matching defs:state
8 #include "login-proxy-state.h"
26 static int login_proxy_state_notify_open(struct login_proxy_state *state);
45 struct login_proxy_state *state;
47 state = i_new(struct login_proxy_state, 1);
48 state->pool = pool_alloconly_create("login proxy state", 1024);
49 hash_table_create(&state->hash, state->pool, 0,
51 state->notify_path = p_strdup(state->pool, notify_path);
52 state->notify_fd = -1;
53 return state;
56 static void login_proxy_state_close(struct login_proxy_state *state)
58 i_close_fd_path(&state->notify_fd, state->notify_path);
63 struct login_proxy_state *state = *_state;
70 iter = hash_table_iterate_init(state->hash);
71 while (hash_table_iterate(iter, state->hash, &rec, &rec))
75 timeout_remove(&state->to_reopen);
76 login_proxy_state_close(state);
77 hash_table_destroy(&state->hash);
78 pool_unref(&state->pool);
79 i_free(state);
83 login_proxy_state_get(struct login_proxy_state *state,
92 rec = hash_table_lookup(state->hash, &key);
94 rec = p_new(state->pool, struct login_proxy_record, 1);
97 hash_table_insert(state->hash, rec, rec);
102 static void login_proxy_state_reopen(struct login_proxy_state *state)
104 timeout_remove(&state->to_reopen);
105 (void)login_proxy_state_notify_open(state);
108 static int login_proxy_state_notify_open(struct login_proxy_state *state)
110 if (state->to_reopen != NULL) {
115 state->notify_fd = open(state->notify_path, O_WRONLY);
116 if (state->notify_fd == -1) {
117 i_error("open(%s) failed: %m", state->notify_path);
118 state->to_reopen = timeout_add(NOTIFY_RETRY_REOPEN_MSECS,
119 login_proxy_state_reopen, state);
122 fd_set_nonblock(state->notify_fd, TRUE);
126 static bool login_proxy_state_try_notify(struct login_proxy_state *state,
132 if (state->notify_fd == -1) {
133 if (login_proxy_state_notify_open(state) < 0)
135 i_assert(state->notify_fd != -1);
143 ret = write(state->notify_fd, cmd, len);
148 i_error("write(%s) failed: %m", state->notify_path);
151 state->notify_path);
153 login_proxy_state_close(state);
160 void login_proxy_state_notify(struct login_proxy_state *state,
163 if (!login_proxy_state_try_notify(state, user))
164 (void)login_proxy_state_try_notify(state, user);