Main Page | Modules | Data Structures | File List | Data Fields | Related Pages

mntsend.c

00001 /***************************************************************************
00002  * CVSID: $Id: mntsend.c,v 1.10 2004/12/19 00:15:36 stefanb Exp $
00003  *
00004  * mntsend.c : Sending dbus signal to MNT daemon from devfs call
00005  *
00006  * Copyright (C) 2004 Stefan Bambach, <sbambach@gmx.net>
00007  *
00008  * Licensed under the GNU General Public License 2.0
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  **************************************************************************/
00025  
00026 #ifdef HAVE_CONFIG_H
00027 #  include <config.h>
00028 #endif
00029 
00030 #include <stdlib.h>
00031 
00032 #include "mntdbus.h"
00033 #include "mntsend.h"
00034 #include "errmanager.h"
00035 #include "libmnt/libmnt.h"
00036 #include "dbug_mem.h"
00037 
00038 
00039 
00054 void usage(void)
00055 {
00056     MSG_ERR("usage: mntsend <subsystem> <action> <devname>");
00057 }
00058 
00059 
00066 int main(int argc, char **argv)
00067 {
00068     DBusConnection *conn = NULL;
00069     char *subsystem = NULL;
00070     char *action = NULL;
00071     char *devname = NULL;
00072     int res = 0;
00073     
00074     // initialize error manager
00075     emInit(LOG_DEBUG, EM_TYPE_SYSLOG, NULL, NULL, NULL, "mntsend");
00076     
00077     // check parameter
00078     if (argc != 4) {
00079         usage();
00080         goto error;
00081     }
00082     
00083     // get parameter
00084     subsystem = argv[1];
00085     action = argv[2];
00086     devname = argv[3];
00087 
00088     // check handled types
00089     if (strcmp(subsystem, "block")!=0 && 
00090          strcmp(subsystem, "tty")!=0 &&
00091          strcmp(subsystem, "disc")!=0) {
00092         MSG_ERR("type '%s' not handled by mntsend (only 'tty', 'block' and 'disc').", subsystem);
00093         goto error;
00094     }
00095     
00096     // connect to dbus
00097     conn = mntdbus_init();
00098     if (conn == NULL) {
00099         MSG_ERR("Couldn't connect to dbus!");
00100         goto error;
00101     }
00102     
00103     // handle action
00104     if (strcmp(action, "add")==0) {
00105         if (mntdbus_add(conn, subsystem, devname) != 0) {
00106             MSG_ERR("Error sending add message");
00107             goto error;
00108         }
00109     } else if (strcmp(action, "remove")==0) {
00110         if (mntdbus_remove(conn, subsystem, devname) != 0) {
00111             MSG_ERR("Error sending remove message");
00112             goto error;
00113         }
00114     } else {
00115         MSG_ERR("Unknown ACTION '%s'.", action);
00116         goto error;
00117     }
00118     
00119     goto cleanup;
00120     
00121 error:
00122     if (conn!=NULL) {
00123         mntdbus_quit(conn);
00124         conn = NULL;
00125     }
00126     res = -1;
00127     
00128 cleanup:    
00129     return res;
00130 }
00131 
00132 

Generated on Wed Mar 30 13:43:27 2005 for Mntd by  doxygen 1.3.9.1