00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00075 emInit(LOG_DEBUG, EM_TYPE_SYSLOG, NULL, NULL, NULL, "mntsend");
00076
00077
00078 if (argc != 4) {
00079 usage();
00080 goto error;
00081 }
00082
00083
00084 subsystem = argv[1];
00085 action = argv[2];
00086 devname = argv[3];
00087
00088
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
00097 conn = mntdbus_init();
00098 if (conn == NULL) {
00099 MSG_ERR("Couldn't connect to dbus!");
00100 goto error;
00101 }
00102
00103
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