1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2010 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
24 #include "pwmd_error.h"
26 static void *write_status_cb(void *arg
)
28 struct assuan_cmd_s
*data
= arg
;
32 pth_cancel_state(PTH_CANCEL_ENABLE
|PTH_CANCEL_ASYNCHRONOUS
, &old
);
33 rc
= assuan_write_status(data
->ctx
, data
->line
, data
->line2
);
34 pth_cancel_state(old
, NULL
);
39 gpg_error_t
send_status(assuan_context_t ctx
, status_msg_t which
,
40 const gchar
*fmt
, ...)
42 const gchar
*line
= NULL
;
43 gchar buf
[ASSUAN_LINELENGTH
+1];
47 struct assuan_cmd_s data
;
51 g_vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
62 line
= print_fmt(buf
, sizeof(buf
), "%i", cache_file_count());
67 MUTEX_LOCK(&cn_mutex
);
68 line
= print_fmt(buf
, sizeof(buf
), "%i", g_slist_length(cn_thread_list
));
69 MUTEX_UNLOCK(&cn_mutex
);
75 case STATUS_KEEPALIVE
:
80 line
= N_("Waiting for lock");
88 case STATUS_DECOMPRESS
:
89 status
= "DECOMPRESS";
97 log_write("%s %s", status
, line
);
104 rc
= do_assuan_command(ctx
, write_status_cb
, &data
);
108 void *client_msg_thread(void *arg
)
110 struct client_thread_s
*thd
= arg
;
111 pth_attr_t attr
= pth_attr_of(pth_self());
113 pth_attr_set(attr
, PTH_ATTR_NAME
, __FUNCTION__
);
114 pth_attr_destroy(attr
);
117 pth_event_t ev
= pth_event(PTH_EVENT_MSG
, thd
->mp
);
119 pth_cleanup_push(cleanup_ev_cb
, ev
);
121 MUTEX_LOCK(&thd
->mp_mutex
);
124 pth_message_t
*msg
= pth_msgport_get(thd
->mp
);
125 status_msg_t
*s
= msg
->m_data
;
128 MUTEX_UNLOCK(&thd
->mp_mutex
);
130 pth_cleanup_push(g_free
, s
);
131 rc
= send_status(thd
->cl
->ctx
, *s
, NULL
);
135 log_write("%s(%i): %s", __FILE__
, __LINE__
, pwmd_strerror(rc
));
136 pth_cancel(thd
->tid
);
140 MUTEX_LOCK(&thd
->mp_mutex
);
141 } while (pth_msgport_pending(thd
->mp
));
143 MUTEX_UNLOCK(&thd
->mp_mutex
);
150 void send_status_all(status_msg_t which
)
154 MUTEX_LOCK(&cn_mutex
);
155 pth_cleanup_push(cleanup_mutex_cb
, &cn_mutex
);
157 for (t
= g_slist_length(cn_thread_list
), i
= 0; i
< t
; i
++) {
158 struct client_thread_s
*cn
= g_slist_nth_data(cn_thread_list
, i
);
162 msg
= g_malloc0(sizeof(pth_message_t
));
165 log_write("%s(%i): %s", __FILE__
, __LINE__
, strerror(ENOMEM
));
170 m
= g_malloc(sizeof(status_msg_t
));
174 log_write("%s(%i): %s", __FILE__
, __LINE__
, strerror(ENOMEM
));
183 MUTEX_LOCK(&cn
->mp_mutex
);
184 pth_msgport_put(cn
->mp
, msg
);
185 MUTEX_UNLOCK(&cn
->mp_mutex
);