#define IXSEQ_TO_IPCID(ix,perm) (((perm._seq) << 16L) | (ix & 0xffff))
#endif
-char *
+static char *
fmt_perm(u_short mode, char write_char)
{
static char buffer[100];
return (&buffer[0]);
}
-void
+static void
cvt_time(time_t t, char *buf)
{
struct tm *tm;
strcpy(buf, "no-entry");
} else {
tm = localtime(&t);
- sprintf(buf, "%2d:%02d:%02d",
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ if (tm != NULL) {
+ sprintf(buf, "%2d:%02d:%02d",
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
+ }
}
}
#define SHMINFO 1
#define PID 8
#define TIME 16
-void usage()
+static void
+usage(void)
{
errx(EX_USAGE, "%s","usage: ipcs [-abcmopqstMQST]\n");
}
-int safe_sysctlbyname(const char *name, void *oldp, size_t *oldlenp, void *newp,
- size_t newlen)
-
-{
- int rv, sv_errno=0;
-
- if (seteuid(0)) /* iterator needs root write access to sysctl */
- err(1, "seteuid(0) failed");
-
- rv = sysctlbyname(name, oldp, oldlenp, newp, newlen);
- if (rv < 0)
- sv_errno = errno;
-
- if (seteuid(getuid()))
- err(1, "seteuid(%d) failed", getuid());
-
- if (rv < 0)
- errno = sv_errno;
- return rv;
-}
-
int
main(argc, argv)
int argc;
char datestring[100];
int i;
- if (seteuid(getuid())) /* run as user */
- err(1, "seteuid(%d) failed", getuid());
-
while ((i = getopt(argc, argv, "MmQqSsabcoptT")) != -1)
switch (i) {
case 'M':
if (display == 0)
display = SHMINFO | MSGINFO | SEMINFO;
now = time(0);
- if (0 == strftime(datestring, sizeof(datestring), "%a %b %e %H:%M:%S %Z %Y", localtime(&now)))
+ struct tm* tm = localtime(&now);
+ if (tm == NULL) {
+ now = 0;
+ tm = localtime(&now);
+ }
+ if (0 == strftime(datestring, sizeof(datestring), "%a %b %e %H:%M:%S %Z %Y", tm))
errx(1, "strftime failed\n");
printf("IPC status from <running system> as of %s\n", datestring);
if ((display & (MSGINFO | MSGTOTAL))) {
ic.ipcs_data = &msginfo;
ic.ipcs_datalen = sizeof(msginfo);
- if (safe_sysctlbyname(IPCS_MSG_SYSCTL, &ic, &ic_size, &ic, ic_size)) {
+ if (sysctlbyname(IPCS_MSG_SYSCTL, &ic, &ic_size, &ic, ic_size)) {
if (errno != EPERM) {
char buffer[1024];
snprintf(buffer, 1024, "sysctlbyname(IPCS_MSG_SYSCTL, op=CONF, &ic, &%ld) datalen=%d",
memset(msqptr, 0, sizeof(*msqptr));
- while(!(safe_sysctlbyname(IPCS_MSG_SYSCTL, &ic, &ic_size, &ic, ic_size))) {
+ while(!(sysctlbyname(IPCS_MSG_SYSCTL, &ic, &ic_size, &ic, ic_size))) {
ic.ipcs_data = msqptr;
if (msqptr->msg_qbytes != 0) {
ic.ipcs_data = &shminfo;
ic.ipcs_datalen = sizeof(shminfo);
- if (safe_sysctlbyname(IPCS_SHM_SYSCTL, &ic, &ic_size, &ic, ic_size)) {
+ if (sysctlbyname(IPCS_SHM_SYSCTL, &ic, &ic_size, &ic, ic_size)) {
if (errno != EPERM) {
errx(1, "sysctlbyname(IPCS_SHM_SYSCTL, op=CONF, &ic, &%ld) datalen=%d failed: %s\n",
sizeof(ic), ic.ipcs_datalen, strerror(errno));
ic.ipcs_cursor = 0; /* start */
ic.ipcs_datalen = sizeof(*shmptr);
ic.ipcs_data = shmptr;
- memset(shmptr, 0, sizeof(shmptr));
+ memset(shmptr, 0, sizeof(*shmptr));
- while(!(safe_sysctlbyname(IPCS_SHM_SYSCTL, &ic, &ic_size, &ic, ic_size))) {
+ while(!(sysctlbyname(IPCS_SHM_SYSCTL, &ic, &ic_size, &ic, ic_size))) {
ic.ipcs_data = shmptr; /* xnu workaround */
if (shmptr->shm_perm.mode & 0x0800) {
ic.ipcs_data = &seminfo;
ic.ipcs_datalen = sizeof(seminfo);
- if (safe_sysctlbyname(IPCS_SEM_SYSCTL, &ic, &ic_size, &ic, ic_size)) {
+ if (sysctlbyname(IPCS_SEM_SYSCTL, &ic, &ic_size, &ic, ic_size)) {
if (errno != EPERM) {
char buffer[1024];
snprintf(buffer, 1024, "sysctlbyname(IPCS_SEM_SYSCTL, op=CONF, &ic, &%ld) datalen=%d",
memset(semaptr, 0, sizeof(*semaptr));
- while(!(safe_sysctlbyname(IPCS_SEM_SYSCTL, &ic, &ic_size, &ic, ic_size))) {
+ while(!(sysctlbyname(IPCS_SEM_SYSCTL, &ic, &ic_size, &ic, ic_size))) {
ic.ipcs_data = semaptr; /* xnu workaround */
if ((semaptr->sem_perm.mode & SEM_ALLOC) != 0) {