~fourmond/pmount/pmount-new

« back to all changes in this revision

Viewing changes to src/pumount.c

  • Committer: martin at piware
  • Date: 2007-01-11 15:30:39 UTC
  • Revision ID: martin@piware.de-20070111153039-6stkvny0z9n57zrq
fix dbus connection: we cannot close a shared connection

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    "  are met (see pumount(1) for details). The mount point directory is removed\n"
46
46
    "  afterwards.\n\n"
47
47
    "Options:\n"
48
 
    "  -l, --lazy   : umount lazily, see umount(8)\n"
49
 
    "  --luks-force : luksClose devices pmount didn't open\n"
50
 
    "  -d, --debug  : enable debug output (very verbose)\n"
51
 
    "  -h, --help   : print help message and exit successfuly\n"
52
 
    "  --version    : print version number and exit successfully\n"),
 
48
    "  -l, --lazy  : umount lazily, see umount(8)\n"
 
49
    "  -d, --debug : enable debug output (very verbose)\n"
 
50
    "  -h, --help  : print help message and exit successfuly\n"
 
51
    "  --version   : print version number and exit successfully\n"),
53
52
        exename, MEDIADIR );
54
53
}
55
54
 
63
62
check_umount_policy( const char* device, int do_lazy ) 
64
63
{
65
64
    int devvalid;
66
 
    char mediadir[PATH_MAX];
67
65
 
68
66
    devvalid = ( do_lazy || device_valid( device ) ) &&
69
67
        device_mounted( device, 1, mntpt );
77
75
        exit( E_INTERNAL );
78
76
    }
79
77
 
80
 
    /* MEDIADIR may be a symlink (for read-only root systems) */
81
 
    if( NULL == realpath( MEDIADIR, mediadir ) ) {
82
 
        fprintf( stderr, _("Error: could not find real path of %s\n"),
83
 
                MEDIADIR );
84
 
        exit( E_INTERNAL );
85
 
    }
86
 
 
87
78
    /* mount point must be below MEDIADIR */
88
 
    if( strncmp( mntpt, mediadir, strlen( mediadir ) ) ) {
 
79
    if( strncmp( mntpt, MEDIADIR, sizeof( MEDIADIR )-1 ) ) {
89
80
        fprintf( stderr, _("Error: mount point %s is not below %s\n"), mntpt,
90
81
                MEDIADIR );
91
82
        return -1;
101
92
 * @param lazy 0 for normal umount, 1 for lazy umount
102
93
 */
103
94
void
104
 
do_umount_fstab( const char* device, int lazy, const char * fstab_mntpt )
 
95
do_umount_fstab( const char* device, int lazy )
105
96
{
106
97
    /* drop all privileges */
107
98
    get_root();
111
102
    }
112
103
 
113
104
    debug( "device %s handled by fstab, calling umount\n", device );
114
 
    if(! strncmp(device, "LABEL=", 6) || ! strncmp(device, "UUID=", 5)) {
115
 
      debug( "'%s' is a label/uuid specification, using mount point %s to umount\n",
116
 
             device, fstab_mntpt);
117
 
      device = fstab_mntpt;     /* device is now the mount point */
118
 
    }
119
105
 
120
106
    if( lazy )
121
107
        execl( UMOUNTPROG, UMOUNTPROG, "-l", device, NULL );
157
143
{
158
144
    char device[PATH_MAX], mntptdev[PATH_MAX], path[PATH_MAX];
159
145
    const char* fstab_device;
160
 
    char fstab_mntpt[MEDIA_STRING_SIZE]; 
161
146
    int is_real_path = 0;
162
147
    int do_lazy = 0;
163
 
    int luks_force = 0;
164
148
 
165
149
    int  option;
166
150
    static struct option long_opts[] = {
167
151
        { "help", 0, NULL, 'h'},
168
152
        { "debug", 0, NULL, 'd'},
169
153
        { "lazy", 0, NULL, 'l'},
170
 
        { "luks-force", 0, NULL, 'L'},
171
154
        { "version", 0, NULL, 'V' },
172
155
        { NULL, 0, NULL, 0}
173
156
    };
198
181
 
199
182
            case 'l':        do_lazy = 1; break;
200
183
 
201
 
            case 'L':        luks_force = 1; break;
202
 
 
203
184
            case 'V': puts(VERSION); return 0;
204
185
 
205
186
            default:
239
220
    }
240
221
 
241
222
    /* is the device already handled by fstab? */
242
 
    fstab_device = fstab_has_device( "/etc/fstab", device, fstab_mntpt, NULL );
 
223
    fstab_device = fstab_has_device( "/etc/fstab", device, NULL, NULL );
243
224
    if( fstab_device ) {
244
 
        do_umount_fstab( fstab_device, do_lazy, fstab_mntpt );
 
225
        do_umount_fstab( fstab_device, do_lazy );
245
226
        return E_EXECUMOUNT;
246
227
    }
247
228
 
248
229
    /* we cannot really check the real path when unmounting lazily since the
249
230
     * device node might not exist any more */
250
231
    if( !is_real_path && !do_lazy ) {
251
 
        /* try to prepend '/dev' */
252
 
        if( strncmp( device, DEVDIR, sizeof( DEVDIR )-1 ) ) { 
253
 
            char d[PATH_MAX];
254
 
            snprintf( d, sizeof( d ), "%s%s", DEVDIR, device );
255
 
            if ( !realpath( d, device ) ) {
256
 
                perror( _("Error: could not determine real path of the device") );
257
 
                return E_DEVICE;
258
 
            }
259
 
            debug( "trying to prepend '" DEVDIR 
260
 
                   "' to device argument, now '%s'\n", device );
261
 
            /* We need to lookup again in fstab: */
262
 
            fstab_device = fstab_has_device( "/etc/fstab", device, 
263
 
                                             fstab_mntpt, NULL );
264
 
            if( fstab_device ) {
265
 
              do_umount_fstab( fstab_device, do_lazy, fstab_mntpt );
266
 
              return E_EXECUMOUNT;
267
 
            }
268
 
        }
 
232
        perror( _("Error: could not determine real path of the device") );
 
233
        return E_DEVICE;
269
234
    }
270
235
 
271
236
    /* does the device start with DEVDIR? */
286
251
        return E_EXECUMOUNT;
287
252
 
288
253
    /* release LUKS device, if appropriate */
289
 
    luks_release( device, 1 );
 
254
    luks_release( device );
290
255
 
291
256
    /* delete mount point */
292
257
    remove_pmount_mntpt( mntpt );