util-cleanupmount.c (1289B)
1 /* --*- c -*-- 2 * Copyright (C) 2015 Enrico Scholz <enrico.scholz@ensc.de> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; version 2 and/or 3 of the License. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #ifdef HAVE_CONFIG_H 18 # include <config.h> 19 #endif 20 21 #include "util.h" 22 23 #include <stdio.h> 24 #include <sys/mount.h> 25 #ifdef HAVE_LINUX_TYPES_H 26 # include <linux/types.h> 27 #endif 28 #include <linux/fs.h> 29 30 #ifndef MS_REC 31 #define MS_REC 0x4000 32 #endif 33 #ifndef MS_PRIVATE 34 #define MS_PRIVATE (1<<18) 35 #endif 36 37 bool cleanupMount(void) 38 { 39 bool rc; 40 41 /* systemd mounts everything with MS_SHARED which breaks our 42 * filesystem mounting. Revert mount status back to pre-systemd */ 43 rc = mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) >= 0; 44 if (!rc) 45 perror("mount(\"/\", MS_REC|MS_PRIVATE)"); 46 47 return rc; 48 }