summaryrefslogtreecommitdiff
path: root/src/worker.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-11-30 11:14:49 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-11-30 11:14:49 +0100
commit1cb35fad9924bfa1ae33a6e6aff2e6c5d5b5f454 (patch)
tree73436ccf68e99d06eecac75136a0b1bb83a83291 /src/worker.c
parent7f10a53e805f26f3c6e0cceea5569b40a43af275 (diff)
downloadbiruda-1cb35fad9924bfa1ae33a6e6aff2e6c5d5b5f454.tar.gz
biruda-1cb35fad9924bfa1ae33a6e6aff2e6c5d5b5f454.tar.bz2
worker data (glib-specific) is stored in worker structures
Diffstat (limited to 'src/worker.c')
-rw-r--r--src/worker.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/worker.c b/src/worker.c
index 4d2db69..f70f84b 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -8,6 +8,9 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+
+#include <signal.h>
const char *worker_exection_mode_str( worker_execution_mode_t mode )
{
@@ -30,15 +33,21 @@ worker_execution_mode_t worker_execution_mode_from_str( const char *s )
}
}
+typedef struct {
+ GPid pid;
+ gint out, err;
+} direct_glib_execution_worker_data_t;
+
int worker_init( worker_t *worker )
{
gchar *argv[] = { worker->command, NULL };
- GPid pid;
- gint out, err;
+ worker->execution_data = malloc( sizeof( direct_glib_execution_worker_data_t ) );
+ direct_glib_execution_worker_data_t *wed =
+ (direct_glib_execution_worker_data_t *)worker->execution_data;
gboolean ret = g_spawn_async_with_pipes( NULL,
argv, NULL, 0, NULL,
- NULL, &pid, NULL, &out, &err, NULL );
+ NULL, &wed->pid, NULL, &wed->out, &wed->err, NULL );
if( !ret ) {
g_error( "Starting worker failed" );
return -1;
@@ -47,8 +56,17 @@ int worker_init( worker_t *worker )
return 0;
}
-void worker_terminate( )
+void worker_terminate( worker_t *worker )
{
+ direct_glib_execution_worker_data_t *wed = (direct_glib_execution_worker_data_t *)worker->execution_data;
+
+#ifndef _WIN32
+ kill( wed->pid, SIGTERM );
+#else
+#error TODO kill on Windows
+#endif
+ free( worker->execution_data );
+ worker->execution_data = NULL;
}
int worker_free( )