* [PATCH 00/13] make ipcs to use proc
@ 2012-10-14 20:22 Sami Kerola
2012-10-14 20:22 ` [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys Sami Kerola
` (14 more replies)
0 siblings, 15 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Hi Karel and others.
Couple weeks ago I decided to do the ipcs todo item, and today patches
got to be ready enough so that I could make final polishing and send them
for review.
The ipcs is still pretty messy. Partly the mess arises from my decision
to keep various ipc info mechanisms as fallback when /proc or /sys is
missing. And then again there are couple values which the ipc does not
seem to expose without calling good ol' multiplexer.
As the change is quite large I assume there has to be few bugs. None of
the where intentional, so having multiple people testing is preferable.
The following changes since commit 71b161ea37c57dc6a8341aeec6c0c2ae7cd4cfe3:
build-sys: clean update-potfiles script (2012-10-10 14:10:30 +0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git ipcs
for you to fetch changes up to b6700fc1b733ebe44612d52e4bd649dc8dfd85be:
docs: update TODO (2012-10-14 20:56:10 +0100)
----------------------------------------------------------------
Sami Kerola (13):
ipcs: add data structures to read state from /proc & /sys
ipcs: add /proc and /sys path definitions
ipcs: determine ipc limits from /proc
ipcs: add new permissions printing function
ipcs: read shared memory values from /proc
ipcs: read message queue values from /proc
ipsc: read semaphore values from /proc
ipcs: clean up permissions printing
ipcs: make individual shared memory id printing to use /proc
ipcs: make individual message queue id printing to use /proc
ipcs: make individual semaphore id printing to use /proc
ipcs: validate numeric user input
docs: update TODO
Documentation/TODO | 4 -
include/pathnames.h | 11 +
sys-utils/Makemodule.am | 2 +-
sys-utils/ipcs.c | 913 ++++++++++++++++++++++++++++++++++++------------
4 files changed, 711 insertions(+), 219 deletions(-)
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 02/13] ipcs: add /proc and /sys path definitions Sami Kerola
` (13 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 2fbca08..ca10c3d 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -106,6 +106,67 @@ union semun {
#define TIME 4
#define PID 5
+/* Structures that are populated by using /proc and /sys data. The
+ * struct type names are aligned with with kernel similar structures in
+ * kernel code. */
+struct ipc_stat {
+ int id;
+ key_t key;
+ uid_t uid; /* current uid */
+ gid_t gid; /* current gid */
+ uid_t cuid; /* creator uid */
+ gid_t cgid; /* creator gid */
+ unsigned int mode;
+};
+struct sem_data {
+ struct ipc_stat sem_perm;
+ time_t sem_otime;
+ time_t sem_ctime;
+ unsigned long sem_nsems;
+ struct sem_data *next;
+};
+struct shm_data {
+ struct ipc_stat shm_perm;
+ unsigned long shm_nattch;
+ unsigned long shm_segsz;
+ time_t shm_atim;
+ time_t shm_dtim;
+ time_t shm_ctim;
+ pid_t shm_cprid;
+ pid_t shm_lprid;
+ unsigned long shm_rss;
+ unsigned long shm_swp;
+ struct shm_data *next;
+};
+struct msg_data {
+ struct ipc_stat msg_perm;
+ time_t q_stime;
+ time_t q_rtime;
+ time_t q_ctime;
+ unsigned long q_qnum;
+ unsigned long q_cbytes;
+ pid_t q_lspid;
+ pid_t q_lrpid;
+ struct msg_data *next;
+};
+struct proc_limits {
+ int shmmni; /* max number of segments */
+ size_t shmmax; /* max segment size (constant) */
+ size_t shmall; /* max total shared memory */
+ size_t shmmin; /* min segment size (constant) */
+
+ int semmni; /* max number of arrays */
+ int semmsl; /* max semaphores per array */
+ int semmns; /* max semaphores system wide */
+ int semopm; /* max ops per semop call */
+ unsigned int semvmx; /* semaphore max value (constant) */
+
+ int msgmni; /* max queues system wide*/
+ size_t msgmax; /* max size of message */
+ int msgmnb; /* default max size of queue */
+};
+/* End of the /proc & /sys structures */
+
void do_shm (char format);
void do_sem (char format);
void do_msg (char format);
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 02/13] ipcs: add /proc and /sys path definitions
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-10-14 20:22 ` [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-11-05 16:43 ` Karel Zak
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
` (12 subsequent siblings)
14 siblings, 1 reply; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The necessary proc and sysfs files are tested to be present. When
information files are missing the ipcs will use obsolted systems, and
data structures, as fallback.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
include/pathnames.h | 11 +++++++++++
sys-utils/ipcs.c | 21 +++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/include/pathnames.h b/include/pathnames.h
index d0ed7a1..99b8417 100644
--- a/include/pathnames.h
+++ b/include/pathnames.h
@@ -150,5 +150,16 @@
/* wdctl path */
#define _PATH_WATCHDOG_DEV "/dev/watchdog"
+/* ipc paths */
+#define _PATH_PROC_IPCMSG "/proc/sysvipc/msg"
+#define _PATH_PROC_IPCSEM "/proc/sysvipc/sem"
+#define _PATH_PROC_IPCSHM "/proc/sysvipc/shm"
+#define _PATH_PROC_IPC_MSGMAX "/proc/sys/kernel/msgmax"
+#define _PATH_PROC_IPC_MSGMNB "/proc/sys/kernel/msgmnb"
+#define _PATH_PROC_IPC_MSGMNI "/proc/sys/kernel/msgmni"
+#define _PATH_PROC_IPC_MSG "/proc/sys/kernel/sem"
+#define _PATH_PROC_IPC_SHMALL "/proc/sys/kernel/shmall"
+#define _PATH_PROC_IPC_SHMMNI "/proc/sys/kernel/shmmni"
+
#endif /* PATHNAMES_H */
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index ca10c3d..900fc65 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -34,6 +34,7 @@
#include "c.h"
#include "nls.h"
#include "closestream.h"
+#include "pathnames.h"
/*
* SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
@@ -167,6 +168,21 @@ struct proc_limits {
};
/* End of the /proc & /sys structures */
+static int test_ipc_proc_paths(void)
+{
+ if (access(_PATH_PROC_IPCMSG, F_OK) == 0 &&
+ access(_PATH_PROC_IPCSEM, F_OK) == 0 &&
+ access(_PATH_PROC_IPCSHM, F_OK) == 0 &&
+ access(_PATH_PROC_IPC_MSGMAX, F_OK) == 0 &&
+ access(_PATH_PROC_IPC_MSGMNB, F_OK) == 0 &&
+ access(_PATH_PROC_IPC_MSGMNI, F_OK) == 0 &&
+ access(_PATH_PROC_IPC_MSG, F_OK) == 0 &&
+ access(_PATH_PROC_IPC_SHMALL, F_OK) == 0 &&
+ access(_PATH_PROC_IPC_SHMMNI, F_OK) == 0)
+ return 1;
+ return 0;
+}
+
void do_shm (char format);
void do_sem (char format);
void do_msg (char format);
@@ -203,6 +219,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
int main (int argc, char **argv)
{
int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
+ int use_proc = 0;
char format = 0;
static const struct option longopts[] = {
{"id", required_argument, NULL, 'i'},
@@ -269,6 +286,10 @@ int main (int argc, char **argv)
}
}
+ use_proc = test_ipc_proc_paths();
+ if (!use_proc)
+ warnx(_("using unreliable syscalls"));
+
if (print) {
if (shm)
print_shm (id);
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 03/13] ipcs: determine ipc limits from /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-10-14 20:22 ` [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys Sami Kerola
2012-10-14 20:22 ` [PATCH 02/13] ipcs: add /proc and /sys path definitions Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-15 2:00 ` Mike Frysinger
2012-11-05 16:49 ` Karel Zak
2012-10-14 20:22 ` [PATCH 04/13] ipcs: add new permissions printing function Sami Kerola
` (11 subsequent siblings)
14 siblings, 2 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 156 +++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 122 insertions(+), 34 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 900fc65..4737f28 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -46,6 +46,16 @@
# define SHM_LOCKED 02000 /* segment will not be swapped */
#endif
+#ifndef SEMVMX
+# define SEMVMX 32767 /* <= 32767 semaphore maximum value */
+#endif
+#ifndef SHMMAX
+# define SHMMAX 0x2000000 /* max shared segment size in bytes */
+#endif
+#ifndef SHMMIN
+# define SHMMIN 1 /* min shared segment size in bytes */
+#endif
+
/* For older kernels the same holds for the defines below */
#ifndef MSG_STAT
# define MSG_STAT 11
@@ -168,6 +178,90 @@ struct proc_limits {
};
/* End of the /proc & /sys structures */
+static int msgctl_limits_wrapper(struct proc_limits *lim, int use_proc)
+{
+ struct msginfo msginfo;
+ if (use_proc) {
+ FILE *f;
+ if ((f = fopen(_PATH_PROC_IPC_MSGMNI, "r")) == NULL)
+ return 1;
+ fscanf(f, "%d", &(lim->msgmni));
+ fclose(f);
+ if ((f = fopen(_PATH_PROC_IPC_MSGMNB, "r")) == NULL)
+ return 1;
+ fscanf(f, "%d", &(lim->msgmnb));
+ fclose(f);
+ if ((f = fopen(_PATH_PROC_IPC_MSGMAX, "r")) == NULL)
+ return 1;
+ fscanf(f, "%zu", &(lim->msgmax));
+ fclose(f);
+ return 0;
+ }
+
+ /* proc not in use */
+ if ((msgctl(0, IPC_INFO, (struct msqid_ds *)(void *)&msginfo)) < 0)
+ return 1;
+ lim->msgmni = (int)msginfo.msgmni;
+ lim->msgmnb = (int)msginfo.msgmnb;
+ lim->msgmax = (size_t)msginfo.msgmax;
+ return 0;
+}
+
+static int semctl_limits_wrapper(struct proc_limits *lim, int use_proc)
+{
+ struct seminfo seminfo;
+ union semun arg;
+
+ lim->semvmx = SEMVMX;
+
+ if (use_proc) {
+ FILE *f;
+ if ((f = fopen(_PATH_PROC_IPC_MSG, "r")) == NULL)
+ return 1;
+ fscanf(f, "%d\t%d\t%d\t%d",
+ &(lim->semmsl),
+ &(lim->semmns), &(lim->semopm), &(lim->semmni));
+ fclose(f);
+ return 0;
+ }
+
+ /* proc not in use */
+ arg.array = (ushort *) (void *)&seminfo; /* damn union */
+ if ((semctl(0, 0, IPC_INFO, arg)) < 0)
+ return 1;
+ lim->semmni = (int)seminfo.semmni;
+ lim->semmsl = (int)seminfo.semmsl;
+ lim->semmns = (int)seminfo.semmns;
+ lim->semopm = (int)seminfo.semopm;
+ return 0;
+}
+
+static int shmctl_limits_wrapper(struct proc_limits *lim, int use_proc)
+{
+ struct shminfo shminfo;
+ lim->shmmax = SHMMAX;
+ lim->shmmin = SHMMIN;
+ if (use_proc) {
+ FILE *f;
+ if ((f = fopen(_PATH_PROC_IPC_SHMMNI, "r")) == NULL)
+ return 1;
+ fscanf(f, "%d", &(lim->shmmni));
+ fclose(f);
+ if ((f = fopen(_PATH_PROC_IPC_SHMALL, "r")) == NULL)
+ return 1;
+ fscanf(f, "%zu", &(lim->shmall));
+ fclose(f);
+ return 0;
+ }
+
+ /* proc not in use */
+ if ((shmctl(0, IPC_INFO, (struct shmid_ds *)(void *)&shminfo)) < 0)
+ return 1;
+ lim->shmmni = (int)shminfo.shmmni;
+ lim->shmall = (size_t)shminfo.shmall;
+ return 0;
+}
+
static int test_ipc_proc_paths(void)
{
if (access(_PATH_PROC_IPCMSG, F_OK) == 0 &&
@@ -183,9 +277,9 @@ static int test_ipc_proc_paths(void)
return 0;
}
-void do_shm (char format);
-void do_sem (char format);
-void do_msg (char format);
+void do_shm (char format, int use_proc);
+void do_sem (char format, int use_proc);
+void do_msg (char format, int use_proc);
void print_shm (int id);
void print_msg (int id);
void print_sem (int id);
@@ -305,15 +399,15 @@ int main (int argc, char **argv)
printf ("\n");
if (shm) {
- do_shm (format);
+ do_shm (format, use_proc);
printf ("\n");
}
if (sem) {
- do_sem (format);
+ do_sem (format, use_proc);
printf ("\n");
}
if (msg) {
- do_msg (format);
+ do_msg (format, use_proc);
printf ("\n");
}
}
@@ -346,14 +440,14 @@ static void print_perms (int id, struct ipc_perm *ipcp)
printf(" %-10u\n", ipcp->gid);
}
-void do_shm (char format)
+void do_shm (char format, int use_proc)
{
int maxid, shmid, id;
struct shmid_ds shmseg;
struct shm_info shm_info;
- struct shminfo shminfo;
struct ipc_perm *ipcp = &shmseg.shm_perm;
struct passwd *pw;
+ struct proc_limits lim;
maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
if (maxid < 0) {
@@ -364,20 +458,13 @@ void do_shm (char format)
switch (format) {
case LIMITS:
printf (_("------ Shared Memory Limits --------\n"));
- if ((shmctl (0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0 )
+ if (shmctl_limits_wrapper(&lim, use_proc))
return;
- /*
- * glibc 2.1.3 and all earlier libc's have ints as fields of
- * struct shminfo; glibc 2.1.91 has unsigned long; ach
- */
- printf (_("max number of segments = %lu\n"),
- (unsigned long) shminfo.shmmni);
- printf (_("max seg size (kbytes) = %lu\n"),
- (unsigned long) (shminfo.shmmax >> 10));
- printf (_("max total shared memory (kbytes) = %llu\n"),
- getpagesize() / 1024 * (unsigned long long) shminfo.shmall);
- printf (_("min seg size (bytes) = %lu\n"),
- (unsigned long) shminfo.shmmin);
+ printf (_("max number of segments = %d\n"), lim.shmmni);
+ printf (_("max seg size (kbytes) = %zu\n"), lim.shmmax / 1024);
+ /* FIXME: is use of getpagesize() as multiplier correct? */
+ printf (_("max total shared memory (kbytes) = %zu\n"), (lim.shmall / 1024) * getpagesize());
+ printf (_("min seg size (bytes) = %zu\n"), lim.shmmin);
return;
case STATUS:
@@ -489,7 +576,7 @@ void do_shm (char format)
return;
}
-void do_sem (char format)
+void do_sem (char format, int use_proc)
{
int maxid, semid, id;
struct semid_ds semary;
@@ -497,6 +584,7 @@ void do_sem (char format)
struct ipc_perm *ipcp = &semary.sem_perm;
struct passwd *pw;
union semun arg;
+ struct proc_limits lim;
arg.array = (ushort *) (void *) &seminfo;
maxid = semctl (0, 0, SEM_INFO, arg);
@@ -508,14 +596,13 @@ void do_sem (char format)
switch (format) {
case LIMITS:
printf (_("------ Semaphore Limits --------\n"));
- arg.array = (ushort *) (void *) &seminfo; /* damn union */
- if ((semctl (0, 0, IPC_INFO, arg)) < 0 )
+ if (semctl_limits_wrapper(&lim, use_proc))
return;
- printf (_("max number of arrays = %d\n"), seminfo.semmni);
- printf (_("max semaphores per array = %d\n"), seminfo.semmsl);
- printf (_("max semaphores system wide = %d\n"), seminfo.semmns);
- printf (_("max ops per semop call = %d\n"), seminfo.semopm);
- printf (_("semaphore max value = %d\n"), seminfo.semvmx);
+ printf (_("max number of arrays = %d\n"), lim.semmni);
+ printf (_("max semaphores per array = %d\n"), lim.semmsl);
+ printf (_("max semaphores system wide = %d\n"), lim.semmns);
+ printf (_("max ops per semop call = %d\n"), lim.semopm);
+ printf (_("semaphore max value = %d\n"), lim.semvmx);
return;
case STATUS:
@@ -590,13 +677,14 @@ void do_sem (char format)
}
}
-void do_msg (char format)
+void do_msg (char format, int use_proc)
{
int maxid, msqid, id;
struct msqid_ds msgque;
struct msginfo msginfo;
struct ipc_perm *ipcp = &msgque.msg_perm;
struct passwd *pw;
+ struct proc_limits lim;
maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
if (maxid < 0) {
@@ -606,12 +694,12 @@ void do_msg (char format)
switch (format) {
case LIMITS:
- if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 )
+ if (msgctl_limits_wrapper(&lim, use_proc))
return;
printf (_("------ Messages Limits --------\n"));
- printf (_("max queues system wide = %d\n"), msginfo.msgmni);
- printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax);
- printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb);
+ printf (_("max queues system wide = %d\n"), lim.msgmni);
+ printf (_("max size of message (bytes) = %zu\n"), lim.msgmax);
+ printf (_("default max size of queue (bytes) = %d\n"), lim.msgmnb);
return;
case STATUS:
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 04/13] ipcs: add new permissions printing function
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (2 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 05/13] ipcs: read shared memory values from /proc Sami Kerola
` (10 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
The function has silly name which eventually will be fixed, once the
current print_perms() that uses legacy structures is obsoleted.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 4737f28..8ac7e1c 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -439,6 +439,31 @@ static void print_perms (int id, struct ipc_perm *ipcp)
else
printf(" %-10u\n", ipcp->gid);
}
+static void FIXED_print_perms(struct ipc_stat *is)
+{
+ struct passwd *pw;
+ struct group *gr;
+
+ printf("%-10d %-10o", is->id, is->mode & 0777);
+
+ if ((pw = getpwuid(is->cuid)))
+ printf(" %-10s", pw->pw_name);
+ else
+ printf(" %-10u", is->cuid);
+ if ((gr = getgrgid(is->cgid)))
+ printf(" %-10s", gr->gr_name);
+ else
+ printf(" %-10u", is->cgid);
+
+ if ((pw = getpwuid(is->uid)))
+ printf(" %-10s", pw->pw_name);
+ else
+ printf(" %-10u", is->uid);
+ if ((gr = getgrgid(is->gid)))
+ printf(" %-10s\n", gr->gr_name);
+ else
+ printf(" %-10u\n", is->gid);
+}
void do_shm (char format, int use_proc)
{
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 05/13] ipcs: read shared memory values from /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (3 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 04/13] ipcs: add new permissions printing function Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-15 2:07 ` Mike Frysinger
2012-10-14 20:22 ` [PATCH 06/13] ipcs: read message queue " Sami Kerola
` (9 subsequent siblings)
14 siblings, 1 reply; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Add shmctl_info_wrapper(), which does the job and take it in use.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 179 +++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 142 insertions(+), 37 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 8ac7e1c..b2d4649 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -35,6 +35,7 @@
#include "nls.h"
#include "closestream.h"
#include "pathnames.h"
+#include "xalloc.h"
/*
* SHM_DEST and SHM_LOCKED are defined in kernel headers, but inside
@@ -262,6 +263,106 @@ static int shmctl_limits_wrapper(struct proc_limits *lim, int use_proc)
return 0;
}
+#if BITS_PER_LONG <= 32 /* FIXME: autotools needs to determine this */
+# define SIZE_SPEC "%10lu"
+#else
+# define SIZE_SPEC "%21lu"
+#endif
+static int shmctl_info_wrapper(int maxid, int id, struct shm_data **shmds,
+ int use_proc)
+{
+ char skipheader[1024];
+ int i, shmid;
+ struct shm_data *shmdsp;
+
+ struct shmid_ds shmseg;
+ struct ipc_perm *ipcp = &shmseg.shm_perm;
+
+ *shmds = xmalloc(sizeof(struct shm_data));
+ shmdsp = *shmds;
+ shmdsp->next = NULL;
+ if (use_proc) {
+ FILE *f;
+ if ((f = fopen(_PATH_PROC_IPCSHM, "r")) == NULL)
+ return -1;
+ fgets(skipheader, 1024, f);
+ for (i = 0; !feof(f); i++) {
+ fscanf(f,
+ "%10d %10d %4o " SIZE_SPEC
+ " %5lu %5lu %5lu %5u %5u %5u %5u %10lu %10lu %10lu "
+ SIZE_SPEC " " SIZE_SPEC "\n",
+ &(shmdsp->shm_perm.key),
+ &(shmdsp->shm_perm.id),
+ &(shmdsp->shm_perm.mode),
+ &(shmdsp->shm_segsz),
+ &(shmdsp->shm_cprid),
+ &(shmdsp->shm_lprid),
+ &(shmdsp->shm_nattch),
+ &(shmdsp->shm_perm.uid),
+ &(shmdsp->shm_perm.gid),
+ &(shmdsp->shm_perm.cuid),
+ &(shmdsp->shm_perm.cgid),
+ &(shmdsp->shm_atim),
+ &(shmdsp->shm_dtim),
+ &(shmdsp->shm_ctim),
+ &(shmdsp->shm_rss),
+ &(shmdsp->shm_swp)
+ );
+ if (id < 0) {
+ shmdsp->next = xmalloc(sizeof(struct shm_data));
+ shmdsp = shmdsp->next;
+ shmdsp->next = NULL;
+ }
+ }
+ if (i == 0)
+ free(*shmds);
+ fclose(f);
+ return i;
+ }
+
+ /* Fallback; /proc or /sys file(s) missing. */
+ if (id < 0)
+ i = 0;
+ else
+ i = id;
+ while (i <= maxid) {
+ shmid = shmctl(i, SHM_STAT, &shmseg);
+ if (shmid < 0) {
+ if (-1 < id) {
+ free(*shmds);
+ return 0;
+ }
+ i++;
+ continue;
+ }
+ shmdsp->shm_perm.key = ipcp->KEY;
+ shmdsp->shm_perm.id = shmid;
+ shmdsp->shm_perm.mode = ipcp->mode;
+ shmdsp->shm_segsz = shmseg.shm_segsz;
+ shmdsp->shm_cprid = shmseg.shm_cpid;
+ shmdsp->shm_lprid = shmseg.shm_lpid;
+ shmdsp->shm_nattch = shmseg.shm_nattch;
+ shmdsp->shm_perm.uid = ipcp->uid;
+ shmdsp->shm_perm.gid = ipcp->gid;
+ shmdsp->shm_perm.cuid = ipcp->cuid;
+ shmdsp->shm_perm.cgid = ipcp->cuid;
+ shmdsp->shm_atim = shmseg.shm_atime;
+ shmdsp->shm_dtim = shmseg.shm_dtime;
+ shmdsp->shm_ctim = shmseg.shm_ctime;
+ shmdsp->shm_rss = 0xdead;
+ shmdsp->shm_swp = 0xdead;
+ if (id < 0) {
+ shmdsp->next = xmalloc(sizeof(struct shm_data));
+ shmdsp = shmdsp->next;
+ shmdsp->next = NULL;
+ i++;
+ } else {
+ return 1;
+ }
+ }
+ return i;
+}
+
static int test_ipc_proc_paths(void)
{
if (access(_PATH_PROC_IPCMSG, F_OK) == 0 &&
@@ -277,7 +378,7 @@ static int test_ipc_proc_paths(void)
return 0;
}
-void do_shm (char format, int use_proc);
+static void do_shm (char format, int use_proc);
void do_sem (char format, int use_proc);
void do_msg (char format, int use_proc);
void print_shm (int id);
@@ -465,13 +566,22 @@ static void FIXED_print_perms(struct ipc_stat *is)
printf(" %-10u\n", is->gid);
}
-void do_shm (char format, int use_proc)
+static void freeshms(struct shm_data *shmds)
{
- int maxid, shmid, id;
- struct shmid_ds shmseg;
+ while (shmds) {
+ struct shm_data *next = shmds->next;
+ free(shmds);
+ shmds = next;
+ }
+ return;
+}
+
+static void do_shm (char format, int use_proc)
+{
+ int maxid;
struct shm_info shm_info;
- struct ipc_perm *ipcp = &shmseg.shm_perm;
struct passwd *pw;
+ struct shm_data *shmds, *shmdsp;
struct proc_limits lim;
maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info);
@@ -544,60 +654,55 @@ void do_shm (char format, int use_proc)
break;
}
- for (id = 0; id <= maxid; id++) {
- shmid = shmctl (id, SHM_STAT, &shmseg);
- if (shmid < 0)
- continue;
+ if (shmctl_info_wrapper (maxid, -1, &shmds, use_proc) < 1)
+ return;
+ shmdsp = shmds;
+
+ for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
if (format == CREATOR) {
- print_perms (shmid, ipcp);
+ FIXED_print_perms (&(shmdsp->shm_perm));
continue;
}
- pw = getpwuid(ipcp->uid);
+ pw = getpwuid(shmdsp->shm_perm.uid);
switch (format) {
case TIME:
if (pw)
- printf ("%-10d %-10.10s", shmid, pw->pw_name);
+ printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
else
- printf ("%-10d %-10u", shmid, ipcp->uid);
+ printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
/* ctime uses static buffer: use separate calls */
- printf(" %-20.16s", shmseg.shm_atime
- ? ctime(&shmseg.shm_atime) + 4 : _("Not set"));
- printf(" %-20.16s", shmseg.shm_dtime
- ? ctime(&shmseg.shm_dtime) + 4 : _("Not set"));
- printf(" %-20.16s\n", shmseg.shm_ctime
- ? ctime(&shmseg.shm_ctime) + 4 : _("Not set"));
+ printf(" %-20.16s", shmdsp->shm_atim
+ ? ctime(&(shmdsp->shm_atim)) + 4 : _("Not set"));
+ printf(" %-20.16s", shmdsp->shm_dtim
+ ? ctime(&(shmdsp->shm_dtim)) + 4 : _("Not set"));
+ printf(" %-20.16s\n", shmdsp->shm_ctim
+ ? ctime(&(shmdsp->shm_ctim)) + 4 : _("Not set"));
break;
case PID:
if (pw)
- printf ("%-10d %-10.10s", shmid, pw->pw_name);
+ printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
else
- printf ("%-10d %-10u", shmid, ipcp->uid);
+ printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
printf (" %-10d %-10d\n",
- shmseg.shm_cpid, shmseg.shm_lpid);
+ shmdsp->shm_cprid, shmdsp->shm_lprid);
break;
default:
- printf("0x%08x ",ipcp->KEY );
+ printf("0x%08x ", shmdsp->shm_perm.key);
if (pw)
- printf ("%-10d %-10.10s", shmid, pw->pw_name);
+ printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
else
- printf ("%-10d %-10u", shmid, ipcp->uid);
+ printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
printf (" %-10o %-10lu %-10ld %-6s %-6s\n",
- ipcp->mode & 0777,
- /*
- * earlier: int, Austin has size_t
- */
- (unsigned long) shmseg.shm_segsz,
- /*
- * glibc-2.1.3 and earlier has unsigned short;
- * Austin has shmatt_t
- */
- (long) shmseg.shm_nattch,
- ipcp->mode & SHM_DEST ? _("dest") : " ",
- ipcp->mode & SHM_LOCKED ? _("locked") : " ");
+ shmdsp->shm_perm.mode & 0777,
+ shmdsp->shm_segsz,
+ shmdsp->shm_nattch,
+ shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ",
+ shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");
break;
}
}
+ freeshms(shmds);
return;
}
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 06/13] ipcs: read message queue values from /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (4 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 05/13] ipcs: read shared memory values from /proc Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 07/13] ipsc: read semaphore " Sami Kerola
` (8 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Add msgctl_info_wrapper(), which does the job and take it in use.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 160 +++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 126 insertions(+), 34 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index b2d4649..db1919b 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -363,6 +363,96 @@ static int shmctl_info_wrapper(int maxid, int id, struct shm_data **shmds,
return i;
}
+static int msgctl_info_wrapper(int maxid, int id, struct msg_data **msgds,
+ int use_proc)
+{
+ char skipheader[1024];
+ int i, msgid;
+ struct msg_data *msgdsp;
+
+ struct msqid_ds msgque;
+ struct ipc_perm *ipcp = &msgque.msg_perm;
+
+ *msgds = xmalloc(sizeof(struct msg_data));
+ msgdsp = *msgds;
+ msgdsp->next = NULL;
+ if (use_proc) {
+ FILE *f;
+ if ((f = fopen(_PATH_PROC_IPCMSG, "r")) == NULL)
+ return -1;
+ fgets(skipheader, 1024, f);
+ for (i = 0; !feof(f); i++) {
+ fscanf(f,
+ "%10d %10d %4o %10lu %10lu %5u %5u %5u %5u %5u %5u %10lu %10lu %10lu\n",
+ &(msgdsp->msg_perm.key),
+ &(msgdsp->msg_perm.id),
+ &(msgdsp->msg_perm.mode),
+ &(msgdsp->q_cbytes),
+ &(msgdsp->q_qnum),
+ &(msgdsp->q_lspid),
+ &(msgdsp->q_lrpid),
+ &(msgdsp->msg_perm.uid),
+ &(msgdsp->msg_perm.gid),
+ &(msgdsp->msg_perm.cuid),
+ &(msgdsp->msg_perm.cgid),
+ &(msgdsp->q_stime),
+ &(msgdsp->q_rtime),
+ &(msgdsp->q_ctime)
+ );
+ if (id < 0) {
+ msgdsp->next = xmalloc(sizeof(struct msg_data));
+ msgdsp = msgdsp->next;
+ msgdsp->next = NULL;
+ }
+ }
+ if (i == 0)
+ free(*msgds);
+ fclose(f);
+ return i;
+ }
+
+ /* Fallback; /proc or /sys file(s) missing. */
+ if (id < 0)
+ i = 0;
+ else
+ i = id;
+ while (i <= maxid) {
+ msgid = msgctl(id, MSG_STAT, &msgque);
+ if (msgid < 0) {
+ if (-1 < id) {
+ free(*msgds);
+ return 0;
+ }
+ i++;
+ continue;
+ }
+ msgdsp->msg_perm.key = ipcp->KEY;
+ msgdsp->msg_perm.id = msgid;
+ msgdsp->msg_perm.mode = ipcp->mode;
+ msgdsp->q_cbytes = msgque.msg_cbytes;
+ msgdsp->q_qnum = msgque.msg_qnum;
+ msgdsp->q_lspid = msgque.msg_lspid;
+ msgdsp->q_lrpid = msgque.msg_lrpid;
+ msgdsp->msg_perm.uid = ipcp->uid;
+ msgdsp->msg_perm.gid = ipcp->gid;
+ msgdsp->msg_perm.cuid = ipcp->cuid;
+ msgdsp->msg_perm.cgid = ipcp->cgid;
+ msgdsp->q_stime = msgque.msg_stime;
+ msgdsp->q_rtime = msgque.msg_rtime;
+ msgdsp->q_ctime = msgque.msg_ctime;
+
+ if (id < 0) {
+ msgdsp->next = xmalloc(sizeof(struct msg_data));
+ msgdsp = msgdsp->next;
+ msgdsp->next = NULL;
+ i++;
+ } else {
+ return 1;
+ }
+ }
+ return i;
+}
+
static int test_ipc_proc_paths(void)
{
if (access(_PATH_PROC_IPCMSG, F_OK) == 0 &&
@@ -380,7 +470,7 @@ static int test_ipc_proc_paths(void)
static void do_shm (char format, int use_proc);
void do_sem (char format, int use_proc);
-void do_msg (char format, int use_proc);
+static void do_msg (char format, int use_proc);
void print_shm (int id);
void print_msg (int id);
void print_sem (int id);
@@ -807,13 +897,22 @@ void do_sem (char format, int use_proc)
}
}
-void do_msg (char format, int use_proc)
+static void freemsgs(struct msg_data *msgds)
{
- int maxid, msqid, id;
- struct msqid_ds msgque;
+ while (msgds) {
+ struct msg_data *next = msgds->next;
+ free(msgds);
+ msgds = next;
+ }
+ return;
+}
+
+static void do_msg (char format, int use_proc)
+{
+ int maxid;
struct msginfo msginfo;
- struct ipc_perm *ipcp = &msgque.msg_perm;
struct passwd *pw;
+ struct msg_data *msgds, *msgdsp;
struct proc_limits lim;
maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo);
@@ -865,56 +964,49 @@ void do_msg (char format, int use_proc)
break;
}
- for (id = 0; id <= maxid; id++) {
- msqid = msgctl (id, MSG_STAT, &msgque);
- if (msqid < 0)
- continue;
+ if (msgctl_info_wrapper (maxid, -1, &msgds, use_proc) < 1)
+ return;
+
+ for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next) {
if (format == CREATOR) {
- print_perms (msqid, ipcp);
+ FIXED_print_perms (&(msgdsp->msg_perm));
continue;
}
- pw = getpwuid(ipcp->uid);
+ pw = getpwuid(msgdsp->msg_perm.uid);
switch (format) {
case TIME:
if (pw)
- printf ("%-8d %-10.10s", msqid, pw->pw_name);
+ printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
else
- printf ("%-8d %-10u", msqid, ipcp->uid);
- printf (" %-20.16s", msgque.msg_stime
- ? ctime(&msgque.msg_stime) + 4 : _("Not set"));
- printf (" %-20.16s", msgque.msg_rtime
- ? ctime(&msgque.msg_rtime) + 4 : _("Not set"));
- printf (" %-20.16s\n", msgque.msg_ctime
- ? ctime(&msgque.msg_ctime) + 4 : _("Not set"));
+ printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
+ printf (" %-20.16s", msgdsp->q_stime
+ ? ctime(&(msgdsp->q_stime)) + 4 : _("Not set"));
+ printf (" %-20.16s", msgdsp->q_rtime
+ ? ctime(&(msgdsp->q_rtime)) + 4 : _("Not set"));
+ printf (" %-20.16s\n", msgdsp->q_ctime
+ ? ctime(&(msgdsp->q_ctime)) + 4 : _("Not set"));
break;
case PID:
if (pw)
- printf ("%-8d %-10.10s", msqid, pw->pw_name);
+ printf ("%-8d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
else
- printf ("%-8d %-10u", msqid, ipcp->uid);
+ printf ("%-8d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
printf (" %5d %5d\n",
- msgque.msg_lspid, msgque.msg_lrpid);
+ msgdsp->q_lspid, msgdsp->q_lrpid);
break;
default:
- printf( "0x%08x ",ipcp->KEY );
+ printf( "0x%08x ", msgdsp->msg_perm.key );
if (pw)
- printf ("%-10d %-10.10s", msqid, pw->pw_name);
+ printf ("%-10d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
else
- printf ("%-10d %-10u", msqid, ipcp->uid);
+ printf ("%-10d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
printf (" %-10o %-12ld %-12ld\n",
- ipcp->mode & 0777,
- /*
- * glibc-2.1.3 and earlier has unsigned
- * short. glibc-2.1.91 has variation between
- * unsigned short, unsigned long. Austin has
- * msgqnum_t
- */
- (long) msgque.msg_cbytes,
- (long) msgque.msg_qnum);
+ msgdsp->msg_perm.mode & 0777, msgdsp->q_cbytes, msgdsp->q_qnum);
break;
}
}
+ freemsgs(msgds);
return;
}
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 07/13] ipsc: read semaphore values from /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (5 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 06/13] ipcs: read message queue " Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 08/13] ipcs: clean up permissions printing Sami Kerola
` (7 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Add semctl_info_wrapper(), which does the job and take it in use.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 148 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 119 insertions(+), 29 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index db1919b..373e85e 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -453,6 +453,92 @@ static int msgctl_info_wrapper(int maxid, int id, struct msg_data **msgds,
return i;
}
+static int semctl_info_wrapper(int maxid, int id, struct sem_data **semds,
+ int use_proc)
+{
+ char skipheader[1024];
+ int i, semid;
+ struct sem_data *semdsp;
+
+ struct semid_ds semary;
+ struct ipc_perm *ipcp = &semary.sem_perm;
+ struct seminfo seminfo;
+ union semun arg;
+
+ *semds = xmalloc(sizeof(struct sem_data));
+ semdsp = *semds;
+ semdsp->next = NULL;
+ if (use_proc) {
+ FILE *f;
+ if ((f = fopen(_PATH_PROC_IPCSEM, "r")) == NULL)
+ return -1;
+ fgets(skipheader, 1024, f);
+ for (i = 0; !feof(f); i++) {
+ fscanf(f,
+ "%10d %10d %4o %10u %5u %5u %5u %5u %10lu %10lu\n",
+ &(semdsp->sem_perm.key),
+ &(semdsp->sem_perm.id),
+ &(semdsp->sem_perm.mode),
+ &(semdsp->sem_nsems),
+ &(semdsp->sem_perm.uid),
+ &(semdsp->sem_perm.gid),
+ &(semdsp->sem_perm.cuid),
+ &(semdsp->sem_perm.cgid),
+ &(semdsp->sem_otime),
+ &(semdsp->sem_ctime)
+ );
+ if (id < 0) {
+ semdsp->next = xmalloc(sizeof(struct sem_data));
+ semdsp = semdsp->next;
+ semdsp->next = NULL;
+ }
+ }
+ if (i == 0)
+ free(*semds);
+ fclose(f);
+ return i;
+ }
+
+ /* Fallback; /proc or /sys file(s) missing. */
+ if (id < 0)
+ i = 0;
+ else
+ i = id;
+ arg.array = (ushort *) (void *)&seminfo;
+ arg.buf = (struct semid_ds *)&semary;
+ while (i <= maxid) {
+ semid = semctl(id, 0, SEM_STAT, arg);
+ if (semid < 0) {
+ if (-1 < semid) {
+ free(*semds);
+ return 0;
+ }
+ i++;
+ continue;
+ }
+ semdsp->sem_perm.key = ipcp->KEY;
+ semdsp->sem_perm.id = semid;
+ semdsp->sem_perm.mode = ipcp->mode;
+ semdsp->sem_nsems = semary.sem_nsems;
+ semdsp->sem_perm.uid = semary.sem_perm.uid;
+ semdsp->sem_perm.gid = semary.sem_perm.gid;
+ semdsp->sem_perm.cuid = semary.sem_perm.cuid;
+ semdsp->sem_perm.cgid = semary.sem_perm.cgid;
+ semdsp->sem_otime = semary.sem_otime;
+ semdsp->sem_ctime = semary.sem_ctime;
+
+ if (id < 0) {
+ semdsp->next = xmalloc(sizeof(struct sem_data));
+ semdsp = semdsp->next;
+ semdsp->next = NULL;
+ i++;
+ } else {
+ return 1;
+ }
+ }
+ return i;
+}
+
static int test_ipc_proc_paths(void)
{
if (access(_PATH_PROC_IPCMSG, F_OK) == 0 &&
@@ -469,7 +555,7 @@ static int test_ipc_proc_paths(void)
}
static void do_shm (char format, int use_proc);
-void do_sem (char format, int use_proc);
+static void do_sem (char format, int use_proc);
static void do_msg (char format, int use_proc);
void print_shm (int id);
void print_msg (int id);
@@ -796,13 +882,22 @@ static void do_shm (char format, int use_proc)
return;
}
-void do_sem (char format, int use_proc)
+static void freesems(struct sem_data *semds)
{
- int maxid, semid, id;
- struct semid_ds semary;
+ while (semds) {
+ struct sem_data *next = semds->next;
+ free(semds);
+ semds = next;
+ }
+ return;
+}
+
+static void do_sem (char format, int use_proc)
+{
+ int maxid;
struct seminfo seminfo;
- struct ipc_perm *ipcp = &semary.sem_perm;
struct passwd *pw;
+ struct sem_data *semds, *semdsp;
union semun arg;
struct proc_limits lim;
@@ -853,48 +948,43 @@ void do_sem (char format, int use_proc)
break;
}
- for (id = 0; id <= maxid; id++) {
- arg.buf = (struct semid_ds *) &semary;
- semid = semctl (id, 0, SEM_STAT, arg);
- if (semid < 0)
- continue;
+ if (semctl_info_wrapper (maxid, -1, &semds, use_proc) < 1)
+ return;
+
+ for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
if (format == CREATOR) {
- print_perms (semid, ipcp);
+ FIXED_print_perms (&(semdsp->sem_perm));
continue;
}
- pw = getpwuid(ipcp->uid);
+ pw = getpwuid(semdsp->sem_perm.uid);
switch (format) {
case TIME:
if (pw)
- printf ("%-8d %-10.10s", semid, pw->pw_name);
+ printf ("%-8d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
else
- printf ("%-8d %-10u", semid, ipcp->uid);
- printf (" %-26.24s", semary.sem_otime
- ? ctime(&semary.sem_otime) : _("Not set"));
- printf (" %-26.24s\n", semary.sem_ctime
- ? ctime(&semary.sem_ctime) : _("Not set"));
+ printf ("%-8d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
+ printf (" %-26.24s", semdsp->sem_otime
+ ? ctime(&semdsp->sem_otime) : _("Not set"));
+ printf (" %-26.24s\n", semdsp->sem_ctime
+ ? ctime(&semdsp->sem_ctime) : _("Not set"));
break;
case PID:
break;
default:
- printf("0x%08x ", ipcp->KEY);
+ printf("0x%08x ", semdsp->sem_perm.key);
if (pw)
- printf ("%-10d %-10.10s", semid, pw->pw_name);
+ printf ("%-10d %-10.10s", semdsp->sem_perm.id, pw->pw_name);
else
- printf ("%-10d %-10u", semid, ipcp->uid);
+ printf ("%-10d %-10u", semdsp->sem_perm.id, semdsp->sem_perm.uid);
printf (" %-10o %-10ld\n",
- ipcp->mode & 0777,
- /*
- * glibc-2.1.3 and earlier has unsigned
- * short. glibc-2.1.91 has variation between
- * unsigned short and unsigned long. Austin
- * prescribes unsigned short.
- */
- (long) semary.sem_nsems);
+ semdsp->sem_perm.mode & 0777,
+ semdsp->sem_nsems);
break;
}
}
+ freesems(semds);
+ return;
}
static void freemsgs(struct msg_data *msgds)
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 08/13] ipcs: clean up permissions printing
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (6 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 07/13] ipsc: read semaphore " Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc Sami Kerola
` (6 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Remove old function, and make the new have same name as the old had.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 33 ++++-----------------------------
1 file changed, 4 insertions(+), 29 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 373e85e..960039e 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -691,32 +691,7 @@ int main (int argc, char **argv)
return EXIT_SUCCESS;
}
-static void print_perms (int id, struct ipc_perm *ipcp)
-{
- struct passwd *pw;
- struct group *gr;
-
- printf ("%-10d %-10o", id, ipcp->mode & 0777);
-
- if ((pw = getpwuid(ipcp->cuid)))
- printf(" %-10s", pw->pw_name);
- else
- printf(" %-10u", ipcp->cuid);
- if ((gr = getgrgid(ipcp->cgid)))
- printf(" %-10s", gr->gr_name);
- else
- printf(" %-10u", ipcp->cgid);
-
- if ((pw = getpwuid(ipcp->uid)))
- printf(" %-10s", pw->pw_name);
- else
- printf(" %-10u", ipcp->uid);
- if ((gr = getgrgid(ipcp->gid)))
- printf(" %-10s\n", gr->gr_name);
- else
- printf(" %-10u\n", ipcp->gid);
-}
-static void FIXED_print_perms(struct ipc_stat *is)
+static void print_perms(struct ipc_stat *is)
{
struct passwd *pw;
struct group *gr;
@@ -836,7 +811,7 @@ static void do_shm (char format, int use_proc)
for (shmdsp = shmds; shmdsp->next != NULL; shmdsp = shmdsp->next) {
if (format == CREATOR) {
- FIXED_print_perms (&(shmdsp->shm_perm));
+ print_perms (&(shmdsp->shm_perm));
continue;
}
pw = getpwuid(shmdsp->shm_perm.uid);
@@ -953,7 +928,7 @@ static void do_sem (char format, int use_proc)
for (semdsp = semds; semdsp->next != NULL; semdsp = semdsp->next) {
if (format == CREATOR) {
- FIXED_print_perms (&(semdsp->sem_perm));
+ print_perms (&(semdsp->sem_perm));
continue;
}
pw = getpwuid(semdsp->sem_perm.uid);
@@ -1059,7 +1034,7 @@ static void do_msg (char format, int use_proc)
for (msgdsp = msgds; msgdsp->next != NULL; msgdsp = msgdsp->next) {
if (format == CREATOR) {
- FIXED_print_perms (&(msgdsp->msg_perm));
+ print_perms (&(msgdsp->msg_perm));
continue;
}
pw = getpwuid(msgdsp->msg_perm.uid);
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (7 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 08/13] ipcs: clean up permissions printing Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-11-05 16:53 ` Karel Zak
2012-10-14 20:22 ` [PATCH 10/13] ipcs: make individual message queue " Sami Kerola
` (5 subsequent siblings)
14 siblings, 1 reply; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
And reindent the print_shm() function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 49 ++++++++++++++++++++++++++++---------------------
1 file changed, 28 insertions(+), 21 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 960039e..cd3d14d 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -308,6 +308,10 @@ static int shmctl_info_wrapper(int maxid, int id, struct shm_data **shmds,
&(shmdsp->shm_rss),
&(shmdsp->shm_swp)
);
+ if (-1 < id && id != shmdsp->shm_perm.id) {
+ i--;
+ continue;
+ }
if (id < 0) {
shmdsp->next = xmalloc(sizeof(struct shm_data));
shmdsp = shmdsp->next;
@@ -557,7 +561,7 @@ static int test_ipc_proc_paths(void)
static void do_shm (char format, int use_proc);
static void do_sem (char format, int use_proc);
static void do_msg (char format, int use_proc);
-void print_shm (int id);
+static void print_shm (int id, int use_proc);
void print_msg (int id);
void print_sem (int id);
@@ -663,7 +667,7 @@ int main (int argc, char **argv)
if (print) {
if (shm)
- print_shm (id);
+ print_shm (id, use_proc);
if (sem)
print_sem (id);
if (msg)
@@ -1075,28 +1079,31 @@ static void do_msg (char format, int use_proc)
return;
}
-void print_shm (int shmid)
+static void print_shm(int shmid, int use_proc)
{
- struct shmid_ds shmds;
- struct ipc_perm *ipcp = &shmds.shm_perm;
+ struct shm_data *shmdata;
- if (shmctl (shmid, IPC_STAT, &shmds) == -1)
- err(EXIT_FAILURE, _("shmctl failed"));
+ if (shmctl_info_wrapper(-1, shmid, &shmdata, use_proc) < 1) {
+ warnx(_("id %d not found"), shmid);
+ return;
+ }
- printf (_("\nShared memory Segment shmid=%d\n"), shmid);
- printf (_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"),
- ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
- printf (_("mode=%#o\taccess_perms=%#o\n"),
- ipcp->mode, ipcp->mode & 0777);
- printf (_("bytes=%lu\tlpid=%d\tcpid=%d\tnattch=%ld\n"),
- (unsigned long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid,
- (long) shmds.shm_nattch);
- printf (_("att_time=%-26.24s\n"),
- shmds.shm_atime ? ctime (&shmds.shm_atime) : _("Not set"));
- printf (_("det_time=%-26.24s\n"),
- shmds.shm_dtime ? ctime (&shmds.shm_dtime) : _("Not set"));
- printf (_("change_time=%-26.24s\n"), ctime (&shmds.shm_ctime));
- printf ("\n");
+ printf(_("\nShared memory Segment shmid=%d\n"), shmid);
+ printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\n"),
+ shmdata->shm_perm.uid, shmdata->shm_perm.uid,
+ shmdata->shm_perm.cuid, shmdata->shm_perm.cgid);
+ printf(_("mode=%#o\taccess_perms=%#o\n"), shmdata->shm_perm.mode,
+ shmdata->shm_perm.mode & 0777);
+ printf(_("bytes=%lu\tlpid=%d\tcpid=%d\tnattch=%ld\n"),
+ shmdata->shm_segsz, shmdata->shm_lprid, shmdata->shm_cprid,
+ shmdata->shm_nattch);
+ printf(_("att_time=%-26.24s\n"),
+ shmdata->shm_atim ? ctime(&(shmdata->shm_atim)) : _("Not set"));
+ printf(_("det_time=%-26.24s\n"),
+ shmdata->shm_dtim ? ctime(&shmdata->shm_dtim) : _("Not set"));
+ printf(_("change_time=%-26.24s\n"), ctime(&shmdata->shm_ctim));
+ printf("\n");
+ free(shmdata);
return;
}
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 10/13] ipcs: make individual message queue id printing to use /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (8 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 11/13] ipcs: make individual semaphore " Sami Kerola
` (4 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
And reindent the print_msg() function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 57 ++++++++++++++++++++++++++++++--------------------------
1 file changed, 31 insertions(+), 26 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index cd3d14d..33759fe 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -403,6 +403,10 @@ static int msgctl_info_wrapper(int maxid, int id, struct msg_data **msgds,
&(msgdsp->q_rtime),
&(msgdsp->q_ctime)
);
+ if (-1 < id && id != msgdsp->msg_perm.id) {
+ i--;
+ continue;
+ }
if (id < 0) {
msgdsp->next = xmalloc(sizeof(struct msg_data));
msgdsp = msgdsp->next;
@@ -562,7 +566,7 @@ static void do_shm (char format, int use_proc);
static void do_sem (char format, int use_proc);
static void do_msg (char format, int use_proc);
static void print_shm (int id, int use_proc);
-void print_msg (int id);
+static void print_msg (int id, int use_proc);
void print_sem (int id);
static void __attribute__ ((__noreturn__)) usage(FILE * out)
@@ -671,7 +675,7 @@ int main (int argc, char **argv)
if (sem)
print_sem (id);
if (msg)
- print_msg (id);
+ print_msg (id, use_proc);
if (!shm && !sem && !msg )
usage (stderr);
} else {
@@ -1107,33 +1111,34 @@ static void print_shm(int shmid, int use_proc)
return;
}
-
-void print_msg (int msqid)
+static void print_msg(int msqid, int use_proc)
{
- struct msqid_ds buf;
- struct ipc_perm *ipcp = &buf.msg_perm;
+ struct msg_data *msgdata;
- if (msgctl (msqid, IPC_STAT, &buf) == -1)
- err(EXIT_FAILURE, _("msgctl failed"));
+ if (msgctl_info_wrapper(-1, msqid, &msgdata, use_proc) < 1) {
+ warnx(_("id %d not found"), msqid);
+ return;
+ }
- printf (_("\nMessage Queue msqid=%d\n"), msqid);
- printf (_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
- ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode);
- printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
- /*
- * glibc-2.1.3 and earlier has unsigned short. glibc-2.1.91
- * has variation between unsigned short, unsigned long.
- * Austin has msgqnum_t (for msg_qbytes)
- */
- (long) buf.msg_cbytes, (long) buf.msg_qbytes,
- (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid);
- printf (_("send_time=%-26.24s\n"),
- buf.msg_stime ? ctime (&buf.msg_stime) : _("Not set"));
- printf (_("rcv_time=%-26.24s\n"),
- buf.msg_rtime ? ctime (&buf.msg_rtime) : _("Not set"));
- printf (_("change_time=%-26.24s\n"),
- buf.msg_ctime ? ctime (&buf.msg_ctime) : _("Not set"));
- printf ("\n");
+ printf(_("\nMessage Queue msqid=%d\n"), msqid);
+ printf(_("uid=%u\tgid=%u\tcuid=%u\tcgid=%u\tmode=%#o\n"),
+ msgdata->msg_perm.uid, msgdata->msg_perm.uid,
+ msgdata->msg_perm.cuid, msgdata->msg_perm.cgid,
+ msgdata->msg_perm.mode & 0777);
+ printf(_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"),
+ /* Old msqid_ds.msg_lqbytes is the same as
+ * msgdata->q_cbytes. See copy_msqid_to_user() from
+ * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=ipc/msg.c */
+ msgdata->q_cbytes, msgdata->q_cbytes,
+ msgdata->q_qnum, msgdata->q_lspid, msgdata->q_lrpid);
+ printf(_("send_time=%-26.24s\n"),
+ msgdata->q_stime ? ctime(&msgdata->q_stime) : _("Not set"));
+ printf(_("rcv_time=%-26.24s\n"),
+ msgdata->q_rtime ? ctime(&msgdata->q_rtime) : _("Not set"));
+ printf(_("change_time=%-26.24s\n"),
+ msgdata->q_ctime ? ctime(&msgdata->q_ctime) : _("Not set"));
+ printf("\n");
+ free(msgdata);
return;
}
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 11/13] ipcs: make individual semaphore id printing to use /proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (9 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 10/13] ipcs: make individual message queue " Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 12/13] ipcs: validate numeric user input Sami Kerola
` (3 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
And reindent the print_sem() function.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/ipcs.c | 67 ++++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 26 deletions(-)
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index 33759fe..a380718 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -495,6 +495,10 @@ static int semctl_info_wrapper(int maxid, int id, struct sem_data **semds,
&(semdsp->sem_otime),
&(semdsp->sem_ctime)
);
+ if (-1 < id && id != semdsp->sem_perm.id) {
+ i--;
+ continue;
+ }
if (id < 0) {
semdsp->next = xmalloc(sizeof(struct sem_data));
semdsp = semdsp->next;
@@ -567,7 +571,7 @@ static void do_sem (char format, int use_proc);
static void do_msg (char format, int use_proc);
static void print_shm (int id, int use_proc);
static void print_msg (int id, int use_proc);
-void print_sem (int id);
+static void print_sem (int id, int use_proc);
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
@@ -673,7 +677,7 @@ int main (int argc, char **argv)
if (shm)
print_shm (id, use_proc);
if (sem)
- print_sem (id);
+ print_sem (id, use_proc);
if (msg)
print_msg (id, use_proc);
if (!shm && !sem && !msg )
@@ -1142,42 +1146,53 @@ static void print_msg(int msqid, int use_proc)
return;
}
-void print_sem (int semid)
+static void print_sem(int semid, int use_proc)
{
struct semid_ds semds;
- struct ipc_perm *ipcp = &semds.sem_perm;
union semun arg;
+ struct sem_data *semdata;
size_t i;
+ if (semctl_info_wrapper(-1, semid, &semdata, use_proc) < 1) {
+ warnx(_("id %d not found"), semid);
+ return;
+ }
+
+ printf(_("\nSemaphore Array semid=%d\n"), semid);
+ printf(_("uid=%u\t gid=%u\t cuid=%u\t cgid=%u\n"),
+ semdata->sem_perm.uid, semdata->sem_perm.uid,
+ semdata->sem_perm.cuid, semdata->sem_perm.cgid);
+ printf(_("mode=%#o, access_perms=%#o\n"),
+ semdata->sem_perm.mode, semdata->sem_perm.mode & 0777);
+ printf(_("nsems = %ld\n"), semdata->sem_nsems);
+ printf(_("otime = %-26.24s\n"),
+ semdata->sem_otime ? ctime(&semdata->sem_otime) : _("Not set"));
+ printf(_("ctime = %-26.24s\n"), ctime(&semdata->sem_ctime));
+
+ printf("%-10s %-10s %-10s %-10s %-10s\n",
+ _("semnum"), _("value"), _("ncount"), _("zcount"), _("pid"));
+
+ /* FIXME (in future): The following are missing from proc. A
+ * kernel change is needed, which will add to
+ * /proc/sysvipc/sem the four data items semctl() is used below.
+ * Meanwhile ipcs has to this old fashioned way. */
arg.buf = &semds;
- if (semctl (semid, 0, IPC_STAT, arg) < 0)
+ if (semctl(semid, 0, IPC_STAT, arg) < 0)
err(EXIT_FAILURE, _("semctl failed"));
-
- printf (_("\nSemaphore Array semid=%d\n"), semid);
- printf (_("uid=%u\t gid=%u\t cuid=%u\t cgid=%u\n"),
- ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid);
- printf (_("mode=%#o, access_perms=%#o\n"),
- ipcp->mode, ipcp->mode & 0777);
- printf (_("nsems = %ld\n"), (long) semds.sem_nsems);
- printf (_("otime = %-26.24s\n"),
- semds.sem_otime ? ctime (&semds.sem_otime) : _("Not set"));
- printf (_("ctime = %-26.24s\n"), ctime (&semds.sem_ctime));
-
- printf ("%-10s %-10s %-10s %-10s %-10s\n",
- _("semnum"),_("value"),_("ncount"),_("zcount"),_("pid"));
arg.val = 0;
- for (i=0; i< semds.sem_nsems; i++) {
+ for (i = 0; i < semds.sem_nsems; i++) {
int val, ncnt, zcnt, pid;
- val = semctl (semid, i, GETVAL, arg);
- ncnt = semctl (semid, i, GETNCNT, arg);
- zcnt = semctl (semid, i, GETZCNT, arg);
- pid = semctl (semid, i, GETPID, arg);
+ val = semctl(semid, i, GETVAL, arg);
+ ncnt = semctl(semid, i, GETNCNT, arg);
+ zcnt = semctl(semid, i, GETZCNT, arg);
+ pid = semctl(semid, i, GETPID, arg);
if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0)
err(EXIT_FAILURE, _("semctl failed"));
- printf ("%-10zd %-10d %-10d %-10d %-10d\n",
- i, val, ncnt, zcnt, pid);
+ printf("%-10zd %-10d %-10d %-10d %-10d\n",
+ i, val, ncnt, zcnt, pid);
}
- printf ("\n");
+ printf("\n");
+ free(semdata);
return;
}
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 12/13] ipcs: validate numeric user input
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (10 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 11/13] ipcs: make individual semaphore " Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
2012-10-14 20:22 ` [PATCH 13/13] docs: update TODO Sami Kerola
` (2 subsequent siblings)
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
sys-utils/Makemodule.am | 2 +-
sys-utils/ipcs.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index a6e3c07..e20c6fb 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -16,7 +16,7 @@ ipcrm_LDADD = $(LDADD) libcommon.la
usrbin_exec_PROGRAMS += ipcs
dist_man_MANS += sys-utils/ipcs.1
-ipcs_SOURCES = sys-utils/ipcs.c
+ipcs_SOURCES = sys-utils/ipcs.c lib/strutils.c
usrbin_exec_PROGRAMS += renice
dist_man_MANS += sys-utils/renice.1
diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
index a380718..b5fcd17 100644
--- a/sys-utils/ipcs.c
+++ b/sys-utils/ipcs.c
@@ -35,6 +35,7 @@
#include "nls.h"
#include "closestream.h"
#include "pathnames.h"
+#include "strutils.h"
#include "xalloc.h"
/*
@@ -629,7 +630,7 @@ int main (int argc, char **argv)
while ((opt = getopt_long(argc, argv, options, longopts, NULL)) != -1) {
switch (opt) {
case 'i':
- id = atoi (optarg);
+ id = strtos32_or_err(optarg, _("failed to parse argument"));
print = 1;
break;
case 'a':
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* [PATCH 13/13] docs: update TODO
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (11 preceding siblings ...)
2012-10-14 20:22 ` [PATCH 12/13] ipcs: validate numeric user input Sami Kerola
@ 2012-10-14 20:22 ` Sami Kerola
[not found] ` <20121015153924.GL18377@x2.net.home>
2012-11-05 16:42 ` Karel Zak
14 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-14 20:22 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
Documentation/TODO | 4 ----
1 file changed, 4 deletions(-)
diff --git a/Documentation/TODO b/Documentation/TODO
index a646127..4735a27 100644
--- a/Documentation/TODO
+++ b/Documentation/TODO
@@ -182,10 +182,6 @@ misc
- add mllockall() and SCHED_FIFO to hwclock,
see http://lkml.org/lkml/2008/10/12/132
-
- - (!) rewrite ipcs to use /proc/sys/kernel rather than unreliable syscalls
- (there are problems with 32bit userspace on 64bit kernel)
-
---------------
exotic requests
--
1.7.12.3
^ permalink raw reply related [flat|nested] 24+ messages in thread
* Re: [PATCH 03/13] ipcs: determine ipc limits from /proc
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
@ 2012-10-15 2:00 ` Mike Frysinger
2012-11-05 16:49 ` Karel Zak
1 sibling, 0 replies; 24+ messages in thread
From: Mike Frysinger @ 2012-10-15 2:00 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
[-- Attachment #1: Type: Text/Plain, Size: 665 bytes --]
On Sunday 14 October 2012 16:22:15 Sami Kerola wrote:
> + fscanf(f, "%d", &(lim->msgmni));
no need for the paren around lim->msgmni. same thing applies many times in
this patch.
> + if ((msgctl(0, IPC_INFO, (struct msqid_ds *)(void *)&msginfo)) < 0)
the paren around msgctl doesn't make sense. seems like you do this multiple
times in this patch and none of them make sense.
> + lim->msgmni = (int)msginfo.msgmni;
> + lim->msgmnb = (int)msginfo.msgmnb;
these casts don't make sense. they're both ints.
> + lim->msgmax = (size_t)msginfo.msgmax;
msgmax is an int, so it seems like blindly casting to size_t isn't a good
idea.
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 05/13] ipcs: read shared memory values from /proc
2012-10-14 20:22 ` [PATCH 05/13] ipcs: read shared memory values from /proc Sami Kerola
@ 2012-10-15 2:07 ` Mike Frysinger
0 siblings, 0 replies; 24+ messages in thread
From: Mike Frysinger @ 2012-10-15 2:07 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
[-- Attachment #1: Type: Text/Plain, Size: 1886 bytes --]
On Sunday 14 October 2012 16:22:17 Sami Kerola wrote:
> +static int shmctl_info_wrapper(int maxid, int id, struct shm_data **shmds,
> + int use_proc)
> +{
> + char skipheader[1024];
> + int i, shmid;
> + struct shm_data *shmdsp;
> +
> + struct shmid_ds shmseg;
> + struct ipc_perm *ipcp = &shmseg.shm_perm;
> +
> + *shmds = xmalloc(sizeof(struct shm_data));
> + shmdsp = *shmds;
could just one line:
shmdsp = *shmds = xmalloc(sizeof(struct shm_data));
> + shmdsp->next = NULL;
> + if (use_proc) {
> + FILE *f;
> + if ((f = fopen(_PATH_PROC_IPCSHM, "r")) == NULL)
> + return -1;
doesn't this leak memory with shmds ?
> + fgets(skipheader, 1024, f);
why not just fseek() ? does that not work on the /proc path ?
> + for (i = 0; !feof(f); i++) {
> + fscanf(f,
> + "%10d %10d %4o " SIZE_SPEC
> + " %5lu %5lu %5lu %5u %5u %5u %5u %10lu %10lu %10lu "
> + SIZE_SPEC " " SIZE_SPEC "\n",
> + &(shmdsp->shm_perm.key),
> + &(shmdsp->shm_perm.id),
> + &(shmdsp->shm_perm.mode),
> + &(shmdsp->shm_segsz),
> + &(shmdsp->shm_cprid),
> + &(shmdsp->shm_lprid),
> + &(shmdsp->shm_nattch),
> + &(shmdsp->shm_perm.uid),
> + &(shmdsp->shm_perm.gid),
> + &(shmdsp->shm_perm.cuid),
> + &(shmdsp->shm_perm.cgid),
> + &(shmdsp->shm_atim),
> + &(shmdsp->shm_dtim),
> + &(shmdsp->shm_ctim),
> + &(shmdsp->shm_rss),
> + &(shmdsp->shm_swp)
> + );
shouldn't this check the return of fscanf() ?
> -void do_shm (char format, int use_proc)
> +static void freeshms(struct shm_data *shmds)
> {
> - int maxid, shmid, id;
> - struct shmid_ds shmseg;
> + while (shmds) {
> + struct shm_data *next = shmds->next;
> + free(shmds);
> + shmds = next;
> + }
> + return;
> +}
pointless return statement -> delete
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 00/13] make ipcs to use proc
[not found] ` <20121015153924.GL18377@x2.net.home>
@ 2012-10-22 20:23 ` Sami Kerola
0 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-10-22 20:23 UTC (permalink / raw)
To: Karel Zak, Mike Frysinger; +Cc: util-linux
Hi Mike, Karel, and others.
Here comes ipcs & /proc try II. Some of the proposed change got to be
done, others not. Detailed comments are after the pull request.
The following changes since commit
0b3e1d9baef8dd7ed121c68a1a480d903fb0ad06:
fdisk: gpt: use swap_efi_guid for new partitions (2012-10-18 12:16:06
+0200)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git ipcs
for you to fetch changes up to 528f67d3b5eb23445a2e8dfe4476dfd1b2eda75b:
docs: update TODO (2012-10-22 20:43:03 +0100)
----------------------------------------------------------------
Sami Kerola (14):
ipcs: add data structures to read state from /proc & /sys
ipcs: add /proc and /sys path definitions
lib/path: add path_getnum_zu() function
ipcs: determine ipc limits from /proc
ipcs: add new permissions printing function
ipcs: read shared memory values from /proc
ipcs: read message queue values from /proc
ipsc: read semaphore values from /proc
ipcs: clean up permissions printing
ipcs: make individual shared memory id printing to use /proc
ipcs: make individual message queue id printing to use /proc
ipcs: make individual semaphore id printing to use /proc
ipcs: validate numeric user input
docs: update TODO
Documentation/TODO | 4 -
configure.ac | 1 +
include/path.h | 3 +
include/pathnames.h | 11 +
lib/path.c | 21 ++
sys-utils/Makemodule.am | 2 +-
sys-utils/ipcs.c | 871
++++++++++++++++++++++++++++++++++++------------
7 files changed, 698 insertions(+), 215 deletions(-)
On Mon, Oct 15, 2012 at 3:00 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Sunday 14 October 2012 16:22:15 Sami Kerola wrote:
>> + fscanf(f, "%d", &(lim->msgmni));
>
> no need for the paren around lim->msgmni. same thing applies many
> times in this patch.
Unnecessary parentheses are removed from lots of place.
>> + if ((msgctl(0, IPC_INFO, (struct msqid_ds *)(void *)&msginfo)) < 0)
>
> the paren around msgctl doesn't make sense. seems like you do this
> multiple times in this patch and none of them make sense.
Also removed.
>> + lim->msgmni = (int)msginfo.msgmni;
>> + lim->msgmnb = (int)msginfo.msgmnb;
>
> these casts don't make sense. they're both ints.
A lot of casts are removed, including non-sense ones you pointed out.
>> + lim->msgmax = (size_t)msginfo.msgmax;
>
> msgmax is an int, so it seems like blindly casting to size_t isn't a
> good idea.
I think I got all casts removed.
On Mon, Oct 15, 2012 at 3:07 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Sunday 14 October 2012 16:22:17 Sami Kerola wrote:
>> +static int shmctl_info_wrapper(int maxid, int id, struct shm_data
>> **shmds,
>> + int use_proc)
>> +{
>> + char skipheader[1024];
>> + int i, shmid;
>> + struct shm_data *shmdsp;
>> +
>> + struct shmid_ds shmseg;
>> + struct ipc_perm *ipcp = &shmseg.shm_perm;
>> +
>> + *shmds = xmalloc(sizeof(struct shm_data));
>> + shmdsp = *shmds;
>
> could just one line:
> shmdsp = *shmds = xmalloc(sizeof(struct shm_data));
True, and done that way.
>> + shmdsp->next = NULL;
>> + if (use_proc) {
>> + FILE *f;
>> + if ((f = fopen(_PATH_PROC_IPCSHM, "r")) == NULL)
>> + return -1;
>
> doesn't this leak memory with shmds ?
Ooops. Yes, it does. Fixed.
>> + fgets(skipheader, 1024, f);
>
> why not just fseek() ? does that not work on the /proc path ?
Maybe searching for first new line suitable alternative.
while (fgetc(f) != '\n')
/* skip header */ ;
>> + for (i = 0; !feof(f); i++) {
>> + fscanf(f,
>> + "%10d %10d %4o " SIZE_SPEC
>> + " %5lu %5lu %5lu %5u %5u %5u %5u %10lu %10lu %10lu "
>> + SIZE_SPEC " " SIZE_SPEC "\n",
>> + &(shmdsp->shm_perm.key),
>> + &(shmdsp->shm_perm.id),
>> + &(shmdsp->shm_perm.mode),
>> + &(shmdsp->shm_segsz),
>> + &(shmdsp->shm_cprid),
>> + &(shmdsp->shm_lprid),
>> + &(shmdsp->shm_nattch),
>> + &(shmdsp->shm_perm.uid),
>> + &(shmdsp->shm_perm.gid),
>> + &(shmdsp->shm_perm.cuid),
>> + &(shmdsp->shm_perm.cgid),
>> + &(shmdsp->shm_atim),
>> + &(shmdsp->shm_dtim),
>> + &(shmdsp->shm_ctim),
>> + &(shmdsp->shm_rss),
>> + &(shmdsp->shm_swp)
>> + );
>
> shouldn't this check the return of fscanf() ?
Yes, that should. Fixed.
>> -void do_shm (char format, int use_proc)
>> +static void freeshms(struct shm_data *shmds)
>> {
>> - int maxid, shmid, id;
>> - struct shmid_ds shmseg;
>> + while (shmds) {
>> + struct shm_data *next = shmds->next;
>> + free(shmds);
>> + shmds = next;
>> + }
>> + return;
>> +}
>
> pointless return statement -> delete
Deleted.
On Mon, Oct 15, 2012 at 6:38 PM, Mike Frysinger <vapier@gentoo.org>
wrote:
> On Sunday 14 October 2012 16:22:25 Sami Kerola wrote:
>> - - (!) rewrite ipcs to use /proc/sys/kernel rather than unreliable syscalls
>> - (there are problems with 32bit userspace on 64bit kernel)
>
> this makes me a bit suspicious since the new code turns around and uses
> size_t to read values. that says to me that the same problems that
> [allegedly] plague the kernel syscall interface will bite your proc
> reading code.
>
> looking at the most common case (which will directly apply to all the
> others):
> - 32bit ia32 kernel: sizeof(size_t) == 4
> - 64bit x86_64 kernel: sizeof(size_t) == 8
> - 64bit x86_64 userland: sizeof(size_t) == 8
> - 32bit ia32 userland: sizeof(size_t) == 4
> - 32bit x86_x32 userland: sizeof(size_t) == 4
>
> so running any of the last two setups could (in theory) be problematic
> because this new code still uses size_t.
Oh, so that what the rather brief TODO item meant. I think I need to go
and do my 32/64 bit homework before attempting to fix this.
On Mon, Oct 15, 2012 at 4:39 PM, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Oct 14, 2012 at 09:22:12PM +0100, Sami Kerola wrote:
>> Couple weeks ago I decided to do the ipcs todo item, and today patches
>> got to be ready enough so that I could make final polishing and send
>> them for review.
>
> What about to use lib/path.c? (you can add things like fscan()
> there..).
>
> These functions allow to redirect open() requests to some
> alternative place (for example /proc/foo to /mytests/proc/foo) so you
> can add --sysroot command line option and write nice regression tests
> :-) See lscpu for more details.
Good idea. I made the ipcs to use path.h, and found out it was not
perfectly clean. Unless someone else is quicker I will someday pull the
cpu related stuff further away from functions meant to be used with proc.
>> As the change is quite large I assume there has to be few bugs. None
>> of the where intentional, so having multiple people testing is
>> preferable.
>
> We can create a nice collection of /proc dumps from many archs (see
> tests/ts/lscpu/mk-input.sh). If you prepare a script for IPC stuff
> then I can create some dumps in our labs.
The ipcs has annoying tendency to print usernames in nearly all outputs
(other than limits & summary). If I am not wrong that will make
relocated /proc not have stable output. But that does not have to be end
of the story. The ipcs could use tt.c, and many of the problems will
vanish, especially if '-n numeric uids' option is added.
I have a hunch this is not the last set of patches to ipcs before next
release.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 00/13] make ipcs to use proc
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
` (13 preceding siblings ...)
[not found] ` <20121015153924.GL18377@x2.net.home>
@ 2012-11-05 16:42 ` Karel Zak
2012-11-07 9:40 ` Sami Kerola
14 siblings, 1 reply; 24+ messages in thread
From: Karel Zak @ 2012-11-05 16:42 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Oct 14, 2012 at 09:22:12PM +0100, Sami Kerola wrote:
> Sami Kerola (13):
I have created ipc branch at hithub and applied some of the patches
(unfortunately with many changes).
Unfortunately I have no more time to play with this stuff this week,
but I guess that it's pretty obvious from already applied patches how
should be implemented the rest.
Changes:
- created sys-utils/ipcutils.{c,h}
- renamed functions
- replaced all 'unsigned long' and 'size_t' with uint64_t
The reason why we want to read from /proc is to be robust on
systems where kernel is 64bit and userspace is 32bit. You cannot
use long or size_t for data from /sys or /proc...
> ipcs: add data structures to read state from /proc & /sys
applied
> ipcs: add /proc and /sys path definitions
applied (btw, where was nice typo)
> ipcs: determine ipc limits from /proc
applied
> ipcs: add new permissions printing function
applied
> ipcs: read shared memory values from /proc
applied
> ipcs: read message queue values from /proc
> ipsc: read semaphore values from /proc
> ipcs: clean up permissions printing
not applied
> ipcs: make individual shared memory id printing to use /proc
applied
> ipcs: make individual message queue id printing to use /proc
> ipcs: make individual semaphore id printing to use /proc
> ipcs: validate numeric user input
> docs: update TODO
not applied
... so, all around share memory should be applied/fixed. Now we need
to do the same for sem and msg stuff.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 02/13] ipcs: add /proc and /sys path definitions
2012-10-14 20:22 ` [PATCH 02/13] ipcs: add /proc and /sys path definitions Sami Kerola
@ 2012-11-05 16:43 ` Karel Zak
0 siblings, 0 replies; 24+ messages in thread
From: Karel Zak @ 2012-11-05 16:43 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Oct 14, 2012 at 09:22:14PM +0100, Sami Kerola wrote:
> +#define _PATH_PROC_IPC_MSG "/proc/sys/kernel/sem"
^^^ ^^^^
:-)
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 03/13] ipcs: determine ipc limits from /proc
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
2012-10-15 2:00 ` Mike Frysinger
@ 2012-11-05 16:49 ` Karel Zak
1 sibling, 0 replies; 24+ messages in thread
From: Karel Zak @ 2012-11-05 16:49 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Oct 14, 2012 at 09:22:15PM +0100, Sami Kerola wrote:
> +static int shmctl_limits_wrapper(struct proc_limits *lim, int use_proc)
The basic rule is to call function by functionality, nobody cares if
the function is wrapper ;-)
IMHO for example ipc_shm_get_limits() is better.
> +{
> + struct shminfo shminfo;
> + lim->shmmax = SHMMAX;
really no, shmmax is also in /proc and it maybe changed by sysctl.
> + lim->shmmin = SHMMIN;
> + if (use_proc) {
> + FILE *f;
> + if ((f = fopen(_PATH_PROC_IPC_SHMMNI, "r")) == NULL)
> + return 1;
> + fscanf(f, "%d", &(lim->shmmni));
> + fclose(f);
> + if ((f = fopen(_PATH_PROC_IPC_SHMALL, "r")) == NULL)
> + return 1;
> + fscanf(f, "%zu", &(lim->shmall));
> + fclose(f);
> + return 0;
> + }
> +
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc
2012-10-14 20:22 ` [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc Sami Kerola
@ 2012-11-05 16:53 ` Karel Zak
0 siblings, 0 replies; 24+ messages in thread
From: Karel Zak @ 2012-11-05 16:53 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Oct 14, 2012 at 09:22:21PM +0100, Sami Kerola wrote:
> And reindent the print_shm() function.
>
> Signed-off-by: Sami Kerola <kerolasa@iki.fi>
> ---
> sys-utils/ipcs.c | 49 ++++++++++++++++++++++++++++---------------------
> 1 file changed, 28 insertions(+), 21 deletions(-)
>
> diff --git a/sys-utils/ipcs.c b/sys-utils/ipcs.c
> index 960039e..cd3d14d 100644
> --- a/sys-utils/ipcs.c
> +++ b/sys-utils/ipcs.c
> @@ -308,6 +308,10 @@ static int shmctl_info_wrapper(int maxid, int id, struct shm_data **shmds,
> &(shmdsp->shm_rss),
> &(shmdsp->shm_swp)
> );
> + if (-1 < id && id != shmdsp->shm_perm.id) {
> + i--;
> + continue;
> + }
And what action is expected when id == shmdsp->shm_perm.id ?
What about
if (id == shmdsp->shm_perm.id)
break;
otherwise ipcs -m -i <id> will return another entry.
BTW,
./ipcs <something> &> new
ipcs <something> &> old
diff -u old new
is nice way how found bugs...
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 00/13] make ipcs to use proc
2012-11-05 16:42 ` Karel Zak
@ 2012-11-07 9:40 ` Sami Kerola
2012-11-07 10:01 ` Karel Zak
0 siblings, 1 reply; 24+ messages in thread
From: Sami Kerola @ 2012-11-07 9:40 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On Mon, Nov 5, 2012 at 4:42 PM, Karel Zak <kzak@redhat.com> wrote:
> On Sun, Oct 14, 2012 at 09:22:12PM +0100, Sami Kerola wrote:
>> Sami Kerola (13):
Hi Karel and others,
> I have created ipc branch at hithub and applied some of the patches
> (unfortunately with many changes).
I would not call code review unfortunate, especially when it causes
changes to code that will make it better.
> Unfortunately I have no more time to play with this stuff this week,
Open source is supposed to be fun. Take your time, so will I. Getting
all IPC related fixes done will most likely take several weeks. For
example it really bugs me that semaphore counts cannot be read from
proc. The only way I can think of getting that fixed is change to
kernel side.
One of the ways to solve the problem would be to add fields
to/proc/sysvipc/sem but that would change ABI. Perhaps making msg sem
& shm directories to proc containing subdirectories that are named
after object id is way to go. Much like how processes are represented.
That would make IPC info easy to extend ever needed, and quite
intuitive to use. But before writing that sort of change I think it's
good idea to ask advice from kernel developers. Looking git log[1] it
seems Al Viro might have opinion whether to add field or to do greater
change.
[1] git shortlog --no-merges -sne v3.0..HEAD ipc
> but I guess that it's pretty obvious from already applied patches how
> should be implemented the rest.
I will investigate...
> Changes:
>
> - created sys-utils/ipcutils.{c,h}
> - renamed functions
> - replaced all 'unsigned long' and 'size_t' with uint64_t
>
> The reason why we want to read from /proc is to be robust on
> systems where kernel is 64bit and userspace is 32bit. You cannot
> use long or size_t for data from /sys or /proc...
...and adapt to correct behavior. Thank you for review and examples.
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 00/13] make ipcs to use proc
2012-11-07 9:40 ` Sami Kerola
@ 2012-11-07 10:01 ` Karel Zak
2012-11-11 23:01 ` Sami Kerola
0 siblings, 1 reply; 24+ messages in thread
From: Karel Zak @ 2012-11-07 10:01 UTC (permalink / raw)
To: kerolasa; +Cc: util-linux
On Wed, Nov 07, 2012 at 09:40:16AM +0000, Sami Kerola wrote:
> On Mon, Nov 5, 2012 at 4:42 PM, Karel Zak <kzak@redhat.com> wrote:
> > On Sun, Oct 14, 2012 at 09:22:12PM +0100, Sami Kerola wrote:
> >> Sami Kerola (13):
>
> Hi Karel and others,
>
> > I have created ipc branch at hithub and applied some of the patches
> > (unfortunately with many changes).
>
> I would not call code review unfortunate, especially when it causes
> changes to code that will make it better.
>
> > Unfortunately I have no more time to play with this stuff this week,
>
> Open source is supposed to be fun. Take your time, so will I. Getting
> all IPC related fixes done will most likely take several weeks. For
> example it really bugs me that semaphore counts cannot be read from
> proc. The only way I can think of getting that fixed is change to
> kernel side.
>
> One of the ways to solve the problem would be to add fields
> to/proc/sysvipc/sem but that would change ABI. Perhaps making msg sem
> & shm directories to proc containing subdirectories that are named
> after object id is way to go. Much like how processes are represented.
> That would make IPC info easy to extend ever needed, and quite
> intuitive to use. But before writing that sort of change I think it's
> good idea to ask advice from kernel developers. Looking git log[1] it
> seems Al Viro might have opinion whether to add field or to do greater
> change.
Well, we don't have to real all from /proc. I think it's fine to read
some problematic variables (shm sizes) from /proc to keep it
32/64-bit independent, but the rest we can read by regular
{sem,msg,shm}ctl() syscalls.
I guess you can mix /proc and {sem,msg,shm}ctl() in many cases
(especially if there is no enough information in /proc).
I think many problems has been already fixed by ipc_shm_ wrappers.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 00/13] make ipcs to use proc
2012-11-07 10:01 ` Karel Zak
@ 2012-11-11 23:01 ` Sami Kerola
0 siblings, 0 replies; 24+ messages in thread
From: Sami Kerola @ 2012-11-11 23:01 UTC (permalink / raw)
To: Karel Zak; +Cc: util-linux
On Wed, Nov 7, 2012 at 10:01 AM, Karel Zak <kzak@redhat.com> wrote:
> On Wed, Nov 07, 2012 at 09:40:16AM +0000, Sami Kerola wrote:
>> On Mon, Nov 5, 2012 at 4:42 PM, Karel Zak <kzak@redhat.com> wrote:
>> > I have created ipc branch at hithub and applied some of the patches
>> > (unfortunately with many changes).
Hi Karel, and others,
Yes, I had a look of the changes and there were quite some indeed, but
they made the command much better. Thank you for that.
>> One of the ways to solve the problem would be to add fields
>> to/proc/sysvipc/sem but that would change ABI. Perhaps making msg sem
>> & shm directories to proc containing subdirectories that are named
>> after object id is way to go. Much like how processes are represented.
>> That would make IPC info easy to extend ever needed, and quite
>> intuitive to use. But before writing that sort of change I think it's
>> good idea to ask advice from kernel developers. Looking git log[1] it
>> seems Al Viro might have opinion whether to add field or to do greater
>> change.
>
> Well, we don't have to real all from /proc. I think it's fine to read
> some problematic variables (shm sizes) from /proc to keep it
> 32/64-bit independent, but the rest we can read by regular
> {sem,msg,shm}ctl() syscalls.
>
> I guess you can mix /proc and {sem,msg,shm}ctl() in many cases
> (especially if there is no enough information in /proc).
While modernizing the rest of the functions I noticed message queues
are also missing single value in proc. See the second last print_msg
for details. I think /proc could be more complete. Let see what kernel
maintainers think.
> I think many problems has been already fixed by ipc_shm_ wrappers.
As usual you are right. The last remaining issue I want to fix in ipcs
is return values. Some of the functions fail, and return void, while
they should tell user as command return value that things did not go
brilliantly. Meanwhile here is the latest.
The following changes since commit c13d60b291cfe3e2c094225195d967c9f195ca54:
agetty: fix autodetection for TERM (2012-11-02 12:38:25 +0100)
are available in the git repository at:
git://github.com/kerolasa/lelux-utiliteetit.git ipc
for you to fetch changes up to e8bc655429c1c0642b1956cf796b424af6e3043e:
ipcs: remove print_perms() (2012-11-11 22:41:24 +0000)
----------------------------------------------------------------
Karel Zak (5):
libblkid: keep header buffer unmodified after failed CRC check.
lib/path: rename functions to be more explicit
lib/path: add path_read_u64()
ipcs: clean up do_shm()
ipcs: fix ipc_shm_get_info(), use calloc
Sami Kerola (9):
ipcs: add /proc and /sys path definitions
ipcs: determine ipc limits from /proc
ipcs: read shared memory values from /proc
ipcs: make individual shared memory id printing to use /proc
ipcs: clean up do_sem(), and add ipc_sem_get_info()
ipcs: make individual semaphore id printing to use /proc
ipcs: clean up do_msg(), and add ipc_msg_get_info()
ipcs: make individual message queue id printing to use /proc
ipcs: remove print_perms()
include/path.h | 18 +-
include/pathnames.h | 12 +
lib/path.c | 40 ++-
libblkid/src/partitions/gpt.c | 8 +-
sys-utils/Makemodule.am | 6 +-
sys-utils/chcpu.c | 22 +-
sys-utils/ipcs.c | 577 ++++++++++++++++++------------------------
sys-utils/ipcutils.c | 466 ++++++++++++++++++++++++++++++++++
sys-utils/ipcutils.h | 170 +++++++++++++
sys-utils/lscpu.c | 30 +--
10 files changed, 972 insertions(+), 377 deletions(-)
create mode 100644 sys-utils/ipcutils.c
create mode 100644 sys-utils/ipcutils.h
--
Sami Kerola
http://www.iki.fi/kerolasa/
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2012-11-11 23:01 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-14 20:22 [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-10-14 20:22 ` [PATCH 01/13] ipcs: add data structures to read state from /proc & /sys Sami Kerola
2012-10-14 20:22 ` [PATCH 02/13] ipcs: add /proc and /sys path definitions Sami Kerola
2012-11-05 16:43 ` Karel Zak
2012-10-14 20:22 ` [PATCH 03/13] ipcs: determine ipc limits from /proc Sami Kerola
2012-10-15 2:00 ` Mike Frysinger
2012-11-05 16:49 ` Karel Zak
2012-10-14 20:22 ` [PATCH 04/13] ipcs: add new permissions printing function Sami Kerola
2012-10-14 20:22 ` [PATCH 05/13] ipcs: read shared memory values from /proc Sami Kerola
2012-10-15 2:07 ` Mike Frysinger
2012-10-14 20:22 ` [PATCH 06/13] ipcs: read message queue " Sami Kerola
2012-10-14 20:22 ` [PATCH 07/13] ipsc: read semaphore " Sami Kerola
2012-10-14 20:22 ` [PATCH 08/13] ipcs: clean up permissions printing Sami Kerola
2012-10-14 20:22 ` [PATCH 09/13] ipcs: make individual shared memory id printing to use /proc Sami Kerola
2012-11-05 16:53 ` Karel Zak
2012-10-14 20:22 ` [PATCH 10/13] ipcs: make individual message queue " Sami Kerola
2012-10-14 20:22 ` [PATCH 11/13] ipcs: make individual semaphore " Sami Kerola
2012-10-14 20:22 ` [PATCH 12/13] ipcs: validate numeric user input Sami Kerola
2012-10-14 20:22 ` [PATCH 13/13] docs: update TODO Sami Kerola
[not found] ` <20121015153924.GL18377@x2.net.home>
2012-10-22 20:23 ` [PATCH 00/13] make ipcs to use proc Sami Kerola
2012-11-05 16:42 ` Karel Zak
2012-11-07 9:40 ` Sami Kerola
2012-11-07 10:01 ` Karel Zak
2012-11-11 23:01 ` Sami Kerola
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).