/* * * This file is part of bufferpool * * Copyright (C) 2007 by LScube team * See AUTHORS for more details * * bufferpool is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * bufferpool is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with bufferpool; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include #include #include /*! @brief This function destroys the shared memory object. * Firstly it unlinks the shm objects referenced in buffer and * then unlink them thus removing them from system. * It doesn't stop on the first error, but completes all operations * and returns the code of first error. * @return 0 on succes or the number of the first error occurred. * */ int bp_shm_destroy(BPBuffer * buffer) { int unmap_err, shm_unlink_err = 0; char *shm_file_name; unmap_err = bp_shm_unmap(buffer); if (! (shm_file_name = bp_ipc_name(buffer->filename, BPBUFF_SHM_CTRLNAME))) return 1; if (shm_unlink(shm_file_name)) { switch (errno) { case ENOENT: bp_log(FNC_LOG_ERR, "SHM Object %s doesn't exists\n"); break; case EACCES: bp_log(FNC_LOG_ERR, "Permission denied on SHM Object %s\n"); break; default: bp_log(FNC_LOG_ERR, "Could not unlink SHM Object %s\n"); break; } shm_unlink_err = errno; } free(shm_file_name); if (! (shm_file_name = bp_ipc_name(buffer->filename, BPBUFF_SHM_SLOTSNAME))) return 1; if (shm_unlink(shm_file_name)) { switch (errno) { case ENOENT: bp_log(FNC_LOG_ERR, "SHM Object %s doesn't exists\n"); break; case EACCES: bp_log(FNC_LOG_ERR, "Permission denied on SHM Object %s\n"); break; default: bp_log(FNC_LOG_ERR, "Could not unlink SHM Object %s\n"); break; } shm_unlink_err = shm_unlink_err ? shm_unlink_err : errno; } free(shm_file_name); return unmap_err ? unmap_err : shm_unlink_err; }