static int do_dm_close (const char *path) { struct dm_ioctl dm = { .version = { DM_VERSION_MAJOR, DM_VERSION_MINOR, DM_VERSION_PATCHLEVEL }, .data_size = sizeof (dm) }; struct stat st; int fd; int r; verbose_do ("Removing block device ", path); if (stat (path, &st) < 0) { verbose_fail (errno); return -1; } dm.dev = st.st_rdev; fd = open_write ("/dev/mapper/control"); if (fd < 0) { verbose_fail (errno); return -1; } r = ioctl (fd, DM_DEV_REMOVE, &dm); if (r < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Block device removed", path, 1); fd_close (fd); return r; }
static void umount_api (const char *path) { verbose_do ("Unmounting ", path); if (umount2 (path, 0) < 0 && umount2 (path, MNT_DETACH) < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Unmounted", path, 1); }
static int do_umount (const char *path) { int r; verbose_do ("Unmounting ", path); r = umount2 (path, umnt_flags); if (r < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Unmounted", path, 1); return r; }
static int do_swapoff (const char *path) { int r; verbose_do ("Turning off swap on ", path); r = swapoff (path); if (r < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Swap turned off", path, 1); return r; }
static int do_loop_close (const char *path) { int fd; int r; verbose_do ("Closing loop device ", path); fd = open_read (path); if (fd < 0) { verbose_fail (errno); return -1; } r = ioctl (fd, LOOP_CLR_FD, 0); if (r < 0) verbose_fail (errno); else if (level > 0) aa_put_title (0, "Loop device closed", path, 1); fd_close (fd); return r; }
static void reset_service (const char *name, intptr_t mode) { aa_service *s; int si; int r; int old_event; int event; r = aa_get_service (name, &si, 1); if (r < 0) { aa_put_err (name, errmsg[-r], 1); return; } r = aa_preload_service (si); if (r < 0) { aa_put_err (name, errmsg[-r], 1); return; } s = aa_service (si); if (aa_service_status_read (&s->st, aa_service_name (s)) < 0 && errno != ENOENT) { int e = errno; aa_put_err (name, "Failed to read service status file: ", 0); aa_bs_noflush (AA_ERR, error_str (e)); aa_end_err (); return; } if (s->st.type == AA_TYPE_LONGRUN) { aa_put_err (name, "Can only reset ont-shot services", 1); return; } /* Starting/Stopping cannot be reset */ if (s->st.event == AA_EVT_STARTING || s->st.event == AA_EVT_STOPPING) return; if (mode == MODE_AUTO) { if (s->st.event == AA_EVT_STARTING_FAILED || s->st.event == AA_EVT_START_FAILED) event = AA_EVT_STARTED; else if (s->st.event == AA_EVT_STOPPING_FAILED || s->st.event == AA_EVT_STOP_FAILED) event = AA_EVT_STOPPED; else return; } else event = (mode == MODE_STARTED) ? AA_EVT_STARTED : AA_EVT_STOPPED; if (s->st.event == event) return; tain_now_g (); old_event = s->st.event; s->st.event = event; s->st.stamp = STAMP; aa_service_status_set_msg (&s->st, ""); if (aa_service_status_write (&s->st, aa_service_name (s)) < 0) { int e = errno; aa_put_err (name, "Failed to write service status file: ", 0); aa_bs_noflush (AA_ERR, error_str (e)); aa_end_err (); } else { aa_put_title (1, name, "", 0); aa_is_noflush (AA_OUT, ANSI_HIGHLIGHT_OFF); aa_bs_noflush (AA_OUT, eventmsg[old_event]); aa_is_noflush (AA_OUT, ANSI_HIGHLIGHT_ON); aa_bs_noflush (AA_OUT, " -> "); aa_bs_noflush (AA_OUT, eventmsg[event]); aa_end_title (); } }