158
161
void (*handler) (Mount *mnt, pid_t pid, int status);
164
typedef struct event_reply_data {
166
void (*handler) (void *data, NihDBusMessage *message);
162
169
Mount *new_mount (const char *mountpoint, const char *device,
163
170
int check, const char *type, const char *opts);
209
218
void mount_showthrough (Mount *root);
211
220
void upstart_disconnected (DBusConnection *connection);
212
void emit_event (const char *name, Mount *mnt);
221
void emit_event (const char *name, Mount *mnt,
222
void (*cb) (void *, NihDBusMessage *message));
213
223
void emit_event_error (void *data, NihDBusMessage *message);
215
225
void udev_monitor_watcher (struct udev_monitor *udev_monitor,
871
888
if (mnt->mount_opts)
872
889
nih_unref (mnt->mount_opts, mounts);
873
890
mnt->mount_opts = opts;
892
/* If remounted, treat as newly done mount below. */
893
if (needed_remount && !needs_remount (mnt))
894
mnt->mounted = FALSE;
875
897
mnt = new_mount (mountpoint, device, FALSE, type, opts);
876
898
mnt->mount_opts = opts;
879
901
if (sscanf (dev, "%d:%d", &maj, &min) == 2)
880
902
mnt->mounted_dev = makedev (maj, min);
882
if (reparsed && (! mnt->mounted)) {
907
/* Fully update mounted state if reparsed.
908
* If invoked first time, just set the flag and leave complete
909
* state update (including event trigger) to mark_mounted ().
911
if (reparsed && ! mnt->pending_call) {
885
914
mnt->mounted = TRUE;
1479
emit_event ("mounted", mnt);
1481
/* Any previous mount options no longer apply
1482
* (ie. we're not read-only anymore)
1484
if (mnt->mount_opts)
1485
nih_unref (mnt->mount_opts, mounts);
1486
mnt->mount_opts = NULL;
1488
if ((! written_mtab))
1493
num_local_mounted++;
1496
num_local_mounted++;
1497
num_timeout_mounted++;
1498
if (num_timeout_mounted == num_timeout) {
1499
nih_message (_("\n %s finished! "), "local_timeout");
1500
/* Stop the timeout waiting for device to get ready"
1502
if (device_ready_timer) {
1503
nih_free (device_ready_timer);
1504
device_ready_timer = NULL;
1509
num_remote_mounted++;
1512
num_virtual_mounted++;
1524
nih_assert_not_reached ();
1504
if (!mnt->pending_call)
1505
emit_event ("mounted", mnt, mounted_event_handled);
1529
1507
fsck_update ();
1597
1575
if ((! virtual_triggered)
1598
1576
&& (num_virtual_mounted == num_virtual)) {
1599
1577
nih_info (_("%s finished"), "virtual");
1600
emit_event ("virtual-filesystems", NULL);
1578
emit_event ("virtual-filesystems", NULL, NULL);
1601
1579
virtual_triggered = TRUE;
1679
1657
|| (! strncmp (mnt->device, "LABEL=", 6))))
1681
1659
nih_message ("%s device not ready in ROOTDELAY sec", MOUNT_NAME (mnt));
1682
emit_event ("device-not-ready", mnt);
1660
emit_event ("device-not-ready", mnt, NULL);
1728
/* All mounts have been attempted, so wait for
1731
NIH_LIST_FOREACH (mounts, iter) {
1732
Mount *mnt = (Mount *)iter;
1733
DBusPendingCall *pending_call = mnt->pending_call;
1738
dbus_pending_call_block (pending_call);
1739
dbus_pending_call_unref (pending_call);
1740
mnt->pending_call = NULL;
1750
1743
if (control_server) {
1751
1744
dbus_server_disconnect (control_server);
1752
1745
dbus_server_unref (control_server);
1855
/* Queue a filesystem check if not yet ready, otherwise run
1856
* swapon or mount as appropriate.
1851
/* Queue a filesystem check if not yet ready, otherwise emit mounting
1852
* event (callback will run swapon or mount as appropriate).
1858
1854
if ((! mnt->ready)
1859
1855
&& (! is_remote (mnt))) {
1860
1856
run_fsck (mnt);
1861
1857
} else if (! strcmp (mnt->type, "swap")) {
1862
emit_event ("mounting", mnt);
1858
nih_info ("mounting event sent for swap %s", mnt->device);
1859
emit_event ("mounting", mnt, mounting_event_handled);
1861
nih_info ("mounting event sent for %s", mnt->mountpoint);
1862
emit_event ("mounting", mnt, mounting_event_handled);
1868
mounting_event_handled (void *data,
1869
NihDBusMessage *message)
1871
Mount *mnt = ((EventReplyData *)data)->mnt;
1875
/* We may generate new pending events below; make sure to clear
1876
* the current one before we do. */
1877
mnt->pending_call = NULL;
1879
if (!strcmp(mnt->type, "swap")) {
1880
nih_info ("mounting event handled for swap %s", mnt->device);
1863
1881
run_swapon (mnt);
1865
emit_event ("mounting", mnt);
1883
nih_info ("mounting event handled for %s", mnt->mountpoint);
1866
1884
run_mount (mnt, FALSE);
1890
mounted_event_handled (void *data,
1891
NihDBusMessage *message)
1893
Mount *mnt = ((EventReplyData *)data)->mnt;
1897
/* We may generate new pending events below; make sure to clear
1898
* the current one before we do. */
1899
mnt->pending_call = NULL;
1901
mnt->mounted = TRUE;
1902
newly_mounted = TRUE;
1903
nih_main_loop_interrupt ();
1905
if (!strcmp(mnt->type, "swap")) {
1906
nih_info ("mounted event handled for swap %s", mnt->device);
1908
nih_info ("mounted event handled for %s", mnt->mountpoint);
1911
/* Any previous mount options no longer apply
1912
* (ie. we're not read-only anymore)
1914
if (mnt->mount_opts)
1915
nih_unref (mnt->mount_opts, mounts);
1916
mnt->mount_opts = NULL;
1918
if ((! written_mtab))
1920
if (written_mtab && mnt->needs_mtab)
1921
run_mount (mnt, TRUE);
1925
num_local_mounted++;
1928
num_local_mounted++;
1929
num_timeout_mounted++;
1930
if (num_timeout_mounted == num_timeout) {
1931
nih_message (_("\n %s finished! "), "local_timeout");
1932
/* Stop the timeout waiting for device to get ready"
1934
if (device_ready_timer) {
1935
nih_free (device_ready_timer);
1936
device_ready_timer = NULL;
1941
num_remote_mounted++;
1944
num_virtual_mounted++;
1956
nih_assert_not_reached ();
1872
1966
* find_on_path:
2127
2221
&& strcmp (mnt->type, "ntfs")
2128
2222
&& strcmp (mnt->type, "ntfs-3g")) {
2129
2223
NIH_MUST (nih_str_array_add (&args, NULL, &args_len, "-n"));
2224
mnt->needs_mtab = TRUE;
2130
2225
} else if (mnt->has_showthrough) {
2131
2226
NIH_MUST (nih_str_array_add (&args, NULL, &args_len, "-n"));
2568
2669
emit_event (const char *name,
2671
void (*cb) (void *, NihDBusMessage *message))
2571
2673
DBusPendingCall *pending_call;
2572
2674
nih_local char **env = NULL;
2573
2675
size_t env_len = 0;
2676
EventReplyData *reply_data = NULL;
2575
2678
nih_assert (name != NULL);
2609
2712
nih_discard (var);
2716
reply_data = NIH_MUST (nih_alloc (NULL, sizeof (EventReplyData)));
2612
2718
pending_call = NIH_SHOULD (upstart_emit_event (upstart,
2613
name, env, mnt ? TRUE : FALSE,
2614
NULL, emit_event_error, NULL,
2719
name, env, reply_data ? TRUE : FALSE,
2720
reply_data ? cb : NULL,
2721
emit_event_error, reply_data,
2615
2722
NIH_DBUS_TIMEOUT_NEVER));
2616
if (! pending_call) {
2728
reply_data->mnt = mnt;
2729
reply_data->handler = cb;
2731
/* If previous event is still pending, wait for it. */
2732
if (mnt->pending_call) {
2733
DBusPendingCall *pending = mnt->pending_call;
2734
dbus_pending_call_block (pending);
2735
dbus_pending_call_unref (pending);
2738
mnt->pending_call = pending_call;
2742
/* Immediate return from upstart, wait for it. */
2743
dbus_pending_call_block (pending_call);
2744
dbus_pending_call_unref (pending_call);
2619
2751
err = nih_error_get ();
2620
2752
nih_warn ("%s", err->message);
2621
2753
nih_free (err);
2755
nih_free (reply_data);
2626
dbus_pending_call_block (pending_call);
2628
dbus_pending_call_unref (pending_call);
2632
2760
emit_event_error (void * data,
2633
2761
NihDBusMessage *message)
2763
EventReplyData *reply_data = (EventReplyData *)data;
2637
2766
err = nih_error_get ();
2638
2767
nih_warn ("%s", err->message);
2639
2768
nih_free (err);
2770
/* Even if the event returned an error, we still want to do the mount */
2772
reply_data->handler (data, message);
3937
4070
nih_free (err);
3940
emit_event("mountallServer", NULL);
4073
emit_event("mountallServer", NULL, NULL);
3941
4074
/* Activate the timer for a fs that is local, unmounted and waits for
3942
4075
* a device to be ready, before it can be mounted onto it. Timer on
3943
4076
* only for fs not marked with a "nobootwait=1" */