]> git.saurik.com Git - apple/file_cmds.git/blobdiff - ipcs/ipcs.c
file_cmds-321.100.10.0.1.tar.gz
[apple/file_cmds.git] / ipcs / ipcs.c
index 72e176a30088457d371487fe346b720a84531ce9..986b229efc035159435f6f882b79565bc4dbcff0 100644 (file)
@@ -63,7 +63,7 @@
 #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];
@@ -83,7 +83,7 @@ fmt_perm(u_short mode, char write_char)
        return (&buffer[0]);
 }
 
-void
+static void
 cvt_time(time_t t, char *buf)
 {
        struct tm *tm;
@@ -92,8 +92,10 @@ cvt_time(time_t t, char *buf)
                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
@@ -109,32 +111,12 @@ cvt_time(time_t t, char *buf)
 #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;
@@ -147,9 +129,6 @@ main(argc, argv)
        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':
@@ -197,7 +176,12 @@ main(argc, argv)
        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))) {
@@ -212,7 +196,7 @@ main(argc, argv)
                        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",
@@ -263,7 +247,7 @@ main(argc, argv)
 
                        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) {
@@ -338,7 +322,7 @@ main(argc, argv)
                        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));
@@ -382,9 +366,9 @@ main(argc, argv)
                        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) {
@@ -460,7 +444,7 @@ else
                        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",
@@ -515,7 +499,7 @@ else
 
                        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) {