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 <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033
00034 #include <libmnt/libmnt.h>
00035
00036 #define _GNU_SOURCE
00037 #include <getopt.h>
00038
00039 #include "errmanager.h"
00040 #include "mntd_hal.h"
00041 #include "mntd_file.h"
00042 #include "mntd_dbus_manager.h"
00043 #include "mntd_volume_manager.h"
00044 #include "main.h"
00045
00046
00047 PVOLUMEMANAGER vols = NULL;
00048
00049 void usage(void);
00050
00051
00062 void
00063 usage(void)
00064 {
00065 printf("Mount Daemon " PACKAGE_VERSION "\n");
00066 printf("Mounts devices automatically and unmount it again. It's meant\n");
00067 printf("to handle hotplug devices like USB storage or similar stuff.\n");
00068 printf("\n");
00069 printf("usage: mntd [-h] [-d] [-f configfile]\n");
00070 printf("\n");
00071 printf(" -h Help (this text)\n");
00072 printf(" -d Daemonize it\n");
00073 printf(" -f,--file Use given configfile\n");
00074 printf("\n");
00075 }
00076
00077
00084 int main(int argc, char* argv[])
00085 {
00086 GMainLoop* loop;
00087 char *config = NULL;
00088 int i=0;
00089 char *configfile = NULL;
00090 char *configfiles[] = {
00091 MNTD_CONF_DIR,
00092 "/etc/mntd/mntd.conf",
00093 "/etc/mntd.conf",
00094 "./mntd.conf",
00095 "../mntd.conf",
00096 NULL
00097 };
00098 int daemonize = FALSE;
00099
00100
00101 while(1) {
00102 int c;
00103 int option_index = 0;
00104 static struct option long_options[] = {
00105 {"help", no_argument, 0, 'h'},
00106 {"daemonize", no_argument, 0, 'd'},
00107 {"file", required_argument, 0, 'f'},
00108 {0, 0, 0, 0}
00109 };
00110 c = getopt_long (argc, argv, "hf:d", long_options, &option_index);
00111 if (c == -1) {
00112 break;
00113 }
00114 switch (c) {
00115 case 'd':
00116 daemonize = TRUE;
00117 break;
00118
00119 case 'f':
00120 config = optarg;
00121 break;
00122
00123 case 'h':
00124 usage();
00125 exit(0);
00126 break;
00127
00128 default:
00129 usage();
00130 exit(1);
00131 break;
00132 }
00133 }
00134
00135
00136 emInit(LOG_DEBUG, EM_TYPE_SYSLOG, NULL, NULL, NULL);
00137
00138
00139 MSG_INF("MNT daemon version " PACKAGE_VERSION " starting up");
00140
00141
00142 if (config == NULL) {
00143 MSG_DEBUG("No config file specified. trying to find it.");
00144 i=0;
00145 while (configfiles[i]!=NULL) {
00146 configfile = configfiles[i];
00147 MSG_DEBUG("trying '%s' ...", configfile);
00148 if (mntd_file_is_file(configfile)) {
00149 MSG_DEBUG("found '%s'", configfile);
00150 config = configfile;
00151 break;
00152 }
00153 i++;
00154 }
00155 }
00156
00157 if (config == NULL) {
00158 MSG_EMERG("No config file given and nothing found. exiting.");
00159 exit(1);
00160 }
00161 if (!mntd_file_is_file(config)) {
00162 MSG_EMERG("Config file '%s' cannot be accessed.", config);
00163 exit(1);
00164 }
00165
00166
00167 if (daemonize==TRUE) {
00168 MSG_INF("daemonize not implemented yet -> ignored");
00169 }
00170
00171
00172 vols = new_VolumeManager(config);
00173 if (vols == NULL) {
00174 MSG_EMERG("Couldn't not initialize system.");
00175 exit(1);
00176 }
00177
00178 loop = g_main_loop_new(NULL, FALSE);
00179
00180
00181 mntd_dbus_init(vols);
00182
00183
00184 mntd_hal_init();
00185
00186
00187 vols->rescan(vols);
00188
00189
00190 g_main_loop_run(loop);
00191
00192
00193 mntd_hal_shutdown();
00194
00195
00196 mntd_dbus_quit();
00197
00198
00199 g_assert(vols!=NULL);
00200 vols->destroy(vols);
00201
00202
00203 MSG_INF("MNT daemon version " PACKAGE_VERSION " exited.");
00204
00205 return 0;
00206 }
00207