}
static int
-block(char *cmd, char *action, char *device)
+block(char *cmd, char *action, char *device, int sync, struct uloop_process *process)
{
pid_t pid = fork();
- int ret = -1;
+ int ret = sync;
int status;
char *argv[5] = { 0 };
int a = 0;
break;
case 0:
+ uloop_end();
+
argv[a++] = "/sbin/block";
argv[a++] = cmd;
argv[a++] = action;
exit(EXIT_FAILURE);
default:
- waitpid(pid, &status, 0);
- ret = WEXITSTATUS(status);
- if (ret)
- ULOG_ERR("failed to run block. %s/%s\n", action, device);
+ if (!sync && process) {
+ process->pid = pid;
+ uloop_process_add(process);
+ } else if (sync) {
+ waitpid(pid, &status, 0);
+ ret = WEXITSTATUS(status);
+ if (ret)
+ ULOG_ERR("failed to run block. %s/%s\n", action, device);
+ }
break;
}
mp = _find_mount_point(device->name);
if (mp) {
- block("autofs", "remove", device->name);
+ block("autofs", "remove", device->name, 0, NULL);
free(mp);
}
device_mount_remove(ctx, old);
device_mount_add(ctx, device);
} else {
- block("mount", NULL, NULL);
+ block("mount", NULL, NULL, 0, NULL);
}
} else if (device->autofs) {
device_mount_add(ctx, device);
pkt = &pktu.missing_indirect;
ULOG_ERR("kernel is requesting a mount -> %s\n", pkt->name);
if (lstat(pkt->name, &st) == -1)
- if (block("autofs", "add", (char *)pkt->name))
+ if (block("autofs", "add", (char *)pkt->name, 1, NULL))
cmd = AUTOFS_IOC_FAIL;
if (ioctl(fd_autofs_write, cmd, pkt->wait_queue_token) < 0)
struct autofs_packet_expire pkt;
while (ioctl(fd_autofs_write, AUTOFS_IOC_EXPIRE, &pkt) == 0)
- block("autofs", "remove", pkt.name);
+ block("autofs", "remove", pkt.name, 1, NULL);
uloop_timeout_set(t, AUTOFS_EXPIRE_TIMER);
}
return 0;
}
-static void blockd_startup(struct uloop_timeout *t)
+static void blockd_startup_cb(struct uloop_process *p, int stat)
{
- block("autofs", "start", NULL);
send_block_notification(&conn.ctx, "ready", NULL);
}
+static struct uloop_process startup_process = {
+ .cb = blockd_startup_cb,
+};
+
+static void blockd_startup(struct uloop_timeout *t)
+{
+ block("autofs", "start", NULL, 0, &startup_process);
+}
+
struct uloop_timeout startup = {
.cb = blockd_startup,
};