/***
This file is part of systemd.
Copyright 2014 Lennart Poettering
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.
systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <mqueue.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "clean-ipc.h"
#include "dirent-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "formats-util.h"
#include "log.h"
#include "macro.h"
#include "string-util.h"
#include "strv.h"
bool first = true;
int ret = 0;
if (!f) {
return 0;
}
unsigned n_attached;
int shmid;
if (first) {
first = false;
continue;
}
if (sscanf(line, "%*i %i %*o %*u " PID_FMT " " PID_FMT " %u " UID_FMT " " GID_FMT " " UID_FMT " " GID_FMT,
continue;
if (n_attached > 0)
continue;
if (uid != delete_uid)
continue;
/* Ignore entries that are already deleted */
continue;
"Failed to remove SysV shared memory segment %i: %m",
shmid);
}
}
return ret;
fail:
}
bool first = true;
int ret = 0;
if (!f) {
return 0;
}
int semid;
if (first) {
first = false;
continue;
}
continue;
if (uid != delete_uid)
continue;
/* Ignore entries that are already deleted */
continue;
"Failed to remove SysV semaphores object %i: %m",
semid);
}
}
return ret;
fail:
}
bool first = true;
int ret = 0;
if (!f) {
return 0;
}
int msgid;
if (first) {
first = false;
continue;
}
if (sscanf(line, "%*i %i %*o %*u %*u " PID_FMT " " PID_FMT " " UID_FMT " " GID_FMT " " UID_FMT " " GID_FMT,
continue;
if (uid != delete_uid)
continue;
/* Ignore entries that are already deleted */
continue;
"Failed to remove SysV message queue %i: %m",
msgid);
}
}
return ret;
fail:
}
int ret = 0, r;
continue;
continue;
continue;
}
continue;
if (!kid) {
}
} else {
if (r < 0)
ret = r;
}
continue;
}
} else {
continue;
}
}
}
return ret;
fail:
return -errno;
}
if (!dir) {
return 0;
}
}
int ret = 0;
if (!dir) {
return 0;
}
continue;
continue;
"Failed to stat() MQ segment %s: %m",
continue;
}
continue;
fn[0] = '/';
continue;
"Failed to unlink POSIX message queue %s: %m",
fn);
}
}
return ret;
fail:
}
int ret = 0, r;
/* Refuse to clean IPC of the root and system users */
if (uid <= SYSTEM_UID_MAX)
return 0;
r = clean_sysvipc_shm(uid);
if (r < 0)
ret = r;
r = clean_sysvipc_sem(uid);
if (r < 0)
ret = r;
r = clean_sysvipc_msg(uid);
if (r < 0)
ret = r;
r = clean_posix_shm(uid);
if (r < 0)
ret = r;
r = clean_posix_mq(uid);
if (r < 0)
ret = r;
return ret;
}