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 #include <glib.h>
00032
00033 #include "mntdbus.h"
00034 #include "mntudev.h"
00035 #include "errmanager.h"
00036 #include "libmnt/libmnt.h"
00037 #include "dbug_mem.h"
00038
00039
00057 int main(int argc, char **argv)
00058 {
00059 DBusConnection *conn = NULL;
00060 char *subsystem = NULL;
00061 char *action = NULL;
00062 char *devname = NULL;
00063 char *devpath = NULL;
00064 gchar **gparts = NULL;
00065 gchar **gparts_it = NULL;
00066 int gparts_idx = 0;
00067 int res = 0;
00068
00069
00070 emInit(LOG_DEBUG, EM_TYPE_SYSLOG, NULL, NULL, NULL, "mntudev");
00071
00072
00073 devpath = mntdbus_getenv("DEVPATH");
00074 if (devpath == NULL) {
00075 goto error;
00076 }
00077
00078
00079 action = mntdbus_getenv("ACTION");
00080 if (action == NULL) {
00081 goto error;
00082 }
00083
00084
00085 devname = mntdbus_getenv("DEVNAME");
00086 if (devname == NULL) {
00087 goto error;
00088 }
00089
00090
00091 gparts = g_strsplit(devpath, G_DIR_SEPARATOR_S, 0);
00092 if (gparts == NULL) {
00093 MSG_ERR("Out of memory.");
00094 goto error;
00095 }
00096 gparts_it = gparts;
00097 while (*gparts_it != NULL) {
00098
00099 if (gparts_idx == 1) {
00100 subsystem = *gparts_it;
00101 }
00102 gparts_it++;
00103 gparts_idx++;
00104 }
00105 if (subsystem == NULL) {
00106 MSG_ERR("DEVPATH '%s' in invalid.", devpath);
00107 goto error;
00108 }
00109
00110
00111 if (strcmp(subsystem, "block")!=0 &&
00112 strcmp(subsystem, "tty")!=0 &&
00113 strcmp(subsystem, "disc")!=0) {
00114 MSG_ERR("type '%s' not handled by mntudev (only 'tty', 'block' and 'disc').", subsystem);
00115 goto error;
00116 }
00117
00118
00119 conn = mntdbus_init();
00120 if (conn == NULL) {
00121 MSG_ERR("Couldn't connect to dbus!");
00122 goto error;
00123 }
00124
00125
00126 if (strcmp(action, "add")==0) {
00127 if (mntdbus_add(conn, subsystem, devname) != 0) {
00128 MSG_ERR("Error sending add message");
00129 goto error;
00130 }
00131 } else if (strcmp(action, "remove")==0) {
00132 if (mntdbus_remove(conn, subsystem, devname) != 0) {
00133 MSG_ERR("Error sending remove message");
00134 goto error;
00135 }
00136 } else {
00137 MSG_ERR("Unknown ACTION '%s'.", action);
00138 goto error;
00139 }
00140
00141 goto cleanup;
00142
00143 error:
00144 if (conn!=NULL) {
00145 mntdbus_quit(conn);
00146 conn = NULL;
00147 }
00148 res = -1;
00149
00150 cleanup:
00151 if (gparts != NULL) {
00152 g_strfreev(gparts);
00153 gparts = NULL;
00154 }
00155
00156 return res;
00157 }
00158
00159