• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

src/xmms/compat/signal_unix.c

Go to the documentation of this file.
00001 /*  XMMS2 - X Music Multiplexer System
00002  *  Copyright (C) 2003-2009 XMMS2 Team
00003  *
00004  *  PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Lesser General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2.1 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Lesser General Public License for more details.
00015  */
00016 
00017 
00018 
00019 
00020 /** @file
00021  * Takes care of unix-signals.
00022  */
00023 
00024 
00025 #include "xmmspriv/xmms_signal.h"
00026 #include "xmms/xmms_log.h"
00027 #include "xmms/xmms_object.h"
00028 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <signal.h>
00032 #include <string.h>
00033 #include <glib.h>
00034 #include <unistd.h>
00035 
00036 
00037 static gpointer
00038 sigwaiter (gpointer data)
00039 {
00040     xmms_object_t *obj = (xmms_object_t *) data;
00041     xmms_object_cmd_arg_t arg;
00042     sigset_t signals;
00043     int caught;
00044 
00045     memset (&signals, 0, sizeof (sigset_t));
00046     sigaddset (&signals, SIGINT);
00047     sigaddset (&signals, SIGTERM);
00048 
00049     while (1337) {
00050         sigwait (&signals, &caught);
00051 
00052         switch (caught){
00053             case SIGINT:
00054             case SIGTERM:
00055                 pthread_sigmask (SIG_UNBLOCK, &signals, NULL);
00056 
00057                 xmms_log_info ("Bye!");
00058 
00059                 xmms_object_cmd_arg_init (&arg);
00060                 memset (&arg, 0, sizeof (arg));
00061                 xmms_error_reset (&arg.error);
00062                 xmms_object_cmd_call (obj, XMMS_IPC_CMD_QUIT, &arg);
00063                 break;
00064         }
00065     }
00066 }
00067 
00068 void
00069 xmms_signal_block (void)
00070 {
00071     sigset_t signals;
00072 
00073     memset (&signals, 0, sizeof (sigset_t));
00074 
00075     sigaddset (&signals, SIGHUP);
00076     sigaddset (&signals, SIGTERM);
00077     sigaddset (&signals, SIGINT);
00078     sigaddset (&signals, SIGPIPE);
00079 
00080     pthread_sigmask (SIG_BLOCK, &signals, NULL);
00081 }
00082 
00083 void
00084 xmms_signal_init (xmms_object_t *obj)
00085 {
00086     g_thread_create (sigwaiter, obj, FALSE, NULL);
00087 }

Generated on Wed Feb 9 2011 for XMMS2 by  doxygen 1.7.1