[Pkg-privacy-commits] [irssi-plugin-otr] 09/267: Better handling of key generation. Now monitoring the child via g_child_watch_add for termination.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:11 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.
commit 9b5771756b7106ad3934a2e72ed358dc51b5771d
Author: Uli Meis <a.sporto+bee at gmail.com>
Date: Thu Jun 5 02:30:49 2008 +0200
Better handling of key generation. Now monitoring the child via
g_child_watch_add for termination.
---
CMakeLists.txt | 9 +++++++
formats.txt | 6 +++++
otr.c | 8 ++++--
otr_key.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 96 insertions(+), 7 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 898b471..c7cd44e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,7 @@ PROJECT(IRSSIOTR)
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-extensions/)
INCLUDE(cmake-extensions/cscope.cmake)
+INCLUDE(CheckFunctionExists)
# GLIB
@@ -81,6 +82,14 @@ SET(IRSSIOTR_INCLUDE_DIRS
include_directories(${IRSSIOTR_INCLUDE_DIRS})
+# check for strsignal
+
+CHECK_FUNCTION_EXISTS(strsignal HAVE_STRSIGNAL)
+IF(HAVE_STRSIGNAL)
+ SET_SOURCE_FILES_PROPERTIES(otr_key.c PROPERTIES COMPILE_FLAGS
+ "-DHAVE_STRSIGNAL")
+ENDIF(HAVE_STRSIGNAL)
+
# defs
ADD_DEFINITIONS(-DHAVE_CONFIG_H -Wall -g)
diff --git a/formats.txt b/formats.txt
index 97b26a8..785d7de 100644
--- a/formats.txt
+++ b/formats.txt
@@ -7,6 +7,12 @@ kg_mkdir created directory %s
kg_pipe Key generation for %s: error creating pipe: %s
kg_fork Key generation for %s: fork() error: %s
kg_initiated Key generation for %s: initiated. This might take several minutes or on some systems even an hour. If you wanna check that something is happening, see if there are two irssi processes.
+kg_exited Key generation for %s: child terminated for unknown reason
+kg_exitsig Key generation for %s: child was killed by signal %s
+kg_pollerr Key generation for %s: error poll()ing child: %s
+kg_abort Key generation for %s: aborted
+kg_needacc I need an account name. Try something like /otr genkey mynick at irc.server.net
+kg_noabort No ongoing key generation to abort
key_not_found no private keys found
key_loaded private keys loaded
key_load_error Error loading private keys: %s (%s)
diff --git a/otr.c b/otr.c
index fc335cd..ccf6e79 100644
--- a/otr.c
+++ b/otr.c
@@ -88,8 +88,12 @@ static void cmd_trust(const char *data, void *server, WI_ITEM_REC *item)
*/
static void cmd_genkey(const char *data, void *server, WI_ITEM_REC *item)
{
- //TODO check data
- keygen_run(data);
+ if (strcmp(data,"abort")==0)
+ keygen_abort();
+ else if (strchr(data,'@'))
+ keygen_run(data);
+ else
+ otr_noticest(TXT_KG_NEEDACC);
}
/*
diff --git a/otr_key.c b/otr_key.c
index aa355f9..48e5128 100644
--- a/otr_key.c
+++ b/otr_key.c
@@ -17,9 +17,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
*/
+#define _GNU_SOURCE
+
#include "otr.h"
#include <libgen.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/poll.h>
+#include <signal.h>
extern OtrlUserState otr_state;
@@ -31,9 +37,51 @@ struct {
char *protocol;
time_t started;
GIOChannel *ch[2];
- guint eid;
+ guint cpid,cwid;
+ pid_t pid;
} kg_st = {.status = KEYGEN_NO };
+void keygen_childwatch(GPid pid,gint status, gpointer data) {
+ struct pollfd pfd = {
+ .fd = g_io_channel_unix_get_fd(kg_st.ch[0]),
+ .events = POLLIN };
+ int ret;
+
+ /* nothing to do if keygen_complete has already been called */
+ if (data)
+ return;
+
+ kg_st.pid = 0;
+
+ ret = poll(&pfd,1,0);
+
+ /* data is there, let's wait for keygen_complete to be called */
+ if (ret == 1)
+ return;
+
+ /* no data, report error and reset kg_st */
+ if (ret==0) {
+ if (WIFSIGNALED(status)) {
+ char sigstr[16];
+
+ sprintf(sigstr,
+#ifndef HAVE_STRSIGNAL
+ "%d",WTERMSIG(status));
+#else
+ "%s",strsignal(WTERMSIG(status)));
+#endif
+ otr_noticest(TXT_KG_EXITSIG,
+ kg_st.accountname,
+ sigstr);
+ }
+ else
+ otr_noticest(TXT_KG_EXITED,kg_st.accountname);
+ } else if (ret==-1)
+ otr_noticest(TXT_KG_POLLERR,kg_st.accountname,strerror(errno));
+
+ keygen_abort();
+}
+
/*
* Installed as g_io_watch and called when the key generation
* process finishs.
@@ -64,6 +112,9 @@ gboolean keygen_complete(GIOChannel *source, GIOCondition condition,
key_load();
}
+ g_source_remove(kg_st.cwid);
+ kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1);
+
kg_st.status = KEYGEN_NO;
g_free(kg_st.accountname);
@@ -125,11 +176,15 @@ void keygen_run(const char *accname)
}
kg_st.status = KEYGEN_RUNNING;
+ kg_st.pid = ret;
+
otr_noticest(TXT_KG_INITIATED,
accname);
- kg_st.eid = g_io_add_watch(kg_st.ch[0], G_IO_IN,
- (GIOFunc) keygen_complete, NULL);
+ kg_st.cpid = g_io_add_watch(kg_st.ch[0], G_IO_IN,
+ (GIOFunc) keygen_complete, NULL);
+ kg_st.cwid = g_child_watch_add(kg_st.pid,keygen_childwatch,NULL);
+
kg_st.started = time(NULL);
return;
}
@@ -148,8 +203,23 @@ void keygen_run(const char *accname)
*/
void keygen_abort()
{
- if (kg_st.status==KEYGEN_RUNNING)
- g_source_remove(kg_st.eid);
+ if (kg_st.status!=KEYGEN_RUNNING) {
+ otr_noticest(TXT_KG_NOABORT);
+ return;
+ }
+
+ otr_noticest(TXT_KG_ABORT,kg_st.accountname);
+
+ g_source_remove(kg_st.cpid);
+ g_source_remove(kg_st.cwid);
+ g_free(kg_st.accountname);
+
+ if (kg_st.pid!=0) {
+ kill(kg_st.pid,SIGTERM);
+ g_child_watch_add(kg_st.pid,keygen_childwatch,(void*)1);
+ }
+
+ kg_st.status = KEYGEN_NO;
}
/*
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git
More information about the Pkg-privacy-commits
mailing list