1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2011 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
28 #include "pwmd_error.h"
30 static void *write_status_cb(void *arg
)
32 struct assuan_cmd_s
*data
= arg
;
36 pth_cancel_state(PTH_CANCEL_ENABLE
|PTH_CANCEL_ASYNCHRONOUS
, &old
);
37 rc
= g_malloc(sizeof(gpg_error_t
));
38 *rc
= assuan_write_status(data
->ctx
, data
->line
, data
->line2
);
39 pth_cancel_state(old
, NULL
);
44 gpg_error_t
send_status(assuan_context_t ctx
, status_msg_t which
,
45 const gchar
*fmt
, ...)
47 const gchar
*line
= NULL
;
48 gchar buf
[ASSUAN_LINELENGTH
+1];
52 struct assuan_cmd_s data
;
56 g_vsnprintf(buf
, sizeof(buf
), fmt
, ap
);
67 line
= print_fmt(buf
, sizeof(buf
), "%i", cache_file_count());
72 MUTEX_LOCK(&cn_mutex
);
73 line
= print_fmt(buf
, sizeof(buf
), "%i", g_slist_length(cn_thread_list
));
74 MUTEX_UNLOCK(&cn_mutex
);
82 line
= _("Waiting for lock");
90 case STATUS_DECOMPRESS
:
91 status
= "DECOMPRESS";
102 log_write("%s %s", status
, line
);
109 rc
= do_assuan_command(ctx
, write_status_cb
, &data
);
113 void *client_msg_thread(void *arg
)
115 struct client_thread_s
*thd
= arg
;
116 pth_attr_t attr
= pth_attr_of(pth_self());
118 pth_attr_set(attr
, PTH_ATTR_NAME
, __FUNCTION__
);
119 pth_attr_destroy(attr
);
122 pth_event_t ev
= pth_event(PTH_EVENT_MSG
, thd
->mp
);
124 pth_cleanup_push(cleanup_ev_cb
, ev
);
126 MUTEX_LOCK(&thd
->mp_mutex
);
129 pth_message_t
*msg
= pth_msgport_get(thd
->mp
);
130 status_msg_t
*s
= msg
->m_data
;
133 MUTEX_UNLOCK(&thd
->mp_mutex
);
135 pth_cleanup_push(g_free
, s
);
136 rc
= send_status(thd
->cl
->ctx
, *s
, NULL
);
140 log_write("%s(%i): %s", __FILE__
, __LINE__
, pwmd_strerror(rc
));
141 pth_cancel(thd
->tid
);
145 MUTEX_LOCK(&thd
->mp_mutex
);
146 } while (pth_msgport_pending(thd
->mp
));
148 MUTEX_UNLOCK(&thd
->mp_mutex
);
155 void send_status_all(status_msg_t which
)
159 MUTEX_LOCK(&cn_mutex
);
160 pth_cleanup_push(cleanup_mutex_cb
, &cn_mutex
);
162 for (t
= g_slist_length(cn_thread_list
), i
= 0; i
< t
; i
++) {
163 struct client_thread_s
*cn
= g_slist_nth_data(cn_thread_list
, i
);
167 msg
= g_malloc0(sizeof(pth_message_t
));
170 log_write("%s(%i): %s", __FILE__
, __LINE__
, pwmd_strerror(GPG_ERR_ENOMEM
));
175 m
= g_malloc(sizeof(status_msg_t
));
179 log_write("%s(%i): %s", __FILE__
, __LINE__
, pwmd_strerror(GPG_ERR_ENOMEM
));
188 MUTEX_LOCK(&cn
->mp_mutex
);
189 pth_msgport_put(cn
->mp
, msg
);
190 MUTEX_UNLOCK(&cn
->mp_mutex
);